Prevent bookkeeping keys from leaking through
Former-commit-id: 1a5af28e115fc123bf250b4a80ac69232bb3add0
This commit is contained in:
parent
682d16b7d3
commit
82e1ed482a
@ -3,6 +3,8 @@
|
||||
#include <sstream>
|
||||
#include <mutex>
|
||||
|
||||
static const char *keyprefix = INTERNAL_KEY_PREFIX;
|
||||
|
||||
RocksDBStorageProvider::RocksDBStorageProvider(std::shared_ptr<rocksdb::DB> &spdb, std::shared_ptr<rocksdb::ColumnFamilyHandle> &spcolfam, const rocksdb::Snapshot *psnapshot, size_t count)
|
||||
: m_spdb(spdb), m_psnapshot(psnapshot), m_spcolfamily(spcolfam), m_count(count)
|
||||
{
|
||||
@ -73,11 +75,23 @@ size_t RocksDBStorageProvider::count() const
|
||||
return m_count;
|
||||
}
|
||||
|
||||
bool RocksDBStorageProvider::FInternalKey(const char *key, size_t cch) const
|
||||
{
|
||||
if (cch > strlen(INTERNAL_KEY_PREFIX))
|
||||
{
|
||||
if (memcmp(key, keyprefix, strlen(INTERNAL_KEY_PREFIX)) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RocksDBStorageProvider::enumerate(callback fn) const
|
||||
{
|
||||
std::unique_ptr<rocksdb::Iterator> it = std::unique_ptr<rocksdb::Iterator>(m_spdb->NewIterator(ReadOptions(), m_spcolfamily.get()));
|
||||
size_t count = 0;
|
||||
for (it->SeekToFirst(); it->Valid(); it->Next()) {
|
||||
if (FInternalKey(it->key().data(), it->key().size()))
|
||||
continue;
|
||||
++count;
|
||||
bool fContinue = fn(it->key().data(), it->key().size(), it->value().data(), it->value().size());
|
||||
if (!fContinue)
|
||||
|
@ -5,8 +5,9 @@
|
||||
#include <rocksdb/db.h>
|
||||
#include "../fastlock.h"
|
||||
|
||||
static const char count_key[] = "\0__keydb__count\1";
|
||||
static const char version_key[] = "\0__keydb__version\1";
|
||||
#define INTERNAL_KEY_PREFIX "\x00\x04\x03\x00\x05\x02\x04"
|
||||
static const char count_key[] = INTERNAL_KEY_PREFIX "__keydb__count\1";
|
||||
static const char version_key[] = INTERNAL_KEY_PREFIX "__keydb__version\1";
|
||||
|
||||
class RocksDBStorageProvider : public IStorage
|
||||
{
|
||||
@ -39,6 +40,7 @@ public:
|
||||
|
||||
protected:
|
||||
bool FKeyExists(const char *key, size_t cchKey) const;
|
||||
bool FInternalKey(const char *key, size_t cchKey) const;
|
||||
|
||||
const rocksdb::ReadOptions &ReadOptions() const { return m_readOptionsTemplate; }
|
||||
rocksdb::WriteOptions WriteOptions() const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user