Commit 9e0f6e12 authored by Daniel Murphy's avatar Daniel Murphy Committed by Commit Bot

[IndexedDB] Make database deletion non-cache-filling

Bug: 810564
Change-Id: I69583e3e9bb54a4eff953e5893e0a23818e7ef64
Reviewed-on: https://chromium-review.googlesource.com/950132
Commit-Queue: Daniel Murphy <dmurph@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Reviewed-by: default avatarJoshua Bell <jsbell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#541668}
parent ce9878bb
...@@ -686,7 +686,8 @@ WARN_UNUSED_RESULT Status IndexedDBBackingStore::SetUpMetadata() { ...@@ -686,7 +686,8 @@ WARN_UNUSED_RESULT Status IndexedDBBackingStore::SetUpMetadata() {
DatabaseNameKey::EncodeMinKeyForOrigin(origin_identifier_); DatabaseNameKey::EncodeMinKeyForOrigin(origin_identifier_);
const std::string stop_key = const std::string stop_key =
DatabaseNameKey::EncodeStopKeyForOrigin(origin_identifier_); DatabaseNameKey::EncodeStopKeyForOrigin(origin_identifier_);
std::unique_ptr<LevelDBIterator> it = db_->CreateIterator(); std::unique_ptr<LevelDBIterator> it =
db_->CreateIterator(db_->DefaultReadOptions());
for (s = it->Seek(start_key); for (s = it->Seek(start_key);
s.ok() && it->IsValid() && CompareKeys(it->Key(), stop_key) < 0; s.ok() && it->IsValid() && CompareKeys(it->Key(), stop_key) < 0;
s = it->Next()) { s = it->Next()) {
...@@ -1093,7 +1094,9 @@ Status IndexedDBBackingStore::DeleteDatabase(const base::string16& name) { ...@@ -1093,7 +1094,9 @@ Status IndexedDBBackingStore::DeleteDatabase(const base::string16& name) {
DatabaseMetaDataKey::Encode(id + 1, DatabaseMetaDataKey::ORIGIN_NAME); DatabaseMetaDataKey::Encode(id + 1, DatabaseMetaDataKey::ORIGIN_NAME);
{ {
IDB_TRACE("IndexedDBBackingStore::DeleteDatabase.DeleteEntries"); IDB_TRACE("IndexedDBBackingStore::DeleteDatabase.DeleteEntries");
std::unique_ptr<LevelDBIterator> it = db_->CreateIterator(); leveldb::ReadOptions options = db_->DefaultReadOptions();
options.fill_cache = false;
std::unique_ptr<LevelDBIterator> it = db_->CreateIterator(options);
for (s = it->Seek(start_key); for (s = it->Seek(start_key);
s.ok() && it->IsValid() && CompareKeys(it->Key(), stop_key) < 0; s.ok() && it->IsValid() && CompareKeys(it->Key(), stop_key) < 0;
s = it->Next()) s = it->Next())
......
...@@ -48,7 +48,8 @@ Status ReadIndexes(LevelDBDatabase* db, ...@@ -48,7 +48,8 @@ Status ReadIndexes(LevelDBDatabase* db,
DCHECK(indexes->empty()); DCHECK(indexes->empty());
std::unique_ptr<LevelDBIterator> it = db->CreateIterator(); std::unique_ptr<LevelDBIterator> it =
db->CreateIterator(db->DefaultReadOptions());
Status s = it->Seek(start_key); Status s = it->Seek(start_key);
while (s.ok() && it->IsValid() && CompareKeys(it->Key(), stop_key) < 0) { while (s.ok() && it->IsValid() && CompareKeys(it->Key(), stop_key) < 0) {
IndexMetaDataKey meta_data_key; IndexMetaDataKey meta_data_key;
...@@ -149,7 +150,8 @@ Status ReadObjectStores( ...@@ -149,7 +150,8 @@ Status ReadObjectStores(
DCHECK(object_stores->empty()); DCHECK(object_stores->empty());
std::unique_ptr<LevelDBIterator> it = db->CreateIterator(); std::unique_ptr<LevelDBIterator> it =
db->CreateIterator(db->DefaultReadOptions());
Status s = it->Seek(start_key); Status s = it->Seek(start_key);
while (s.ok() && it->IsValid() && CompareKeys(it->Key(), stop_key) < 0) { while (s.ok() && it->IsValid() && CompareKeys(it->Key(), stop_key) < 0) {
ObjectStoreMetaDataKey meta_data_key; ObjectStoreMetaDataKey meta_data_key;
...@@ -321,7 +323,8 @@ leveldb::Status IndexedDBMetadataCoding::ReadDatabaseNames( ...@@ -321,7 +323,8 @@ leveldb::Status IndexedDBMetadataCoding::ReadDatabaseNames(
DCHECK(names->empty()); DCHECK(names->empty());
std::unique_ptr<LevelDBIterator> it = db->CreateIterator(); std::unique_ptr<LevelDBIterator> it =
db->CreateIterator(db->DefaultReadOptions());
Status s; Status s;
for (s = it->Seek(start_key); for (s = it->Seek(start_key);
s.ok() && it->IsValid() && CompareKeys(it->Key(), stop_key) < 0; s.ok() && it->IsValid() && CompareKeys(it->Key(), stop_key) < 0;
......
...@@ -430,20 +430,15 @@ leveldb::Status LevelDBDatabase::Write(const LevelDBWriteBatch& write_batch) { ...@@ -430,20 +430,15 @@ leveldb::Status LevelDBDatabase::Write(const LevelDBWriteBatch& write_batch) {
} }
std::unique_ptr<LevelDBIterator> LevelDBDatabase::CreateIterator( std::unique_ptr<LevelDBIterator> LevelDBDatabase::CreateIterator(
const LevelDBSnapshot* snapshot) { const leveldb::ReadOptions& options) {
leveldb::ReadOptions read_options;
read_options.verify_checksums = true; // TODO(jsbell): Disable this if the
// performance impact is too great.
read_options.snapshot = snapshot ? snapshot->snapshot_ : nullptr;
num_iterators_++; num_iterators_++;
max_iterators_ = std::max(max_iterators_, num_iterators_); max_iterators_ = std::max(max_iterators_, num_iterators_);
// Iterator isn't added to lru cache until it is used, as memory isn't loaded // Iterator isn't added to lru cache until it is used, as memory isn't loaded
// for the iterator until it's first Seek call. // for the iterator until it's first Seek call.
std::unique_ptr<leveldb::Iterator> i(db_->NewIterator(read_options)); std::unique_ptr<leveldb::Iterator> i(db_->NewIterator(options));
return std::unique_ptr<LevelDBIterator>( return std::unique_ptr<LevelDBIterator>(
IndexedDBClassFactory::Get()->CreateIteratorImpl(std::move(i), this, IndexedDBClassFactory::Get()->CreateIteratorImpl(std::move(i), this,
read_options.snapshot)); options.snapshot));
} }
const LevelDBComparator* LevelDBDatabase::Comparator() const { const LevelDBComparator* LevelDBDatabase::Comparator() const {
...@@ -464,6 +459,19 @@ void LevelDBDatabase::CompactAll() { ...@@ -464,6 +459,19 @@ void LevelDBDatabase::CompactAll() {
db_->CompactRange(nullptr, nullptr); db_->CompactRange(nullptr, nullptr);
} }
leveldb::ReadOptions LevelDBDatabase::DefaultReadOptions() {
return DefaultReadOptions(nullptr);
}
leveldb::ReadOptions LevelDBDatabase::DefaultReadOptions(
const LevelDBSnapshot* snapshot) {
leveldb::ReadOptions read_options;
read_options.verify_checksums = true; // TODO(jsbell): Disable this if the
// performance impact is too great.
read_options.snapshot = snapshot ? snapshot->snapshot_ : nullptr;
return read_options;
}
bool LevelDBDatabase::OnMemoryDump( bool LevelDBDatabase::OnMemoryDump(
const base::trace_event::MemoryDumpArgs& args, const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* pmd) { base::trace_event::ProcessMemoryDump* pmd) {
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/trace_event/memory_dump_provider.h" #include "base/trace_event/memory_dump_provider.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "third_party/leveldatabase/src/include/leveldb/comparator.h" #include "third_party/leveldatabase/src/include/leveldb/comparator.h"
#include "third_party/leveldatabase/src/include/leveldb/options.h"
#include "third_party/leveldatabase/src/include/leveldb/status.h" #include "third_party/leveldatabase/src/include/leveldb/status.h"
namespace leveldb { namespace leveldb {
...@@ -84,11 +85,16 @@ class CONTENT_EXPORT LevelDBDatabase ...@@ -84,11 +85,16 @@ class CONTENT_EXPORT LevelDBDatabase
bool* found, bool* found,
const LevelDBSnapshot* = 0); const LevelDBSnapshot* = 0);
leveldb::Status Write(const LevelDBWriteBatch& write_batch); leveldb::Status Write(const LevelDBWriteBatch& write_batch);
std::unique_ptr<LevelDBIterator> CreateIterator(const LevelDBSnapshot* = 0); // Note: Use DefaultReadOptions() and then adjust any values afterwards.
std::unique_ptr<LevelDBIterator> CreateIterator(
const leveldb::ReadOptions& options);
const LevelDBComparator* Comparator() const; const LevelDBComparator* Comparator() const;
void Compact(const base::StringPiece& start, const base::StringPiece& stop); void Compact(const base::StringPiece& start, const base::StringPiece& stop);
void CompactAll(); void CompactAll();
leveldb::ReadOptions DefaultReadOptions();
leveldb::ReadOptions DefaultReadOptions(const LevelDBSnapshot* snapshot);
// base::trace_event::MemoryDumpProvider implementation. // base::trace_event::MemoryDumpProvider implementation.
bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* pmd) override; base::trace_event::ProcessMemoryDump* pmd) override;
......
...@@ -240,8 +240,8 @@ LevelDBTransaction::TransactionIterator::TransactionIterator( ...@@ -240,8 +240,8 @@ LevelDBTransaction::TransactionIterator::TransactionIterator(
: transaction_(transaction), : transaction_(transaction),
comparator_(transaction_->comparator_), comparator_(transaction_->comparator_),
data_iterator_(DataIterator::Create(transaction_.get())), data_iterator_(DataIterator::Create(transaction_.get())),
db_iterator_( db_iterator_(transaction_->db_->CreateIterator(
transaction_->db_->CreateIterator(&transaction_->snapshot_)) { transaction_->db_->DefaultReadOptions(&transaction_->snapshot_))) {
transaction_->RegisterIterator(this); transaction_->RegisterIterator(this);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment