]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/experimental.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / db / experimental.cc
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 "rocksdb/experimental.h"
7
8 #include "db/db_impl/db_impl.h"
9 #include "db/version_util.h"
10 #include "logging/logging.h"
11
12 namespace ROCKSDB_NAMESPACE {
13 namespace experimental {
14
15 #ifndef ROCKSDB_LITE
16
17 Status SuggestCompactRange(DB* db, ColumnFamilyHandle* column_family,
18 const Slice* begin, const Slice* end) {
19 if (db == nullptr) {
20 return Status::InvalidArgument("DB is empty");
21 }
22
23 return db->SuggestCompactRange(column_family, begin, end);
24 }
25
26 Status PromoteL0(DB* db, ColumnFamilyHandle* column_family, int target_level) {
27 if (db == nullptr) {
28 return Status::InvalidArgument("Didn't recognize DB object");
29 }
30 return db->PromoteL0(column_family, target_level);
31 }
32
33 #else // ROCKSDB_LITE
34
35 Status SuggestCompactRange(DB* /*db*/, ColumnFamilyHandle* /*column_family*/,
36 const Slice* /*begin*/, const Slice* /*end*/) {
37 return Status::NotSupported("Not supported in RocksDB LITE");
38 }
39
40 Status PromoteL0(DB* /*db*/, ColumnFamilyHandle* /*column_family*/,
41 int /*target_level*/) {
42 return Status::NotSupported("Not supported in RocksDB LITE");
43 }
44
45 #endif // ROCKSDB_LITE
46
47 Status SuggestCompactRange(DB* db, const Slice* begin, const Slice* end) {
48 return SuggestCompactRange(db, db->DefaultColumnFamily(), begin, end);
49 }
50
51 Status UpdateManifestForFilesState(
52 const DBOptions& db_opts, const std::string& db_name,
53 const std::vector<ColumnFamilyDescriptor>& column_families,
54 const UpdateManifestForFilesStateOptions& opts) {
55 OfflineManifestWriter w(db_opts, db_name);
56 Status s = w.Recover(column_families);
57
58 size_t files_updated = 0;
59 size_t cfs_updated = 0;
60 auto fs = db_opts.env->GetFileSystem();
61
62 for (auto cfd : *w.Versions().GetColumnFamilySet()) {
63 if (!s.ok()) {
64 break;
65 }
66 assert(cfd);
67
68 if (cfd->IsDropped() || !cfd->initialized()) {
69 continue;
70 }
71
72 const auto* current = cfd->current();
73 assert(current);
74
75 const auto* vstorage = current->storage_info();
76 assert(vstorage);
77
78 VersionEdit edit;
79 edit.SetColumnFamily(cfd->GetID());
80
81 /* SST files */
82 for (int level = 0; level < cfd->NumberLevels(); level++) {
83 if (!s.ok()) {
84 break;
85 }
86 const auto& level_files = vstorage->LevelFiles(level);
87
88 for (const auto& lf : level_files) {
89 assert(lf);
90
91 uint64_t number = lf->fd.GetNumber();
92 std::string fname =
93 TableFileName(w.IOptions().db_paths, number, lf->fd.GetPathId());
94
95 std::unique_ptr<FSSequentialFile> f;
96 FileOptions fopts;
97 // Use kUnknown to signal the FileSystem to search all tiers for the
98 // file.
99 fopts.temperature = Temperature::kUnknown;
100
101 IOStatus file_ios =
102 fs->NewSequentialFile(fname, fopts, &f, /*dbg*/ nullptr);
103 if (file_ios.ok()) {
104 if (opts.update_temperatures) {
105 Temperature temp = f->GetTemperature();
106 if (temp != Temperature::kUnknown && temp != lf->temperature) {
107 // Current state inconsistent with manifest
108 ++files_updated;
109 edit.DeleteFile(level, number);
110 edit.AddFile(
111 level, number, lf->fd.GetPathId(), lf->fd.GetFileSize(),
112 lf->smallest, lf->largest, lf->fd.smallest_seqno,
113 lf->fd.largest_seqno, lf->marked_for_compaction, temp,
114 lf->oldest_blob_file_number, lf->oldest_ancester_time,
115 lf->file_creation_time, lf->file_checksum,
116 lf->file_checksum_func_name, lf->unique_id);
117 }
118 }
119 } else {
120 s = file_ios;
121 break;
122 }
123 }
124 }
125
126 if (s.ok() && edit.NumEntries() > 0) {
127 std::unique_ptr<FSDirectory> db_dir;
128 s = fs->NewDirectory(db_name, IOOptions(), &db_dir, nullptr);
129 if (s.ok()) {
130 s = w.LogAndApply(cfd, &edit, db_dir.get());
131 }
132 if (s.ok()) {
133 ++cfs_updated;
134 }
135 }
136 }
137
138 if (cfs_updated > 0) {
139 ROCKS_LOG_INFO(db_opts.info_log,
140 "UpdateManifestForFilesState: updated %zu files in %zu CFs",
141 files_updated, cfs_updated);
142 } else if (s.ok()) {
143 ROCKS_LOG_INFO(db_opts.info_log,
144 "UpdateManifestForFilesState: no updates needed");
145 }
146 if (!s.ok()) {
147 ROCKS_LOG_ERROR(db_opts.info_log, "UpdateManifestForFilesState failed: %s",
148 s.ToString().c_str());
149 }
150
151 return s;
152 }
153
154 } // namespace experimental
155 } // namespace ROCKSDB_NAMESPACE