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

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

Issue 2712713005: Revert of IndexedDB: Optimize range deletion operations (e.g. clearing a store) (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 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" 5 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "content/browser/indexed_db/indexed_db_tracing.h" 11 #include "content/browser/indexed_db/indexed_db_tracing.h"
12 #include "content/browser/indexed_db/leveldb/leveldb_database.h" 12 #include "content/browser/indexed_db/leveldb/leveldb_database.h"
13 #include "content/browser/indexed_db/leveldb/leveldb_write_batch.h" 13 #include "content/browser/indexed_db/leveldb/leveldb_write_batch.h"
14 #include "third_party/leveldatabase/src/include/leveldb/db.h" 14 #include "third_party/leveldatabase/src/include/leveldb/db.h"
15 15
16 using base::StringPiece; 16 using base::StringPiece;
17 17
18 namespace content { 18 namespace content {
19 19
20 LevelDBTransaction::LevelDBTransaction(LevelDBDatabase* db) 20 LevelDBTransaction::LevelDBTransaction(LevelDBDatabase* db)
21 : db_(db), 21 : db_(db),
22 snapshot_(db), 22 snapshot_(db),
23 comparator_(db->Comparator()), 23 comparator_(db->Comparator()),
24 data_comparator_(comparator_), 24 data_comparator_(comparator_),
25 data_(data_comparator_), 25 data_(data_comparator_),
26 finished_(false) {} 26 finished_(false) {}
27 27
28 LevelDBTransaction::Record::Record() {} 28 LevelDBTransaction::Record::Record() : deleted(false) {}
29 LevelDBTransaction::Record::~Record() {} 29 LevelDBTransaction::Record::~Record() {}
30 30
31 LevelDBTransaction::~LevelDBTransaction() {} 31 LevelDBTransaction::~LevelDBTransaction() {}
32 32
33 bool LevelDBTransaction::Set(const StringPiece& key, 33 bool LevelDBTransaction::Set(const StringPiece& key,
34 std::string* value, 34 std::string* value,
35 bool deleted) { 35 bool deleted) {
36 DCHECK(!finished_); 36 DCHECK(!finished_);
37 DataType::iterator it = data_.find(key); 37 DataType::iterator it = data_.find(key);
38 38
(...skipping 14 matching lines...) Expand all
53 53
54 void LevelDBTransaction::Put(const StringPiece& key, std::string* value) { 54 void LevelDBTransaction::Put(const StringPiece& key, std::string* value) {
55 Set(key, value, false); 55 Set(key, value, false);
56 } 56 }
57 57
58 bool LevelDBTransaction::Remove(const StringPiece& key) { 58 bool LevelDBTransaction::Remove(const StringPiece& key) {
59 std::string empty; 59 std::string empty;
60 return !Set(key, &empty, true); 60 return !Set(key, &empty, true);
61 } 61 }
62 62
63 leveldb::Status LevelDBTransaction::RemoveRange(const StringPiece& begin,
64 const StringPiece& end,
65 bool upper_open) {
66 IDB_TRACE("LevelDBTransaction::RemoveRange");
67 data_.erase(data_.lower_bound(begin), data_.lower_bound(end));
68 if (!upper_open)
69 data_.erase(end);
70 std::unique_ptr<LevelDBIterator> it = CreateIterator();
71 leveldb::Status s;
72 for (s = it->Seek(begin);
73 s.ok() && it->IsValid() &&
74 (upper_open ? comparator_->Compare(it->Key(), end) < 0
75 : comparator_->Compare(it->Key(), end) <= 0);
76 s = it->Next()) {
77 std::unique_ptr<Record> record = base::MakeUnique<Record>();
78 record->key = it->Key().as_string();
79 record->deleted = true;
80 data_[record->key] = std::move(record);
81 }
82 NotifyIterators();
83 return s;
84 }
85
86 leveldb::Status LevelDBTransaction::Get(const StringPiece& key, 63 leveldb::Status LevelDBTransaction::Get(const StringPiece& key,
87 std::string* value, 64 std::string* value,
88 bool* found) { 65 bool* found) {
89 *found = false; 66 *found = false;
90 DCHECK(!finished_); 67 DCHECK(!finished_);
91 std::string string_key(key.begin(), key.end() - key.begin()); 68 std::string string_key(key.begin(), key.end() - key.begin());
92 DataType::const_iterator it = data_.find(string_key); 69 DataType::const_iterator it = data_.find(string_key);
93 70
94 if (it != data_.end()) { 71 if (it != data_.end()) {
95 if (it->second->deleted) 72 if (it->second->deleted)
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 487
511 leveldb::Status s = db_->Write(*write_batch_); 488 leveldb::Status s = db_->Write(*write_batch_);
512 if (s.ok()) { 489 if (s.ok()) {
513 finished_ = true; 490 finished_ = true;
514 write_batch_->Clear(); 491 write_batch_->Clear();
515 } 492 }
516 return s; 493 return s;
517 } 494 }
518 495
519 } // namespace content 496 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698