YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/rocksdb/sst_file_manager.h
Line
Count
Source
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
// The following only applies to changes made to this file as part of YugaByte development.
7
//
8
// Portions Copyright (c) YugaByte, Inc.
9
//
10
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
11
// in compliance with the License.  You may obtain a copy of the License at
12
//
13
// http://www.apache.org/licenses/LICENSE-2.0
14
//
15
// Unless required by applicable law or agreed to in writing, software distributed under the License
16
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
17
// or implied.  See the License for the specific language governing permissions and limitations
18
// under the License.
19
//
20
21
#ifndef YB_ROCKSDB_SST_FILE_MANAGER_H
22
#define YB_ROCKSDB_SST_FILE_MANAGER_H
23
24
#pragma once
25
26
#include <memory>
27
#include <string>
28
#include <unordered_map>
29
30
#include "yb/util/status.h"
31
32
namespace rocksdb {
33
34
class Env;
35
class Logger;
36
37
// SstFileManager is used to track SST files in the DB and control there
38
// deletion rate.
39
// All SstFileManager public functions are thread-safe.
40
class SstFileManager {
41
 public:
42
11
  virtual ~SstFileManager() {}
43
44
  // Update the maximum allowed space that should be used by RocksDB, if
45
  // the total size of the SST files exceeds max_allowed_space, writes to
46
  // RocksDB will fail.
47
  //
48
  // Setting max_allowed_space to 0 will disable this feature, maximum allowed
49
  // space will be infinite (Default value).
50
  //
51
  // thread-safe.
52
  virtual void SetMaxAllowedSpaceUsage(uint64_t max_allowed_space) = 0;
53
54
  // Return true if the total size of SST files exceeded the maximum allowed
55
  // space usage.
56
  //
57
  // thread-safe.
58
  virtual bool IsMaxAllowedSpaceReached() = 0;
59
60
  // Return the total size of all tracked files.
61
  // thread-safe
62
  virtual uint64_t GetTotalSize() = 0;
63
64
  // Return a map containing all tracked files and there corresponding sizes.
65
  // thread-safe
66
  virtual std::unordered_map<std::string, uint64_t> GetTrackedFiles() = 0;
67
68
  // Return delete rate limit in bytes per second.
69
  // thread-safe
70
  virtual int64_t GetDeleteRateBytesPerSecond() = 0;
71
};
72
73
// Create a new SstFileManager that can be shared among multiple RocksDB
74
// instances to track SST file and control there deletion rate.
75
//
76
// @param env: Pointer to Env object, please see "rocksdb/env.h".
77
// @param info_log: If not nullptr, info_log will be used to log errors.
78
//
79
// == Deletion rate limiting specific arguments ==
80
// @param trash_dir: Path to the directory where deleted files will be moved
81
//    to be deleted in a background thread while applying rate limiting. If this
82
//    directory dont exist, it will be created. This directory should not be
83
//    used by any other process or any other SstFileManager, Set to "" to
84
//    disable deletion rate limiting.
85
// @param rate_bytes_per_sec: How many bytes should be deleted per second, If
86
//    this value is set to 1024 (1 Kb / sec) and we deleted a file of size 4 Kb
87
//    in 1 second, we will wait for another 3 seconds before we delete other
88
//    files, Set to 0 to disable deletion rate limiting.
89
// @param delete_exisitng_trash: If set to true, the newly created
90
//    SstFileManager will delete files that already exist in trash_dir.
91
// @param status: If not nullptr, status will contain any errors that happened
92
//    during creating the missing trash_dir or deleting existing files in trash.
93
yb::Result<SstFileManager*> NewSstFileManager(
94
    Env* env, std::shared_ptr<Logger> info_log = nullptr,
95
    std::string trash_dir = "", int64_t rate_bytes_per_sec = 0,
96
    bool delete_exisitng_trash = true);
97
98
}  // namespace rocksdb
99
100
#endif // YB_ROCKSDB_SST_FILE_MANAGER_H