-
Notifications
You must be signed in to change notification settings - Fork 468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support limit WriteBatch size #2508
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3622d44
feat: support limit WriteBatch size
AntiTopQuark 87d5603
add unit case
AntiTopQuark 9f87948
update code style
AntiTopQuark 461379a
Merge branch 'unstable' into limit_write_batch
AntiTopQuark 38652da
update
AntiTopQuark 81b60f1
Merge branch 'unstable' into limit_write_batch
git-hulk 27533c0
Merge branch 'unstable' into limit_write_batch
AntiTopQuark bd68c43
update
AntiTopQuark 216567b
Merge branch 'limit_write_batch' of github.com:AntiTopQuark/kvrocks i…
AntiTopQuark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,11 +49,16 @@ StatusOr<HnswNodeFieldMetadata> HnswNode::DecodeMetadata(engine::Context& ctx, c | |
return metadata; | ||
} | ||
|
||
void HnswNode::PutMetadata(HnswNodeFieldMetadata* node_meta, const SearchKey& search_key, engine::Storage* storage, | ||
rocksdb::WriteBatchBase* batch) const { | ||
Status HnswNode::PutMetadata(HnswNodeFieldMetadata* node_meta, const SearchKey& search_key, engine::Storage* storage, | ||
rocksdb::WriteBatchBase* batch) const { | ||
std::string updated_metadata; | ||
node_meta->Encode(&updated_metadata); | ||
batch->Put(storage->GetCFHandle(ColumnFamilyID::Search), search_key.ConstructHnswNode(level, key), updated_metadata); | ||
auto s = batch->Put(storage->GetCFHandle(ColumnFamilyID::Search), search_key.ConstructHnswNode(level, key), | ||
updated_metadata); | ||
if (!s.ok()) { | ||
return {Status::NotOK, s.ToString()}; | ||
} | ||
return Status::OK(); | ||
} | ||
|
||
void HnswNode::DecodeNeighbours(engine::Context& ctx, const SearchKey& search_key) { | ||
|
@@ -75,11 +80,16 @@ void HnswNode::DecodeNeighbours(engine::Context& ctx, const SearchKey& search_ke | |
Status HnswNode::AddNeighbour(engine::Context& ctx, const NodeKey& neighbour_key, const SearchKey& search_key, | ||
rocksdb::WriteBatchBase* batch) const { | ||
auto edge_index_key = search_key.ConstructHnswEdge(level, key, neighbour_key); | ||
batch->Put(ctx.storage->GetCFHandle(ColumnFamilyID::Search), edge_index_key, Slice()); | ||
|
||
auto rocket_s = batch->Put(ctx.storage->GetCFHandle(ColumnFamilyID::Search), edge_index_key, Slice()); | ||
if (!rocket_s.ok()) { | ||
return {Status::NotOK, rocket_s.ToString()}; | ||
} | ||
HnswNodeFieldMetadata node_metadata = GET_OR_RET(DecodeMetadata(ctx, search_key)); | ||
node_metadata.num_neighbours++; | ||
PutMetadata(&node_metadata, search_key, ctx.storage, batch); | ||
auto s = PutMetadata(&node_metadata, search_key, ctx.storage, batch); | ||
if (!s.IsOK()) { | ||
return s; | ||
} | ||
return Status::OK(); | ||
} | ||
|
||
|
@@ -93,7 +103,10 @@ Status HnswNode::RemoveNeighbour(engine::Context& ctx, const NodeKey& neighbour_ | |
|
||
HnswNodeFieldMetadata node_metadata = GET_OR_RET(DecodeMetadata(ctx, search_key)); | ||
node_metadata.num_neighbours--; | ||
PutMetadata(&node_metadata, search_key, ctx.storage, batch); | ||
auto redis_status = PutMetadata(&node_metadata, search_key, ctx.storage, batch); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RETURN_NOT_OK or just return this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
if (!redis_status.IsOK()) { | ||
return redis_status; | ||
} | ||
return Status::OK(); | ||
} | ||
|
||
|
@@ -445,7 +458,10 @@ Status HnswIndex::InsertVectorEntryInternal(engine::Context& ctx, std::string_vi | |
|
||
// Update inserted node metadata | ||
HnswNodeFieldMetadata node_metadata(static_cast<uint16_t>(connected_edges_set.size()), vector); | ||
node.PutMetadata(&node_metadata, search_key, storage, batch.Get()); | ||
auto s = node.PutMetadata(&node_metadata, search_key, storage, batch.Get()); | ||
if (!s.IsOK()) { | ||
return s; | ||
} | ||
|
||
// Update modified nodes metadata | ||
for (const auto& node_edges : deleted_edges_map) { | ||
|
@@ -458,14 +474,20 @@ Status HnswIndex::InsertVectorEntryInternal(engine::Context& ctx, std::string_vi | |
connected_edges_set.erase(current_node_key); | ||
} | ||
current_node_metadata.num_neighbours = new_num_neighbours; | ||
current_node.PutMetadata(¤t_node_metadata, search_key, storage, batch.Get()); | ||
s = current_node.PutMetadata(¤t_node_metadata, search_key, storage, batch.Get()); | ||
if (!s.IsOK()) { | ||
return s; | ||
} | ||
} | ||
|
||
for (const auto& current_node_key : connected_edges_set) { | ||
auto current_node = HnswNode(current_node_key, level); | ||
HnswNodeFieldMetadata current_node_metadata = GET_OR_RET(current_node.DecodeMetadata(ctx, search_key)); | ||
current_node_metadata.num_neighbours++; | ||
current_node.PutMetadata(¤t_node_metadata, search_key, storage, batch.Get()); | ||
s = current_node.PutMetadata(¤t_node_metadata, search_key, storage, batch.Get()); | ||
if (!s.IsOK()) { | ||
return s; | ||
} | ||
} | ||
|
||
entry_points.clear(); | ||
|
@@ -476,21 +498,30 @@ Status HnswIndex::InsertVectorEntryInternal(engine::Context& ctx, std::string_vi | |
} else { | ||
auto node = HnswNode(std::string(key), 0); | ||
HnswNodeFieldMetadata node_metadata(0, vector); | ||
node.PutMetadata(&node_metadata, search_key, storage, batch.Get()); | ||
auto s = node.PutMetadata(&node_metadata, search_key, storage, batch.Get()); | ||
if (!s.IsOK()) { | ||
return s; | ||
} | ||
metadata->num_levels = 1; | ||
} | ||
|
||
while (target_level > metadata->num_levels - 1) { | ||
auto node = HnswNode(std::string(key), metadata->num_levels); | ||
HnswNodeFieldMetadata node_metadata(0, vector); | ||
node.PutMetadata(&node_metadata, search_key, storage, batch.Get()); | ||
auto s = node.PutMetadata(&node_metadata, search_key, storage, batch.Get()); | ||
if (!s.IsOK()) { | ||
return s; | ||
} | ||
metadata->num_levels++; | ||
} | ||
|
||
std::string encoded_index_metadata; | ||
metadata->Encode(&encoded_index_metadata); | ||
auto index_meta_key = search_key.ConstructFieldMeta(); | ||
batch->Put(cf_handle, index_meta_key, encoded_index_metadata); | ||
auto s = batch->Put(cf_handle, index_meta_key, encoded_index_metadata); | ||
if (!s.ok()) { | ||
return {Status::NotOK, s.ToString()}; | ||
} | ||
|
||
return Status::OK(); | ||
} | ||
|
@@ -524,7 +555,10 @@ Status HnswIndex::DeleteVectorEntry(engine::Context& ctx, std::string_view key, | |
auto neighbour_node = HnswNode(neighbour_key, level); | ||
HnswNodeFieldMetadata neighbour_node_metadata = GET_OR_RET(neighbour_node.DecodeMetadata(ctx, search_key)); | ||
neighbour_node_metadata.num_neighbours--; | ||
neighbour_node.PutMetadata(&neighbour_node_metadata, search_key, storage, batch.Get()); | ||
auto s = neighbour_node.PutMetadata(&neighbour_node_metadata, search_key, storage, batch.Get()); | ||
if (!s.IsOK()) { | ||
return s; | ||
} | ||
} | ||
} | ||
|
||
|
@@ -559,8 +593,10 @@ Status HnswIndex::DeleteVectorEntry(engine::Context& ctx, std::string_view key, | |
std::string encoded_index_metadata; | ||
metadata->Encode(&encoded_index_metadata); | ||
auto index_meta_key = search_key.ConstructFieldMeta(); | ||
batch->Put(storage->GetCFHandle(ColumnFamilyID::Search), index_meta_key, encoded_index_metadata); | ||
|
||
auto s = batch->Put(storage->GetCFHandle(ColumnFamilyID::Search), index_meta_key, encoded_index_metadata); | ||
if (!s.ok()) { | ||
return {Status::NotOK, s.ToString()}; | ||
} | ||
return Status::OK(); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done