Skip to content

Commit

Permalink
refactor: use rocksdb_wrapper::get to reimplement check_and_mutate (#655
Browse files Browse the repository at this point in the history
)
  • Loading branch information
levy5307 authored Dec 14, 2020
1 parent 8bd9ce9 commit df8f41e
Showing 1 changed file with 13 additions and 23 deletions.
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

0 comments on commit df8f41e

Please sign in to comment.