Skip to content

Commit

Permalink
Multiple BTrees.
Browse files Browse the repository at this point in the history
  • Loading branch information
szmyd committed Sep 2, 2023
1 parent 47ae4c0 commit 1272ed1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/lib/memory/blob_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ BlobManager::Result< blob_id > MemoryHomeObject::_put_blob(ShardInfo const& shar
}
{
auto lg = std::scoped_lock(_index_lock);
auto [_, happened] = _in_memory_index.try_emplace(BlobRoute{shard.id, new_id}, new_blkid);
auto [btree_it, h1] = _in_memory_index.try_emplace(shard.id, btree());
RELEASE_ASSERT(_in_memory_index.end() != btree_it, "Could not create BTree!");
auto [r_it, happened] = btree_it->second.try_emplace(BlobRoute{shard.id, new_id}, new_blkid);
RELEASE_ASSERT(happened, "Generated duplicate BlobRoute!");
}
return new_id;
Expand All @@ -26,7 +28,9 @@ BlobManager::Result< Blob > MemoryHomeObject::_get_blob(ShardInfo const& shard,
{
auto lg = std::shared_lock(_index_lock);
LOGDEBUGMOD(homeobject, "Looking up Blob {} in set of {}", route.blob, _in_memory_disk.size());
if (auto it = _in_memory_index.find(route); _in_memory_index.end() != it) { d_it = it->second; }
if (auto b_it = _in_memory_index.find(shard.id); _in_memory_index.end() != b_it) {
if (auto it = b_it->second.find(route); b_it->second.end() != it) { d_it = it->second; }
}
}
if (_in_memory_disk.cend() == d_it) {
LOGWARNMOD(homeobject, "Blob missing {} during get", route.blob);
Expand All @@ -48,7 +52,9 @@ BlobManager::NullResult MemoryHomeObject::_del_blob(ShardInfo const& shard, blob
auto lg = std::scoped_lock(_index_lock);
LOGDEBUGMOD(homeobject, "Looking up Blob {} in set of {}", route.blob, _in_memory_index.size());
// TODO We defer GC of the BLOB leaking BLOB into disk
if (0 < _in_memory_index.erase(route)) return folly::Unit();
if (auto b_it = _in_memory_index.find(shard.id); _in_memory_index.end() != b_it) {
if (0 < b_it->second.erase(route)) return folly::Unit();
}
LOGWARNMOD(homeobject, "Blob missing {} during delete", route.blob);
return folly::makeUnexpected(BlobError::UNKNOWN_BLOB);
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/memory/homeobject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class MemoryHomeObject : public HomeObjectImpl {

/// Simulates the Shard=>Chunk mapping in IndexSvc
mutable std::shared_mutex _index_lock;
std::unordered_map< BlobRoute, blkid > _in_memory_index;
using btree = std::unordered_map< BlobRoute, blkid >;
std::unordered_map< shard_id, btree > _in_memory_index;
///

/// Helpers
Expand Down

0 comments on commit 1272ed1

Please sign in to comment.