YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/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 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
#include <memory>
22
#include "yb/util/slice.h"
23
#include "yb/rocksdb/merge_operator.h"
24
#include "yb/rocksdb/utilities/merge_operators.h"
25
26
namespace rocksdb {
27
28
namespace { // anonymous namespace
29
30
// A merge operator that mimics Put semantics
31
// Since this merge-operator will not be used in production,
32
// it is implemented as a non-associative merge operator to illustrate the
33
// new interface and for testing purposes. (That is, we inherit from
34
// the MergeOperator class rather than the AssociativeMergeOperator
35
// which would be simpler in this case).
36
//
37
// From the client-perspective, semantics are the same.
38
class PutOperator : public MergeOperator {
39
 public:
40
  virtual bool FullMerge(const Slice& key,
41
                         const Slice* existing_value,
42
                         const std::deque<std::string>& operand_sequence,
43
                         std::string* new_value,
44
74.3k
                         Logger* logger) const override {
45
    // Put basically only looks at the current/latest value
46
74.3k
    assert(!operand_sequence.empty());
47
0
    assert(new_value != nullptr);
48
0
    new_value->assign(operand_sequence.back());
49
74.3k
    return true;
50
74.3k
  }
51
52
  virtual bool PartialMerge(const Slice& key,
53
                            const Slice& left_operand,
54
                            const Slice& right_operand,
55
                            std::string* new_value,
56
0
                            Logger* logger) const override {
57
0
    new_value->assign(right_operand.cdata(), right_operand.size());
58
0
    return true;
59
0
  }
60
61
  using MergeOperator::PartialMergeMulti;
62
  virtual bool PartialMergeMulti(const Slice& key,
63
                                 const std::deque<Slice>& operand_list,
64
                                 std::string* new_value,
65
1.04k
                                 Logger* logger) const override {
66
1.04k
    new_value->assign(operand_list.back().cdata(), operand_list.back().size());
67
1.04k
    return true;
68
1.04k
  }
69
70
1.07k
  const char* Name() const override {
71
1.07k
    return "PutOperator";
72
1.07k
  }
73
};
74
75
} // end of anonymous namespace
76
77
98
std::shared_ptr<MergeOperator> MergeOperators::CreatePutOperator() {
78
98
  return std::make_shared<PutOperator>();
79
98
}
80
81
} // namespace rocksdb