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: use rocksdb_wrapper::get to reimplement check_and_mutate #655

Merged
merged 2 commits into from
Dec 14, 2020
Merged
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
36 changes: 13 additions & 23 deletions src/server/pegasus_write_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,41 +412,31 @@ class pegasus_write_service::impl : public dsn::replication::replica_base

::dsn::blob check_key;
pegasus_generate_key(check_key, update.hash_key, update.check_sort_key);
rocksdb::Slice check_raw_key(check_key.data(), check_key.length());
std::string check_raw_value;
rocksdb::Status check_status = _db->Get(_rd_opts, check_raw_key, &check_raw_value);
if (check_status.ok()) {
// read check value succeed
if (check_if_record_expired(
_pegasus_data_version, utils::epoch_now(), check_raw_value)) {
// check value ttl timeout
_pfc_recent_expire_count->increment();
check_status = rocksdb::Status::NotFound();
}
} else if (!check_status.IsNotFound()) {

db_get_context get_context;
dsn::string_view check_raw_key(check_key.data(), check_key.length());
int err = _rocksdb_wrapper->get(check_raw_key, &get_context);
if (err != 0) {
// read check value failed
derror_rocksdb("GetCheckValue for CheckAndMutate",
check_status.ToString(),
"decree: {}, hash_key: {}, check_sort_key: {}",
derror_rocksdb("Error to GetCheckValue for CheckAndMutate decree: {}, hash_key: {}, "
"check_sort_key: {}",
decree,
utils::c_escape_string(update.hash_key),
utils::c_escape_string(update.check_sort_key));
resp.error = check_status.code();
resp.error = err;
return resp.error;
}
dassert_f(check_status.ok() || check_status.IsNotFound(),
"status = %s",
check_status.ToString().c_str());

::dsn::blob check_value;
if (check_status.ok()) {
bool value_exist = !get_context.expired && get_context.found;
if (value_exist) {
pegasus_extract_user_data(
_pegasus_data_version, std::move(check_raw_value), check_value);
_pegasus_data_version, std::move(get_context.raw_value), check_value);
}

if (update.return_check_value) {
resp.check_value_returned = true;
if (check_status.ok()) {
if (value_exist) {
resp.check_value_exist = true;
resp.check_value = check_value;
}
Expand All @@ -456,7 +446,7 @@ class pegasus_write_service::impl : public dsn::replication::replica_base
bool passed = validate_check(decree,
update.check_type,
update.check_operand,
check_status.ok(),
value_exist,
check_value,
invalid_argument);

Expand Down