2019-04-18 19:51:19 +02:00
|
|
|
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
|
2015-07-20 20:24:54 +02:00
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
|
2017-04-06 23:49:13 +02:00
|
|
|
#include <map>
|
2013-08-13 19:56:20 +02:00
|
|
|
#include <memory>
|
2021-08-06 17:26:23 +02:00
|
|
|
|
2013-08-23 17:38:13 +02:00
|
|
|
#include "rocksdb/compaction_filter.h"
|
2021-08-06 17:26:23 +02:00
|
|
|
#include "rocksdb/convenience.h"
|
|
|
|
#include "rocksdb/merge_operator.h"
|
2014-07-23 16:21:38 +02:00
|
|
|
#include "rocksdb/utilities/db_ttl.h"
|
2021-08-06 17:26:23 +02:00
|
|
|
#include "rocksdb/utilities/object_registry.h"
|
2019-05-30 20:21:38 +02:00
|
|
|
#include "test_util/testharness.h"
|
2019-05-31 02:39:43 +02:00
|
|
|
#include "util/string_util.h"
|
2021-08-06 17:26:23 +02:00
|
|
|
#include "utilities/merge_operators/bytesxor.h"
|
|
|
|
#include "utilities/ttl/db_ttl_impl.h"
|
2015-07-02 01:13:49 +02:00
|
|
|
#ifndef OS_WIN
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
#include <unistd.h>
|
2015-07-02 01:13:49 +02:00
|
|
|
#endif
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
|
|
|
|
namespace {
|
2013-08-03 09:40:22 +02:00
|
|
|
|
2021-09-07 20:31:12 +02:00
|
|
|
using KVMap = std::map<std::string, std::string>;
|
2013-08-03 09:40:22 +02:00
|
|
|
|
2015-07-13 21:11:05 +02:00
|
|
|
enum BatchOperation { OP_PUT = 0, OP_DELETE = 1 };
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 16:13:51 +02:00
|
|
|
class SpecialTimeEnv : public EnvWrapper {
|
|
|
|
public:
|
|
|
|
explicit SpecialTimeEnv(Env* base) : EnvWrapper(base) {
|
2020-12-23 08:44:44 +01:00
|
|
|
EXPECT_OK(base->GetCurrentTime(¤t_time_));
|
2014-05-02 16:13:51 +02:00
|
|
|
}
|
2022-01-05 01:44:54 +01:00
|
|
|
const char* Name() const override { return "SpecialTimeEnv"; }
|
2014-05-02 16:13:51 +02:00
|
|
|
void Sleep(int64_t sleep_time) { current_time_ += sleep_time; }
|
2019-02-14 22:52:47 +01:00
|
|
|
Status GetCurrentTime(int64_t* current_time) override {
|
2014-05-02 16:13:51 +02:00
|
|
|
*current_time = current_time_;
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-07-05 21:02:00 +02:00
|
|
|
int64_t current_time_ = 0;
|
2014-05-02 16:13:51 +02:00
|
|
|
};
|
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
class TtlTest : public testing::Test {
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
public:
|
|
|
|
TtlTest() {
|
2014-05-02 16:13:51 +02:00
|
|
|
env_.reset(new SpecialTimeEnv(Env::Default()));
|
2018-07-14 02:18:39 +02:00
|
|
|
dbname_ = test::PerThreadDBPath("db_ttl");
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
options_.create_if_missing = true;
|
2014-05-02 16:13:51 +02:00
|
|
|
options_.env = env_.get();
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
// ensure that compaction is kicked in to always strip timestamp from kvs
|
2016-06-17 01:02:52 +02:00
|
|
|
options_.max_compaction_bytes = 1;
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
// compaction should take place always from level0 for determinism
|
|
|
|
db_ttl_ = nullptr;
|
|
|
|
DestroyDB(dbname_, Options());
|
|
|
|
}
|
|
|
|
|
2019-02-14 22:52:47 +01:00
|
|
|
~TtlTest() override {
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
CloseTtl();
|
|
|
|
DestroyDB(dbname_, Options());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open database with TTL support when TTL not provided with db_ttl_ pointer
|
|
|
|
void OpenTtl() {
|
2014-04-22 20:27:33 +02:00
|
|
|
ASSERT_TRUE(db_ttl_ ==
|
|
|
|
nullptr); // db should be closed before opening again
|
2014-04-29 05:34:20 +02:00
|
|
|
ASSERT_OK(DBWithTTL::Open(options_, dbname_, &db_ttl_));
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Open database with TTL support when TTL provided with db_ttl_ pointer
|
|
|
|
void OpenTtl(int32_t ttl) {
|
2014-04-22 20:27:33 +02:00
|
|
|
ASSERT_TRUE(db_ttl_ == nullptr);
|
2014-04-29 05:34:20 +02:00
|
|
|
ASSERT_OK(DBWithTTL::Open(options_, dbname_, &db_ttl_, ttl));
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
}
|
|
|
|
|
2013-08-03 09:40:22 +02:00
|
|
|
// Open with TestFilter compaction filter
|
|
|
|
void OpenTtlWithTestCompaction(int32_t ttl) {
|
2013-08-13 19:56:20 +02:00
|
|
|
options_.compaction_filter_factory =
|
|
|
|
std::shared_ptr<CompactionFilterFactory>(
|
|
|
|
new TestFilterFactory(kSampleSize_, kNewValue_));
|
2013-08-03 09:40:22 +02:00
|
|
|
OpenTtl(ttl);
|
|
|
|
}
|
|
|
|
|
2013-05-10 23:19:47 +02:00
|
|
|
// Open database with TTL support in read_only mode
|
|
|
|
void OpenReadOnlyTtl(int32_t ttl) {
|
2014-04-22 20:27:33 +02:00
|
|
|
ASSERT_TRUE(db_ttl_ == nullptr);
|
2014-04-29 05:34:20 +02:00
|
|
|
ASSERT_OK(DBWithTTL::Open(options_, dbname_, &db_ttl_, ttl, true));
|
2013-05-10 23:19:47 +02:00
|
|
|
}
|
|
|
|
|
2019-06-20 22:04:13 +02:00
|
|
|
// Call db_ttl_->Close() before delete db_ttl_
|
2019-09-20 21:00:55 +02:00
|
|
|
void CloseTtl() { CloseTtlHelper(true); }
|
2019-06-20 22:04:13 +02:00
|
|
|
|
|
|
|
// No db_ttl_->Close() before delete db_ttl_
|
2019-09-20 21:00:55 +02:00
|
|
|
void CloseTtlNoDBClose() { CloseTtlHelper(false); }
|
2019-06-20 22:04:13 +02:00
|
|
|
|
|
|
|
void CloseTtlHelper(bool close_db) {
|
|
|
|
if (db_ttl_ != nullptr) {
|
|
|
|
if (close_db) {
|
2021-01-08 00:21:51 +01:00
|
|
|
EXPECT_OK(db_ttl_->Close());
|
2019-06-20 22:04:13 +02:00
|
|
|
}
|
|
|
|
delete db_ttl_;
|
|
|
|
db_ttl_ = nullptr;
|
|
|
|
}
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Populates and returns a kv-map
|
|
|
|
void MakeKVMap(int64_t num_entries) {
|
|
|
|
kvmap_.clear();
|
2013-08-03 09:40:22 +02:00
|
|
|
int digits = 1;
|
2014-11-11 22:47:22 +01:00
|
|
|
for (int64_t dummy = num_entries; dummy /= 10; ++digits) {
|
|
|
|
}
|
2013-08-03 09:40:22 +02:00
|
|
|
int digits_in_i = 1;
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
for (int64_t i = 0; i < num_entries; i++) {
|
|
|
|
std::string key = "key";
|
|
|
|
std::string value = "value";
|
2013-08-03 09:40:22 +02:00
|
|
|
if (i % 10 == 0) {
|
|
|
|
digits_in_i++;
|
|
|
|
}
|
|
|
|
for(int j = digits_in_i; j < digits; j++) {
|
|
|
|
key.append("0");
|
|
|
|
value.append("0");
|
|
|
|
}
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
AppendNumberTo(&key, i);
|
|
|
|
AppendNumberTo(&value, i);
|
|
|
|
kvmap_[key] = value;
|
|
|
|
}
|
2014-11-11 22:47:22 +01:00
|
|
|
ASSERT_EQ(static_cast<int64_t>(kvmap_.size()),
|
|
|
|
num_entries); // check all insertions done
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
}
|
|
|
|
|
2013-05-16 00:00:57 +02:00
|
|
|
// Makes a write-batch with key-vals from kvmap_ and 'Write''s it
|
2014-11-11 22:47:22 +01:00
|
|
|
void MakePutWriteBatch(const BatchOperation* batch_ops, int64_t num_ops) {
|
|
|
|
ASSERT_LE(num_ops, static_cast<int64_t>(kvmap_.size()));
|
2013-05-16 00:00:57 +02:00
|
|
|
static WriteOptions wopts;
|
|
|
|
static FlushOptions flush_opts;
|
|
|
|
WriteBatch batch;
|
|
|
|
kv_it_ = kvmap_.begin();
|
2014-11-11 22:47:22 +01:00
|
|
|
for (int64_t i = 0; i < num_ops && kv_it_ != kvmap_.end(); i++, ++kv_it_) {
|
2013-05-16 00:00:57 +02:00
|
|
|
switch (batch_ops[i]) {
|
2015-07-02 01:13:49 +02:00
|
|
|
case OP_PUT:
|
2021-01-08 00:21:51 +01:00
|
|
|
ASSERT_OK(batch.Put(kv_it_->first, kv_it_->second));
|
2013-05-16 00:00:57 +02:00
|
|
|
break;
|
2015-07-02 01:13:49 +02:00
|
|
|
case OP_DELETE:
|
2021-01-08 00:21:51 +01:00
|
|
|
ASSERT_OK(batch.Delete(kv_it_->first));
|
2013-05-16 00:00:57 +02:00
|
|
|
break;
|
|
|
|
default:
|
2017-07-17 06:23:33 +02:00
|
|
|
FAIL();
|
2013-05-16 00:00:57 +02:00
|
|
|
}
|
|
|
|
}
|
2021-01-08 00:21:51 +01:00
|
|
|
ASSERT_OK(db_ttl_->Write(wopts, &batch));
|
|
|
|
ASSERT_OK(db_ttl_->Flush(flush_opts));
|
2013-05-16 00:00:57 +02:00
|
|
|
}
|
|
|
|
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
// Puts num_entries starting from start_pos_map from kvmap_ into the database
|
2014-11-11 22:47:22 +01:00
|
|
|
void PutValues(int64_t start_pos_map, int64_t num_entries, bool flush = true,
|
2014-04-22 20:27:33 +02:00
|
|
|
ColumnFamilyHandle* cf = nullptr) {
|
|
|
|
ASSERT_TRUE(db_ttl_);
|
2014-11-11 22:47:22 +01:00
|
|
|
ASSERT_LE(start_pos_map + num_entries, static_cast<int64_t>(kvmap_.size()));
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
static WriteOptions wopts;
|
|
|
|
static FlushOptions flush_opts;
|
|
|
|
kv_it_ = kvmap_.begin();
|
|
|
|
advance(kv_it_, start_pos_map);
|
2014-11-11 22:47:22 +01:00
|
|
|
for (int64_t i = 0; kv_it_ != kvmap_.end() && i < num_entries;
|
|
|
|
i++, ++kv_it_) {
|
2014-04-22 20:27:33 +02:00
|
|
|
ASSERT_OK(cf == nullptr
|
|
|
|
? db_ttl_->Put(wopts, kv_it_->first, kv_it_->second)
|
|
|
|
: db_ttl_->Put(wopts, cf, kv_it_->first, kv_it_->second));
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
}
|
|
|
|
// Put a mock kv at the end because CompactionFilter doesn't delete last key
|
2014-04-22 20:27:33 +02:00
|
|
|
ASSERT_OK(cf == nullptr ? db_ttl_->Put(wopts, "keymock", "valuemock")
|
|
|
|
: db_ttl_->Put(wopts, cf, "keymock", "valuemock"));
|
2013-09-02 06:04:20 +02:00
|
|
|
if (flush) {
|
2014-04-22 20:27:33 +02:00
|
|
|
if (cf == nullptr) {
|
2021-01-08 00:21:51 +01:00
|
|
|
ASSERT_OK(db_ttl_->Flush(flush_opts));
|
2014-04-22 20:27:33 +02:00
|
|
|
} else {
|
2021-01-08 00:21:51 +01:00
|
|
|
ASSERT_OK(db_ttl_->Flush(flush_opts, cf));
|
2014-04-22 20:27:33 +02:00
|
|
|
}
|
2013-09-02 06:04:20 +02:00
|
|
|
}
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Runs a manual compaction
|
2021-01-08 00:21:51 +01:00
|
|
|
Status ManualCompact(ColumnFamilyHandle* cf = nullptr) {
|
2014-04-22 20:27:33 +02:00
|
|
|
if (cf == nullptr) {
|
2021-01-08 00:21:51 +01:00
|
|
|
return db_ttl_->CompactRange(CompactRangeOptions(), nullptr, nullptr);
|
2014-04-22 20:27:33 +02:00
|
|
|
} else {
|
2021-01-08 00:21:51 +01:00
|
|
|
return db_ttl_->CompactRange(CompactRangeOptions(), cf, nullptr, nullptr);
|
2014-04-22 20:27:33 +02:00
|
|
|
}
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
}
|
|
|
|
|
2021-06-18 00:59:53 +02:00
|
|
|
// Runs a DeleteRange
|
|
|
|
void MakeDeleteRange(std::string start, std::string end,
|
|
|
|
ColumnFamilyHandle* cf = nullptr) {
|
|
|
|
ASSERT_TRUE(db_ttl_);
|
|
|
|
static WriteOptions wops;
|
|
|
|
WriteBatch wb;
|
|
|
|
ASSERT_OK(cf == nullptr
|
|
|
|
? wb.DeleteRange(db_ttl_->DefaultColumnFamily(), start, end)
|
|
|
|
: wb.DeleteRange(cf, start, end));
|
|
|
|
ASSERT_OK(db_ttl_->Write(wops, &wb));
|
|
|
|
}
|
|
|
|
|
2013-08-24 02:36:00 +02:00
|
|
|
// checks the whole kvmap_ to return correct values using KeyMayExist
|
|
|
|
void SimpleKeyMayExistCheck() {
|
|
|
|
static ReadOptions ropts;
|
|
|
|
bool value_found;
|
|
|
|
std::string val;
|
|
|
|
for(auto &kv : kvmap_) {
|
|
|
|
bool ret = db_ttl_->KeyMayExist(ropts, kv.first, &val, &value_found);
|
|
|
|
if (ret == false || value_found == false) {
|
|
|
|
fprintf(stderr, "KeyMayExist could not find key=%s in the database but"
|
|
|
|
" should have\n", kv.first.c_str());
|
2017-07-17 06:23:33 +02:00
|
|
|
FAIL();
|
2013-08-24 02:36:00 +02:00
|
|
|
} else if (val.compare(kv.second) != 0) {
|
|
|
|
fprintf(stderr, " value for key=%s present in database is %s but"
|
|
|
|
" should be %s\n", kv.first.c_str(), val.c_str(),
|
|
|
|
kv.second.c_str());
|
2017-07-17 06:23:33 +02:00
|
|
|
FAIL();
|
2013-08-24 02:36:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-20 12:46:37 +01:00
|
|
|
// checks the whole kvmap_ to return correct values using MultiGet
|
|
|
|
void SimpleMultiGetTest() {
|
|
|
|
static ReadOptions ropts;
|
|
|
|
std::vector<Slice> keys;
|
|
|
|
std::vector<std::string> values;
|
|
|
|
|
|
|
|
for (auto& kv : kvmap_) {
|
|
|
|
keys.emplace_back(kv.first);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto statuses = db_ttl_->MultiGet(ropts, keys, &values);
|
|
|
|
size_t i = 0;
|
|
|
|
for (auto& kv : kvmap_) {
|
|
|
|
ASSERT_OK(statuses[i]);
|
|
|
|
ASSERT_EQ(values[i], kv.second);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-08 00:21:51 +01:00
|
|
|
void CompactCheck(int64_t st_pos, int64_t span, bool check = true,
|
|
|
|
bool test_compaction_change = false,
|
|
|
|
ColumnFamilyHandle* cf = nullptr) {
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
static ReadOptions ropts;
|
|
|
|
kv_it_ = kvmap_.begin();
|
|
|
|
advance(kv_it_, st_pos);
|
|
|
|
std::string v;
|
2014-11-11 22:47:22 +01:00
|
|
|
for (int64_t i = 0; kv_it_ != kvmap_.end() && i < span; i++, ++kv_it_) {
|
2014-04-22 20:27:33 +02:00
|
|
|
Status s = (cf == nullptr) ? db_ttl_->Get(ropts, kv_it_->first, &v)
|
|
|
|
: db_ttl_->Get(ropts, cf, kv_it_->first, &v);
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
if (s.ok() != check) {
|
2013-08-03 09:40:22 +02:00
|
|
|
fprintf(stderr, "key=%s ", kv_it_->first.c_str());
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
if (!s.ok()) {
|
|
|
|
fprintf(stderr, "is absent from db but was expected to be present\n");
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "is present in db but was expected to be absent\n");
|
|
|
|
}
|
2017-07-17 06:23:33 +02:00
|
|
|
FAIL();
|
2013-08-03 09:40:22 +02:00
|
|
|
} else if (s.ok()) {
|
|
|
|
if (test_compaction_change && v.compare(kNewValue_) != 0) {
|
|
|
|
fprintf(stderr, " value for key=%s present in database is %s but "
|
|
|
|
" should be %s\n", kv_it_->first.c_str(), v.c_str(),
|
|
|
|
kNewValue_.c_str());
|
2017-07-17 06:23:33 +02:00
|
|
|
FAIL();
|
2013-08-03 09:40:22 +02:00
|
|
|
} else if (!test_compaction_change && v.compare(kv_it_->second) !=0) {
|
|
|
|
fprintf(stderr, " value for key=%s present in database is %s but "
|
|
|
|
" should be %s\n", kv_it_->first.c_str(), v.c_str(),
|
|
|
|
kv_it_->second.c_str());
|
2017-07-17 06:23:33 +02:00
|
|
|
FAIL();
|
2013-08-03 09:40:22 +02:00
|
|
|
}
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-08 00:21:51 +01:00
|
|
|
// Sleeps for slp_tim then runs a manual compaction
|
|
|
|
// Checks span starting from st_pos from kvmap_ in the db and
|
|
|
|
// Gets should return true if check is true and false otherwise
|
|
|
|
// Also checks that value that we got is the same as inserted; and =kNewValue
|
|
|
|
// if test_compaction_change is true
|
|
|
|
void SleepCompactCheck(int slp_tim, int64_t st_pos, int64_t span,
|
|
|
|
bool check = true, bool test_compaction_change = false,
|
|
|
|
ColumnFamilyHandle* cf = nullptr) {
|
|
|
|
ASSERT_TRUE(db_ttl_);
|
|
|
|
|
|
|
|
env_->Sleep(slp_tim);
|
|
|
|
ASSERT_OK(ManualCompact(cf));
|
|
|
|
CompactCheck(st_pos, span, check, test_compaction_change, cf);
|
|
|
|
}
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
|
|
|
|
// Similar as SleepCompactCheck but uses TtlIterator to read from db
|
2014-11-11 22:47:22 +01:00
|
|
|
void SleepCompactCheckIter(int slp, int st_pos, int64_t span,
|
|
|
|
bool check = true) {
|
2014-04-22 20:27:33 +02:00
|
|
|
ASSERT_TRUE(db_ttl_);
|
2014-05-02 16:13:51 +02:00
|
|
|
env_->Sleep(slp);
|
2021-01-08 00:21:51 +01:00
|
|
|
ASSERT_OK(ManualCompact());
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
static ReadOptions ropts;
|
|
|
|
Iterator *dbiter = db_ttl_->NewIterator(ropts);
|
|
|
|
kv_it_ = kvmap_.begin();
|
|
|
|
advance(kv_it_, st_pos);
|
|
|
|
|
|
|
|
dbiter->Seek(kv_it_->first);
|
|
|
|
if (!check) {
|
|
|
|
if (dbiter->Valid()) {
|
|
|
|
ASSERT_NE(dbiter->value().compare(kv_it_->second), 0);
|
|
|
|
}
|
|
|
|
} else { // dbiter should have found out kvmap_[st_pos]
|
2014-11-11 22:47:22 +01:00
|
|
|
for (int64_t i = st_pos; kv_it_ != kvmap_.end() && i < st_pos + span;
|
|
|
|
i++, ++kv_it_) {
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
ASSERT_TRUE(dbiter->Valid());
|
|
|
|
ASSERT_EQ(dbiter->value().compare(kv_it_->second), 0);
|
|
|
|
dbiter->Next();
|
|
|
|
}
|
|
|
|
}
|
2021-01-08 00:21:51 +01:00
|
|
|
ASSERT_OK(dbiter->status());
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
delete dbiter;
|
|
|
|
}
|
|
|
|
|
2018-01-18 19:41:26 +01:00
|
|
|
// Set ttl on open db
|
|
|
|
void SetTtl(int32_t ttl, ColumnFamilyHandle* cf = nullptr) {
|
|
|
|
ASSERT_TRUE(db_ttl_);
|
|
|
|
cf == nullptr ? db_ttl_->SetTtl(ttl) : db_ttl_->SetTtl(cf, ttl);
|
|
|
|
}
|
|
|
|
|
2013-08-03 09:40:22 +02:00
|
|
|
class TestFilter : public CompactionFilter {
|
|
|
|
public:
|
2014-10-01 11:53:00 +02:00
|
|
|
TestFilter(const int64_t kSampleSize, const std::string& kNewValue)
|
2013-08-03 09:40:22 +02:00
|
|
|
: kSampleSize_(kSampleSize),
|
|
|
|
kNewValue_(kNewValue) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// Works on keys of the form "key<number>"
|
|
|
|
// Drops key if number at the end of key is in [0, kSampleSize_/3),
|
|
|
|
// Keeps key if it is in [kSampleSize_/3, 2*kSampleSize_/3),
|
|
|
|
// Change value if it is in [2*kSampleSize_/3, kSampleSize_)
|
|
|
|
// Eg. kSampleSize_=6. Drop:key0-1...Keep:key2-3...Change:key4-5...
|
2019-02-14 22:52:47 +01:00
|
|
|
bool Filter(int /*level*/, const Slice& key, const Slice& /*value*/,
|
|
|
|
std::string* new_value, bool* value_changed) const override {
|
2013-08-03 09:40:22 +02:00
|
|
|
assert(new_value != nullptr);
|
|
|
|
|
|
|
|
std::string search_str = "0123456789";
|
|
|
|
std::string key_string = key.ToString();
|
|
|
|
size_t pos = key_string.find_first_of(search_str);
|
|
|
|
int num_key_end;
|
|
|
|
if (pos != std::string::npos) {
|
2015-06-08 20:43:55 +02:00
|
|
|
auto key_substr = key_string.substr(pos, key.size() - pos);
|
|
|
|
#ifndef CYGWIN
|
|
|
|
num_key_end = std::stoi(key_substr);
|
|
|
|
#else
|
|
|
|
num_key_end = std::strtol(key_substr.c_str(), 0, 10);
|
|
|
|
#endif
|
|
|
|
|
2013-08-03 09:40:22 +02:00
|
|
|
} else {
|
|
|
|
return false; // Keep keys not matching the format "key<NUMBER>"
|
|
|
|
}
|
|
|
|
|
2014-11-11 22:47:22 +01:00
|
|
|
int64_t partition = kSampleSize_ / 3;
|
2013-08-03 09:40:22 +02:00
|
|
|
if (num_key_end < partition) {
|
|
|
|
return true;
|
|
|
|
} else if (num_key_end < partition * 2) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
*new_value = kNewValue_;
|
|
|
|
*value_changed = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-14 22:52:47 +01:00
|
|
|
const char* Name() const override { return "TestFilter"; }
|
2013-08-03 09:40:22 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
const int64_t kSampleSize_;
|
|
|
|
const std::string kNewValue_;
|
|
|
|
};
|
|
|
|
|
2013-08-13 19:56:20 +02:00
|
|
|
class TestFilterFactory : public CompactionFilterFactory {
|
|
|
|
public:
|
2014-10-01 11:53:00 +02:00
|
|
|
TestFilterFactory(const int64_t kSampleSize, const std::string& kNewValue)
|
2013-08-13 19:56:20 +02:00
|
|
|
: kSampleSize_(kSampleSize),
|
|
|
|
kNewValue_(kNewValue) {
|
|
|
|
}
|
|
|
|
|
2019-02-14 22:52:47 +01:00
|
|
|
std::unique_ptr<CompactionFilter> CreateCompactionFilter(
|
2018-03-05 22:08:17 +01:00
|
|
|
const CompactionFilter::Context& /*context*/) override {
|
2013-08-13 19:56:20 +02:00
|
|
|
return std::unique_ptr<CompactionFilter>(
|
|
|
|
new TestFilter(kSampleSize_, kNewValue_));
|
|
|
|
}
|
|
|
|
|
2019-02-14 22:52:47 +01:00
|
|
|
const char* Name() const override { return "TestFilterFactory"; }
|
2013-08-13 19:56:20 +02:00
|
|
|
|
2019-02-14 22:52:47 +01:00
|
|
|
private:
|
2013-08-13 19:56:20 +02:00
|
|
|
const int64_t kSampleSize_;
|
|
|
|
const std::string kNewValue_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
// Choose carefully so that Put, Gets & Compaction complete in 1 second buffer
|
2015-07-02 01:13:49 +02:00
|
|
|
static const int64_t kSampleSize_ = 100;
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
std::string dbname_;
|
2014-04-29 05:34:20 +02:00
|
|
|
DBWithTTL* db_ttl_;
|
2018-11-09 20:17:34 +01:00
|
|
|
std::unique_ptr<SpecialTimeEnv> env_;
|
2014-04-22 20:27:33 +02:00
|
|
|
|
|
|
|
private:
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
Options options_;
|
|
|
|
KVMap kvmap_;
|
|
|
|
KVMap::iterator kv_it_;
|
2013-08-03 09:40:22 +02:00
|
|
|
const std::string kNewValue_ = "new_value";
|
2018-11-09 20:17:34 +01:00
|
|
|
std::unique_ptr<CompactionFilter> test_comp_filter_;
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
}; // class TtlTest
|
|
|
|
|
|
|
|
// If TTL is non positive or not provided, the behaviour is TTL = infinity
|
|
|
|
// This test opens the db 3 times with such default behavior and inserts a
|
2013-11-16 12:21:34 +01:00
|
|
|
// bunch of kvs each time. All kvs should accumulate in the db till the end
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
// Partitions the sample-size provided into 3 sets over boundary1 and boundary2
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(TtlTest, NoEffect) {
|
2013-08-03 09:40:22 +02:00
|
|
|
MakeKVMap(kSampleSize_);
|
2014-11-11 22:47:22 +01:00
|
|
|
int64_t boundary1 = kSampleSize_ / 3;
|
|
|
|
int64_t boundary2 = 2 * boundary1;
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
|
|
|
|
OpenTtl();
|
|
|
|
PutValues(0, boundary1); //T=0: Set1 never deleted
|
|
|
|
SleepCompactCheck(1, 0, boundary1); //T=1: Set1 still there
|
|
|
|
CloseTtl();
|
|
|
|
|
|
|
|
OpenTtl(0);
|
|
|
|
PutValues(boundary1, boundary2 - boundary1); //T=1: Set2 never deleted
|
|
|
|
SleepCompactCheck(1, 0, boundary2); //T=2: Sets1 & 2 still there
|
|
|
|
CloseTtl();
|
|
|
|
|
|
|
|
OpenTtl(-1);
|
2013-08-03 09:40:22 +02:00
|
|
|
PutValues(boundary2, kSampleSize_ - boundary2); //T=3: Set3 never deleted
|
|
|
|
SleepCompactCheck(1, 0, kSampleSize_, true); //T=4: Sets 1,2,3 still there
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
CloseTtl();
|
|
|
|
}
|
|
|
|
|
2019-06-20 22:04:13 +02:00
|
|
|
// Rerun the NoEffect test with a different version of CloseTtl
|
|
|
|
// function, where db is directly deleted without close.
|
|
|
|
TEST_F(TtlTest, DestructWithoutClose) {
|
|
|
|
MakeKVMap(kSampleSize_);
|
|
|
|
int64_t boundary1 = kSampleSize_ / 3;
|
|
|
|
int64_t boundary2 = 2 * boundary1;
|
|
|
|
|
|
|
|
OpenTtl();
|
2019-09-20 21:00:55 +02:00
|
|
|
PutValues(0, boundary1); // T=0: Set1 never deleted
|
|
|
|
SleepCompactCheck(1, 0, boundary1); // T=1: Set1 still there
|
2019-06-20 22:04:13 +02:00
|
|
|
CloseTtlNoDBClose();
|
|
|
|
|
|
|
|
OpenTtl(0);
|
2019-09-20 21:00:55 +02:00
|
|
|
PutValues(boundary1, boundary2 - boundary1); // T=1: Set2 never deleted
|
|
|
|
SleepCompactCheck(1, 0, boundary2); // T=2: Sets1 & 2 still there
|
2019-06-20 22:04:13 +02:00
|
|
|
CloseTtlNoDBClose();
|
|
|
|
|
|
|
|
OpenTtl(-1);
|
2019-09-20 21:00:55 +02:00
|
|
|
PutValues(boundary2, kSampleSize_ - boundary2); // T=3: Set3 never deleted
|
|
|
|
SleepCompactCheck(1, 0, kSampleSize_, true); // T=4: Sets 1,2,3 still there
|
2019-06-20 22:04:13 +02:00
|
|
|
CloseTtlNoDBClose();
|
|
|
|
}
|
|
|
|
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
// Puts a set of values and checks its presence using Get during ttl
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(TtlTest, PresentDuringTTL) {
|
2013-08-03 09:40:22 +02:00
|
|
|
MakeKVMap(kSampleSize_);
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
|
|
|
|
OpenTtl(2); // T=0:Open the db with ttl = 2
|
2013-08-03 09:40:22 +02:00
|
|
|
PutValues(0, kSampleSize_); // T=0:Insert Set1. Delete at t=2
|
|
|
|
SleepCompactCheck(1, 0, kSampleSize_, true); // T=1:Set1 should still be there
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
CloseTtl();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Puts a set of values and checks its absence using Get after ttl
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(TtlTest, AbsentAfterTTL) {
|
2013-08-03 09:40:22 +02:00
|
|
|
MakeKVMap(kSampleSize_);
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
|
|
|
|
OpenTtl(1); // T=0:Open the db with ttl = 2
|
2013-08-03 09:40:22 +02:00
|
|
|
PutValues(0, kSampleSize_); // T=0:Insert Set1. Delete at t=2
|
|
|
|
SleepCompactCheck(2, 0, kSampleSize_, false); // T=2:Set1 should not be there
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
CloseTtl();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resets the timestamp of a set of kvs by updating them and checks that they
|
|
|
|
// are not deleted according to the old timestamp
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(TtlTest, ResetTimestamp) {
|
2013-08-03 09:40:22 +02:00
|
|
|
MakeKVMap(kSampleSize_);
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
|
|
|
|
OpenTtl(3);
|
2013-08-03 09:40:22 +02:00
|
|
|
PutValues(0, kSampleSize_); // T=0: Insert Set1. Delete at t=3
|
2014-05-02 16:13:51 +02:00
|
|
|
env_->Sleep(2); // T=2
|
2013-08-03 09:40:22 +02:00
|
|
|
PutValues(0, kSampleSize_); // T=2: Insert Set1. Delete at t=5
|
|
|
|
SleepCompactCheck(2, 0, kSampleSize_); // T=4: Set1 should still be there
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
CloseTtl();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Similar to PresentDuringTTL but uses Iterator
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(TtlTest, IterPresentDuringTTL) {
|
2013-08-03 09:40:22 +02:00
|
|
|
MakeKVMap(kSampleSize_);
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
|
|
|
|
OpenTtl(2);
|
2013-08-03 09:40:22 +02:00
|
|
|
PutValues(0, kSampleSize_); // T=0: Insert. Delete at t=2
|
|
|
|
SleepCompactCheckIter(1, 0, kSampleSize_); // T=1: Set should be there
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
CloseTtl();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Similar to AbsentAfterTTL but uses Iterator
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(TtlTest, IterAbsentAfterTTL) {
|
2013-08-03 09:40:22 +02:00
|
|
|
MakeKVMap(kSampleSize_);
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
|
|
|
|
OpenTtl(1);
|
2013-08-03 09:40:22 +02:00
|
|
|
PutValues(0, kSampleSize_); // T=0: Insert. Delete at t=1
|
|
|
|
SleepCompactCheckIter(2, 0, kSampleSize_, false); // T=2: Should not be there
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
CloseTtl();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checks presence while opening the same db more than once with the same ttl
|
|
|
|
// Note: The second open will open the same db
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(TtlTest, MultiOpenSamePresent) {
|
2013-08-03 09:40:22 +02:00
|
|
|
MakeKVMap(kSampleSize_);
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
|
|
|
|
OpenTtl(2);
|
2013-08-03 09:40:22 +02:00
|
|
|
PutValues(0, kSampleSize_); // T=0: Insert. Delete at t=2
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
CloseTtl();
|
|
|
|
|
|
|
|
OpenTtl(2); // T=0. Delete at t=2
|
2013-08-03 09:40:22 +02:00
|
|
|
SleepCompactCheck(1, 0, kSampleSize_); // T=1: Set should be there
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
CloseTtl();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checks absence while opening the same db more than once with the same ttl
|
|
|
|
// Note: The second open will open the same db
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(TtlTest, MultiOpenSameAbsent) {
|
2013-08-03 09:40:22 +02:00
|
|
|
MakeKVMap(kSampleSize_);
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
|
|
|
|
OpenTtl(1);
|
2013-08-03 09:40:22 +02:00
|
|
|
PutValues(0, kSampleSize_); // T=0: Insert. Delete at t=1
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
CloseTtl();
|
|
|
|
|
|
|
|
OpenTtl(1); // T=0.Delete at t=1
|
2013-08-03 09:40:22 +02:00
|
|
|
SleepCompactCheck(2, 0, kSampleSize_, false); // T=2: Set should not be there
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
CloseTtl();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checks presence while opening the same db more than once with bigger ttl
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(TtlTest, MultiOpenDifferent) {
|
2013-08-03 09:40:22 +02:00
|
|
|
MakeKVMap(kSampleSize_);
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
|
|
|
|
OpenTtl(1);
|
2013-08-03 09:40:22 +02:00
|
|
|
PutValues(0, kSampleSize_); // T=0: Insert. Delete at t=1
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
CloseTtl();
|
|
|
|
|
|
|
|
OpenTtl(3); // T=0: Set deleted at t=3
|
2013-08-03 09:40:22 +02:00
|
|
|
SleepCompactCheck(2, 0, kSampleSize_); // T=2: Set should be there
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
CloseTtl();
|
|
|
|
}
|
|
|
|
|
2013-05-10 23:19:47 +02:00
|
|
|
// Checks presence during ttl in read_only mode
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(TtlTest, ReadOnlyPresentForever) {
|
2013-08-03 09:40:22 +02:00
|
|
|
MakeKVMap(kSampleSize_);
|
2013-05-10 23:19:47 +02:00
|
|
|
|
|
|
|
OpenTtl(1); // T=0:Open the db normally
|
2021-01-08 00:21:51 +01:00
|
|
|
PutValues(0, kSampleSize_); // T=0:Insert Set1. Delete at t=1
|
2013-05-10 23:19:47 +02:00
|
|
|
CloseTtl();
|
|
|
|
|
|
|
|
OpenReadOnlyTtl(1);
|
2021-01-08 00:21:51 +01:00
|
|
|
ASSERT_TRUE(db_ttl_);
|
|
|
|
|
|
|
|
env_->Sleep(2);
|
|
|
|
Status s = ManualCompact(); // T=2:Set1 should still be there
|
|
|
|
ASSERT_TRUE(s.IsNotSupported());
|
|
|
|
CompactCheck(0, kSampleSize_);
|
2013-05-16 00:00:57 +02:00
|
|
|
CloseTtl();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checks whether WriteBatch works well with TTL
|
|
|
|
// Puts all kvs in kvmap_ in a batch and writes first, then deletes first half
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(TtlTest, WriteBatchTest) {
|
2013-08-03 09:40:22 +02:00
|
|
|
MakeKVMap(kSampleSize_);
|
|
|
|
BatchOperation batch_ops[kSampleSize_];
|
|
|
|
for (int i = 0; i < kSampleSize_; i++) {
|
2015-07-02 01:13:49 +02:00
|
|
|
batch_ops[i] = OP_PUT;
|
2013-05-16 00:00:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
OpenTtl(2);
|
2013-08-03 09:40:22 +02:00
|
|
|
MakePutWriteBatch(batch_ops, kSampleSize_);
|
|
|
|
for (int i = 0; i < kSampleSize_ / 2; i++) {
|
2015-07-02 01:13:49 +02:00
|
|
|
batch_ops[i] = OP_DELETE;
|
2013-05-16 00:00:57 +02:00
|
|
|
}
|
2013-08-03 09:40:22 +02:00
|
|
|
MakePutWriteBatch(batch_ops, kSampleSize_ / 2);
|
|
|
|
SleepCompactCheck(0, 0, kSampleSize_ / 2, false);
|
|
|
|
SleepCompactCheck(0, kSampleSize_ / 2, kSampleSize_ - kSampleSize_ / 2);
|
|
|
|
CloseTtl();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checks user's compaction filter for correctness with TTL logic
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(TtlTest, CompactionFilter) {
|
2013-08-03 09:40:22 +02:00
|
|
|
MakeKVMap(kSampleSize_);
|
|
|
|
|
|
|
|
OpenTtlWithTestCompaction(1);
|
|
|
|
PutValues(0, kSampleSize_); // T=0:Insert Set1. Delete at t=1
|
|
|
|
// T=2: TTL logic takes precedence over TestFilter:-Set1 should not be there
|
|
|
|
SleepCompactCheck(2, 0, kSampleSize_, false);
|
|
|
|
CloseTtl();
|
|
|
|
|
|
|
|
OpenTtlWithTestCompaction(3);
|
|
|
|
PutValues(0, kSampleSize_); // T=0:Insert Set1.
|
2014-11-11 22:47:22 +01:00
|
|
|
int64_t partition = kSampleSize_ / 3;
|
|
|
|
SleepCompactCheck(1, 0, partition, false); // Part dropped
|
|
|
|
SleepCompactCheck(0, partition, partition); // Part kept
|
2013-08-03 09:40:22 +02:00
|
|
|
SleepCompactCheck(0, 2 * partition, partition, true, true); // Part changed
|
2013-05-10 23:19:47 +02:00
|
|
|
CloseTtl();
|
|
|
|
}
|
|
|
|
|
2013-08-24 02:36:00 +02:00
|
|
|
// Insert some key-values which KeyMayExist should be able to get and check that
|
|
|
|
// values returned are fine
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(TtlTest, KeyMayExist) {
|
2013-08-24 02:36:00 +02:00
|
|
|
MakeKVMap(kSampleSize_);
|
|
|
|
|
|
|
|
OpenTtl();
|
2013-09-02 06:04:20 +02:00
|
|
|
PutValues(0, kSampleSize_, false);
|
2013-08-24 02:36:00 +02:00
|
|
|
|
|
|
|
SimpleKeyMayExistCheck();
|
|
|
|
|
|
|
|
CloseTtl();
|
|
|
|
}
|
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(TtlTest, MultiGetTest) {
|
2014-12-20 12:46:37 +01:00
|
|
|
MakeKVMap(kSampleSize_);
|
|
|
|
|
|
|
|
OpenTtl();
|
|
|
|
PutValues(0, kSampleSize_, false);
|
|
|
|
|
|
|
|
SimpleMultiGetTest();
|
|
|
|
|
|
|
|
CloseTtl();
|
|
|
|
}
|
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(TtlTest, ColumnFamiliesTest) {
|
2014-04-22 20:27:33 +02:00
|
|
|
DB* db;
|
|
|
|
Options options;
|
|
|
|
options.create_if_missing = true;
|
2014-05-02 16:13:51 +02:00
|
|
|
options.env = env_.get();
|
2014-04-22 20:27:33 +02:00
|
|
|
|
|
|
|
DB::Open(options, dbname_, &db);
|
|
|
|
ColumnFamilyHandle* handle;
|
|
|
|
ASSERT_OK(db->CreateColumnFamily(ColumnFamilyOptions(options),
|
|
|
|
"ttl_column_family", &handle));
|
|
|
|
|
|
|
|
delete handle;
|
|
|
|
delete db;
|
|
|
|
|
|
|
|
std::vector<ColumnFamilyDescriptor> column_families;
|
|
|
|
column_families.push_back(ColumnFamilyDescriptor(
|
|
|
|
kDefaultColumnFamilyName, ColumnFamilyOptions(options)));
|
|
|
|
column_families.push_back(ColumnFamilyDescriptor(
|
|
|
|
"ttl_column_family", ColumnFamilyOptions(options)));
|
|
|
|
|
|
|
|
std::vector<ColumnFamilyHandle*> handles;
|
|
|
|
|
2014-04-29 05:34:20 +02:00
|
|
|
ASSERT_OK(DBWithTTL::Open(DBOptions(options), dbname_, column_families,
|
2014-04-29 21:19:54 +02:00
|
|
|
&handles, &db_ttl_, {3, 5}, false));
|
2014-04-22 20:27:33 +02:00
|
|
|
ASSERT_EQ(handles.size(), 2U);
|
2014-04-29 05:34:20 +02:00
|
|
|
ColumnFamilyHandle* new_handle;
|
|
|
|
ASSERT_OK(db_ttl_->CreateColumnFamilyWithTtl(options, "ttl_column_family_2",
|
|
|
|
&new_handle, 2));
|
|
|
|
handles.push_back(new_handle);
|
2014-04-22 20:27:33 +02:00
|
|
|
|
|
|
|
MakeKVMap(kSampleSize_);
|
|
|
|
PutValues(0, kSampleSize_, false, handles[0]);
|
|
|
|
PutValues(0, kSampleSize_, false, handles[1]);
|
2014-04-29 05:34:20 +02:00
|
|
|
PutValues(0, kSampleSize_, false, handles[2]);
|
2014-04-22 20:27:33 +02:00
|
|
|
|
|
|
|
// everything should be there after 1 second
|
|
|
|
SleepCompactCheck(1, 0, kSampleSize_, true, false, handles[0]);
|
|
|
|
SleepCompactCheck(0, 0, kSampleSize_, true, false, handles[1]);
|
2014-04-29 05:34:20 +02:00
|
|
|
SleepCompactCheck(0, 0, kSampleSize_, true, false, handles[2]);
|
2014-04-22 20:27:33 +02:00
|
|
|
|
2014-04-29 21:19:54 +02:00
|
|
|
// only column family 1 should be alive after 4 seconds
|
|
|
|
SleepCompactCheck(3, 0, kSampleSize_, false, false, handles[0]);
|
2014-04-22 20:27:33 +02:00
|
|
|
SleepCompactCheck(0, 0, kSampleSize_, true, false, handles[1]);
|
2014-04-29 05:34:20 +02:00
|
|
|
SleepCompactCheck(0, 0, kSampleSize_, false, false, handles[2]);
|
2014-04-22 20:27:33 +02:00
|
|
|
|
2014-04-29 21:19:54 +02:00
|
|
|
// nothing should be there after 6 seconds
|
2014-04-22 20:27:33 +02:00
|
|
|
SleepCompactCheck(2, 0, kSampleSize_, false, false, handles[0]);
|
|
|
|
SleepCompactCheck(0, 0, kSampleSize_, false, false, handles[1]);
|
2014-04-29 05:34:20 +02:00
|
|
|
SleepCompactCheck(0, 0, kSampleSize_, false, false, handles[2]);
|
2014-04-22 20:27:33 +02:00
|
|
|
|
|
|
|
for (auto h : handles) {
|
|
|
|
delete h;
|
|
|
|
}
|
|
|
|
delete db_ttl_;
|
|
|
|
db_ttl_ = nullptr;
|
|
|
|
}
|
|
|
|
|
2018-01-18 19:41:26 +01:00
|
|
|
// Puts a set of values and checks its absence using Get after ttl
|
|
|
|
TEST_F(TtlTest, ChangeTtlOnOpenDb) {
|
|
|
|
MakeKVMap(kSampleSize_);
|
|
|
|
|
|
|
|
OpenTtl(1); // T=0:Open the db with ttl = 2
|
|
|
|
SetTtl(3);
|
2020-04-20 20:37:36 +02:00
|
|
|
PutValues(0, kSampleSize_); // T=0:Insert Set1. Delete at t=2
|
2018-01-18 19:41:26 +01:00
|
|
|
SleepCompactCheck(2, 0, kSampleSize_, true); // T=2:Set1 should be there
|
|
|
|
CloseTtl();
|
|
|
|
}
|
|
|
|
|
2021-06-18 00:59:53 +02:00
|
|
|
// Test DeleteRange for DBWithTtl
|
|
|
|
TEST_F(TtlTest, DeleteRangeTest) {
|
|
|
|
OpenTtl();
|
|
|
|
ASSERT_OK(db_ttl_->Put(WriteOptions(), "a", "val"));
|
|
|
|
MakeDeleteRange("a", "b");
|
|
|
|
ASSERT_OK(db_ttl_->Put(WriteOptions(), "c", "val"));
|
|
|
|
MakeDeleteRange("b", "d");
|
|
|
|
ASSERT_OK(db_ttl_->Put(WriteOptions(), "e", "val"));
|
|
|
|
MakeDeleteRange("d", "e");
|
|
|
|
// first iteration verifies query correctness in memtable, second verifies
|
|
|
|
// query correctness for a single SST file
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
if (i > 0) {
|
|
|
|
ASSERT_OK(db_ttl_->Flush(FlushOptions()));
|
|
|
|
}
|
|
|
|
std::string value;
|
|
|
|
ASSERT_TRUE(db_ttl_->Get(ReadOptions(), "a", &value).IsNotFound());
|
|
|
|
ASSERT_TRUE(db_ttl_->Get(ReadOptions(), "c", &value).IsNotFound());
|
|
|
|
ASSERT_OK(db_ttl_->Get(ReadOptions(), "e", &value));
|
|
|
|
}
|
|
|
|
CloseTtl();
|
|
|
|
}
|
|
|
|
|
2021-08-06 17:26:23 +02:00
|
|
|
class DummyFilter : public CompactionFilter {
|
|
|
|
public:
|
|
|
|
bool Filter(int /*level*/, const Slice& /*key*/, const Slice& /*value*/,
|
|
|
|
std::string* /*new_value*/,
|
|
|
|
bool* /*value_changed*/) const override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* Name() const override { return kClassName(); }
|
|
|
|
static const char* kClassName() { return "DummyFilter"; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class DummyFilterFactory : public CompactionFilterFactory {
|
|
|
|
public:
|
|
|
|
const char* Name() const override { return kClassName(); }
|
|
|
|
static const char* kClassName() { return "DummyFilterFactory"; }
|
|
|
|
|
|
|
|
std::unique_ptr<CompactionFilter> CreateCompactionFilter(
|
|
|
|
const CompactionFilter::Context&) override {
|
|
|
|
std::unique_ptr<CompactionFilter> f(new DummyFilter());
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static int RegisterTestObjects(ObjectLibrary& library,
|
|
|
|
const std::string& /*arg*/) {
|
2022-01-11 15:32:42 +01:00
|
|
|
library.AddFactory<CompactionFilter>(
|
2021-08-06 17:26:23 +02:00
|
|
|
"DummyFilter", [](const std::string& /*uri*/,
|
|
|
|
std::unique_ptr<CompactionFilter>* /*guard*/,
|
|
|
|
std::string* /* errmsg */) {
|
|
|
|
static DummyFilter dummy;
|
|
|
|
return &dummy;
|
|
|
|
});
|
2022-01-11 15:32:42 +01:00
|
|
|
library.AddFactory<CompactionFilterFactory>(
|
2021-08-06 17:26:23 +02:00
|
|
|
"DummyFilterFactory", [](const std::string& /*uri*/,
|
|
|
|
std::unique_ptr<CompactionFilterFactory>* guard,
|
|
|
|
std::string* /* errmsg */) {
|
|
|
|
guard->reset(new DummyFilterFactory());
|
|
|
|
return guard->get();
|
|
|
|
});
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
class TtlOptionsTest : public testing::Test {
|
|
|
|
public:
|
|
|
|
TtlOptionsTest() {
|
|
|
|
config_options_.registry->AddLibrary("RegisterTtlObjects",
|
|
|
|
RegisterTtlObjects, "");
|
|
|
|
config_options_.registry->AddLibrary("RegisterTtlTestObjects",
|
|
|
|
RegisterTestObjects, "");
|
|
|
|
}
|
|
|
|
ConfigOptions config_options_;
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(TtlOptionsTest, LoadTtlCompactionFilter) {
|
|
|
|
const CompactionFilter* filter = nullptr;
|
|
|
|
|
|
|
|
ASSERT_OK(CompactionFilter::CreateFromString(
|
|
|
|
config_options_, TtlCompactionFilter::kClassName(), &filter));
|
|
|
|
ASSERT_NE(filter, nullptr);
|
|
|
|
ASSERT_STREQ(filter->Name(), TtlCompactionFilter::kClassName());
|
|
|
|
auto ttl = filter->GetOptions<int32_t>("TTL");
|
|
|
|
ASSERT_NE(ttl, nullptr);
|
|
|
|
ASSERT_EQ(*ttl, 0);
|
|
|
|
ASSERT_OK(filter->ValidateOptions(DBOptions(), ColumnFamilyOptions()));
|
|
|
|
delete filter;
|
|
|
|
filter = nullptr;
|
|
|
|
|
|
|
|
ASSERT_OK(CompactionFilter::CreateFromString(
|
|
|
|
config_options_, "id=TtlCompactionFilter; ttl=123", &filter));
|
|
|
|
ASSERT_NE(filter, nullptr);
|
|
|
|
ttl = filter->GetOptions<int32_t>("TTL");
|
|
|
|
ASSERT_NE(ttl, nullptr);
|
|
|
|
ASSERT_EQ(*ttl, 123);
|
|
|
|
ASSERT_OK(filter->ValidateOptions(DBOptions(), ColumnFamilyOptions()));
|
|
|
|
delete filter;
|
|
|
|
filter = nullptr;
|
|
|
|
|
|
|
|
ASSERT_OK(CompactionFilter::CreateFromString(
|
|
|
|
config_options_,
|
|
|
|
"id=TtlCompactionFilter; ttl=456; user_filter=DummyFilter;", &filter));
|
|
|
|
ASSERT_NE(filter, nullptr);
|
|
|
|
auto inner = filter->CheckedCast<DummyFilter>();
|
|
|
|
ASSERT_NE(inner, nullptr);
|
|
|
|
ASSERT_OK(filter->ValidateOptions(DBOptions(), ColumnFamilyOptions()));
|
|
|
|
std::string mismatch;
|
|
|
|
std::string opts_str = filter->ToString(config_options_);
|
|
|
|
const CompactionFilter* copy = nullptr;
|
|
|
|
ASSERT_OK(
|
|
|
|
CompactionFilter::CreateFromString(config_options_, opts_str, ©));
|
|
|
|
ASSERT_TRUE(filter->AreEquivalent(config_options_, copy, &mismatch));
|
|
|
|
delete filter;
|
|
|
|
delete copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TtlOptionsTest, LoadTtlCompactionFilterFactory) {
|
|
|
|
std::shared_ptr<CompactionFilterFactory> cff;
|
|
|
|
|
|
|
|
ASSERT_OK(CompactionFilterFactory::CreateFromString(
|
|
|
|
config_options_, TtlCompactionFilterFactory::kClassName(), &cff));
|
|
|
|
ASSERT_NE(cff.get(), nullptr);
|
|
|
|
ASSERT_STREQ(cff->Name(), TtlCompactionFilterFactory::kClassName());
|
|
|
|
auto ttl = cff->GetOptions<int32_t>("TTL");
|
|
|
|
ASSERT_NE(ttl, nullptr);
|
|
|
|
ASSERT_EQ(*ttl, 0);
|
|
|
|
ASSERT_OK(cff->ValidateOptions(DBOptions(), ColumnFamilyOptions()));
|
|
|
|
|
|
|
|
ASSERT_OK(CompactionFilterFactory::CreateFromString(
|
|
|
|
config_options_, "id=TtlCompactionFilterFactory; ttl=123", &cff));
|
|
|
|
ASSERT_NE(cff.get(), nullptr);
|
|
|
|
ASSERT_STREQ(cff->Name(), TtlCompactionFilterFactory::kClassName());
|
|
|
|
ttl = cff->GetOptions<int32_t>("TTL");
|
|
|
|
ASSERT_NE(ttl, nullptr);
|
|
|
|
ASSERT_EQ(*ttl, 123);
|
|
|
|
ASSERT_OK(cff->ValidateOptions(DBOptions(), ColumnFamilyOptions()));
|
|
|
|
|
|
|
|
ASSERT_OK(CompactionFilterFactory::CreateFromString(
|
|
|
|
config_options_,
|
|
|
|
"id=TtlCompactionFilterFactory; ttl=456; "
|
|
|
|
"user_filter_factory=DummyFilterFactory;",
|
|
|
|
&cff));
|
|
|
|
ASSERT_NE(cff.get(), nullptr);
|
|
|
|
auto filter = cff->CreateCompactionFilter(CompactionFilter::Context());
|
|
|
|
ASSERT_NE(filter.get(), nullptr);
|
|
|
|
auto ttlf = filter->CheckedCast<TtlCompactionFilter>();
|
|
|
|
ASSERT_EQ(filter.get(), ttlf);
|
|
|
|
auto user = filter->CheckedCast<DummyFilter>();
|
|
|
|
ASSERT_NE(user, nullptr);
|
|
|
|
ASSERT_OK(cff->ValidateOptions(DBOptions(), ColumnFamilyOptions()));
|
|
|
|
|
|
|
|
std::string opts_str = cff->ToString(config_options_);
|
|
|
|
std::string mismatch;
|
|
|
|
std::shared_ptr<CompactionFilterFactory> copy;
|
|
|
|
ASSERT_OK(CompactionFilterFactory::CreateFromString(config_options_, opts_str,
|
|
|
|
©));
|
|
|
|
ASSERT_TRUE(cff->AreEquivalent(config_options_, copy.get(), &mismatch));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TtlOptionsTest, LoadTtlMergeOperator) {
|
|
|
|
std::shared_ptr<MergeOperator> mo;
|
|
|
|
|
|
|
|
config_options_.invoke_prepare_options = false;
|
|
|
|
ASSERT_OK(MergeOperator::CreateFromString(
|
|
|
|
config_options_, TtlMergeOperator::kClassName(), &mo));
|
|
|
|
ASSERT_NE(mo.get(), nullptr);
|
|
|
|
ASSERT_STREQ(mo->Name(), TtlMergeOperator::kClassName());
|
|
|
|
ASSERT_NOK(mo->ValidateOptions(DBOptions(), ColumnFamilyOptions()));
|
|
|
|
|
|
|
|
config_options_.invoke_prepare_options = true;
|
|
|
|
ASSERT_OK(MergeOperator::CreateFromString(
|
|
|
|
config_options_, "id=TtlMergeOperator; user_operator=bytesxor", &mo));
|
|
|
|
ASSERT_NE(mo.get(), nullptr);
|
|
|
|
ASSERT_STREQ(mo->Name(), TtlMergeOperator::kClassName());
|
|
|
|
ASSERT_OK(mo->ValidateOptions(DBOptions(), ColumnFamilyOptions()));
|
|
|
|
auto ttl_mo = mo->CheckedCast<TtlMergeOperator>();
|
|
|
|
ASSERT_EQ(mo.get(), ttl_mo);
|
|
|
|
auto user = ttl_mo->CheckedCast<BytesXOROperator>();
|
|
|
|
ASSERT_NE(user, nullptr);
|
|
|
|
|
|
|
|
std::string mismatch;
|
|
|
|
std::string opts_str = mo->ToString(config_options_);
|
|
|
|
std::shared_ptr<MergeOperator> copy;
|
|
|
|
ASSERT_OK(MergeOperator::CreateFromString(config_options_, opts_str, ©));
|
|
|
|
ASSERT_TRUE(mo->AreEquivalent(config_options_, copy.get(), &mismatch));
|
|
|
|
}
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
|
|
|
|
// A black-box test for the ttl wrapper around rocksdb
|
|
|
|
int main(int argc, char** argv) {
|
2015-03-17 22:08:00 +01:00
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
return RUN_ALL_TESTS();
|
Timestamp and TTL Wrapper for rocksdb
Summary:
When opened with DBTimestamp::Open call, timestamps are prepended to and stripped from the value during subsequent Put and Get calls respectively. The Timestamp is used to discard values in Get and custom compaction filter which have exceeded their TTL which is specified during Open.
Have made a temporary change to Makefile to let us test with the temporary file TestTime.cc. Have also changed the private members of db_impl.h to protected to let them be inherited by the new class DBTimestamp
Test Plan: make db_timestamp; TestTime.cc(will not check it in) shows how to use the apis currently, but I will write unit-tests shortly
Reviewers: dhruba, vamsi, haobo, sheki, heyongqiang, vkrest
Reviewed By: vamsi
CC: zshao, xjin, vkrest, MarkCallaghan
Differential Revision: https://reviews.facebook.net/D10311
2013-04-15 22:33:13 +02:00
|
|
|
}
|
2015-07-20 20:24:54 +02:00
|
|
|
|
|
|
|
#else
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2018-04-16 02:19:57 +02:00
|
|
|
int main(int /*argc*/, char** /*argv*/) {
|
2015-07-20 20:24:54 +02:00
|
|
|
fprintf(stderr, "SKIPPED as DBWithTTL is not supported in ROCKSDB_LITE\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !ROCKSDB_LITE
|