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

Side by Side Diff: components/leveldb/leveldb_database_impl.cc

Issue 2953473002: Use leveldb_env::OpenDB() to open leveldb databases. (Closed)
Patch Set: Rebase; add comments to CHECK() 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 "components/leveldb/leveldb_database_impl.h" 5 #include "components/leveldb/leveldb_database_impl.h"
6 6
7 #include <inttypes.h> 7 #include <inttypes.h>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/optional.h" 12 #include "base/optional.h"
13 #include "base/rand_util.h" 13 #include "base/rand_util.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/trace_event/memory_dump_manager.h" 16 #include "base/trace_event/memory_dump_manager.h"
17 #include "components/leveldb/env_mojo.h" 17 #include "components/leveldb/env_mojo.h"
18 #include "components/leveldb/public/cpp/util.h" 18 #include "components/leveldb/public/cpp/util.h"
19 #include "third_party/leveldatabase/env_chromium.h"
19 #include "third_party/leveldatabase/src/include/leveldb/db.h" 20 #include "third_party/leveldatabase/src/include/leveldb/db.h"
20 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" 21 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h"
21 22
22 namespace leveldb { 23 namespace leveldb {
23 namespace { 24 namespace {
24 25
25 template <typename FunctionType> 26 template <typename FunctionType>
26 leveldb::Status ForEachWithPrefix(leveldb::DB* db, 27 leveldb::Status ForEachWithPrefix(leveldb::DB* db,
27 const leveldb::Slice& key_prefix, 28 const leveldb::Slice& key_prefix,
28 FunctionType function) { 29 FunctionType function) {
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, 304 mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
304 base::trace_event::MemoryAllocatorDump::kUnitsBytes, 305 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
305 memory_usage); 306 memory_usage);
306 if (cache_) { 307 if (cache_) {
307 auto* cache_mad = pmd->CreateAllocatorDump(name + "/block_cache"); 308 auto* cache_mad = pmd->CreateAllocatorDump(name + "/block_cache");
308 cache_mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, 309 cache_mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
309 base::trace_event::MemoryAllocatorDump::kUnitsBytes, 310 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
310 cache_->TotalCharge()); 311 cache_->TotalCharge());
311 } 312 }
312 313
313 const char* system_allocator_name = 314 // All leveldb databases are already dumped by leveldb_env::DBTracker. Add
314 base::trace_event::MemoryDumpManager::GetInstance() 315 // an edge to avoid double counting.
315 ->system_allocator_pool_name(); 316 pmd->AddSuballocation(mad->guid(),
316 if (system_allocator_name) 317 leveldb_env::DBTracker::GetMemoryDumpName(db_.get()));
317 pmd->AddSuballocation(mad->guid(), system_allocator_name);
318 318
319 if (memory_dump_id_) { 319 if (memory_dump_id_) {
320 auto* global_dump = pmd->CreateSharedGlobalAllocatorDump(*memory_dump_id_); 320 auto* global_dump = pmd->CreateSharedGlobalAllocatorDump(*memory_dump_id_);
321 pmd->AddOwnershipEdge(global_dump->guid(), mad->guid()); 321 pmd->AddOwnershipEdge(global_dump->guid(), mad->guid());
322 // Add size to global dump to propagate the size of the database to the 322 // Add size to global dump to propagate the size of the database to the
323 // client's dump. 323 // client's dump.
324 global_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, 324 global_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
325 base::trace_event::MemoryAllocatorDump::kUnitsBytes, 325 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
326 memory_usage); 326 memory_usage);
327 } 327 }
(...skipping 18 matching lines...) Expand all
346 const leveldb::Slice& key_prefix, 346 const leveldb::Slice& key_prefix,
347 leveldb::WriteBatch* batch) { 347 leveldb::WriteBatch* batch) {
348 leveldb::Status status = ForEachWithPrefix(db_.get(), key_prefix, 348 leveldb::Status status = ForEachWithPrefix(db_.get(), key_prefix,
349 [batch](const leveldb::Slice& key, const leveldb::Slice& value) { 349 [batch](const leveldb::Slice& key, const leveldb::Slice& value) {
350 batch->Delete(key); 350 batch->Delete(key);
351 }); 351 });
352 return status; 352 return status;
353 } 353 }
354 354
355 } // namespace leveldb 355 } // namespace leveldb
OLDNEW
« no previous file with comments | « components/drive/resource_metadata_storage.cc ('k') | components/leveldb/leveldb_service_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698