Coverage Report

Created: 2024-09-08 07:17

/src/rocksdb/utilities/merge_operators/uint64add.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 "utilities/merge_operators/uint64add.h"
7
8
#include <memory>
9
10
#include "logging/logging.h"
11
#include "rocksdb/env.h"
12
#include "rocksdb/merge_operator.h"
13
#include "rocksdb/slice.h"
14
#include "util/coding.h"
15
#include "utilities/merge_operators.h"
16
17
namespace ROCKSDB_NAMESPACE {  // anonymous namespace
18
19
bool UInt64AddOperator::Merge(const Slice& /*key*/, const Slice* existing_value,
20
                              const Slice& value, std::string* new_value,
21
0
                              Logger* logger) const {
22
0
  uint64_t orig_value = 0;
23
0
  if (existing_value) {
24
0
    orig_value = DecodeInteger(*existing_value, logger);
25
0
  }
26
0
  uint64_t operand = DecodeInteger(value, logger);
27
28
0
  assert(new_value);
29
0
  new_value->clear();
30
0
  PutFixed64(new_value, orig_value + operand);
31
32
0
  return true;  // Return true always since corruption will be treated as 0
33
0
}
34
35
uint64_t UInt64AddOperator::DecodeInteger(const Slice& value,
36
0
                                          Logger* logger) const {
37
0
  uint64_t result = 0;
38
39
0
  if (value.size() == sizeof(uint64_t)) {
40
0
    result = DecodeFixed64(value.data());
41
0
  } else if (logger != nullptr) {
42
    // If value is corrupted, treat it as 0
43
0
    ROCKS_LOG_ERROR(logger,
44
0
                    "uint64 value corruption, size: %" ROCKSDB_PRIszt
45
0
                    " > %" ROCKSDB_PRIszt,
46
0
                    value.size(), sizeof(uint64_t));
47
0
  }
48
49
0
  return result;
50
0
}
51
52
0
std::shared_ptr<MergeOperator> MergeOperators::CreateUInt64AddOperator() {
53
0
  return std::make_shared<UInt64AddOperator>();
54
0
}
55
56
}  // namespace ROCKSDB_NAMESPACE