Skip to content

Commit f5c322f

Browse files
authored
refactor: specify data column family explicitly for RocksDB wrapper (#2182)
Currently the wrapper operates RocksDB data still by default column family handler. To make data/meta column family both specified explicitly while accessing RocksDB instance, introduce data column family handler into the wrapper.
1 parent 12f331f commit f5c322f

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/server/rocksdb_wrapper.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ rocksdb_wrapper::rocksdb_wrapper(pegasus_server_impl *server)
6161
: replica_base(server),
6262
_db(server->_db),
6363
_rd_opts(server->_data_cf_rd_opts),
64+
_data_cf(server->_data_cf),
6465
_meta_cf(server->_meta_cf),
6566
_pegasus_data_version(server->_pegasus_data_version),
6667
METRIC_VAR_INIT_replica(read_expired_values),
@@ -78,7 +79,8 @@ int rocksdb_wrapper::get(std::string_view raw_key, /*out*/ db_get_context *ctx)
7879
{
7980
FAIL_POINT_INJECT_F("db_get", [](std::string_view) -> int { return FAIL_DB_GET; });
8081

81-
rocksdb::Status s = _db->Get(_rd_opts, utils::to_rocksdb_slice(raw_key), &(ctx->raw_value));
82+
rocksdb::Status s =
83+
_db->Get(_rd_opts, _data_cf, utils::to_rocksdb_slice(raw_key), &ctx->raw_value);
8284
if (dsn_likely(s.ok())) {
8385
// success
8486
ctx->found = true;
@@ -94,7 +96,8 @@ int rocksdb_wrapper::get(std::string_view raw_key, /*out*/ db_get_context *ctx)
9496
return rocksdb::Status::kOk;
9597
}
9698

97-
dsn::blob hash_key, sort_key;
99+
dsn::blob hash_key;
100+
dsn::blob sort_key;
98101
pegasus_restore_key(dsn::blob(raw_key.data(), 0, raw_key.size()), hash_key, sort_key);
99102
LOG_ERROR_ROCKSDB("Get",
100103
s.ToString(),
@@ -152,9 +155,10 @@ int rocksdb_wrapper::write_batch_put_ctx(const db_write_context &ctx,
152155
rocksdb::SliceParts skey_parts(&skey, 1);
153156
rocksdb::SliceParts svalue = _value_generator->generate_value(
154157
_pegasus_data_version, value, db_expire_ts(expire_sec), new_timetag);
155-
rocksdb::Status s = _write_batch->Put(skey_parts, svalue);
158+
rocksdb::Status s = _write_batch->Put(_data_cf, skey_parts, svalue);
156159
if (dsn_unlikely(!s.ok())) {
157-
::dsn::blob hash_key, sort_key;
160+
dsn::blob hash_key;
161+
dsn::blob sort_key;
158162
pegasus_restore_key(::dsn::blob(raw_key.data(), 0, raw_key.size()), hash_key, sort_key);
159163
LOG_ERROR_ROCKSDB("WriteBatchPut",
160164
s.ToString(),
@@ -199,9 +203,10 @@ int rocksdb_wrapper::write_batch_delete(int64_t decree, std::string_view raw_key
199203
FAIL_POINT_INJECT_F("db_write_batch_delete",
200204
[](std::string_view) -> int { return FAIL_DB_WRITE_BATCH_DELETE; });
201205

202-
rocksdb::Status s = _write_batch->Delete(utils::to_rocksdb_slice(raw_key));
206+
rocksdb::Status s = _write_batch->Delete(_data_cf, utils::to_rocksdb_slice(raw_key));
203207
if (dsn_unlikely(!s.ok())) {
204-
dsn::blob hash_key, sort_key;
208+
dsn::blob hash_key;
209+
dsn::blob sort_key;
205210
pegasus_restore_key(dsn::blob(raw_key.data(), 0, raw_key.size()), hash_key, sort_key);
206211
LOG_ERROR_ROCKSDB("write_batch_delete",
207212
s.ToString(),
@@ -223,7 +228,7 @@ int rocksdb_wrapper::ingest_files(int64_t decree,
223228
ifo.move_files = true;
224229
ifo.ingest_behind = ingest_behind;
225230
ifo.write_global_seqno = FLAGS_rocksdb_write_global_seqno;
226-
rocksdb::Status s = _db->IngestExternalFile(sst_file_list, ifo);
231+
rocksdb::Status s = _db->IngestExternalFile(_data_cf, sst_file_list, ifo);
227232
if (dsn_unlikely(!s.ok())) {
228233
LOG_ERROR_ROCKSDB("IngestExternalFile",
229234
s.ToString(),

src/server/rocksdb_wrapper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class rocksdb_wrapper : public dsn::replication::replica_base
8181
std::unique_ptr<pegasus_value_generator> _value_generator;
8282
std::unique_ptr<rocksdb::WriteBatch> _write_batch;
8383
std::unique_ptr<rocksdb::WriteOptions> _wt_opts;
84+
rocksdb::ColumnFamilyHandle *_data_cf;
8485
rocksdb::ColumnFamilyHandle *_meta_cf;
8586

8687
const uint32_t _pegasus_data_version;

0 commit comments

Comments
 (0)