YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/rocksdb/write_batch_base.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
// 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
// The following only applies to changes made to this file as part of YugaByte development.
10
//
11
// Portions Copyright (c) YugaByte, Inc.
12
//
13
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
14
// in compliance with the License.  You may obtain a copy of the License at
15
//
16
// http://www.apache.org/licenses/LICENSE-2.0
17
//
18
// Unless required by applicable law or agreed to in writing, software distributed under the License
19
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
20
// or implied.  See the License for the specific language governing permissions and limitations
21
// under the License.
22
//
23
#ifndef YB_ROCKSDB_WRITE_BATCH_BASE_H
24
#define YB_ROCKSDB_WRITE_BATCH_BASE_H
25
26
#pragma once
27
28
#include "yb/util/status_fwd.h"
29
#include "yb/util/slice.h"
30
#include "yb/rocksdb/status.h"
31
32
namespace rocksdb {
33
34
class ColumnFamilyHandle;
35
class WriteBatch;
36
37
// Abstract base class that defines the basic interface for a write batch.
38
// See WriteBatch for a basic implementation and WrithBatchWithIndex for an
39
// indexed implemenation.
40
class WriteBatchBase {
41
 public:
42
40.7M
  virtual ~WriteBatchBase() {}
43
44
  // Store the mapping "key->value" in the database.
45
  virtual void Put(ColumnFamilyHandle* column_family, const Slice& key,
46
                   const Slice& value) = 0;
47
  virtual void Put(const Slice& key, const Slice& value) = 0;
48
49
  // Variant of Put() that gathers output like writev(2).  The key and value
50
  // that will be written to the database are concatentations of arrays of
51
  // slices.
52
  virtual void Put(ColumnFamilyHandle* column_family, const SliceParts& key,
53
                   const SliceParts& value);
54
  virtual void Put(const SliceParts& key, const SliceParts& value);
55
56
  // Merge "value" with the existing value of "key" in the database.
57
  // "key->merge(existing, value)"
58
  virtual void Merge(ColumnFamilyHandle* column_family, const Slice& key,
59
                     const Slice& value) = 0;
60
  virtual void Merge(const Slice& key, const Slice& value) = 0;
61
62
  // variant that takes SliceParts
63
  virtual void Merge(ColumnFamilyHandle* column_family, const SliceParts& key,
64
                     const SliceParts& value);
65
  virtual void Merge(const SliceParts& key, const SliceParts& value);
66
67
  // If the database contains a mapping for "key", erase it.  Else do nothing.
68
  virtual void Delete(ColumnFamilyHandle* column_family, const Slice& key) = 0;
69
  virtual void Delete(const Slice& key) = 0;
70
71
  // variant that takes SliceParts
72
  virtual void Delete(ColumnFamilyHandle* column_family, const SliceParts& key);
73
  virtual void Delete(const SliceParts& key);
74
75
  // If the database contains a mapping for "key", erase it. Expects that the
76
  // key was not overwritten. Else do nothing.
77
  virtual void SingleDelete(ColumnFamilyHandle* column_family,
78
                            const Slice& key) = 0;
79
  virtual void SingleDelete(const Slice& key) = 0;
80
81
  // variant that takes SliceParts
82
  virtual void SingleDelete(ColumnFamilyHandle* column_family,
83
                            const SliceParts& key);
84
  virtual void SingleDelete(const SliceParts& key);
85
86
  // Append a blob of arbitrary size to the records in this batch. The blob will
87
  // be stored in the transaction log but not in any other file. In particular,
88
  // it will not be persisted to the SST files. When iterating over this
89
  // WriteBatch, WriteBatch::Handler::LogData will be called with the contents
90
  // of the blob as it is encountered. Blobs, puts, deletes, and merges will be
91
  // encountered in the same order in thich they were inserted. The blob will
92
  // NOT consume sequence number(s) and will NOT increase the count of the batch
93
  //
94
  // Example application: add timestamps to the transaction log for use in
95
  // replication.
96
  virtual void PutLogData(const Slice& blob) = 0;
97
98
  // Clear all updates buffered in this batch.
99
  virtual void Clear() = 0;
100
101
  // Covert this batch into a WriteBatch.  This is an abstracted way of
102
  // converting any WriteBatchBase(eg WriteBatchWithIndex) into a basic
103
  // WriteBatch.
104
  virtual WriteBatch* GetWriteBatch() = 0;
105
106
  // Records the state of the batch for future calls to RollbackToSavePoint().
107
  // May be called multiple times to set multiple save points.
108
  virtual void SetSavePoint() = 0;
109
110
  // Remove all entries in this batch (Put, Merge, Delete, PutLogData) since the
111
  // most recent call to SetSavePoint() and removes the most recent save point.
112
  // If there is no previous call to SetSavePoint(), behaves the same as
113
  // Clear().
114
  virtual Status RollbackToSavePoint() = 0;
115
};
116
117
}  // namespace rocksdb
118
119
#endif // YB_ROCKSDB_WRITE_BATCH_BASE_H