diff --git a/src/buffer_pool.cc b/src/buffer_pool.cc index b75687467..a913fe353 100644 --- a/src/buffer_pool.cc +++ b/src/buffer_pool.cc @@ -1670,7 +1670,8 @@ api::Status PlaceBlob(SharedMemoryContext *context, RpcContext *rpc, HERMES_END_TIMED_BLOCK(); // NOTE(chogan): Update all metadata associated with this Put - AttachBlobToBucket(context, rpc, name.c_str(), bucket_id, buffer_ids); + AttachBlobToBucket(context, rpc, name.c_str(), bucket_id, buffer_ids, + false, called_from_buffer_organizer); } else { if (called_from_buffer_organizer) { result = PLACE_SWAP_BLOB_TO_BUF_FAILED; diff --git a/src/metadata_management.cc b/src/metadata_management.cc index 5c2bb5b51..58f3754a8 100644 --- a/src/metadata_management.cc +++ b/src/metadata_management.cc @@ -619,12 +619,28 @@ BufferIdArray GetBufferIdsFromBlobId(Arena *arena, void AttachBlobToBucket(SharedMemoryContext *context, RpcContext *rpc, const char *blob_name, BucketID bucket_id, const std::vector &buffer_ids, - bool is_swap_blob) { + bool is_swap_blob, bool called_from_buffer_organizer) { MetadataManager *mdm = GetMetadataManagerFromContext(context); std::string internal_name = MakeInternalBlobName(blob_name, bucket_id); int target_node = HashString(mdm, rpc, internal_name.c_str()); + BlobID blob_id = {}; + if (called_from_buffer_organizer) { + blob_id = GetBlobId(context, rpc, blob_name, bucket_id); + + if (!IsNullBlobId(blob_id)) { + // Remove old BlobID from the bucket's list of Blobs + RemoveBlobFromBucketInfo(context, rpc, bucket_id, blob_id); + + // Release the IDs that represented the SwapBlob info + FreeBufferIdList(context, rpc, blob_id); + } else { + LOG(WARNING) << "Expected to find BlobID " << blob_id.as_int + << " in Map but didn't." << std::endl; + } + } + // NOTE(chogan): A negative node_id indicates a swap blob blob_id.bits.node_id = is_swap_blob ? -target_node : target_node; blob_id.bits.buffer_ids_offset = AllocateBufferIdList(context, rpc, diff --git a/src/metadata_management.h b/src/metadata_management.h index cd4d38853..5e77cd0e9 100644 --- a/src/metadata_management.h +++ b/src/metadata_management.h @@ -223,7 +223,8 @@ VBucketID GetOrCreateVBucketId(SharedMemoryContext *context, RpcContext *rpc, void AttachBlobToBucket(SharedMemoryContext *context, RpcContext *rpc, const char *blob_name, BucketID bucket_id, const std::vector &buffer_ids, - bool is_swap_blob = false); + bool is_swap_blob = false, + bool called_from_buffer_organizer = false); /** * @@ -343,6 +344,12 @@ void AttachBlobToVBucket(SharedMemoryContext *context, RpcContext *rpc, const char *blob_name, const char *bucket_name, VBucketID vbucket_id); +/** + * + */ +void RemoveBlobFromBucketInfo(SharedMemoryContext *context, RpcContext *rpc, + BucketID bucket_id, BlobID blob_id); + /** * */