YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/rocksdb/utilities/db_ttl.h
Line
Count
Source
1
//  Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2
//  This source code is licensed under the BSD-style license found in the
3
//  LICENSE file in the root directory of this source tree. An additional grant
4
//  of patent rights can be found in the PATENTS file in the same directory.
5
//
6
// The following only applies to changes made to this file as part of YugaByte development.
7
//
8
// Portions Copyright (c) YugaByte, Inc.
9
//
10
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
11
// in compliance with the License.  You may obtain a copy of the License at
12
//
13
// http://www.apache.org/licenses/LICENSE-2.0
14
//
15
// Unless required by applicable law or agreed to in writing, software distributed under the License
16
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
17
// or implied.  See the License for the specific language governing permissions and limitations
18
// under the License.
19
//
20
21
#pragma once
22
#ifndef ROCKSDB_LITE
23
24
#include <string>
25
#include <vector>
26
27
#include "yb/rocksdb/utilities/stackable_db.h"
28
#include "yb/rocksdb/db.h"
29
30
namespace rocksdb {
31
32
// Database with TTL support.
33
//
34
// USE-CASES:
35
// This API should be used to open the db when key-values inserted are
36
//  meant to be removed from the db in a non-strict 'ttl' amount of time
37
//  Therefore, this guarantees that key-values inserted will remain in the
38
//  db for >= ttl amount of time and the db will make efforts to remove the
39
//  key-values as soon as possible after ttl seconds of their insertion.
40
//
41
// BEHAVIOUR:
42
// TTL is accepted in seconds
43
// (int32_t)Timestamp(creation) is suffixed to values in Put internally
44
// Expired TTL values deleted in compaction only:(Timestamp+ttl<time_now)
45
// Get/Iterator may return expired entries(compaction not run on them yet)
46
// Different TTL may be used during different Opens
47
// Example: Open1 at t=0 with ttl=4 and insert k1,k2, close at t=2
48
//          Open2 at t=3 with ttl=5. Now k1,k2 should be deleted at t>=5
49
// read_only=true opens in the usual read-only mode. Compactions will not be
50
//  triggered(neither manual nor automatic), so no expired entries removed
51
//
52
// CONSTRAINTS:
53
// Not specifying/passing or non-positive TTL behaves like TTL = infinity
54
//
55
// !!!WARNING!!!:
56
// Calling DB::Open directly to re-open a db created by this API will get
57
//  corrupt values(timestamp suffixed) and no ttl effect will be there
58
//  during the second Open, so use this API consistently to open the db
59
// Be careful when passing ttl with a small positive value because the
60
//  whole database may be deleted in a small amount of time
61
62
class DBWithTTL : public StackableDB {
63
 public:
64
  virtual Status CreateColumnFamilyWithTtl(
65
      const ColumnFamilyOptions& options, const std::string& column_family_name,
66
      ColumnFamilyHandle** handle, int ttl) = 0;
67
68
  static Status Open(const Options& options, const std::string& dbname,
69
                     DBWithTTL** dbptr, int32_t ttl = 0,
70
                     bool read_only = false);
71
72
  static Status Open(const DBOptions& db_options, const std::string& dbname,
73
                     const std::vector<ColumnFamilyDescriptor>& column_families,
74
                     std::vector<ColumnFamilyHandle*>* handles,
75
                     DBWithTTL** dbptr, std::vector<int32_t> ttls,
76
                     bool read_only = false);
77
78
 protected:
79
37
  explicit DBWithTTL(DB* db) : StackableDB(db) {}
80
};
81
82
}  // namespace rocksdb
83
#endif  // ROCKSDB_LITE