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

Method getCachedOrFetchCollectionId

src/brpc/couchbase.cpp:819–890  ·  view source on GitHub ↗

collectionID fetching either from the metadata cache or if doesn't exist then fetch from the server.

Source from the content-addressed store, hash-verified

817// collectionID fetching either from the metadata cache or if doesn't exist then
818// fetch from the server.
819bool CouchbaseOperations::CouchbaseRequest::getCachedOrFetchCollectionId(
820 std::string collection_name, uint8_t* coll_id,
821 brpc::CouchbaseManifestManager* metadata_tracking, brpc::Channel* channel,
822 const std::string& server, const std::string& selected_bucket,
823 std:: unordered_map<std::string, CouchbaseManifestManager::CollectionManifest>*
824 local_cache) {
825 if (collection_name.empty()) {
826 DEBUG_PRINT("Empty collection name");
827 return false;
828 }
829 if (channel == nullptr) {
830 DEBUG_PRINT("No channel found, make sure to call Authenticate() first");
831 return false;
832 }
833 if (server.empty()) {
834 DEBUG_PRINT("Server is empty, make sure to call Authenticate() first");
835 return false;
836 }
837 if (selected_bucket.empty()) {
838 DEBUG_PRINT("No bucket selected, make sure to call SelectBucket() first");
839 return false;
840 }
841
842 brpc::CouchbaseManifestManager::CollectionManifest manifest;
843 // check if the server/bucket exists in the cached collection manifest
844 if (!metadata_tracking->getBucketToCollectionManifest(server, selected_bucket,
845 &manifest)) {
846 DEBUG_PRINT("No cached collection manifest found for bucket "
847 << selected_bucket << " on server " << server
848 << ", fetching from server");
849 // No cached manifest found, fetch from server
850 if (!metadata_tracking->refreshCollectionManifest(
851 channel, server, selected_bucket, local_cache)) {
852 return false;
853 }
854 // local cache will also be updated in refreshCollectionManifest
855 // get the reference to collectionID from local cache
856 if (!getLocalCachedCollectionId(selected_bucket, "_default",
857 collection_name, coll_id)) {
858 // collectionID not found in the latest manifest fetched from server
859 return false;
860 }
861 // collectionID has been found in the latest manifest fetched from server
862 // and is stored in coll_id
863 return true;
864 } else {
865 // check if collection name to id mapping exists.
866 if (!metadata_tracking->getManifestToCollectionId(
867 &manifest, "_default", collection_name, coll_id)) {
868 // Just to verify that the collectionID does not exist in the manifest
869 // refresh manifest from server and try again
870 if (!metadata_tracking->refreshCollectionManifest(
871 channel, server, selected_bucket, local_cache)) {
872 return false;
873 }
874 // local cache will also be updated in refreshCollectionManifest
875 // get the reference to collectionID from local cache
876 if (!getLocalCachedCollectionId(selected_bucket, "_default",

Callers

nothing calls this directly

Calls 4

emptyMethod · 0.45

Tested by

no test coverage detected