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

Side by Side Diff: components/leveldb_proto/leveldb_database.cc

Issue 2953473002: Use leveldb_env::OpenDB() to open leveldb databases. (Closed)
Patch Set: Rebase; address comments 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/leveldb_proto/leveldb_database.h" 5 #include "components/leveldb_proto/leveldb_database.h"
6 6
7 #include <inttypes.h> 7 #include <inttypes.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( 55 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
56 this); 56 this);
57 } 57 }
58 58
59 bool LevelDB::InitWithOptions(const base::FilePath& database_dir, 59 bool LevelDB::InitWithOptions(const base::FilePath& database_dir,
60 const leveldb::Options& options) { 60 const leveldb::Options& options) {
61 DFAKE_SCOPED_LOCK(thread_checker_); 61 DFAKE_SCOPED_LOCK(thread_checker_);
62 62
63 std::string path = database_dir.AsUTF8Unsafe(); 63 std::string path = database_dir.AsUTF8Unsafe();
64 64
65 leveldb::DB* db = NULL; 65 leveldb::Status status = leveldb_env::OpenDB(options, path, &db_);
66 leveldb::Status status = leveldb::DB::Open(options, path, &db);
67 if (open_histogram_) 66 if (open_histogram_)
68 open_histogram_->Add(leveldb_env::GetLevelDBStatusUMAValue(status)); 67 open_histogram_->Add(leveldb_env::GetLevelDBStatusUMAValue(status));
69 if (status.IsCorruption()) { 68 if (status.IsCorruption()) {
70 base::DeleteFile(database_dir, true); 69 base::DeleteFile(database_dir, true);
71 status = leveldb::DB::Open(options, path, &db); 70 status = leveldb_env::OpenDB(options, path, &db_);
72 } 71 }
73 72
74 if (status.ok()) { 73 if (status.ok()) {
75 CHECK(db);
nyquist 2017/07/18 18:48:16 This CHECK seems to be kept in place some places,
DmitrySkiba 2017/07/18 19:01:05 OpenDB() guarantees that now (i.e. CHECK effective
76 db_.reset(db);
77
78 base::trace_event::MemoryDumpManager::GetInstance() 74 base::trace_event::MemoryDumpManager::GetInstance()
79 ->RegisterDumpProviderWithSequencedTaskRunner( 75 ->RegisterDumpProviderWithSequencedTaskRunner(
80 this, "LevelDB", base::SequencedTaskRunnerHandle::Get(), 76 this, "LevelDB", base::SequencedTaskRunnerHandle::Get(),
81 base::trace_event::MemoryDumpProvider::Options()); 77 base::trace_event::MemoryDumpProvider::Options());
82 return true; 78 return true;
83 } 79 }
84 80
85 LOG(WARNING) << "Unable to open " << database_dir.value() << ": " 81 LOG(WARNING) << "Unable to open " << database_dir.value() << ": "
86 << status.ToString(); 82 << status.ToString();
87 return false; 83 return false;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 base::StringPrintf("leveldb/leveldb_proto/0x%" PRIXPTR, 212 base::StringPrintf("leveldb/leveldb_proto/0x%" PRIXPTR,
217 reinterpret_cast<uintptr_t>(db_.get()))); 213 reinterpret_cast<uintptr_t>(db_.get())));
218 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, 214 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
219 base::trace_event::MemoryAllocatorDump::kUnitsBytes, size); 215 base::trace_event::MemoryAllocatorDump::kUnitsBytes, size);
220 if (!client_name_.empty() && 216 if (!client_name_.empty() &&
221 dump_args.level_of_detail != 217 dump_args.level_of_detail !=
222 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND) { 218 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND) {
223 dump->AddString("client_name", "", client_name_); 219 dump->AddString("client_name", "", client_name_);
224 } 220 }
225 221
226 // Memory is allocated from system allocator (malloc). 222 // All leveldb databases are already dumped by leveldb_env::DBTracker. Add
227 const char* system_allocator_pool_name = 223 // an edge to avoid double counting.
228 base::trace_event::MemoryDumpManager::GetInstance() 224 pmd->AddSuballocation(dump->guid(),
229 ->system_allocator_pool_name(); 225 leveldb_env::DBTracker::GetMemoryDumpName(db_.get()));
230 if (system_allocator_pool_name)
231 pmd->AddSuballocation(dump->guid(), system_allocator_pool_name);
232 226
233 return true; 227 return true;
234 } 228 }
235 229
236 } // namespace leveldb_proto 230 } // namespace leveldb_proto
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698