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

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

Issue 2953473002: Use leveldb_env::OpenDB() to open leveldb databases. (Closed)
Patch Set: Use OpenDB in unittests; add allocation edges 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( 54 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
55 this); 55 this);
56 } 56 }
57 57
58 bool LevelDB::InitWithOptions(const base::FilePath& database_dir, 58 bool LevelDB::InitWithOptions(const base::FilePath& database_dir,
59 const leveldb::Options& options) { 59 const leveldb::Options& options) {
60 DFAKE_SCOPED_LOCK(thread_checker_); 60 DFAKE_SCOPED_LOCK(thread_checker_);
61 61
62 std::string path = database_dir.AsUTF8Unsafe(); 62 std::string path = database_dir.AsUTF8Unsafe();
63 63
64 leveldb::DB* db = NULL; 64 leveldb::Status status = leveldb_env::OpenDB(options, path, &db_);
65 leveldb::Status status = leveldb::DB::Open(options, path, &db);
66 if (open_histogram_) 65 if (open_histogram_)
67 open_histogram_->Add(leveldb_env::GetLevelDBStatusUMAValue(status)); 66 open_histogram_->Add(leveldb_env::GetLevelDBStatusUMAValue(status));
68 if (status.IsCorruption()) { 67 if (status.IsCorruption()) {
69 base::DeleteFile(database_dir, true); 68 base::DeleteFile(database_dir, true);
70 status = leveldb::DB::Open(options, path, &db); 69 status = leveldb_env::OpenDB(options, path, &db_);
71 } 70 }
72 71
73 if (status.ok()) { 72 if (status.ok()) {
74 CHECK(db);
pwnall 2017/07/06 14:32:25 Can you please leave the CHECK in? I think CHECK(d
DmitrySkiba 2017/07/06 23:15:13 I think this is better done on OpenDB() side - I'v
75 db_.reset(db);
76
77 base::trace_event::MemoryDumpManager::GetInstance() 73 base::trace_event::MemoryDumpManager::GetInstance()
78 ->RegisterDumpProviderWithSequencedTaskRunner( 74 ->RegisterDumpProviderWithSequencedTaskRunner(
79 this, "LevelDB", base::SequencedTaskRunnerHandle::Get(), 75 this, "LevelDB", base::SequencedTaskRunnerHandle::Get(),
80 base::trace_event::MemoryDumpProvider::Options()); 76 base::trace_event::MemoryDumpProvider::Options());
81 return true; 77 return true;
82 } 78 }
83 79
84 LOG(WARNING) << "Unable to open " << database_dir.value() << ": " 80 LOG(WARNING) << "Unable to open " << database_dir.value() << ": "
85 << status.ToString(); 81 << status.ToString();
86 return false; 82 return false;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 base::StringPrintf("leveldb/leveldb_proto/0x%" PRIXPTR, 194 base::StringPrintf("leveldb/leveldb_proto/0x%" PRIXPTR,
199 reinterpret_cast<uintptr_t>(db_.get()))); 195 reinterpret_cast<uintptr_t>(db_.get())));
200 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, 196 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
201 base::trace_event::MemoryAllocatorDump::kUnitsBytes, size); 197 base::trace_event::MemoryAllocatorDump::kUnitsBytes, size);
202 if (!client_name_.empty() && 198 if (!client_name_.empty() &&
203 dump_args.level_of_detail != 199 dump_args.level_of_detail !=
204 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND) { 200 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND) {
205 dump->AddString("client_name", "", client_name_); 201 dump->AddString("client_name", "", client_name_);
206 } 202 }
207 203
208 // Memory is allocated from system allocator (malloc). 204 // All leveldb databases are already dumped by leveldb_env::DBTracker. Add
209 const char* system_allocator_pool_name = 205 // an edge to avoid double counting.
210 base::trace_event::MemoryDumpManager::GetInstance() 206 pmd->AddSuballocation(dump->guid(),
211 ->system_allocator_pool_name(); 207 leveldb_env::DBTracker::GetMemoryDumpName(db_.get()));
212 if (system_allocator_pool_name)
213 pmd->AddSuballocation(dump->guid(), system_allocator_pool_name);
214 208
215 return true; 209 return true;
216 } 210 }
217 211
218 } // namespace leveldb_proto 212 } // namespace leveldb_proto
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698