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).
6 #include "rocksdb/experimental.h"
8 #include "db/db_impl/db_impl.h"
9 #include "db/version_util.h"
10 #include "logging/logging.h"
12 namespace ROCKSDB_NAMESPACE
{
13 namespace experimental
{
17 Status
SuggestCompactRange(DB
* db
, ColumnFamilyHandle
* column_family
,
18 const Slice
* begin
, const Slice
* end
) {
20 return Status::InvalidArgument("DB is empty");
23 return db
->SuggestCompactRange(column_family
, begin
, end
);
26 Status
PromoteL0(DB
* db
, ColumnFamilyHandle
* column_family
, int target_level
) {
28 return Status::InvalidArgument("Didn't recognize DB object");
30 return db
->PromoteL0(column_family
, target_level
);
35 Status
SuggestCompactRange(DB
* /*db*/, ColumnFamilyHandle
* /*column_family*/,
36 const Slice
* /*begin*/, const Slice
* /*end*/) {
37 return Status::NotSupported("Not supported in RocksDB LITE");
40 Status
PromoteL0(DB
* /*db*/, ColumnFamilyHandle
* /*column_family*/,
41 int /*target_level*/) {
42 return Status::NotSupported("Not supported in RocksDB LITE");
45 #endif // ROCKSDB_LITE
47 Status
SuggestCompactRange(DB
* db
, const Slice
* begin
, const Slice
* end
) {
48 return SuggestCompactRange(db
, db
->DefaultColumnFamily(), begin
, end
);
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
);
58 size_t files_updated
= 0;
59 size_t cfs_updated
= 0;
60 auto fs
= db_opts
.env
->GetFileSystem();
62 for (auto cfd
: *w
.Versions().GetColumnFamilySet()) {
68 if (cfd
->IsDropped() || !cfd
->initialized()) {
72 const auto* current
= cfd
->current();
75 const auto* vstorage
= current
->storage_info();
79 edit
.SetColumnFamily(cfd
->GetID());
82 for (int level
= 0; level
< cfd
->NumberLevels(); level
++) {
86 const auto& level_files
= vstorage
->LevelFiles(level
);
88 for (const auto& lf
: level_files
) {
91 uint64_t number
= lf
->fd
.GetNumber();
93 TableFileName(w
.IOptions().db_paths
, number
, lf
->fd
.GetPathId());
95 std::unique_ptr
<FSSequentialFile
> f
;
97 // Use kUnknown to signal the FileSystem to search all tiers for the
99 fopts
.temperature
= Temperature::kUnknown
;
102 fs
->NewSequentialFile(fname
, fopts
, &f
, /*dbg*/ nullptr);
104 if (opts
.update_temperatures
) {
105 Temperature temp
= f
->GetTemperature();
106 if (temp
!= Temperature::kUnknown
&& temp
!= lf
->temperature
) {
107 // Current state inconsistent with manifest
109 edit
.DeleteFile(level
, number
);
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
);
126 if (s
.ok() && edit
.NumEntries() > 0) {
127 std::unique_ptr
<FSDirectory
> db_dir
;
128 s
= fs
->NewDirectory(db_name
, IOOptions(), &db_dir
, nullptr);
130 s
= w
.LogAndApply(cfd
, &edit
, db_dir
.get());
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
);
143 ROCKS_LOG_INFO(db_opts
.info_log
,
144 "UpdateManifestForFilesState: no updates needed");
147 ROCKS_LOG_ERROR(db_opts
.info_log
, "UpdateManifestForFilesState failed: %s",
148 s
.ToString().c_str());
154 } // namespace experimental
155 } // namespace ROCKSDB_NAMESPACE