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