Coverage Report

Created: 2025-10-26 07:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/rocksdb/util/file_checksum_helper.cc
Line
Count
Source
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
//  Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7
//  Use of this source code is governed by a BSD-style license that can be
8
//  found in the LICENSE file. See the AUTHORS file for names of contributors.
9
10
#include "util/file_checksum_helper.h"
11
12
#include "rocksdb/utilities/customizable_util.h"
13
14
namespace ROCKSDB_NAMESPACE {
15
16
0
void FileChecksumListImpl::reset() { checksum_map_.clear(); }
17
18
0
size_t FileChecksumListImpl::size() const { return checksum_map_.size(); }
19
20
Status FileChecksumListImpl::GetAllFileChecksums(
21
    std::vector<uint64_t>* file_numbers, std::vector<std::string>* checksums,
22
0
    std::vector<std::string>* checksum_func_names) {
23
0
  if (file_numbers == nullptr || checksums == nullptr ||
24
0
      checksum_func_names == nullptr) {
25
0
    return Status::InvalidArgument("Pointer has not been initiated");
26
0
  }
27
28
0
  for (const auto& i : checksum_map_) {
29
0
    file_numbers->push_back(i.first);
30
0
    checksums->push_back(i.second.first);
31
0
    checksum_func_names->push_back(i.second.second);
32
0
  }
33
0
  return Status::OK();
34
0
}
35
36
Status FileChecksumListImpl::SearchOneFileChecksum(
37
    uint64_t file_number, std::string* checksum,
38
0
    std::string* checksum_func_name) {
39
0
  if (checksum == nullptr || checksum_func_name == nullptr) {
40
0
    return Status::InvalidArgument("Pointer has not been initiated");
41
0
  }
42
43
0
  auto it = checksum_map_.find(file_number);
44
0
  if (it == checksum_map_.end()) {
45
0
    return Status::NotFound();
46
0
  } else {
47
0
    *checksum = it->second.first;
48
0
    *checksum_func_name = it->second.second;
49
0
  }
50
0
  return Status::OK();
51
0
}
52
53
Status FileChecksumListImpl::InsertOneFileChecksum(
54
    uint64_t file_number, const std::string& checksum,
55
0
    const std::string& checksum_func_name) {
56
0
  auto it = checksum_map_.find(file_number);
57
0
  if (it == checksum_map_.end()) {
58
0
    checksum_map_.insert(std::make_pair(
59
0
        file_number, std::make_pair(checksum, checksum_func_name)));
60
0
  } else {
61
0
    it->second.first = checksum;
62
0
    it->second.second = checksum_func_name;
63
0
  }
64
0
  return Status::OK();
65
0
}
66
67
0
Status FileChecksumListImpl::RemoveOneFileChecksum(uint64_t file_number) {
68
0
  auto it = checksum_map_.find(file_number);
69
0
  if (it == checksum_map_.end()) {
70
0
    return Status::NotFound();
71
0
  } else {
72
0
    checksum_map_.erase(it);
73
0
  }
74
0
  return Status::OK();
75
0
}
76
77
0
FileChecksumList* NewFileChecksumList() {
78
0
  FileChecksumListImpl* checksum_list = new FileChecksumListImpl();
79
0
  return checksum_list;
80
0
}
81
82
0
std::shared_ptr<FileChecksumGenFactory> GetFileChecksumGenCrc32cFactory() {
83
0
  static std::shared_ptr<FileChecksumGenFactory> default_crc32c_gen_factory(
84
0
      new FileChecksumGenCrc32cFactory());
85
0
  return default_crc32c_gen_factory;
86
0
}
87
88
namespace {
89
static int RegisterFileChecksumGenFactories(ObjectLibrary& library,
90
2
                                            const std::string& /*arg*/) {
91
2
  library.AddFactory<FileChecksumGenFactory>(
92
2
      FileChecksumGenCrc32cFactory::kClassName(),
93
2
      [](const std::string& /*uri*/,
94
2
         std::unique_ptr<FileChecksumGenFactory>* guard,
95
2
         std::string* /* errmsg */) {
96
0
        guard->reset(new FileChecksumGenCrc32cFactory());
97
0
        return guard->get();
98
0
      });
99
2
  return 1;
100
2
}
101
}  // namespace
102
103
Status FileChecksumGenFactory::CreateFromString(
104
    const ConfigOptions& options, const std::string& value,
105
82.5k
    std::shared_ptr<FileChecksumGenFactory>* result) {
106
82.5k
  static std::once_flag once;
107
82.5k
  std::call_once(once, [&]() {
108
2
    RegisterFileChecksumGenFactories(*(ObjectLibrary::Default().get()), "");
109
2
  });
110
82.5k
  if (value == FileChecksumGenCrc32cFactory::kClassName()) {
111
0
    *result = GetFileChecksumGenCrc32cFactory();
112
0
    return Status::OK();
113
82.5k
  } else {
114
82.5k
    Status s = LoadSharedObject<FileChecksumGenFactory>(options, value, result);
115
82.5k
    return s;
116
82.5k
  }
117
82.5k
}
118
}  // namespace ROCKSDB_NAMESPACE