Skip to content
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

refactor: move write_batch_delete into rocksdb_wrapper #669

Merged
merged 5 commits into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/server/pegasus_write_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,21 +169,19 @@ class pegasus_write_service::impl : public dsn::replication::replica_base
return empty_put(decree);
}

auto cleanup = dsn::defer([this]() { _rocksdb_wrapper->clear_up_write_batch(); });
for (auto &sort_key : update.sort_keys) {
resp.error =
db_write_batch_delete(decree, composite_raw_key(update.hash_key, sort_key));
resp.error = _rocksdb_wrapper->write_batch_delete(
decree, composite_raw_key(update.hash_key, sort_key));
if (resp.error) {
clear_up_batch_states(decree, resp.error);
return resp.error;
}
}

resp.error = db_write(decree);
resp.error = _rocksdb_wrapper->write(decree);
if (resp.error == 0) {
resp.count = update.sort_keys.size();
}

clear_up_batch_states(decree, resp.error);
return resp.error;
}

Expand Down
19 changes: 19 additions & 0 deletions src/server/rocksdb_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,25 @@ int rocksdb_wrapper::write(int64_t decree)
return status.code();
}

int rocksdb_wrapper::write_batch_delete(int64_t decree, dsn::string_view raw_key)
{
FAIL_POINT_INJECT_F("db_write_batch_delete",
[](dsn::string_view) -> int { return FAIL_DB_WRITE_BATCH_DELETE; });

rocksdb::Status s = _write_batch->Delete(utils::to_rocksdb_slice(raw_key));
if (dsn_unlikely(!s.ok())) {
dsn::blob hash_key, sort_key;
pegasus_restore_key(dsn::blob(raw_key.data(), 0, raw_key.size()), hash_key, sort_key);
derror_rocksdb("write_batch_delete",
s.ToString(),
"decree: {}, hash_key: {}, sort_key: {}",
decree,
utils::c_escape_string(hash_key),
utils::c_escape_string(sort_key));
}
return s.code();
}

void rocksdb_wrapper::clear_up_write_batch() { _write_batch->Clear(); }

void rocksdb_wrapper::set_default_ttl(uint32_t ttl)
Expand Down
1 change: 1 addition & 0 deletions src/server/rocksdb_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class rocksdb_wrapper : public dsn::replication::replica_base
dsn::string_view value,
uint32_t expire_sec);
int write(int64_t decree);
int write_batch_delete(int64_t decree, dsn::string_view raw_key);
void clear_up_write_batch();

void set_default_ttl(uint32_t ttl);
Expand Down