Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
empiredan committed Jan 24, 2025
1 parent f8a2cc7 commit da1877c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/server/pegasus_write_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class pegasus_write_service::impl : public dsn::replication::replica_base
{
// Get old value from the RocksDB instance according to the provided key.
db_get_context get_ctx;
int err = _rocksdb_wrapper->get(req.key.to_string_view(), &get_ctx);
const int err = _rocksdb_wrapper->get(req.key.to_string_view(), &get_ctx);
if (dsn_unlikely(err != rocksdb::Status::kOk)) {
return make_error_response(err, err_resp);
}
Expand Down Expand Up @@ -254,8 +254,9 @@ class pegasus_write_service::impl : public dsn::replication::replica_base
return resp.error;
}

// Shouldn't fail to parse since the value must be a valid int64.
CHECK(dsn::buf2int64(update.value.to_string_view(), resp.new_value),
"invalid int64 value for put incr: key={}, value={}",
"invalid int64 value for put idempotent incr: key={}, value={}",
update.key,
update.value);

Expand Down
13 changes: 9 additions & 4 deletions src/server/rocksdb_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,25 @@ int rocksdb_wrapper::get(std::string_view raw_key, /*out*/ db_get_context *ctx)
{
FAIL_POINT_INJECT_F("db_get", [](std::string_view) -> int { return FAIL_DB_GET; });

rocksdb::Status s =
const rocksdb::Status s =
_db->Get(_rd_opts, _data_cf, utils::to_rocksdb_slice(raw_key), &ctx->raw_value);
if (dsn_likely(s.ok())) {
// success
// The key is found and read successfully.
ctx->found = true;
ctx->expire_ts = pegasus_extract_expire_ts(_pegasus_data_version, ctx->raw_value);
if (check_if_ts_expired(utils::epoch_now(), ctx->expire_ts)) {
ctx->expired = true;
METRIC_VAR_INCREMENT(read_expired_values);
} else {
ctx->expired = false;
}
return rocksdb::Status::kOk;
} else if (s.IsNotFound()) {
// NotFound is an acceptable error
}

if (s.IsNotFound()) {
// NotFound is considered normal since the key may not be present in DB now.
ctx->found = false;
ctx->expired = false;
return rocksdb::Status::kOk;
}

Expand Down

0 comments on commit da1877c

Please sign in to comment.