OLD | NEW |
1 // Copyright (c) 2013 The LevelDB Authors. All rights reserved. | 1 // Copyright (c) 2013 The LevelDB Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. See the AUTHORS file for names of contributors. | 3 // found in the LICENSE file. See the AUTHORS file for names of contributors. |
4 | 4 |
5 #ifndef THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ | 5 #ifndef THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ |
6 #define THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ | 6 #define THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 29 matching lines...) Expand all Loading... |
40 kGetTestDirectory, | 40 kGetTestDirectory, |
41 kNewLogger, | 41 kNewLogger, |
42 kSyncParent, | 42 kSyncParent, |
43 kGetChildren, | 43 kGetChildren, |
44 kNumEntries | 44 kNumEntries |
45 }; | 45 }; |
46 | 46 |
47 const char* MethodIDToString(MethodID method); | 47 const char* MethodIDToString(MethodID method); |
48 | 48 |
49 leveldb::Status MakeIOError(leveldb::Slice filename, | 49 leveldb::Status MakeIOError(leveldb::Slice filename, |
50 const char* message, | 50 const std::string& message, |
51 MethodID method, | |
52 int saved_errno); | |
53 leveldb::Status MakeIOError(leveldb::Slice filename, | |
54 const char* message, | |
55 MethodID method, | 51 MethodID method, |
56 base::File::Error error); | 52 base::File::Error error); |
57 leveldb::Status MakeIOError(leveldb::Slice filename, | 53 leveldb::Status MakeIOError(leveldb::Slice filename, |
58 const char* message, | 54 const std::string& message, |
59 MethodID method); | 55 MethodID method); |
60 | 56 |
61 enum ErrorParsingResult { | 57 enum ErrorParsingResult { |
62 METHOD_ONLY, | 58 METHOD_ONLY, |
63 METHOD_AND_PFE, | 59 METHOD_AND_PFE, |
64 METHOD_AND_ERRNO, | 60 METHOD_AND_ERRNO, |
65 NONE, | 61 NONE, |
66 }; | 62 }; |
67 | 63 |
68 ErrorParsingResult ParseMethodAndError(const char* string, | 64 ErrorParsingResult ParseMethodAndError(const char* string, |
69 MethodID* method, | 65 MethodID* method, |
70 int* error); | 66 int* error); |
71 int GetCorruptionCode(const leveldb::Status& status); | 67 int GetCorruptionCode(const leveldb::Status& status); |
72 int GetNumCorruptionCodes(); | 68 int GetNumCorruptionCodes(); |
73 std::string GetCorruptionMessage(const leveldb::Status& status); | 69 std::string GetCorruptionMessage(const leveldb::Status& status); |
74 bool IndicatesDiskFull(const leveldb::Status& status); | 70 bool IndicatesDiskFull(const leveldb::Status& status); |
75 bool IsIOError(const leveldb::Status& status); | 71 bool IsIOError(const leveldb::Status& status); |
76 bool IsCorruption(const leveldb::Status& status); | 72 bool IsCorruption(const leveldb::Status& status); |
77 std::string FilePathToString(const base::FilePath& file_path); | 73 std::string FilePathToString(const base::FilePath& file_path); |
78 | 74 |
79 class UMALogger { | 75 class UMALogger { |
80 public: | 76 public: |
81 virtual void RecordErrorAt(MethodID method) const = 0; | 77 virtual void RecordErrorAt(MethodID method) const = 0; |
82 virtual void RecordOSError(MethodID method, int saved_errno) const = 0; | |
83 virtual void RecordOSError(MethodID method, | 78 virtual void RecordOSError(MethodID method, |
84 base::File::Error error) const = 0; | 79 base::File::Error error) const = 0; |
85 virtual void RecordBackupResult(bool success) const = 0; | 80 virtual void RecordBackupResult(bool success) const = 0; |
86 }; | 81 }; |
87 | 82 |
88 class RetrierProvider { | 83 class RetrierProvider { |
89 public: | 84 public: |
90 virtual int MaxRetryTimeMillis() const = 0; | 85 virtual int MaxRetryTimeMillis() const = 0; |
91 virtual base::HistogramBase* GetRetryTimeHistogram(MethodID method) const = 0; | 86 virtual base::HistogramBase* GetRetryTimeHistogram(MethodID method) const = 0; |
92 virtual base::HistogramBase* GetRecoveredFromErrorHistogram( | 87 virtual base::HistogramBase* GetRecoveredFromErrorHistogram( |
93 MethodID method) const = 0; | 88 MethodID method) const = 0; |
94 }; | 89 }; |
95 | 90 |
96 class WriteTracker { | 91 class WriteTracker { |
97 public: | 92 public: |
98 virtual void DidCreateNewFile(const std::string& fname) = 0; | 93 virtual void DidCreateNewFile(const std::string& fname) = 0; |
99 virtual bool DoesDirNeedSync(const std::string& fname) = 0; | 94 virtual bool DoesDirNeedSync(const std::string& fname) = 0; |
100 virtual void DidSyncDir(const std::string& fname) = 0; | 95 virtual void DidSyncDir(const std::string& fname) = 0; |
101 }; | 96 }; |
102 | 97 |
103 class ChromiumEnv : public leveldb::Env, | 98 class ChromiumEnv : public leveldb::Env, |
104 public UMALogger, | 99 public UMALogger, |
105 public RetrierProvider, | 100 public RetrierProvider, |
106 public WriteTracker { | 101 public WriteTracker { |
107 public: | 102 public: |
| 103 ChromiumEnv(); |
| 104 |
108 typedef void(ScheduleFunc)(void*); | 105 typedef void(ScheduleFunc)(void*); |
109 | 106 |
110 static bool MakeBackup(const std::string& fname); | 107 static bool MakeBackup(const std::string& fname); |
111 static base::FilePath CreateFilePath(const std::string& file_path); | 108 static base::FilePath CreateFilePath(const std::string& file_path); |
112 static const char* FileErrorString(::base::File::Error error); | 109 static const char* FileErrorString(::base::File::Error error); |
113 static bool HasTableExtension(const base::FilePath& path); | 110 static bool HasTableExtension(const base::FilePath& path); |
114 virtual ~ChromiumEnv(); | 111 virtual ~ChromiumEnv(); |
115 | 112 |
116 virtual bool FileExists(const std::string& fname); | 113 virtual bool FileExists(const std::string& fname); |
117 virtual leveldb::Status GetChildren(const std::string& dir, | 114 virtual leveldb::Status GetChildren(const std::string& dir, |
118 std::vector<std::string>* result); | 115 std::vector<std::string>* result); |
119 virtual leveldb::Status DeleteFile(const std::string& fname); | 116 virtual leveldb::Status DeleteFile(const std::string& fname); |
120 virtual leveldb::Status CreateDir(const std::string& name); | 117 virtual leveldb::Status CreateDir(const std::string& name); |
121 virtual leveldb::Status DeleteDir(const std::string& name); | 118 virtual leveldb::Status DeleteDir(const std::string& name); |
122 virtual leveldb::Status GetFileSize(const std::string& fname, uint64_t* size); | 119 virtual leveldb::Status GetFileSize(const std::string& fname, uint64_t* size); |
123 virtual leveldb::Status RenameFile(const std::string& src, | 120 virtual leveldb::Status RenameFile(const std::string& src, |
124 const std::string& dst); | 121 const std::string& dst); |
125 virtual leveldb::Status LockFile(const std::string& fname, | 122 virtual leveldb::Status LockFile(const std::string& fname, |
126 leveldb::FileLock** lock); | 123 leveldb::FileLock** lock); |
127 virtual leveldb::Status UnlockFile(leveldb::FileLock* lock); | 124 virtual leveldb::Status UnlockFile(leveldb::FileLock* lock); |
128 virtual void Schedule(ScheduleFunc*, void* arg); | 125 virtual void Schedule(ScheduleFunc*, void* arg); |
129 virtual void StartThread(void (*function)(void* arg), void* arg); | 126 virtual void StartThread(void (*function)(void* arg), void* arg); |
130 virtual leveldb::Status GetTestDirectory(std::string* path); | 127 virtual leveldb::Status GetTestDirectory(std::string* path); |
131 virtual uint64_t NowMicros(); | 128 virtual uint64_t NowMicros(); |
132 virtual void SleepForMicroseconds(int micros); | 129 virtual void SleepForMicroseconds(int micros); |
| 130 virtual leveldb::Status NewSequentialFile(const std::string& fname, |
| 131 leveldb::SequentialFile** result); |
| 132 virtual leveldb::Status NewRandomAccessFile( |
| 133 const std::string& fname, |
| 134 leveldb::RandomAccessFile** result); |
| 135 virtual leveldb::Status NewWritableFile(const std::string& fname, |
| 136 leveldb::WritableFile** result); |
| 137 virtual leveldb::Status NewLogger(const std::string& fname, |
| 138 leveldb::Logger** result); |
133 | 139 |
134 protected: | 140 protected: |
135 ChromiumEnv(); | |
136 | |
137 virtual void DidCreateNewFile(const std::string& fname); | |
138 virtual bool DoesDirNeedSync(const std::string& fname); | |
139 virtual void DidSyncDir(const std::string& fname); | 141 virtual void DidSyncDir(const std::string& fname); |
140 virtual base::File::Error GetDirectoryEntries( | |
141 const base::FilePath& dir_param, | |
142 std::vector<base::FilePath>* result) const = 0; | |
143 virtual void RecordErrorAt(MethodID method) const; | |
144 virtual void RecordOSError(MethodID method, int saved_errno) const; | |
145 virtual void RecordOSError(MethodID method, | |
146 base::File::Error error) const; | |
147 base::HistogramBase* GetMaxFDHistogram(const std::string& type) const; | |
148 base::HistogramBase* GetOSErrorHistogram(MethodID method, int limit) const; | |
149 | 142 |
150 std::string name_; | 143 std::string name_; |
151 bool make_backup_; | 144 bool make_backup_; |
152 | 145 |
153 private: | 146 private: |
| 147 virtual void DidCreateNewFile(const std::string& fname); |
| 148 virtual bool DoesDirNeedSync(const std::string& fname); |
| 149 virtual void RecordErrorAt(MethodID method) const; |
| 150 virtual void RecordOSError(MethodID method, |
| 151 base::File::Error error) const; |
| 152 void RecordOpenFilesLimit(const std::string& type); |
| 153 base::HistogramBase* GetMaxFDHistogram(const std::string& type) const; |
| 154 base::HistogramBase* GetOSErrorHistogram(MethodID method, int limit) const; |
| 155 |
154 // File locks may not be exclusive within a process (e.g. on POSIX). Track | 156 // File locks may not be exclusive within a process (e.g. on POSIX). Track |
155 // locks held by the ChromiumEnv to prevent access within the process. | 157 // locks held by the ChromiumEnv to prevent access within the process. |
156 class LockTable { | 158 class LockTable { |
157 public: | 159 public: |
158 bool Insert(const std::string& fname) { | 160 bool Insert(const std::string& fname) { |
159 leveldb::MutexLock l(&mu_); | 161 leveldb::MutexLock l(&mu_); |
160 return locked_files_.insert(fname).second; | 162 return locked_files_.insert(fname).second; |
161 } | 163 } |
162 bool Remove(const std::string& fname) { | 164 bool Remove(const std::string& fname) { |
163 leveldb::MutexLock l(&mu_); | 165 leveldb::MutexLock l(&mu_); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 void (*function)(void*); | 206 void (*function)(void*); |
205 }; | 207 }; |
206 typedef std::deque<BGItem> BGQueue; | 208 typedef std::deque<BGItem> BGQueue; |
207 BGQueue queue_; | 209 BGQueue queue_; |
208 LockTable locks_; | 210 LockTable locks_; |
209 }; | 211 }; |
210 | 212 |
211 } // namespace leveldb_env | 213 } // namespace leveldb_env |
212 | 214 |
213 #endif // THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ | 215 #endif // THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ |
OLD | NEW |