2019-04-18 17:51:19 +00: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 20:33:13 +00: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.
|
|
|
|
|
2013-10-05 05:32:05 +00:00
|
|
|
#pragma once
|
2014-04-22 18:27:33 +00:00
|
|
|
|
2014-03-25 00:57:13 +00:00
|
|
|
#include <deque>
|
|
|
|
#include <string>
|
2014-04-22 18:27:33 +00:00
|
|
|
#include <vector>
|
2014-03-25 00:57:13 +00:00
|
|
|
|
2019-05-31 22:21:36 +00:00
|
|
|
#include "db/db_impl/db_impl.h"
|
|
|
|
#include "rocksdb/compaction_filter.h"
|
2013-08-23 15:38:13 +00:00
|
|
|
#include "rocksdb/db.h"
|
|
|
|
#include "rocksdb/merge_operator.h"
|
2021-03-15 11:32:24 +00:00
|
|
|
#include "rocksdb/system_clock.h"
|
2014-07-23 14:21:38 +00:00
|
|
|
#include "rocksdb/utilities/db_ttl.h"
|
2020-06-30 00:30:04 +00:00
|
|
|
#include "utilities/compaction_filters/layered_compaction_filter_base.h"
|
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 20:33:13 +00:00
|
|
|
|
2015-07-16 19:10:16 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
// Windows API macro interference
|
|
|
|
#undef GetCurrentTime
|
|
|
|
#endif
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2021-08-06 15:26:23 +00:00
|
|
|
struct ConfigOptions;
|
|
|
|
class ObjectLibrary;
|
|
|
|
class ObjectRegistry;
|
2014-04-29 03:34:20 +00:00
|
|
|
class DBWithTTLImpl : public DBWithTTL {
|
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 20:33:13 +00:00
|
|
|
public:
|
2014-05-02 14:13:51 +00:00
|
|
|
static void SanitizeOptions(int32_t ttl, ColumnFamilyOptions* options,
|
2021-03-15 11:32:24 +00:00
|
|
|
SystemClock* clock);
|
2013-12-07 00:10:43 +00:00
|
|
|
|
2021-08-06 15:26:23 +00:00
|
|
|
static void RegisterTtlClasses();
|
2014-04-29 03:34:20 +00:00
|
|
|
explicit DBWithTTLImpl(DB* db);
|
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 20:33:13 +00:00
|
|
|
|
2014-04-29 03:34:20 +00:00
|
|
|
virtual ~DBWithTTLImpl();
|
|
|
|
|
2024-01-31 21:14:42 +00:00
|
|
|
Status Close() override;
|
2019-06-20 20:04:13 +00:00
|
|
|
|
2014-04-29 03:34:20 +00:00
|
|
|
Status CreateColumnFamilyWithTtl(const ColumnFamilyOptions& options,
|
|
|
|
const std::string& column_family_name,
|
|
|
|
ColumnFamilyHandle** handle,
|
|
|
|
int ttl) override;
|
|
|
|
|
|
|
|
Status CreateColumnFamily(const ColumnFamilyOptions& options,
|
|
|
|
const std::string& column_family_name,
|
|
|
|
ColumnFamilyHandle** handle) 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 20:33:13 +00:00
|
|
|
|
[RocksDB] [Column Family] Interface proposal
Summary:
<This diff is for Column Family branch>
Sharing some of the work I've done so far. This diff compiles and passes the tests.
The biggest change is in options.h - I broke down Options into two parts - DBOptions and ColumnFamilyOptions. DBOptions is DB-specific (env, create_if_missing, block_cache, etc.) and ColumnFamilyOptions is column family-specific (all compaction options, compresion options, etc.). Note that this does not break backwards compatibility at all.
Further, I created DBWithColumnFamily which inherits DB interface and adds new functions with column family support. Clients can transparently switch to DBWithColumnFamily and it will not break their backwards compatibility.
There are few methods worth checking out: ListColumnFamilies(), MultiNewIterator(), MultiGet() and GetSnapshot(). [GetSnapshot() returns the snapshot across all column families for now - I think that's what we agreed on]
Finally, I made small changes to WriteBatch so we are able to atomically insert data across column families.
Please provide feedback.
Test Plan: make check works, the code is backward compatible
Reviewers: dhruba, haobo, sdong, kailiu, emayanke
CC: leveldb
Differential Revision: https://reviews.facebook.net/D14445
2013-12-03 19:14:09 +00:00
|
|
|
using StackableDB::Put;
|
2024-01-31 21:14:42 +00:00
|
|
|
Status Put(const WriteOptions& options, ColumnFamilyHandle* column_family,
|
|
|
|
const Slice& key, const Slice& val) 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 20:33:13 +00:00
|
|
|
|
[RocksDB] [Column Family] Interface proposal
Summary:
<This diff is for Column Family branch>
Sharing some of the work I've done so far. This diff compiles and passes the tests.
The biggest change is in options.h - I broke down Options into two parts - DBOptions and ColumnFamilyOptions. DBOptions is DB-specific (env, create_if_missing, block_cache, etc.) and ColumnFamilyOptions is column family-specific (all compaction options, compresion options, etc.). Note that this does not break backwards compatibility at all.
Further, I created DBWithColumnFamily which inherits DB interface and adds new functions with column family support. Clients can transparently switch to DBWithColumnFamily and it will not break their backwards compatibility.
There are few methods worth checking out: ListColumnFamilies(), MultiNewIterator(), MultiGet() and GetSnapshot(). [GetSnapshot() returns the snapshot across all column families for now - I think that's what we agreed on]
Finally, I made small changes to WriteBatch so we are able to atomically insert data across column families.
Please provide feedback.
Test Plan: make check works, the code is backward compatible
Reviewers: dhruba, haobo, sdong, kailiu, emayanke
CC: leveldb
Differential Revision: https://reviews.facebook.net/D14445
2013-12-03 19:14:09 +00:00
|
|
|
using StackableDB::Get;
|
2024-01-31 21:14:42 +00:00
|
|
|
Status Get(const ReadOptions& options, ColumnFamilyHandle* column_family,
|
2024-02-16 17:21:06 +00:00
|
|
|
const Slice& key, PinnableSlice* value,
|
|
|
|
std::string* timestamp) 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 20:33:13 +00:00
|
|
|
|
[RocksDB] [Column Family] Interface proposal
Summary:
<This diff is for Column Family branch>
Sharing some of the work I've done so far. This diff compiles and passes the tests.
The biggest change is in options.h - I broke down Options into two parts - DBOptions and ColumnFamilyOptions. DBOptions is DB-specific (env, create_if_missing, block_cache, etc.) and ColumnFamilyOptions is column family-specific (all compaction options, compresion options, etc.). Note that this does not break backwards compatibility at all.
Further, I created DBWithColumnFamily which inherits DB interface and adds new functions with column family support. Clients can transparently switch to DBWithColumnFamily and it will not break their backwards compatibility.
There are few methods worth checking out: ListColumnFamilies(), MultiNewIterator(), MultiGet() and GetSnapshot(). [GetSnapshot() returns the snapshot across all column families for now - I think that's what we agreed on]
Finally, I made small changes to WriteBatch so we are able to atomically insert data across column families.
Please provide feedback.
Test Plan: make check works, the code is backward compatible
Reviewers: dhruba, haobo, sdong, kailiu, emayanke
CC: leveldb
Differential Revision: https://reviews.facebook.net/D14445
2013-12-03 19:14:09 +00:00
|
|
|
using StackableDB::MultiGet;
|
2024-02-16 17:21:06 +00:00
|
|
|
void MultiGet(const ReadOptions& options, const size_t num_keys,
|
|
|
|
ColumnFamilyHandle** column_families, const Slice* keys,
|
|
|
|
PinnableSlice* values, std::string* timestamps,
|
|
|
|
Status* statuses, const bool sorted_input) override;
|
2013-06-05 18:22:38 +00:00
|
|
|
|
[RocksDB] [Column Family] Interface proposal
Summary:
<This diff is for Column Family branch>
Sharing some of the work I've done so far. This diff compiles and passes the tests.
The biggest change is in options.h - I broke down Options into two parts - DBOptions and ColumnFamilyOptions. DBOptions is DB-specific (env, create_if_missing, block_cache, etc.) and ColumnFamilyOptions is column family-specific (all compaction options, compresion options, etc.). Note that this does not break backwards compatibility at all.
Further, I created DBWithColumnFamily which inherits DB interface and adds new functions with column family support. Clients can transparently switch to DBWithColumnFamily and it will not break their backwards compatibility.
There are few methods worth checking out: ListColumnFamilies(), MultiNewIterator(), MultiGet() and GetSnapshot(). [GetSnapshot() returns the snapshot across all column families for now - I think that's what we agreed on]
Finally, I made small changes to WriteBatch so we are able to atomically insert data across column families.
Please provide feedback.
Test Plan: make check works, the code is backward compatible
Reviewers: dhruba, haobo, sdong, kailiu, emayanke
CC: leveldb
Differential Revision: https://reviews.facebook.net/D14445
2013-12-03 19:14:09 +00:00
|
|
|
using StackableDB::KeyMayExist;
|
2024-01-31 21:14:42 +00:00
|
|
|
bool KeyMayExist(const ReadOptions& options,
|
|
|
|
ColumnFamilyHandle* column_family, const Slice& key,
|
|
|
|
std::string* value, bool* value_found = nullptr) override;
|
2013-07-06 01:49:18 +00:00
|
|
|
|
[RocksDB] [Column Family] Interface proposal
Summary:
<This diff is for Column Family branch>
Sharing some of the work I've done so far. This diff compiles and passes the tests.
The biggest change is in options.h - I broke down Options into two parts - DBOptions and ColumnFamilyOptions. DBOptions is DB-specific (env, create_if_missing, block_cache, etc.) and ColumnFamilyOptions is column family-specific (all compaction options, compresion options, etc.). Note that this does not break backwards compatibility at all.
Further, I created DBWithColumnFamily which inherits DB interface and adds new functions with column family support. Clients can transparently switch to DBWithColumnFamily and it will not break their backwards compatibility.
There are few methods worth checking out: ListColumnFamilies(), MultiNewIterator(), MultiGet() and GetSnapshot(). [GetSnapshot() returns the snapshot across all column families for now - I think that's what we agreed on]
Finally, I made small changes to WriteBatch so we are able to atomically insert data across column families.
Please provide feedback.
Test Plan: make check works, the code is backward compatible
Reviewers: dhruba, haobo, sdong, kailiu, emayanke
CC: leveldb
Differential Revision: https://reviews.facebook.net/D14445
2013-12-03 19:14:09 +00:00
|
|
|
using StackableDB::Merge;
|
2024-01-31 21:14:42 +00:00
|
|
|
Status Merge(const WriteOptions& options, ColumnFamilyHandle* column_family,
|
|
|
|
const Slice& key, const Slice& value) 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 20:33:13 +00:00
|
|
|
|
2024-01-31 21:14:42 +00:00
|
|
|
Status Write(const WriteOptions& opts, WriteBatch* updates) 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 20:33:13 +00:00
|
|
|
|
[RocksDB] [Column Family] Interface proposal
Summary:
<This diff is for Column Family branch>
Sharing some of the work I've done so far. This diff compiles and passes the tests.
The biggest change is in options.h - I broke down Options into two parts - DBOptions and ColumnFamilyOptions. DBOptions is DB-specific (env, create_if_missing, block_cache, etc.) and ColumnFamilyOptions is column family-specific (all compaction options, compresion options, etc.). Note that this does not break backwards compatibility at all.
Further, I created DBWithColumnFamily which inherits DB interface and adds new functions with column family support. Clients can transparently switch to DBWithColumnFamily and it will not break their backwards compatibility.
There are few methods worth checking out: ListColumnFamilies(), MultiNewIterator(), MultiGet() and GetSnapshot(). [GetSnapshot() returns the snapshot across all column families for now - I think that's what we agreed on]
Finally, I made small changes to WriteBatch so we are able to atomically insert data across column families.
Please provide feedback.
Test Plan: make check works, the code is backward compatible
Reviewers: dhruba, haobo, sdong, kailiu, emayanke
CC: leveldb
Differential Revision: https://reviews.facebook.net/D14445
2013-12-03 19:14:09 +00:00
|
|
|
using StackableDB::NewIterator;
|
2024-01-31 21:14:42 +00:00
|
|
|
Iterator* NewIterator(const ReadOptions& _read_options,
|
|
|
|
ColumnFamilyHandle* column_family) 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 20:33:13 +00:00
|
|
|
|
2024-01-31 21:14:42 +00:00
|
|
|
DB* GetBaseDB() override { return db_; }
|
2013-08-06 00:55:44 +00:00
|
|
|
|
2021-03-15 11:32:24 +00:00
|
|
|
static bool IsStale(const Slice& value, int32_t ttl, SystemClock* clock);
|
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 20:33:13 +00:00
|
|
|
|
2021-03-15 11:32:24 +00:00
|
|
|
static Status AppendTS(const Slice& val, std::string* val_with_ts,
|
|
|
|
SystemClock* clock);
|
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 20:33:13 +00:00
|
|
|
|
2013-06-20 18:50:33 +00:00
|
|
|
static Status SanityCheckTimestamp(const Slice& str);
|
2013-05-10 00:33:27 +00: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 20:33:13 +00:00
|
|
|
static Status StripTS(std::string* str);
|
|
|
|
|
2017-03-13 18:44:50 +00:00
|
|
|
static Status StripTS(PinnableSlice* str);
|
|
|
|
|
2014-04-29 03:34:20 +00:00
|
|
|
static const uint32_t kTSLength = sizeof(int32_t); // size of timestamp
|
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 20:33:13 +00:00
|
|
|
|
2014-04-29 03:34:20 +00:00
|
|
|
static const int32_t kMinTimestamp = 1368146402; // 05/09/2013:5:40PM GMT-8
|
2013-06-19 02:57:54 +00:00
|
|
|
|
2014-04-29 03:34:20 +00:00
|
|
|
static const int32_t kMaxTimestamp = 2147483647; // 01/18/2038:7:14PM GMT-8
|
2018-01-18 18:41:26 +00:00
|
|
|
|
|
|
|
void SetTtl(int32_t ttl) override { SetTtl(DefaultColumnFamily(), ttl); }
|
|
|
|
|
2022-10-24 23:38:09 +00:00
|
|
|
void SetTtl(ColumnFamilyHandle* h, int32_t ttl) override;
|
2019-06-20 20:04:13 +00:00
|
|
|
|
|
|
|
private:
|
2019-09-20 19:00:55 +00:00
|
|
|
// remember whether the Close completes or not
|
|
|
|
bool closed_;
|
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 20:33:13 +00:00
|
|
|
};
|
|
|
|
|
2013-06-19 02:57:54 +00:00
|
|
|
class TtlIterator : public Iterator {
|
|
|
|
public:
|
2014-04-29 03:34:20 +00:00
|
|
|
explicit TtlIterator(Iterator* iter) : iter_(iter) { assert(iter_); }
|
2013-06-19 02:57:54 +00:00
|
|
|
|
2014-04-29 03:34:20 +00:00
|
|
|
~TtlIterator() { delete iter_; }
|
2013-06-19 02:57:54 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
bool Valid() const override { return iter_->Valid(); }
|
2013-06-19 02:57:54 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
void SeekToFirst() override { iter_->SeekToFirst(); }
|
2013-06-19 02:57:54 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
void SeekToLast() override { iter_->SeekToLast(); }
|
2013-06-19 02:57:54 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
void Seek(const Slice& target) override { iter_->Seek(target); }
|
2013-06-19 02:57:54 +00:00
|
|
|
|
2016-09-28 01:20:57 +00:00
|
|
|
void SeekForPrev(const Slice& target) override { iter_->SeekForPrev(target); }
|
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
void Next() override { iter_->Next(); }
|
2013-06-19 02:57:54 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
void Prev() override { iter_->Prev(); }
|
2013-06-19 02:57:54 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
Slice key() const override { return iter_->key(); }
|
2013-06-19 02:57:54 +00:00
|
|
|
|
2020-03-07 00:21:03 +00:00
|
|
|
int32_t ttl_timestamp() const {
|
2014-04-29 03:34:20 +00:00
|
|
|
return DecodeFixed32(iter_->value().data() + iter_->value().size() -
|
|
|
|
DBWithTTLImpl::kTSLength);
|
2013-06-19 02:57:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
Slice value() const override {
|
2014-04-29 03:34:20 +00:00
|
|
|
// TODO: handle timestamp corruption like in general iterator semantics
|
|
|
|
assert(DBWithTTLImpl::SanityCheckTimestamp(iter_->value()).ok());
|
2013-06-19 02:57:54 +00:00
|
|
|
Slice trimmed_value = iter_->value();
|
2014-04-29 03:34:20 +00:00
|
|
|
trimmed_value.size_ -= DBWithTTLImpl::kTSLength;
|
2013-06-19 02:57:54 +00:00
|
|
|
return trimmed_value;
|
|
|
|
}
|
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
Status status() const override { return iter_->status(); }
|
2013-06-19 02:57:54 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Iterator* iter_;
|
|
|
|
};
|
|
|
|
|
2020-06-30 00:30:04 +00:00
|
|
|
class TtlCompactionFilter : public LayeredCompactionFilterBase {
|
2013-08-03 07:40:22 +00:00
|
|
|
public:
|
2021-03-15 11:32:24 +00:00
|
|
|
TtlCompactionFilter(int32_t ttl, SystemClock* clock,
|
2020-06-30 00:30:04 +00:00
|
|
|
const CompactionFilter* _user_comp_filter,
|
|
|
|
std::unique_ptr<const CompactionFilter>
|
2021-08-06 15:26:23 +00:00
|
|
|
_user_comp_filter_from_factory = nullptr);
|
2013-08-03 07:40:22 +00:00
|
|
|
|
2024-01-31 21:14:42 +00:00
|
|
|
bool Filter(int level, const Slice& key, const Slice& old_val,
|
|
|
|
std::string* new_val, bool* value_changed) const override;
|
2021-08-06 15:26:23 +00:00
|
|
|
|
|
|
|
const char* Name() const override { return kClassName(); }
|
|
|
|
static const char* kClassName() { return "TtlCompactionFilter"; }
|
|
|
|
bool IsInstanceOf(const std::string& name) const override {
|
|
|
|
if (name == "Delete By TTL") {
|
2013-08-03 07:40:22 +00:00
|
|
|
return true;
|
2021-08-06 15:26:23 +00:00
|
|
|
} else {
|
|
|
|
return LayeredCompactionFilterBase::IsInstanceOf(name);
|
2013-08-03 07:40:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-06 15:26:23 +00:00
|
|
|
Status PrepareOptions(const ConfigOptions& config_options) override;
|
|
|
|
Status ValidateOptions(const DBOptions& db_opts,
|
|
|
|
const ColumnFamilyOptions& cf_opts) const override;
|
2013-08-03 07:40:22 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
int32_t ttl_;
|
2021-03-15 11:32:24 +00:00
|
|
|
SystemClock* clock_;
|
2013-08-13 17:56:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class TtlCompactionFilterFactory : public CompactionFilterFactory {
|
2014-04-29 03:34:20 +00:00
|
|
|
public:
|
|
|
|
TtlCompactionFilterFactory(
|
2021-03-15 11:32:24 +00:00
|
|
|
int32_t ttl, SystemClock* clock,
|
2021-08-06 15:26:23 +00:00
|
|
|
std::shared_ptr<CompactionFilterFactory> comp_filter_factory);
|
2013-08-13 17:56:20 +00:00
|
|
|
|
2021-08-06 15:26:23 +00:00
|
|
|
std::unique_ptr<CompactionFilter> CreateCompactionFilter(
|
|
|
|
const CompactionFilter::Context& context) override;
|
2022-10-24 23:38:09 +00:00
|
|
|
void SetTtl(int32_t ttl) { ttl_ = ttl; }
|
2018-01-18 18:41:26 +00:00
|
|
|
|
2021-08-06 15:26:23 +00:00
|
|
|
const char* Name() const override { return kClassName(); }
|
|
|
|
static const char* kClassName() { return "TtlCompactionFilterFactory"; }
|
|
|
|
Status PrepareOptions(const ConfigOptions& config_options) override;
|
|
|
|
Status ValidateOptions(const DBOptions& db_opts,
|
|
|
|
const ColumnFamilyOptions& cf_opts) const override;
|
|
|
|
const Customizable* Inner() const override {
|
|
|
|
return user_comp_filter_factory_.get();
|
2014-04-29 03:34:20 +00:00
|
|
|
}
|
2013-08-13 17:56:20 +00:00
|
|
|
|
2014-04-29 03:34:20 +00:00
|
|
|
private:
|
|
|
|
int32_t ttl_;
|
2021-03-15 11:32:24 +00:00
|
|
|
SystemClock* clock_;
|
2014-04-29 03:34:20 +00:00
|
|
|
std::shared_ptr<CompactionFilterFactory> user_comp_filter_factory_;
|
2013-08-03 07:40:22 +00:00
|
|
|
};
|
|
|
|
|
2013-07-22 23:49:55 +00:00
|
|
|
class TtlMergeOperator : public MergeOperator {
|
|
|
|
public:
|
2014-09-26 17:35:20 +00:00
|
|
|
explicit TtlMergeOperator(const std::shared_ptr<MergeOperator>& merge_op,
|
2021-08-06 15:26:23 +00:00
|
|
|
SystemClock* clock);
|
2013-07-22 23:49:55 +00:00
|
|
|
|
2021-08-06 15:26:23 +00:00
|
|
|
bool FullMergeV2(const MergeOperationInput& merge_in,
|
|
|
|
MergeOperationOutput* merge_out) const override;
|
[RocksDB] [MergeOperator] The new Merge Interface! Uses merge sequences.
Summary:
Here are the major changes to the Merge Interface. It has been expanded
to handle cases where the MergeOperator is not associative. It does so by stacking
up merge operations while scanning through the key history (i.e.: during Get() or
Compaction), until a valid Put/Delete/end-of-history is encountered; it then
applies all of the merge operations in the correct sequence starting with the
base/sentinel value.
I have also introduced an "AssociativeMerge" function which allows the user to
take advantage of associative merge operations (such as in the case of counters).
The implementation will always attempt to merge the operations/operands themselves
together when they are encountered, and will resort to the "stacking" method if
and only if the "associative-merge" fails.
This implementation is conjectured to allow MergeOperator to handle the general
case, while still providing the user with the ability to take advantage of certain
efficiencies in their own merge-operator / data-structure.
NOTE: This is a preliminary diff. This must still go through a lot of review,
revision, and testing. Feedback welcome!
Test Plan:
-This is a preliminary diff. I have only just begun testing/debugging it.
-I will be testing this with the existing MergeOperator use-cases and unit-tests
(counters, string-append, and redis-lists)
-I will be "desk-checking" and walking through the code with the help gdb.
-I will find a way of stress-testing the new interface / implementation using
db_bench, db_test, merge_test, and/or db_stress.
-I will ensure that my tests cover all cases: Get-Memtable,
Get-Immutable-Memtable, Get-from-Disk, Iterator-Range-Scan, Flush-Memtable-to-L0,
Compaction-L0-L1, Compaction-Ln-L(n+1), Put/Delete found, Put/Delete not-found,
end-of-history, end-of-file, etc.
-A lot of feedback from the reviewers.
Reviewers: haobo, dhruba, zshao, emayanke
Reviewed By: haobo
CC: leveldb
Differential Revision: https://reviews.facebook.net/D11499
2013-08-06 03:14:32 +00:00
|
|
|
|
2021-08-06 15:26:23 +00:00
|
|
|
bool PartialMergeMulti(const Slice& key,
|
|
|
|
const std::deque<Slice>& operand_list,
|
|
|
|
std::string* new_value, Logger* logger) const override;
|
[RocksDB] [MergeOperator] The new Merge Interface! Uses merge sequences.
Summary:
Here are the major changes to the Merge Interface. It has been expanded
to handle cases where the MergeOperator is not associative. It does so by stacking
up merge operations while scanning through the key history (i.e.: during Get() or
Compaction), until a valid Put/Delete/end-of-history is encountered; it then
applies all of the merge operations in the correct sequence starting with the
base/sentinel value.
I have also introduced an "AssociativeMerge" function which allows the user to
take advantage of associative merge operations (such as in the case of counters).
The implementation will always attempt to merge the operations/operands themselves
together when they are encountered, and will resort to the "stacking" method if
and only if the "associative-merge" fails.
This implementation is conjectured to allow MergeOperator to handle the general
case, while still providing the user with the ability to take advantage of certain
efficiencies in their own merge-operator / data-structure.
NOTE: This is a preliminary diff. This must still go through a lot of review,
revision, and testing. Feedback welcome!
Test Plan:
-This is a preliminary diff. I have only just begun testing/debugging it.
-I will be testing this with the existing MergeOperator use-cases and unit-tests
(counters, string-append, and redis-lists)
-I will be "desk-checking" and walking through the code with the help gdb.
-I will find a way of stress-testing the new interface / implementation using
db_bench, db_test, merge_test, and/or db_stress.
-I will ensure that my tests cover all cases: Get-Memtable,
Get-Immutable-Memtable, Get-from-Disk, Iterator-Range-Scan, Flush-Memtable-to-L0,
Compaction-L0-L1, Compaction-Ln-L(n+1), Put/Delete found, Put/Delete not-found,
end-of-history, end-of-file, etc.
-A lot of feedback from the reviewers.
Reviewers: haobo, dhruba, zshao, emayanke
Reviewed By: haobo
CC: leveldb
Differential Revision: https://reviews.facebook.net/D11499
2013-08-06 03:14:32 +00:00
|
|
|
|
2021-08-06 15:26:23 +00:00
|
|
|
static const char* kClassName() { return "TtlMergeOperator"; }
|
2013-08-19 18:42:47 +00:00
|
|
|
|
2021-08-06 15:26:23 +00:00
|
|
|
const char* Name() const override { return kClassName(); }
|
|
|
|
bool IsInstanceOf(const std::string& name) const override {
|
|
|
|
if (name == "Merge By TTL") {
|
[RocksDB] [MergeOperator] The new Merge Interface! Uses merge sequences.
Summary:
Here are the major changes to the Merge Interface. It has been expanded
to handle cases where the MergeOperator is not associative. It does so by stacking
up merge operations while scanning through the key history (i.e.: during Get() or
Compaction), until a valid Put/Delete/end-of-history is encountered; it then
applies all of the merge operations in the correct sequence starting with the
base/sentinel value.
I have also introduced an "AssociativeMerge" function which allows the user to
take advantage of associative merge operations (such as in the case of counters).
The implementation will always attempt to merge the operations/operands themselves
together when they are encountered, and will resort to the "stacking" method if
and only if the "associative-merge" fails.
This implementation is conjectured to allow MergeOperator to handle the general
case, while still providing the user with the ability to take advantage of certain
efficiencies in their own merge-operator / data-structure.
NOTE: This is a preliminary diff. This must still go through a lot of review,
revision, and testing. Feedback welcome!
Test Plan:
-This is a preliminary diff. I have only just begun testing/debugging it.
-I will be testing this with the existing MergeOperator use-cases and unit-tests
(counters, string-append, and redis-lists)
-I will be "desk-checking" and walking through the code with the help gdb.
-I will find a way of stress-testing the new interface / implementation using
db_bench, db_test, merge_test, and/or db_stress.
-I will ensure that my tests cover all cases: Get-Memtable,
Get-Immutable-Memtable, Get-from-Disk, Iterator-Range-Scan, Flush-Memtable-to-L0,
Compaction-L0-L1, Compaction-Ln-L(n+1), Put/Delete found, Put/Delete not-found,
end-of-history, end-of-file, etc.
-A lot of feedback from the reviewers.
Reviewers: haobo, dhruba, zshao, emayanke
Reviewed By: haobo
CC: leveldb
Differential Revision: https://reviews.facebook.net/D11499
2013-08-06 03:14:32 +00:00
|
|
|
return true;
|
2013-07-22 23:49:55 +00:00
|
|
|
} else {
|
2021-08-06 15:26:23 +00:00
|
|
|
return MergeOperator::IsInstanceOf(name);
|
2013-07-22 23:49:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-06 15:26:23 +00:00
|
|
|
Status PrepareOptions(const ConfigOptions& config_options) override;
|
|
|
|
Status ValidateOptions(const DBOptions& db_opts,
|
|
|
|
const ColumnFamilyOptions& cf_opts) const override;
|
|
|
|
const Customizable* Inner() const override { return user_merge_op_.get(); }
|
2013-07-22 23:49:55 +00:00
|
|
|
|
|
|
|
private:
|
2013-08-20 20:35:28 +00:00
|
|
|
std::shared_ptr<MergeOperator> user_merge_op_;
|
2021-03-15 11:32:24 +00:00
|
|
|
SystemClock* clock_;
|
2013-07-22 23:49:55 +00:00
|
|
|
};
|
2021-08-06 15:26:23 +00:00
|
|
|
extern "C" {
|
|
|
|
int RegisterTtlObjects(ObjectLibrary& library, const std::string& /*arg*/);
|
|
|
|
} // extern "C"
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|