]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/include/rocksdb/sst_file_manager.h
add subtree-ish sources for 12.0.3
[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 the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
5
6 #pragma once
7
8 #include <memory>
9 #include <string>
10 #include <unordered_map>
11
12 #include "rocksdb/status.h"
13
14 namespace rocksdb {
15
16 class Env;
17 class Logger;
18
19 // SstFileManager is used to track SST files in the DB and control there
20 // deletion rate.
21 // All SstFileManager public functions are thread-safe.
22 class SstFileManager {
23 public:
24 virtual ~SstFileManager() {}
25
26 // Update the maximum allowed space that should be used by RocksDB, if
27 // the total size of the SST files exceeds max_allowed_space, writes to
28 // RocksDB will fail.
29 //
30 // Setting max_allowed_space to 0 will disable this feature, maximum allowed
31 // space will be infinite (Default value).
32 //
33 // thread-safe.
34 virtual void SetMaxAllowedSpaceUsage(uint64_t max_allowed_space) = 0;
35
36 // Return true if the total size of SST files exceeded the maximum allowed
37 // space usage.
38 //
39 // thread-safe.
40 virtual bool IsMaxAllowedSpaceReached() = 0;
41
42 // Return the total size of all tracked files.
43 // thread-safe
44 virtual uint64_t GetTotalSize() = 0;
45
46 // Return a map containing all tracked files and there corresponding sizes.
47 // thread-safe
48 virtual std::unordered_map<std::string, uint64_t> GetTrackedFiles() = 0;
49
50 // Return delete rate limit in bytes per second.
51 // thread-safe
52 virtual int64_t GetDeleteRateBytesPerSecond() = 0;
53
54 // Update the delete rate limit in bytes per second.
55 // zero means disable delete rate limiting and delete files immediately
56 // thread-safe
57 virtual void SetDeleteRateBytesPerSecond(int64_t delete_rate) = 0;
58 };
59
60 // Create a new SstFileManager that can be shared among multiple RocksDB
61 // instances to track SST file and control there deletion rate.
62 //
63 // @param env: Pointer to Env object, please see "rocksdb/env.h".
64 // @param info_log: If not nullptr, info_log will be used to log errors.
65 //
66 // == Deletion rate limiting specific arguments ==
67 // @param trash_dir: Path to the directory where deleted files will be moved
68 // to be deleted in a background thread while applying rate limiting. If this
69 // directory dont exist, it will be created. This directory should not be
70 // used by any other process or any other SstFileManager, Set to "" to
71 // disable deletion rate limiting.
72 // @param rate_bytes_per_sec: How many bytes should be deleted per second, If
73 // this value is set to 1024 (1 Kb / sec) and we deleted a file of size 4 Kb
74 // in 1 second, we will wait for another 3 seconds before we delete other
75 // files, Set to 0 to disable deletion rate limiting.
76 // @param delete_existing_trash: If set to true, the newly created
77 // SstFileManager will delete files that already exist in trash_dir.
78 // @param status: If not nullptr, status will contain any errors that happened
79 // during creating the missing trash_dir or deleting existing files in trash.
80 extern SstFileManager* NewSstFileManager(
81 Env* env, std::shared_ptr<Logger> info_log = nullptr,
82 std::string trash_dir = "", int64_t rate_bytes_per_sec = 0,
83 bool delete_existing_trash = true, Status* status = nullptr);
84
85 } // namespace rocksdb