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