This is an automated email from the ASF dual-hosted git repository.
yuchenhe pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git
The following commit(s) were added to refs/heads/master by this push:
new 8bd9ce9 refactor: use rocksdb_wrapper::get to reimplement
check_and_set (#654)
8bd9ce9 is described below
commit 8bd9ce9a289f08bea7f0f137b6d98941bf50309a
Author: zhao liwei <[email protected]>
AuthorDate: Mon Dec 14 09:56:12 2020 +0800
refactor: use rocksdb_wrapper::get to reimplement check_and_set (#654)
---
src/server/pegasus_write_service_impl.h | 36 ++++++++++++---------------------
1 file changed, 13 insertions(+), 23 deletions(-)
diff --git a/src/server/pegasus_write_service_impl.h
b/src/server/pegasus_write_service_impl.h
index d9bdb75..3655a6c 100644
--- a/src/server/pegasus_write_service_impl.h
+++ b/src/server/pegasus_write_service_impl.h
@@ -292,41 +292,31 @@ public:
::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 CheckAndSet",
- check_status.ToString(),
- "decree: {}, hash_key: {}, check_sort_key: {}",
+ derror_rocksdb("Error to GetCheckValue for CheckAndSet 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;
}
@@ -336,7 +326,7 @@ public:
bool passed = validate_check(decree,
update.check_type,
update.check_operand,
- check_status.ok(),
+ value_exist,
check_value,
invalid_argument);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]