]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/include/rocksdb/sst_file_manager.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / include / rocksdb / sst_file_manager.h
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 #pragma once
7
8 #include <memory>
9 #include <string>
10 #include <unordered_map>
11 #include <vector>
12
13 #include "rocksdb/file_system.h"
14 #include "rocksdb/statistics.h"
15 #include "rocksdb/status.h"
16
17 namespace ROCKSDB_NAMESPACE {
18
19 class Env;
20 class Logger;
21
22 // SstFileManager is used to track SST and blob files in the DB and control
23 // their deletion rate. All SstFileManager public functions are thread-safe.
24 // SstFileManager is NOT an extensible interface but a public interface for
25 // result of NewSstFileManager. Any derived classes must be RocksDB internal.
26 class SstFileManager {
27 public:
28 virtual ~SstFileManager() {}
29
30 // Update the maximum allowed space that should be used by RocksDB, if
31 // the total size of the SST and blob files exceeds max_allowed_space, writes
32 // to RocksDB will fail.
33 //
34 // Setting max_allowed_space to 0 will disable this feature; maximum allowed
35 // space will be infinite (Default value).
36 //
37 // thread-safe.
38 virtual void SetMaxAllowedSpaceUsage(uint64_t max_allowed_space) = 0;
39
40 // Set the amount of buffer room each compaction should be able to leave.
41 // In other words, at its maximum disk space consumption, the compaction
42 // should still leave compaction_buffer_size available on the disk so that
43 // other background functions may continue, such as logging and flushing.
44 virtual void SetCompactionBufferSize(uint64_t compaction_buffer_size) = 0;
45
46 // Return true if the total size of SST and blob files exceeded the maximum
47 // allowed space usage.
48 //
49 // thread-safe.
50 virtual bool IsMaxAllowedSpaceReached() = 0;
51
52 // Returns true if the total size of SST and blob files as well as estimated
53 // size of ongoing compactions exceeds the maximums allowed space usage.
54 virtual bool IsMaxAllowedSpaceReachedIncludingCompactions() = 0;
55
56 // Return the total size of all tracked files.
57 // thread-safe
58 virtual uint64_t GetTotalSize() = 0;
59
60 // Return a map containing all tracked files and their corresponding sizes.
61 // thread-safe
62 virtual std::unordered_map<std::string, uint64_t> GetTrackedFiles() = 0;
63
64 // Return delete rate limit in bytes per second.
65 // thread-safe
66 virtual int64_t GetDeleteRateBytesPerSecond() = 0;
67
68 // Update the delete rate limit in bytes per second.
69 // zero means disable delete rate limiting and delete files immediately
70 // thread-safe
71 virtual void SetDeleteRateBytesPerSecond(int64_t delete_rate) = 0;
72
73 // Return trash/DB size ratio where new files will be deleted immediately
74 // thread-safe
75 virtual double GetMaxTrashDBRatio() = 0;
76
77 // Update trash/DB size ratio where new files will be deleted immediately
78 // thread-safe
79 virtual void SetMaxTrashDBRatio(double ratio) = 0;
80
81 // Return the total size of trash files
82 // thread-safe
83 virtual uint64_t GetTotalTrashSize() = 0;
84
85 // Set the statistics ptr to dump the stat information
86 virtual void SetStatisticsPtr(const std::shared_ptr<Statistics>& stats) = 0;
87 };
88
89 // Create a new SstFileManager that can be shared among multiple RocksDB
90 // instances to track SST and blob files and control there deletion rate.
91 // Even though SstFileManager don't track WAL files but it still control
92 // there deletion rate.
93 //
94 // @param env: Pointer to Env object, please see "rocksdb/env.h".
95 // @param fs: Pointer to FileSystem object (rocksdb/file_system.h"
96 // @param info_log: If not nullptr, info_log will be used to log errors.
97 //
98 // == Deletion rate limiting specific arguments ==
99 // @param trash_dir: Deprecated, this argument have no effect
100 // @param rate_bytes_per_sec: How many bytes should be deleted per second, If
101 // this value is set to 1024 (1 Kb / sec) and we deleted a file of size 4 Kb
102 // in 1 second, we will wait for another 3 seconds before we delete other
103 // files, Set to 0 to disable deletion rate limiting.
104 // This option also affect the delete rate of WAL files in the DB.
105 // @param delete_existing_trash: Deprecated, this argument have no effect, but
106 // if user provide trash_dir we will schedule deletes for files in the dir
107 // @param status: If not nullptr, status will contain any errors that happened
108 // during creating the missing trash_dir or deleting existing files in trash.
109 // @param max_trash_db_ratio: If the trash size constitutes for more than this
110 // fraction of the total DB size we will start deleting new files passed to
111 // DeleteScheduler immediately
112 // @param bytes_max_delete_chunk: if a file to delete is larger than delete
113 // chunk, ftruncate the file by this size each time, rather than dropping the
114 // whole file. 0 means to always delete the whole file. If the file has more
115 // than one linked names, the file will be deleted as a whole. Either way,
116 // `rate_bytes_per_sec` will be appreciated. NOTE that with this option,
117 // files already renamed as a trash may be partial, so users should not
118 // directly recover them without checking.
119 extern SstFileManager* NewSstFileManager(
120 Env* env, std::shared_ptr<FileSystem> fs,
121 std::shared_ptr<Logger> info_log = nullptr,
122 const std::string& trash_dir = "", int64_t rate_bytes_per_sec = 0,
123 bool delete_existing_trash = true, Status* status = nullptr,
124 double max_trash_db_ratio = 0.25,
125 uint64_t bytes_max_delete_chunk = 64 * 1024 * 1024);
126
127 // Same as above, but takes a pointer to a legacy Env object, instead of
128 // Env and FileSystem objects
129 extern SstFileManager* NewSstFileManager(
130 Env* env, std::shared_ptr<Logger> info_log = nullptr,
131 std::string trash_dir = "", int64_t rate_bytes_per_sec = 0,
132 bool delete_existing_trash = true, Status* status = nullptr,
133 double max_trash_db_ratio = 0.25,
134 uint64_t bytes_max_delete_chunk = 64 * 1024 * 1024);
135
136 } // namespace ROCKSDB_NAMESPACE