OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/browser/indexed_db/leveldb/leveldb_database.h" | 5 #include "content/browser/indexed_db/leveldb/leveldb_database.h" |
6 | 6 |
7 #include <inttypes.h> | 7 #include <inttypes.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <cerrno> | 10 #include <cerrno> |
(...skipping 23 matching lines...) Expand all Loading... | |
34 #include "third_party/leveldatabase/env_chromium.h" | 34 #include "third_party/leveldatabase/env_chromium.h" |
35 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" | 35 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" |
36 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 36 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
37 #include "third_party/leveldatabase/src/include/leveldb/env.h" | 37 #include "third_party/leveldatabase/src/include/leveldb/env.h" |
38 #include "third_party/leveldatabase/src/include/leveldb/filter_policy.h" | 38 #include "third_party/leveldatabase/src/include/leveldb/filter_policy.h" |
39 #include "third_party/leveldatabase/src/include/leveldb/slice.h" | 39 #include "third_party/leveldatabase/src/include/leveldb/slice.h" |
40 | 40 |
41 using base::StringPiece; | 41 using base::StringPiece; |
42 | 42 |
43 namespace content { | 43 namespace content { |
44 static const size_t kMaxOpenIteratorsPerDatabase = 50; | |
jsbell
2017/03/21 00:15:48
We should get UMA stats on this. It may be that we
dmurph
2017/03/21 20:13:25
Hm... so I'll keep track of the max, and then repo
| |
44 | 45 |
45 // Forcing flushes to disk at the end of a transaction guarantees that the | 46 // Forcing flushes to disk at the end of a transaction guarantees that the |
46 // data hit disk, but drastically impacts throughput when the filesystem is | 47 // data hit disk, but drastically impacts throughput when the filesystem is |
47 // busy with background compactions. Not syncing trades off reliability for | 48 // busy with background compactions. Not syncing trades off reliability for |
48 // performance. Note that background compactions which move data from the | 49 // performance. Note that background compactions which move data from the |
49 // log to SSTs are always done with reliable writes. | 50 // log to SSTs are always done with reliable writes. |
50 // | 51 // |
51 // Sync writes are necessary on Windows for quota calculations; POSIX | 52 // Sync writes are necessary on Windows for quota calculations; POSIX |
52 // calculates file sizes correctly even when not synced to disk. | 53 // calculates file sizes correctly even when not synced to disk. |
53 #if defined(OS_WIN) | 54 #if defined(OS_WIN) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 const leveldb::Slice& limit) const {} | 86 const leveldb::Slice& limit) const {} |
86 | 87 |
87 void LevelDBDatabase::ComparatorAdapter::FindShortSuccessor( | 88 void LevelDBDatabase::ComparatorAdapter::FindShortSuccessor( |
88 std::string* key) const {} | 89 std::string* key) const {} |
89 | 90 |
90 LevelDBSnapshot::LevelDBSnapshot(LevelDBDatabase* db) | 91 LevelDBSnapshot::LevelDBSnapshot(LevelDBDatabase* db) |
91 : db_(db->db_.get()), snapshot_(db_->GetSnapshot()) {} | 92 : db_(db->db_.get()), snapshot_(db_->GetSnapshot()) {} |
92 | 93 |
93 LevelDBSnapshot::~LevelDBSnapshot() { db_->ReleaseSnapshot(snapshot_); } | 94 LevelDBSnapshot::~LevelDBSnapshot() { db_->ReleaseSnapshot(snapshot_); } |
94 | 95 |
95 LevelDBDatabase::LevelDBDatabase() {} | 96 LevelDBDatabase::LevelDBDatabase() |
97 : iterator_lru_(kMaxOpenIteratorsPerDatabase) {} | |
96 | 98 |
97 LevelDBDatabase::~LevelDBDatabase() { | 99 LevelDBDatabase::~LevelDBDatabase() { |
98 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 100 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
99 this); | 101 this); |
100 // db_'s destructor uses comparator_adapter_; order of deletion is important. | 102 // db_'s destructor uses comparator_adapter_; order of deletion is important. |
101 CloseDatabase(); | 103 CloseDatabase(); |
102 comparator_adapter_.reset(); | 104 comparator_adapter_.reset(); |
103 env_.reset(); | 105 env_.reset(); |
104 } | 106 } |
105 | 107 |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
472 base::trace_event::MemoryAllocatorDump::kUnitsBytes, size); | 474 base::trace_event::MemoryAllocatorDump::kUnitsBytes, size); |
473 dump->AddString("file_name", "", file_name_for_tracing); | 475 dump->AddString("file_name", "", file_name_for_tracing); |
474 | 476 |
475 // Memory is allocated from system allocator (malloc). | 477 // Memory is allocated from system allocator (malloc). |
476 pmd->AddSuballocation(dump->guid(), | 478 pmd->AddSuballocation(dump->guid(), |
477 base::trace_event::MemoryDumpManager::GetInstance() | 479 base::trace_event::MemoryDumpManager::GetInstance() |
478 ->system_allocator_pool_name()); | 480 ->system_allocator_pool_name()); |
479 return true; | 481 return true; |
480 } | 482 } |
481 | 483 |
484 void LevelDBDatabase::NotifyIteratorUsed(LevelDBIterator* iter) { | |
485 if (iterator_lru_.size() == iterator_lru_.max_size()) { | |
486 auto to_evict_iter = iterator_lru_.rbegin(); | |
487 LevelDBIterator* to_evict = to_evict_iter->first; | |
488 to_evict->EvictWorkingMemory(); | |
489 iterator_lru_.Erase(to_evict_iter); | |
490 } | |
491 iterator_lru_.Put(iter, iter); | |
492 } | |
493 | |
494 void LevelDBDatabase::NotifyIteratorDestroyed(LevelDBIterator* iter) { | |
495 auto it = iterator_lru_.Get(iter); | |
496 if (it == iterator_lru_.end()) { | |
jsbell
2017/03/21 00:15:48
nit: no need for {}
dmurph
2017/03/21 20:13:25
Done.
| |
497 return; | |
498 } | |
499 iterator_lru_.Erase(it); | |
500 LOG(ERROR) << "iterator erased"; | |
jsbell
2017/03/21 00:15:48
nit: obviously remove before landing. :)
dmurph
2017/03/21 20:13:25
Done.
| |
501 } | |
482 } // namespace content | 502 } // namespace content |
OLD | NEW |