Key count is innacurate after overwrite
Former-commit-id: 180c5a8e401415cede36548ab8d01f3e4ff8fb7f
This commit is contained in:
parent
1b56e36309
commit
033eda6016
@ -12,13 +12,16 @@ RocksDBStorageProvider::RocksDBStorageProvider(std::shared_ptr<rocksdb::DB> &spd
|
||||
void RocksDBStorageProvider::insert(const char *key, size_t cchKey, void *data, size_t cb)
|
||||
{
|
||||
rocksdb::Status status;
|
||||
bool fOverwrite = FKeyExists(key, cchKey);
|
||||
if (m_spbatch != nullptr)
|
||||
status = m_spbatch->Put(m_spcolfamily.get(), rocksdb::Slice(key, cchKey), rocksdb::Slice((const char*)data, cb));
|
||||
else
|
||||
status = m_spdb->Put(WriteOptions(), m_spcolfamily.get(), rocksdb::Slice(key, cchKey), rocksdb::Slice((const char*)data, cb));
|
||||
if (!status.ok())
|
||||
throw status.ToString();
|
||||
++m_count;
|
||||
|
||||
if (!fOverwrite)
|
||||
++m_count;
|
||||
}
|
||||
|
||||
bool RocksDBStorageProvider::erase(const char *key, size_t cchKey)
|
||||
@ -30,13 +33,12 @@ bool RocksDBStorageProvider::erase(const char *key, size_t cchKey)
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string strT;
|
||||
if (!m_spdb->Get(ReadOptions(), m_spcolfamily.get(), rocksdb::Slice(key, cchKey), &strT).ok())
|
||||
if (!FKeyExists(key, cchKey))
|
||||
return false;
|
||||
status = m_spdb->Delete(WriteOptions(), m_spcolfamily.get(), rocksdb::Slice(key, cchKey));
|
||||
}
|
||||
if (status.ok())
|
||||
-- m_count;
|
||||
--m_count;
|
||||
return status.ok();
|
||||
}
|
||||
|
||||
@ -123,4 +125,10 @@ void RocksDBStorageProvider::endWriteBatch()
|
||||
void RocksDBStorageProvider::flush()
|
||||
{
|
||||
m_spdb->SyncWAL();
|
||||
}
|
||||
|
||||
bool RocksDBStorageProvider::FKeyExists(const char *key, size_t cch) const
|
||||
{
|
||||
std::string strT;
|
||||
return m_spdb->Get(ReadOptions(), m_spcolfamily.get(), rocksdb::Slice(key, cch), &strT).ok();
|
||||
}
|
@ -33,6 +33,7 @@ public:
|
||||
size_t count() const;
|
||||
|
||||
protected:
|
||||
bool FKeyExists(const char *key, size_t cchKey) const;
|
||||
|
||||
const rocksdb::ReadOptions &ReadOptions() const { return m_readOptionsTemplate; }
|
||||
rocksdb::WriteOptions WriteOptions() const;
|
||||
|
@ -7,13 +7,19 @@ start_server {tags {"flash"} overrides {"storage-provider flash ./rocks.db"}} {
|
||||
}
|
||||
|
||||
test { DEL of nonexistant key returns 0 } {
|
||||
r flushall
|
||||
assert_equal {0} [r del foobar]
|
||||
assert_equal {0} [r dbsize] "Key count is accurate after non-existant delete"
|
||||
}
|
||||
|
||||
test { SET of existing but flushed key works } {
|
||||
r flushall
|
||||
r set testkey foo
|
||||
assert_equal {1} [r dbsize] "Only one key after first insert"
|
||||
r flushall cache
|
||||
assert_equal {1} [r dbsize] "Only one key after flushall cache"
|
||||
r set testkey bar
|
||||
assert_equal {1} [r dbsize] "Only one key after overwrite"
|
||||
assert_equal {bar} [r get testkey]
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user