RocksDB zstd encryption; cache tuning; readonly open mode

This commit is contained in:
Thomas Krijnen
2025-09-03 11:11:55 +02:00
parent a831884ee6
commit 59a5bf2344
15 changed files with 170 additions and 79 deletions
+9 -9
View File
@@ -20,7 +20,7 @@
#ifndef ROCKSDB_SET_VIEW_H
#define ROCKSDB_SET_VIEW_H
#ifdef WITH_ROCKSDB
#ifdef IFOPSH_WITH_ROCKSDB
#include <rocksdb/db.h>
#include <rocksdb/options.h>
#endif
@@ -66,7 +66,7 @@ public:
// Helper: extract the key (i.e. the value) from the current RocksDB key.
value_type extract_current_value() const {
#ifdef WITH_ROCKSDB
#ifdef IFOPSH_WITH_ROCKSDB
std::string full_key = it_->key().ToString();
std::string remainder = full_key.substr(prefix_.size());
size_t pos = remainder.find('|');
@@ -79,7 +79,7 @@ public:
// Validates the current iterator state.
void check_valid() {
#ifdef WITH_ROCKSDB
#ifdef IFOPSH_WITH_ROCKSDB
if (!it_ || !it_->Valid() || !it_->key().starts_with(prefix_))
it_.reset();
#endif
@@ -98,7 +98,7 @@ public:
iterator(const iterator& other)
: db_(other.db_), prefix_(other.prefix_)
{
#ifdef WITH_ROCKSDB
#ifdef IFOPSH_WITH_ROCKSDB
if (other.it_) {
std::string curr = other.it_->key().ToString();
it_.reset(db_->NewIterator(rocksdb::ReadOptions{}));
@@ -110,7 +110,7 @@ public:
}
iterator& operator=(const iterator& other) {
#ifdef WITH_ROCKSDB
#ifdef IFOPSH_WITH_ROCKSDB
if (this != &other) {
db_ = other.db_;
prefix_ = other.prefix_;
@@ -141,7 +141,7 @@ public:
// Pre-increment: advance the iterator and skip over any duplicate keys.
iterator& operator++() {
#ifdef WITH_ROCKSDB
#ifdef IFOPSH_WITH_ROCKSDB
if (it_) {
// Record the current key value.
value_type curr = extract_current_value();
@@ -163,7 +163,7 @@ public:
}
bool operator==(const iterator& other) const {
#ifdef WITH_ROCKSDB
#ifdef IFOPSH_WITH_ROCKSDB
if (!it_ && !other.it_)
return true;
if (it_ && other.it_)
@@ -179,7 +179,7 @@ public:
// Returns an iterator to the first element in the key-space (or end() if none exist).
iterator begin() const {
#ifdef WITH_ROCKSDB
#ifdef IFOPSH_WITH_ROCKSDB
auto iter = std::unique_ptr<rocksdb::Iterator>(db_->NewIterator(rocksdb::ReadOptions{}));
iter->Seek(prefix_);
if (iter->Valid() && iter->key().starts_with(prefix_))
@@ -195,7 +195,7 @@ public:
// Read-only find: returns an iterator to the element with the given key if it exists.
iterator find(const key_type& key) const {
#ifdef WITH_ROCKSDB
#ifdef IFOPSH_WITH_ROCKSDB
std::string key_str = key_to_string(key);
// Construct the search key: prefix + key_str + separator.
std::string start_key = prefix_ + key_str + "|";