MCPcopy Create free account
hub / github.com/apache/brpc / selectBucket

Method selectBucket

src/brpc/couchbase.cpp:2282–2350  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2280}
2281
2282CouchbaseOperations::Result CouchbaseOperations::selectBucket(
2283 const std::string& bucket_name) {
2284 CouchbaseRequest request(&local_bucket_to_collection_manifest_);
2285 CouchbaseResponse response;
2286 brpc::Controller cntl;
2287 CouchbaseOperations::Result result;
2288 if (request.selectBucketRequest(bucket_name.c_str()) == false) {
2289 DEBUG_PRINT(
2290 "Failed to create Select Bucket request for bucket: " << bucket_name);
2291 result.success = false;
2292 result.value = "";
2293 return result;
2294 }
2295 channel_->CallMethod(NULL, &cntl, &request, &response, NULL);
2296 if (cntl.Failed()) {
2297 DEBUG_PRINT("Failed to select bucket: "
2298 << bucket_name << " from Couchbase: " << cntl.ErrorText());
2299 result.success = false;
2300 result.value = "";
2301 result.error_message = cntl.ErrorText();
2302 return result;
2303 }
2304 if (response.popSelectBucket(NULL) == false) {
2305 result.success = false;
2306 result.value = "";
2307 result.error_message = response.lastError();
2308 result.status_code = response._status_code;
2309 return result;
2310 }
2311 // Successfully selected the bucket
2312 selected_bucket_ = bucket_name;
2313 result.success = true;
2314 result.value = "";
2315 result.status_code = 0;
2316
2317 // fetch the collection manifest for this bucket and store it in local cache
2318 if (request.local_collection_manifest_cache->find(bucket_name) ==
2319 request.local_collection_manifest_cache->end()) {
2320 // only fetch if not already present in the local cache
2321 CouchbaseManifestManager::CollectionManifest manifest;
2322 if (!common_metadata_tracking.getBucketToCollectionManifest(
2323 server_address_, bucket_name, &manifest)) {
2324 DEBUG_PRINT("Collection manifest for bucket: "
2325 << bucket_name
2326 << " not found in global cache, the local cache");
2327
2328 // manifest for this bucket/server is not cached yet, will fetch it from
2329 // server now. refresh will also update the local cache with the fetched
2330 // manifest
2331 request.metadata_tracking->refreshCollectionManifest(
2332 channel_, server_address_, bucket_name,
2333 request.local_collection_manifest_cache);
2334 // We simply try once to prefetch the manifest, before any collection
2335 // operation. If it fails, it will be lazily updated when a collection
2336 // operation is performed.
2337 } else {
2338 // update the local cache with the cache manifest from global
2339 // cache(common_metadata_tracking)

Callers 1

mainFunction · 0.80

Calls 10

selectBucketRequestMethod · 0.80
ErrorTextMethod · 0.80
popSelectBucketMethod · 0.80
c_strMethod · 0.45
CallMethodMethod · 0.45
FailedMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected