Coverage Report

Created: 2025-07-23 07:17

/src/rocksdb/utilities/merge_operators/put.cc
Line
Count
Source (jump to first uncovered line)
1
//  Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
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).
5
6
#include <memory>
7
8
#include "rocksdb/merge_operator.h"
9
#include "rocksdb/slice.h"
10
#include "utilities/merge_operators.h"
11
#include "utilities/merge_operators/put_operator.h"
12
13
namespace ROCKSDB_NAMESPACE {
14
15
// A merge operator that mimics Put semantics
16
// Since this merge-operator will not be used in production,
17
// it is implemented as a non-associative merge operator to illustrate the
18
// new interface and for testing purposes. (That is, we inherit from
19
// the MergeOperator class rather than the AssociativeMergeOperator
20
// which would be simpler in this case).
21
//
22
// From the client-perspective, semantics are the same.
23
bool PutOperator::FullMerge(const Slice& /*key*/,
24
                            const Slice* /*existing_value*/,
25
                            const std::deque<std::string>& operand_sequence,
26
0
                            std::string* new_value, Logger* /*logger*/) const {
27
  // Put basically only looks at the current/latest value
28
0
  assert(!operand_sequence.empty());
29
0
  assert(new_value != nullptr);
30
0
  new_value->assign(operand_sequence.back());
31
0
  return true;
32
0
}
33
34
bool PutOperator::PartialMerge(const Slice& /*key*/,
35
                               const Slice& /*left_operand*/,
36
                               const Slice& right_operand,
37
                               std::string* new_value,
38
0
                               Logger* /*logger*/) const {
39
0
  new_value->assign(right_operand.data(), right_operand.size());
40
0
  return true;
41
0
}
42
43
bool PutOperator::PartialMergeMulti(const Slice& /*key*/,
44
                                    const std::deque<Slice>& operand_list,
45
                                    std::string* new_value,
46
0
                                    Logger* /*logger*/) const {
47
0
  new_value->assign(operand_list.back().data(), operand_list.back().size());
48
0
  return true;
49
0
}
50
51
bool PutOperatorV2::FullMerge(
52
    const Slice& /*key*/, const Slice* /*existing_value*/,
53
    const std::deque<std::string>& /*operand_sequence*/,
54
0
    std::string* /*new_value*/, Logger* /*logger*/) const {
55
0
  assert(false);
56
0
  return false;
57
0
}
58
59
bool PutOperatorV2::FullMergeV2(const MergeOperationInput& merge_in,
60
0
                                MergeOperationOutput* merge_out) const {
61
  // Put basically only looks at the current/latest value
62
0
  assert(!merge_in.operand_list.empty());
63
0
  merge_out->existing_operand = merge_in.operand_list.back();
64
0
  return true;
65
0
}
66
67
0
std::shared_ptr<MergeOperator> MergeOperators::CreateDeprecatedPutOperator() {
68
0
  return std::make_shared<PutOperator>();
69
0
}
70
71
0
std::shared_ptr<MergeOperator> MergeOperators::CreatePutOperator() {
72
0
  return std::make_shared<PutOperatorV2>();
73
0
}
74
}  // namespace ROCKSDB_NAMESPACE