| 237 | } |
| 238 | |
| 239 | bool CouchbaseManifestManager::refreshCollectionManifest( |
| 240 | brpc::Channel* channel, const std::string& server, const std::string& bucket, |
| 241 | std:: unordered_map<std::string, CollectionManifest>* |
| 242 | local_collection_manifest_cache) { |
| 243 | // first fetch the manifest |
| 244 | // then compare the UID with the cached one |
| 245 | if (channel == nullptr) { |
| 246 | DEBUG_PRINT("No channel found, make sure to call Authenticate() first"); |
| 247 | return false; |
| 248 | } |
| 249 | if (server.empty()) { |
| 250 | DEBUG_PRINT("Server is empty, make sure to call Authenticate() first"); |
| 251 | return false; |
| 252 | } |
| 253 | if (bucket.empty()) { |
| 254 | DEBUG_PRINT("No bucket selected, make sure to call SelectBucket() first"); |
| 255 | return false; |
| 256 | } |
| 257 | CouchbaseOperations::CouchbaseRequest temp_get_manifest_request; |
| 258 | CouchbaseOperations::CouchbaseResponse temp_get_manifest_response; |
| 259 | brpc::Controller temp_cntl; |
| 260 | temp_get_manifest_request.getCollectionManifest(); |
| 261 | channel->CallMethod(NULL, &temp_cntl, &temp_get_manifest_request, |
| 262 | &temp_get_manifest_response, NULL); |
| 263 | if (temp_cntl.Failed()) { |
| 264 | DEBUG_PRINT("Failed to get collection manifest: bRPC controller error " |
| 265 | << temp_cntl.ErrorText()); |
| 266 | return false; |
| 267 | } |
| 268 | std::string manifest_json; |
| 269 | if (!temp_get_manifest_response.popManifest(&manifest_json)) { |
| 270 | DEBUG_PRINT("Failed to parse response for refreshing collection Manifest: " |
| 271 | << temp_get_manifest_response.lastError()); |
| 272 | return false; |
| 273 | } |
| 274 | brpc::CouchbaseManifestManager::CollectionManifest manifest; |
| 275 | if (!common_metadata_tracking.jsonToCollectionManifest(manifest_json, |
| 276 | &manifest)) { |
| 277 | DEBUG_PRINT("Failed to parse collection manifest JSON"); |
| 278 | return false; |
| 279 | } |
| 280 | brpc::CouchbaseManifestManager::CollectionManifest cached_manifest; |
| 281 | if (!common_metadata_tracking.getBucketToCollectionManifest( |
| 282 | server, bucket, &cached_manifest)) { |
| 283 | // No cached manifest found, set the new one |
| 284 | if (!common_metadata_tracking.setBucketToCollectionManifest(server, bucket, |
| 285 | manifest)) { |
| 286 | DEBUG_PRINT("Failed to cache collection manifest for bucket " |
| 287 | << bucket << " on server " << server); |
| 288 | return false; |
| 289 | } |
| 290 | DEBUG_PRINT("Cached collection manifest for bucket " |
| 291 | << bucket << " on server " << server); |
| 292 | // also update the local cache |
| 293 | if (local_collection_manifest_cache != nullptr) { |
| 294 | (*local_collection_manifest_cache)[bucket] = manifest; |
| 295 | } |
| 296 | return true; |
no test coverage detected