]> git.proxmox.com Git - ceph.git/blob - ceph/src/os/bluestore/BlueRocksEnv.h
82cffcd809bdd27d7313c38b3a6c715cdc576ec4
[ceph.git] / ceph / src / os / bluestore / BlueRocksEnv.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 #ifndef CEPH_OS_BLUESTORE_BLUEROCKSENV_H
4 #define CEPH_OS_BLUESTORE_BLUEROCKSENV_H
5
6 #include <memory>
7 #include <string>
8
9 #include "rocksdb/options.h"
10 #include "rocksdb/status.h"
11 #include "rocksdb/utilities/env_mirror.h"
12
13 #include "include/ceph_assert.h"
14 #include "kv/RocksDBStore.h"
15
16 class BlueFS;
17
18 class BlueRocksEnv : public rocksdb::EnvWrapper {
19 void split(const std::string &fn, std::string *dir, std::string *file) {
20 size_t slash = fn.rfind('/');
21 *file = fn.substr(slash + 1);
22 while (slash && fn[slash-1] == '/')
23 --slash;
24 *dir = fn.substr(0, slash);
25 }
26
27 public:
28 // Create a brand new sequentially-readable file with the specified name.
29 // On success, stores a pointer to the new file in *result and returns OK.
30 // On failure, stores nullptr in *result and returns non-OK. If the file does
31 // not exist, returns a non-OK status.
32 //
33 // The returned file will only be accessed by one thread at a time.
34 rocksdb::Status NewSequentialFile(
35 const std::string& fname,
36 std::unique_ptr<rocksdb::SequentialFile>* result,
37 const rocksdb::EnvOptions& options) override;
38
39 // Create a brand new random access read-only file with the
40 // specified name. On success, stores a pointer to the new file in
41 // *result and returns OK. On failure, stores nullptr in *result and
42 // returns non-OK. If the file does not exist, returns a non-OK
43 // status.
44 //
45 // The returned file may be concurrently accessed by multiple threads.
46 rocksdb::Status NewRandomAccessFile(
47 const std::string& fname,
48 std::unique_ptr<rocksdb::RandomAccessFile>* result,
49 const rocksdb::EnvOptions& options) override;
50
51 // Create an object that writes to a new file with the specified
52 // name. Deletes any existing file with the same name and creates a
53 // new file. On success, stores a pointer to the new file in
54 // *result and returns OK. On failure, stores nullptr in *result and
55 // returns non-OK.
56 //
57 // The returned file will only be accessed by one thread at a time.
58 rocksdb::Status NewWritableFile(
59 const std::string& fname,
60 std::unique_ptr<rocksdb::WritableFile>* result,
61 const rocksdb::EnvOptions& options) override;
62
63 // Reuse an existing file by renaming it and opening it as writable.
64 rocksdb::Status ReuseWritableFile(
65 const std::string& fname,
66 const std::string& old_fname,
67 std::unique_ptr<rocksdb::WritableFile>* result,
68 const rocksdb::EnvOptions& options) override;
69
70 // Create an object that represents a directory. Will fail if directory
71 // doesn't exist. If the directory exists, it will open the directory
72 // and create a new Directory object.
73 //
74 // On success, stores a pointer to the new Directory in
75 // *result and returns OK. On failure stores nullptr in *result and
76 // returns non-OK.
77 rocksdb::Status NewDirectory(
78 const std::string& name,
79 std::unique_ptr<rocksdb::Directory>* result) override;
80
81 // Returns OK if the named file exists.
82 // NotFound if the named file does not exist,
83 // the calling process does not have permission to determine
84 // whether this file exists, or if the path is invalid.
85 // IOError if an IO Error was encountered
86 rocksdb::Status FileExists(const std::string& fname) override;
87
88 // Store in *result the names of the children of the specified directory.
89 // The names are relative to "dir".
90 // Original contents of *results are dropped.
91 rocksdb::Status GetChildren(const std::string& dir,
92 std::vector<std::string>* result) override;
93
94 // Delete the named file.
95 rocksdb::Status DeleteFile(const std::string& fname) override;
96
97 // Create the specified directory. Returns error if directory exists.
98 rocksdb::Status CreateDir(const std::string& dirname) override;
99
100 // Create directory if missing. Return Ok if it exists, or successful in
101 // Creating.
102 rocksdb::Status CreateDirIfMissing(const std::string& dirname) override;
103
104 // Delete the specified directory.
105 rocksdb::Status DeleteDir(const std::string& dirname) override;
106
107 // Store the size of fname in *file_size.
108 rocksdb::Status GetFileSize(const std::string& fname, uint64_t* file_size) override;
109
110 // Store the last modification time of fname in *file_mtime.
111 rocksdb::Status GetFileModificationTime(const std::string& fname,
112 uint64_t* file_mtime) override;
113 // Rename file src to target.
114 rocksdb::Status RenameFile(const std::string& src,
115 const std::string& target) override;
116 // Hard Link file src to target.
117 rocksdb::Status LinkFile(const std::string& src, const std::string& target) override;
118
119 // Tell if two files are identical
120 rocksdb::Status AreFilesSame(const std::string& first,
121 const std::string& second, bool* res) override;
122
123 // Lock the specified file. Used to prevent concurrent access to
124 // the same db by multiple processes. On failure, stores nullptr in
125 // *lock and returns non-OK.
126 //
127 // On success, stores a pointer to the object that represents the
128 // acquired lock in *lock and returns OK. The caller should call
129 // UnlockFile(*lock) to release the lock. If the process exits,
130 // the lock will be automatically released.
131 //
132 // If somebody else already holds the lock, finishes immediately
133 // with a failure. I.e., this call does not wait for existing locks
134 // to go away.
135 //
136 // May create the named file if it does not already exist.
137 rocksdb::Status LockFile(const std::string& fname, rocksdb::FileLock** lock) override;
138
139 // Release the lock acquired by a previous successful call to LockFile.
140 // REQUIRES: lock was returned by a successful LockFile() call
141 // REQUIRES: lock has not already been unlocked.
142 rocksdb::Status UnlockFile(rocksdb::FileLock* lock) override;
143
144 // *path is set to a temporary directory that can be used for testing. It may
145 // or may not have just been created. The directory may or may not differ
146 // between runs of the same process, but subsequent calls will return the
147 // same directory.
148 rocksdb::Status GetTestDirectory(std::string* path) override;
149
150 // Create and return a log file for storing informational messages.
151 rocksdb::Status NewLogger(
152 const std::string& fname,
153 std::shared_ptr<rocksdb::Logger>* result) override;
154
155 // Get full directory name for this db.
156 rocksdb::Status GetAbsolutePath(const std::string& db_path,
157 std::string* output_path) override;
158
159 explicit BlueRocksEnv(BlueFS *f);
160 private:
161 BlueFS *fs;
162 };
163
164 #endif