Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: extensions/browser/value_store/lazy_leveldb.cc

Issue 2953473002: Use leveldb_env::OpenDB() to open leveldb databases. (Closed)
Patch Set: Don't dump in background mode Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium 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. 3 // found in the LICENSE file.
4 4
5 #include "extensions/browser/value_store/lazy_leveldb.h" 5 #include "extensions/browser/value_store/lazy_leveldb.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 ValueStore::BackingStoreRestoreStatus restore_status = 174 ValueStore::BackingStoreRestoreStatus restore_status =
175 ValueStore::RESTORE_NONE; 175 ValueStore::RESTORE_NONE;
176 176
177 leveldb::Options repair_options; 177 leveldb::Options repair_options;
178 repair_options.create_if_missing = true; 178 repair_options.create_if_missing = true;
179 repair_options.paranoid_checks = true; 179 repair_options.paranoid_checks = true;
180 180
181 // RepairDB can drop an unbounded number of leveldb tables (key/value sets). 181 // RepairDB can drop an unbounded number of leveldb tables (key/value sets).
182 s = leveldb::RepairDB(db_path_.AsUTF8Unsafe(), repair_options); 182 s = leveldb::RepairDB(db_path_.AsUTF8Unsafe(), repair_options);
183 183
184 leveldb::DB* db = nullptr;
185 if (s.ok()) { 184 if (s.ok()) {
186 restore_status = ValueStore::DB_RESTORE_REPAIR_SUCCESS; 185 restore_status = ValueStore::DB_RESTORE_REPAIR_SUCCESS;
187 s = leveldb::DB::Open(open_options_, db_path_.AsUTF8Unsafe(), &db); 186 s = leveldb_env::OpenDB(open_options_, db_path_.AsUTF8Unsafe(), &db_);
188 } 187 }
189 188
190 if (!s.ok()) { 189 if (!s.ok()) {
191 if (DeleteDbFile()) { 190 if (DeleteDbFile()) {
192 restore_status = ValueStore::DB_RESTORE_DELETE_SUCCESS; 191 restore_status = ValueStore::DB_RESTORE_DELETE_SUCCESS;
193 s = leveldb::DB::Open(open_options_, db_path_.AsUTF8Unsafe(), &db); 192 s = leveldb_env::OpenDB(open_options_, db_path_.AsUTF8Unsafe(), &db_);
194 } else { 193 } else {
195 restore_status = ValueStore::DB_RESTORE_DELETE_FAILURE; 194 restore_status = ValueStore::DB_RESTORE_DELETE_FAILURE;
196 } 195 }
197 } 196 }
198 197
199 if (s.ok()) 198 if (!s.ok())
200 db_.reset(db);
201 else
202 db_unrecoverable_ = true; 199 db_unrecoverable_ = true;
203 200
204 if (s.ok() && key) { 201 if (s.ok() && key) {
205 s = DeleteValue(db_.get(), *key); 202 s = DeleteValue(db_.get(), *key);
206 if (s.ok()) { 203 if (s.ok()) {
207 restore_status = ValueStore::VALUE_RESTORE_DELETE_SUCCESS; 204 restore_status = ValueStore::VALUE_RESTORE_DELETE_SUCCESS;
208 } else if (s.IsIOError()) { 205 } else if (s.IsIOError()) {
209 restore_status = ValueStore::VALUE_RESTORE_DELETE_FAILURE; 206 restore_status = ValueStore::VALUE_RESTORE_DELETE_FAILURE;
210 } else { 207 } else {
211 db_.reset(db); 208 db_.reset();
212 if (!DeleteDbFile()) 209 if (!DeleteDbFile())
213 db_unrecoverable_ = true; 210 db_unrecoverable_ = true;
214 restore_status = ValueStore::DB_RESTORE_DELETE_FAILURE; 211 restore_status = ValueStore::DB_RESTORE_DELETE_FAILURE;
215 } 212 }
216 } 213 }
217 214
218 // Only log for the final and most extreme form of database restoration. 215 // Only log for the final and most extreme form of database restoration.
219 LogRestoreStatus(restore_status); 216 LogRestoreStatus(restore_status);
220 217
221 return restore_status; 218 return restore_status;
222 } 219 }
223 220
224 ValueStore::Status LazyLevelDb::EnsureDbIsOpen() { 221 ValueStore::Status LazyLevelDb::EnsureDbIsOpen() {
225 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 222 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
226 223
227 if (db_) 224 if (db_)
228 return ValueStore::Status(); 225 return ValueStore::Status();
229 226
230 if (db_unrecoverable_) { 227 if (db_unrecoverable_) {
231 return ValueStore::Status(ValueStore::CORRUPTION, 228 return ValueStore::Status(ValueStore::CORRUPTION,
232 ValueStore::DB_RESTORE_DELETE_FAILURE, 229 ValueStore::DB_RESTORE_DELETE_FAILURE,
233 "Database corrupted"); 230 "Database corrupted");
234 } 231 }
235 232
236 leveldb::DB* db = nullptr;
237 leveldb::Status ldb_status = 233 leveldb::Status ldb_status =
238 leveldb::DB::Open(open_options_, db_path_.AsUTF8Unsafe(), &db); 234 leveldb_env::OpenDB(open_options_, db_path_.AsUTF8Unsafe(), &db_);
239 open_histogram_->Add(leveldb_env::GetLevelDBStatusUMAValue(ldb_status)); 235 open_histogram_->Add(leveldb_env::GetLevelDBStatusUMAValue(ldb_status));
240 ValueStore::Status status = ToValueStoreError(ldb_status); 236 ValueStore::Status status = ToValueStoreError(ldb_status);
241 if (ldb_status.ok()) { 237 if (ldb_status.IsCorruption()) {
242 db_.reset(db);
243 } else if (ldb_status.IsCorruption()) {
244 status.restore_status = FixCorruption(nullptr); 238 status.restore_status = FixCorruption(nullptr);
245 if (status.restore_status != ValueStore::DB_RESTORE_DELETE_FAILURE) { 239 if (status.restore_status != ValueStore::DB_RESTORE_DELETE_FAILURE) {
246 status.code = ValueStore::OK; 240 status.code = ValueStore::OK;
247 status.message = kRestoredDuringOpen; 241 status.message = kRestoredDuringOpen;
248 } 242 }
249 } 243 }
250 244
251 return status; 245 return status;
252 } 246 }
253 247
(...skipping 25 matching lines...) Expand all
279 273
280 ValueStore::Status LazyLevelDb::CreateIterator( 274 ValueStore::Status LazyLevelDb::CreateIterator(
281 const leveldb::ReadOptions& read_options, 275 const leveldb::ReadOptions& read_options,
282 std::unique_ptr<leveldb::Iterator>* iterator) { 276 std::unique_ptr<leveldb::Iterator>* iterator) {
283 ValueStore::Status status = EnsureDbIsOpen(); 277 ValueStore::Status status = EnsureDbIsOpen();
284 if (!status.ok()) 278 if (!status.ok())
285 return status; 279 return status;
286 *iterator = base::WrapUnique(db_->NewIterator(read_options)); 280 *iterator = base::WrapUnique(db_->NewIterator(read_options));
287 return ValueStore::Status(); 281 return ValueStore::Status();
288 } 282 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698