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

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

Issue 2760163002: [IndexedDB] Pool and evict leveldb iterators, to save memory (Closed)
Patch Set: 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_TRANSACTION_H_ 5 #ifndef CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_TRANSACTION_H_
6 #define CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_TRANSACTION_H_ 6 #define CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_TRANSACTION_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 static std::unique_ptr<DataIterator> Create( 86 static std::unique_ptr<DataIterator> Create(
87 LevelDBTransaction* transaction); 87 LevelDBTransaction* transaction);
88 ~DataIterator() override; 88 ~DataIterator() override;
89 bool IsValid() const override; 89 bool IsValid() const override;
90 leveldb::Status SeekToLast() override; 90 leveldb::Status SeekToLast() override;
91 leveldb::Status Seek(const base::StringPiece& slice) override; 91 leveldb::Status Seek(const base::StringPiece& slice) override;
92 leveldb::Status Next() override; 92 leveldb::Status Next() override;
93 leveldb::Status Prev() override; 93 leveldb::Status Prev() override;
94 base::StringPiece Key() const override; 94 base::StringPiece Key() const override;
95 base::StringPiece Value() const override; 95 base::StringPiece Value() const override;
96
96 bool IsDeleted() const; 97 bool IsDeleted() const;
97 98
98 // Mark the current record as deleted. 99 // Mark the current record as deleted.
99 void Delete(); 100 void Delete();
100 101
101 private: 102 private:
102 explicit DataIterator(LevelDBTransaction* transaction); 103 explicit DataIterator(LevelDBTransaction* transaction);
103 DataType* data_; 104 DataType* data_;
104 DataType::iterator iterator_; 105 DataType::iterator iterator_;
105 106
(...skipping 10 matching lines...) Expand all
116 static std::unique_ptr<TransactionIterator> Create( 117 static std::unique_ptr<TransactionIterator> Create(
117 scoped_refptr<LevelDBTransaction> transaction); 118 scoped_refptr<LevelDBTransaction> transaction);
118 119
119 bool IsValid() const override; 120 bool IsValid() const override;
120 leveldb::Status SeekToLast() override; 121 leveldb::Status SeekToLast() override;
121 leveldb::Status Seek(const base::StringPiece& target) override; 122 leveldb::Status Seek(const base::StringPiece& target) override;
122 leveldb::Status Next() override; 123 leveldb::Status Next() override;
123 leveldb::Status Prev() override; 124 leveldb::Status Prev() override;
124 base::StringPiece Key() const override; 125 base::StringPiece Key() const override;
125 base::StringPiece Value() const override; 126 base::StringPiece Value() const override;
127 void EvictWorkingMemory() override;
128
126 void DataChanged(); 129 void DataChanged();
127 130
128 // Mark the current record as deleted. If an existing record 131 // Mark the current record as deleted. If an existing record
129 // is present in the uncommitted data this will convert it to 132 // is present in the uncommitted data this will convert it to
130 // a deletion record, otherwise it will insert a new one. 133 // a deletion record, otherwise it will insert a new one.
131 void Delete(); 134 void Delete();
132 135
133 private: 136 private:
134 enum Direction { FORWARD, REVERSE }; 137 enum Direction { FORWARD, REVERSE };
135 138
136 explicit TransactionIterator(scoped_refptr<LevelDBTransaction> transaction); 139 explicit TransactionIterator(scoped_refptr<LevelDBTransaction> transaction);
137 void HandleConflictsAndDeletes(); 140 void HandleConflictsAndDeletes();
138 void SetCurrentIteratorToSmallestKey(); 141 void SetCurrentIteratorToSmallestKey();
139 void SetCurrentIteratorToLargestKey(); 142 void SetCurrentIteratorToLargestKey();
140 void RefreshDataIterator() const; 143 void RefreshDataIterator() const;
141 bool DataIteratorIsLower() const; 144 bool DataIteratorIsLower() const;
142 bool DataIteratorIsHigher() const; 145 bool DataIteratorIsHigher() const;
143 146
147 void LoadDBIteratorIfEvicted();
148
144 scoped_refptr<LevelDBTransaction> transaction_; 149 scoped_refptr<LevelDBTransaction> transaction_;
145 const LevelDBComparator* comparator_; 150 const LevelDBComparator* comparator_;
146 mutable std::unique_ptr<DataIterator> data_iterator_; 151 mutable std::unique_ptr<DataIterator> data_iterator_;
147 std::unique_ptr<LevelDBIterator> db_iterator_; 152 std::unique_ptr<LevelDBIterator> db_iterator_;
148 LevelDBIterator* current_ = nullptr; 153 LevelDBIterator* current_ = nullptr;
149 154
155 bool is_evicted_ = false;
156 std::string key_after_eviction_;
157
150 Direction direction_ = FORWARD; 158 Direction direction_ = FORWARD;
151 mutable bool data_changed_ = false; 159 mutable bool data_changed_ = false;
152 160
153 DISALLOW_COPY_AND_ASSIGN(TransactionIterator); 161 DISALLOW_COPY_AND_ASSIGN(TransactionIterator);
154 }; 162 };
155 163
156 void Set(const base::StringPiece& key, std::string* value, bool deleted); 164 void Set(const base::StringPiece& key, std::string* value, bool deleted);
157 void RegisterIterator(TransactionIterator* iterator); 165 void RegisterIterator(TransactionIterator* iterator);
158 void UnregisterIterator(TransactionIterator* iterator); 166 void UnregisterIterator(TransactionIterator* iterator);
159 void NotifyIterators(); 167 void NotifyIterators();
(...skipping 29 matching lines...) Expand all
189 LevelDBDatabase* db_; 197 LevelDBDatabase* db_;
190 std::unique_ptr<LevelDBWriteBatch> write_batch_; 198 std::unique_ptr<LevelDBWriteBatch> write_batch_;
191 bool finished_ = false; 199 bool finished_ = false;
192 200
193 DISALLOW_COPY_AND_ASSIGN(LevelDBDirectTransaction); 201 DISALLOW_COPY_AND_ASSIGN(LevelDBDirectTransaction);
194 }; 202 };
195 203
196 } // namespace content 204 } // namespace content
197 205
198 #endif // CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_TRANSACTION_H_ 206 #endif // CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_TRANSACTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698