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

Side by Side Diff: content/browser/indexed_db/leveldb/leveldb_database.h

Issue 2760163002: [IndexedDB] Pool and evict leveldb iterators, to save memory (Closed)
Patch Set: compile fixed Created 3 years, 9 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 (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"
16 #include "content/common/content_export.h" 17 #include "content/common/content_export.h"
17 #include "third_party/leveldatabase/src/include/leveldb/comparator.h" 18 #include "third_party/leveldatabase/src/include/leveldb/comparator.h"
18 #include "third_party/leveldatabase/src/include/leveldb/status.h" 19 #include "third_party/leveldatabase/src/include/leveldb/status.h"
19 20
20 namespace leveldb { 21 namespace leveldb {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 const char* Name() const override; 69 const char* Name() const override;
69 70
70 void FindShortestSeparator(std::string* start, 71 void FindShortestSeparator(std::string* start,
71 const leveldb::Slice& limit) const override; 72 const leveldb::Slice& limit) const override;
72 void FindShortSuccessor(std::string* key) const override; 73 void FindShortSuccessor(std::string* key) const override;
73 74
74 private: 75 private:
75 const LevelDBComparator* comparator_; 76 const LevelDBComparator* comparator_;
76 }; 77 };
77 78
79 static leveldb::Status OpenForTesting(const base::FilePath& file_name,
80 const LevelDBComparator* comparator,
81 std::unique_ptr<LevelDBDatabase>* db,
82 size_t max_open_cursors);
83
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,
81 bool* is_disk_full = 0); 87 bool* is_disk_full = 0);
82 static std::unique_ptr<LevelDBDatabase> OpenInMemory( 88 static std::unique_ptr<LevelDBDatabase> OpenInMemory(
83 const LevelDBComparator* comparator); 89 const LevelDBComparator* comparator);
84 static leveldb::Status Destroy(const base::FilePath& file_name); 90 static leveldb::Status Destroy(const base::FilePath& file_name);
85 static std::unique_ptr<LevelDBLock> LockForTesting( 91 static std::unique_ptr<LevelDBLock> LockForTesting(
86 const base::FilePath& file_name); 92 const base::FilePath& file_name);
87 ~LevelDBDatabase() override; 93 ~LevelDBDatabase() override;
88 94
89 leveldb::Status Put(const base::StringPiece& key, std::string* value); 95 leveldb::Status Put(const base::StringPiece& key, std::string* value);
90 leveldb::Status Remove(const base::StringPiece& key); 96 leveldb::Status Remove(const base::StringPiece& key);
91 virtual leveldb::Status Get(const base::StringPiece& key, 97 virtual leveldb::Status Get(const base::StringPiece& key,
92 std::string* value, 98 std::string* value,
93 bool* found, 99 bool* found,
94 const LevelDBSnapshot* = 0); 100 const LevelDBSnapshot* = 0);
95 leveldb::Status Write(const LevelDBWriteBatch& write_batch); 101 leveldb::Status Write(const LevelDBWriteBatch& write_batch);
96 std::unique_ptr<LevelDBIterator> CreateIterator(const LevelDBSnapshot* = 0); 102 std::unique_ptr<LevelDBIterator> CreateIterator(const LevelDBSnapshot* = 0);
97 const LevelDBComparator* Comparator() const; 103 const LevelDBComparator* Comparator() const;
98 void Compact(const base::StringPiece& start, const base::StringPiece& stop); 104 void Compact(const base::StringPiece& start, const base::StringPiece& stop);
99 void CompactAll(); 105 void CompactAll();
100 106
101 // base::trace_event::MemoryDumpProvider implementation. 107 // base::trace_event::MemoryDumpProvider implementation.
102 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, 108 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
103 base::trace_event::ProcessMemoryDump* pmd) override; 109 base::trace_event::ProcessMemoryDump* pmd) override;
104 110
111 void NotifyIteratorCreated(LevelDBIterator*);
112 void NotifyIteratorUsed(LevelDBIterator*);
113 void NotifyIteratorDestroyed(LevelDBIterator*);
114
105 protected: 115 protected:
106 LevelDBDatabase(); 116 LevelDBDatabase();
117 LevelDBDatabase(size_t max_open_iterators);
107 118
108 private: 119 private:
109 friend class LevelDBSnapshot; 120 friend class LevelDBSnapshot;
110 121
111 void CloseDatabase(); 122 void CloseDatabase();
112 123
113 std::unique_ptr<leveldb::Env> env_; 124 std::unique_ptr<leveldb::Env> env_;
114 std::unique_ptr<leveldb::Comparator> comparator_adapter_; 125 std::unique_ptr<leveldb::Comparator> comparator_adapter_;
115 std::unique_ptr<leveldb::DB> db_; 126 std::unique_ptr<leveldb::DB> db_;
116 std::unique_ptr<const leveldb::FilterPolicy> filter_policy_; 127 std::unique_ptr<const leveldb::FilterPolicy> filter_policy_;
117 const LevelDBComparator* comparator_; 128 const LevelDBComparator* comparator_;
129
130 // Despite the type name, this object uses LRU eviction.
131 base::MRUCache<LevelDBIterator*, LevelDBIterator*> iterator_lru_;
132 // Recorded for UMA reporting.
133 uint32_t num_iterators_ = 0;
134 uint32_t max_iterators_ = 0;
135
118 std::string file_name_for_tracing; 136 std::string file_name_for_tracing;
119 }; 137 };
120 138
121 } // namespace content 139 } // namespace content
122 140
123 #endif // CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_DATABASE_H_ 141 #endif // CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698