]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/include/rocksdb/utilities/date_tiered_db.h
build: use dgit for download target
[ceph.git] / ceph / src / rocksdb / include / rocksdb / utilities / date_tiered_db.h
CommitLineData
7c673cae 1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
11fdf7f2
TL
2// This source code is licensed under both the GPLv2 (found in the
3// COPYING file in the root directory) and Apache 2.0 License
4// (found in the LICENSE.Apache file in the root directory).
7c673cae
FG
5
6#pragma once
7#ifndef ROCKSDB_LITE
8
9#include <map>
10#include <string>
11#include <vector>
12
13#include "rocksdb/db.h"
14
15namespace rocksdb {
16
17// Date tiered database is a wrapper of DB that implements
18// a simplified DateTieredCompactionStrategy by using multiple column famillies
19// as time windows.
20//
21// DateTieredDB provides an interface similar to DB, but it assumes that user
22// provides keys with last 8 bytes encoded as timestamp in seconds. DateTieredDB
23// is assigned with a TTL to declare when data should be deleted.
24//
25// DateTieredDB hides column families layer from standard RocksDB instance. It
26// uses multiple column families to manage time series data, each containing a
27// specific range of time. Column families are named by its maximum possible
28// timestamp. A column family is created automatically when data newer than
29// latest timestamp of all existing column families. The time range of a column
30// family is configurable by `column_family_interval`. By doing this, we
31// guarantee that compaction will only happen in a column family.
32//
33// DateTieredDB is assigned with a TTL. When all data in a column family are
34// expired (CF_Timestamp <= CUR_Timestamp - TTL), we directly drop the whole
35// column family.
36//
37// TODO(jhli): This is only a simplified version of DTCS. In a complete DTCS,
38// time windows can be merged over time, so that older time windows will have
39// larger time range. Also, compaction are executed only for adjacent SST files
40// to guarantee there is no time overlap between SST files.
41
42class DateTieredDB {
43 public:
44 // Open a DateTieredDB whose name is `dbname`.
45 // Similar to DB::Open(), created database object is stored in dbptr.
46 //
47 // Two parameters can be configured: `ttl` to specify the length of time that
48 // keys should exist in the database, and `column_family_interval` to specify
49 // the time range of a column family interval.
50 //
51 // Open a read only database if read only is set as true.
52 // TODO(jhli): Should use an option object that includes ttl and
53 // column_family_interval.
54 static Status Open(const Options& options, const std::string& dbname,
55 DateTieredDB** dbptr, int64_t ttl,
56 int64_t column_family_interval, bool read_only = false);
57
58 explicit DateTieredDB() {}
59
60 virtual ~DateTieredDB() {}
61
62 // Wrapper for Put method. Similar to DB::Put(), but column family to be
63 // inserted is decided by the timestamp in keys, i.e. the last 8 bytes of user
64 // key. If key is already obsolete, it will not be inserted.
65 //
66 // When client put a key value pair in DateTieredDB, it assumes last 8 bytes
67 // of keys are encoded as timestamp. Timestamp is a 64-bit signed integer
68 // encoded as the number of seconds since 1970-01-01 00:00:00 (UTC) (Same as
69 // Env::GetCurrentTime()). Timestamp should be encoded in big endian.
70 virtual Status Put(const WriteOptions& options, const Slice& key,
71 const Slice& val) = 0;
72
73 // Wrapper for Get method. Similar to DB::Get() but column family is decided
74 // by timestamp in keys. If key is already obsolete, it will not be found.
75 virtual Status Get(const ReadOptions& options, const Slice& key,
76 std::string* value) = 0;
77
78 // Wrapper for Delete method. Similar to DB::Delete() but column family is
79 // decided by timestamp in keys. If key is already obsolete, return NotFound
80 // status.
81 virtual Status Delete(const WriteOptions& options, const Slice& key) = 0;
82
83 // Wrapper for KeyMayExist method. Similar to DB::KeyMayExist() but column
84 // family is decided by timestamp in keys. Return false when key is already
85 // obsolete.
86 virtual bool KeyMayExist(const ReadOptions& options, const Slice& key,
87 std::string* value, bool* value_found = nullptr) = 0;
88
89 // Wrapper for Merge method. Similar to DB::Merge() but column family is
90 // decided by timestamp in keys.
91 virtual Status Merge(const WriteOptions& options, const Slice& key,
92 const Slice& value) = 0;
93
94 // Create an iterator that hides low level details. This iterator internally
95 // merge results from all active time series column families. Note that
96 // column families are not deleted until all data are obsolete, so this
97 // iterator can possibly access obsolete key value pairs.
98 virtual Iterator* NewIterator(const ReadOptions& opts) = 0;
99
100 // Explicitly drop column families in which all keys are obsolete. This
101 // process is also inplicitly done in Put() operation.
102 virtual Status DropObsoleteColumnFamilies() = 0;
103
104 static const uint64_t kTSLength = sizeof(int64_t); // size of timestamp
105};
106
107} // namespace rocksdb
108#endif // ROCKSDB_LITE