Chromium Code Reviews| 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 #ifndef CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_DATABASE_H_ | 5 #ifndef CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_DATABASE_H_ |
| 6 #define CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_DATABASE_H_ | 6 #define CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_DATABASE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/containers/mru_cache.h" | |
| 11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 14 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
| 15 #include "base/trace_event/memory_dump_provider.h" | 16 #include "base/trace_event/memory_dump_provider.h" |
| 17 #include "content/browser/indexed_db/leveldb/leveldb_iterator_pool_controller.h" | |
| 16 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
| 17 #include "third_party/leveldatabase/src/include/leveldb/comparator.h" | 19 #include "third_party/leveldatabase/src/include/leveldb/comparator.h" |
| 18 #include "third_party/leveldatabase/src/include/leveldb/status.h" | 20 #include "third_party/leveldatabase/src/include/leveldb/status.h" |
| 19 | 21 |
| 20 namespace leveldb { | 22 namespace leveldb { |
| 21 class Comparator; | 23 class Comparator; |
| 22 class DB; | 24 class DB; |
| 23 class FilterPolicy; | 25 class FilterPolicy; |
| 24 class Env; | 26 class Env; |
| 25 class Snapshot; | 27 class Snapshot; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 49 class CONTENT_EXPORT LevelDBLock { | 51 class CONTENT_EXPORT LevelDBLock { |
| 50 public: | 52 public: |
| 51 LevelDBLock() {} | 53 LevelDBLock() {} |
| 52 virtual ~LevelDBLock() {} | 54 virtual ~LevelDBLock() {} |
| 53 | 55 |
| 54 private: | 56 private: |
| 55 DISALLOW_COPY_AND_ASSIGN(LevelDBLock); | 57 DISALLOW_COPY_AND_ASSIGN(LevelDBLock); |
| 56 }; | 58 }; |
| 57 | 59 |
| 58 class CONTENT_EXPORT LevelDBDatabase | 60 class CONTENT_EXPORT LevelDBDatabase |
| 59 : public base::trace_event::MemoryDumpProvider { | 61 : public base::trace_event::MemoryDumpProvider, |
| 62 NON_EXPORTED_BASE(public LevelDBIteratorPoolController) { | |
|
pwnall
2017/03/24 09:16:02
I'm not a big fan of the interface and extra name
dmurph
2017/03/24 23:33:39
That sounds fine to me - just trying to make the i
| |
| 60 public: | 63 public: |
| 61 class ComparatorAdapter : public leveldb::Comparator { | 64 class ComparatorAdapter : public leveldb::Comparator { |
| 62 public: | 65 public: |
| 63 explicit ComparatorAdapter(const LevelDBComparator* comparator); | 66 explicit ComparatorAdapter(const LevelDBComparator* comparator); |
| 64 | 67 |
| 65 int Compare(const leveldb::Slice& a, | 68 int Compare(const leveldb::Slice& a, |
| 66 const leveldb::Slice& b) const override; | 69 const leveldb::Slice& b) const override; |
| 67 | 70 |
| 68 const char* Name() const override; | 71 const char* Name() const override; |
| 69 | 72 |
| 70 void FindShortestSeparator(std::string* start, | 73 void FindShortestSeparator(std::string* start, |
| 71 const leveldb::Slice& limit) const override; | 74 const leveldb::Slice& limit) const override; |
| 72 void FindShortSuccessor(std::string* key) const override; | 75 void FindShortSuccessor(std::string* key) const override; |
| 73 | 76 |
| 74 private: | 77 private: |
| 75 const LevelDBComparator* comparator_; | 78 const LevelDBComparator* comparator_; |
| 76 }; | 79 }; |
| 77 | 80 |
| 81 enum { NO_CURSOR_EVICTION = 0 }; | |
|
pwnall
2017/03/24 09:16:03
It seems to me that this option is only used for t
dmurph
2017/03/24 23:33:39
Based on offline conversation, doing it so the beh
| |
| 82 | |
| 83 // Set |max_open_cursors| to NO_CURSOR_EVICTION to disable eviction. | |
| 78 static leveldb::Status Open(const base::FilePath& file_name, | 84 static leveldb::Status Open(const base::FilePath& file_name, |
| 79 const LevelDBComparator* comparator, | 85 const LevelDBComparator* comparator, |
| 80 std::unique_ptr<LevelDBDatabase>* db, | 86 std::unique_ptr<LevelDBDatabase>* db, |
| 87 size_t max_open_cursors, | |
| 81 bool* is_disk_full = 0); | 88 bool* is_disk_full = 0); |
| 89 | |
| 82 static std::unique_ptr<LevelDBDatabase> OpenInMemory( | 90 static std::unique_ptr<LevelDBDatabase> OpenInMemory( |
| 83 const LevelDBComparator* comparator); | 91 const LevelDBComparator* comparator); |
| 84 static leveldb::Status Destroy(const base::FilePath& file_name); | 92 static leveldb::Status Destroy(const base::FilePath& file_name); |
| 85 static std::unique_ptr<LevelDBLock> LockForTesting( | 93 static std::unique_ptr<LevelDBLock> LockForTesting( |
| 86 const base::FilePath& file_name); | 94 const base::FilePath& file_name); |
| 87 ~LevelDBDatabase() override; | 95 ~LevelDBDatabase() override; |
| 88 | 96 |
| 89 leveldb::Status Put(const base::StringPiece& key, std::string* value); | 97 leveldb::Status Put(const base::StringPiece& key, std::string* value); |
| 90 leveldb::Status Remove(const base::StringPiece& key); | 98 leveldb::Status Remove(const base::StringPiece& key); |
| 91 virtual leveldb::Status Get(const base::StringPiece& key, | 99 virtual leveldb::Status Get(const base::StringPiece& key, |
| 92 std::string* value, | 100 std::string* value, |
| 93 bool* found, | 101 bool* found, |
| 94 const LevelDBSnapshot* = 0); | 102 const LevelDBSnapshot* = 0); |
| 95 leveldb::Status Write(const LevelDBWriteBatch& write_batch); | 103 leveldb::Status Write(const LevelDBWriteBatch& write_batch); |
| 96 std::unique_ptr<LevelDBIterator> CreateIterator(const LevelDBSnapshot* = 0); | 104 std::unique_ptr<LevelDBIterator> CreateIterator(const LevelDBSnapshot* = 0); |
| 97 const LevelDBComparator* Comparator() const; | 105 const LevelDBComparator* Comparator() const; |
| 98 void Compact(const base::StringPiece& start, const base::StringPiece& stop); | 106 void Compact(const base::StringPiece& start, const base::StringPiece& stop); |
| 99 void CompactAll(); | 107 void CompactAll(); |
| 100 | 108 |
| 101 // base::trace_event::MemoryDumpProvider implementation. | 109 // base::trace_event::MemoryDumpProvider implementation. |
| 102 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | 110 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, |
| 103 base::trace_event::ProcessMemoryDump* pmd) override; | 111 base::trace_event::ProcessMemoryDump* pmd) override; |
| 104 | 112 |
| 113 // Methods for iterator pooling. | |
| 114 std::unique_ptr<leveldb::Iterator> CreateLevelDBIterator( | |
|
pwnall
2017/03/24 09:16:02
Would it make sense to have these be private and a
dmurph
2017/03/24 23:33:39
Sure.
| |
| 115 const leveldb::Snapshot*) override; | |
| 116 void NotifyIteratorUsed(LevelDBIterator*) override; | |
| 117 void NotifyIteratorDestroyed(LevelDBIterator*) override; | |
| 118 | |
| 105 protected: | 119 protected: |
| 106 LevelDBDatabase(); | 120 LevelDBDatabase(size_t max_open_iterators); |
| 107 | 121 |
| 108 private: | 122 private: |
| 109 friend class LevelDBSnapshot; | 123 friend class LevelDBSnapshot; |
| 110 | 124 |
| 111 void CloseDatabase(); | 125 void CloseDatabase(); |
| 112 | 126 |
| 113 std::unique_ptr<leveldb::Env> env_; | 127 std::unique_ptr<leveldb::Env> env_; |
| 114 std::unique_ptr<leveldb::Comparator> comparator_adapter_; | 128 std::unique_ptr<leveldb::Comparator> comparator_adapter_; |
| 115 std::unique_ptr<leveldb::DB> db_; | 129 std::unique_ptr<leveldb::DB> db_; |
| 116 std::unique_ptr<const leveldb::FilterPolicy> filter_policy_; | 130 std::unique_ptr<const leveldb::FilterPolicy> filter_policy_; |
| 117 const LevelDBComparator* comparator_; | 131 const LevelDBComparator* comparator_; |
| 132 | |
| 133 // Despite the type name, this object uses LRU eviction. | |
| 134 bool eviction_enabled_ = false; | |
| 135 base::MRUCache<LevelDBIterator*, LevelDBIterator*> iterator_lru_; | |
|
pwnall
2017/03/24 09:16:03
Would it make sense to use a HashingMRUCache here?
dmurph
2017/03/24 23:33:39
Sure.
| |
| 136 // Recorded for UMA reporting. | |
| 137 uint32_t num_iterators_ = 0; | |
| 138 uint32_t max_iterators_ = 0; | |
| 139 | |
| 118 std::string file_name_for_tracing; | 140 std::string file_name_for_tracing; |
| 119 }; | 141 }; |
| 120 | 142 |
| 121 } // namespace content | 143 } // namespace content |
| 122 | 144 |
| 123 #endif // CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_DATABASE_H_ | 145 #endif // CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_DATABASE_H_ |
| OLD | NEW |