]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/include/rocksdb/write_batch_base.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / rocksdb / include / rocksdb / write_batch_base.h
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 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
6 // Use of this source code is governed by a BSD-style license that can be
7 // found in the LICENSE file. See the AUTHORS file for names of contributors.
8
9 #pragma once
10
11 #include <cstddef>
12
13 namespace rocksdb {
14
15 class Slice;
16 class Status;
17 class ColumnFamilyHandle;
18 class WriteBatch;
19 struct SliceParts;
20
21 // Abstract base class that defines the basic interface for a write batch.
22 // See WriteBatch for a basic implementation and WrithBatchWithIndex for an
23 // indexed implemenation.
24 class WriteBatchBase {
25 public:
26 virtual ~WriteBatchBase() {}
27
28 // Store the mapping "key->value" in the database.
29 virtual Status Put(ColumnFamilyHandle* column_family, const Slice& key,
30 const Slice& value) = 0;
31 virtual Status Put(const Slice& key, const Slice& value) = 0;
32
33 // Variant of Put() that gathers output like writev(2). The key and value
34 // that will be written to the database are concatentations of arrays of
35 // slices.
36 virtual Status Put(ColumnFamilyHandle* column_family, const SliceParts& key,
37 const SliceParts& value);
38 virtual Status Put(const SliceParts& key, const SliceParts& value);
39
40 // Merge "value" with the existing value of "key" in the database.
41 // "key->merge(existing, value)"
42 virtual Status Merge(ColumnFamilyHandle* column_family, const Slice& key,
43 const Slice& value) = 0;
44 virtual Status Merge(const Slice& key, const Slice& value) = 0;
45
46 // variant that takes SliceParts
47 virtual Status Merge(ColumnFamilyHandle* column_family, const SliceParts& key,
48 const SliceParts& value);
49 virtual Status Merge(const SliceParts& key, const SliceParts& value);
50
51 // If the database contains a mapping for "key", erase it. Else do nothing.
52 virtual Status Delete(ColumnFamilyHandle* column_family,
53 const Slice& key) = 0;
54 virtual Status Delete(const Slice& key) = 0;
55
56 // variant that takes SliceParts
57 virtual Status Delete(ColumnFamilyHandle* column_family,
58 const SliceParts& key);
59 virtual Status Delete(const SliceParts& key);
60
61 // If the database contains a mapping for "key", erase it. Expects that the
62 // key was not overwritten. Else do nothing.
63 virtual Status SingleDelete(ColumnFamilyHandle* column_family,
64 const Slice& key) = 0;
65 virtual Status SingleDelete(const Slice& key) = 0;
66
67 // variant that takes SliceParts
68 virtual Status SingleDelete(ColumnFamilyHandle* column_family,
69 const SliceParts& key);
70 virtual Status SingleDelete(const SliceParts& key);
71
72 // If the database contains mappings in the range ["begin_key", "end_key"],
73 // erase them. Else do nothing.
74 virtual Status DeleteRange(ColumnFamilyHandle* column_family,
75 const Slice& begin_key, const Slice& end_key) = 0;
76 virtual Status DeleteRange(const Slice& begin_key, const Slice& end_key) = 0;
77
78 // variant that takes SliceParts
79 virtual Status DeleteRange(ColumnFamilyHandle* column_family,
80 const SliceParts& begin_key,
81 const SliceParts& end_key);
82 virtual Status DeleteRange(const SliceParts& begin_key,
83 const SliceParts& end_key);
84
85 // Append a blob of arbitrary size to the records in this batch. The blob will
86 // be stored in the transaction log but not in any other file. In particular,
87 // it will not be persisted to the SST files. When iterating over this
88 // WriteBatch, WriteBatch::Handler::LogData will be called with the contents
89 // of the blob as it is encountered. Blobs, puts, deletes, and merges will be
90 // encountered in the same order in thich they were inserted. The blob will
91 // NOT consume sequence number(s) and will NOT increase the count of the batch
92 //
93 // Example application: add timestamps to the transaction log for use in
94 // replication.
95 virtual Status PutLogData(const Slice& blob) = 0;
96
97 // Clear all updates buffered in this batch.
98 virtual void Clear() = 0;
99
100 // Covert this batch into a WriteBatch. This is an abstracted way of
101 // converting any WriteBatchBase(eg WriteBatchWithIndex) into a basic
102 // WriteBatch.
103 virtual WriteBatch* GetWriteBatch() = 0;
104
105 // Records the state of the batch for future calls to RollbackToSavePoint().
106 // May be called multiple times to set multiple save points.
107 virtual void SetSavePoint() = 0;
108
109 // Remove all entries in this batch (Put, Merge, Delete, PutLogData) since the
110 // most recent call to SetSavePoint() and removes the most recent save point.
111 // If there is no previous call to SetSavePoint(), behaves the same as
112 // Clear().
113 virtual Status RollbackToSavePoint() = 0;
114
115 // Sets the maximum size of the write batch in bytes. 0 means no limit.
116 virtual void SetMaxBytes(size_t max_bytes) = 0;
117 };
118
119 } // namespace rocksdb