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() {
DatabaseNameKey::EncodeMinKeyForOrigin(origin_identifier_);
const std::string stop_key =
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);
s.ok() && it->IsValid() && CompareKeys(it->Key(), stop_key) < 0;
s = it->Next()) {
......@@ -1093,7 +1094,9 @@ Status IndexedDBBackingStore::DeleteDatabase(const base::string16& name) {
DatabaseMetaDataKey::Encode(id + 1, DatabaseMetaDataKey::ORIGIN_NAME);
{
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);
s.ok() && it->IsValid() && CompareKeys(it->Key(), stop_key) < 0;
s = it->Next())
......
......@@ -48,7 +48,8 @@ Status ReadIndexes(LevelDBDatabase* db,
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);
while (s.ok() && it->IsValid() && CompareKeys(it->Key(), stop_key) < 0) {
IndexMetaDataKey meta_data_key;
......@@ -149,7 +150,8 @@ Status ReadObjectStores(
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);
while (s.ok() && it->IsValid() && CompareKeys(it->Key(), stop_key) < 0) {
ObjectStoreMetaDataKey meta_data_key;
......@@ -321,7 +323,8 @@ leveldb::Status IndexedDBMetadataCoding::ReadDatabaseNames(
DCHECK(names->empty());
std::unique_ptr<LevelDBIterator> it = db->CreateIterator();
std::unique_ptr<LevelDBIterator> it =
db->CreateIterator(db->DefaultReadOptions());
Status s;
for (s = it->Seek(start_key);
s.ok() && it->IsValid() && CompareKeys(it->Key(), stop_key) < 0;
......
......@@ -430,20 +430,15 @@ leveldb::Status LevelDBDatabase::Write(const LevelDBWriteBatch& write_batch) {
}
std::unique_ptr<LevelDBIterator> LevelDBDatabase::CreateIterator(
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;
const leveldb::ReadOptions& options) {
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
// 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>(
IndexedDBClassFactory::Get()->CreateIteratorImpl(std::move(i), this,
read_options.snapshot));
options.snapshot));
}
const LevelDBComparator* LevelDBDatabase::Comparator() const {
......@@ -464,6 +459,19 @@ void LevelDBDatabase::CompactAll() {
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(
const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* pmd) {
......
......@@ -17,6 +17,7 @@
#include "base/trace_event/memory_dump_provider.h"
#include "content/common/content_export.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"
namespace leveldb {
......@@ -84,11 +85,16 @@ class CONTENT_EXPORT LevelDBDatabase
bool* found,
const LevelDBSnapshot* = 0);
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;
void Compact(const base::StringPiece& start, const base::StringPiece& stop);
void CompactAll();
leveldb::ReadOptions DefaultReadOptions();
leveldb::ReadOptions DefaultReadOptions(const LevelDBSnapshot* snapshot);
// base::trace_event::MemoryDumpProvider implementation.
bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* pmd) override;
......
......@@ -240,8 +240,8 @@ LevelDBTransaction::TransactionIterator::TransactionIterator(
: transaction_(transaction),
comparator_(transaction_->comparator_),
data_iterator_(DataIterator::Create(transaction_.get())),
db_iterator_(
transaction_->db_->CreateIterator(&transaction_->snapshot_)) {
db_iterator_(transaction_->db_->CreateIterator(
transaction_->db_->DefaultReadOptions(&transaction_->snapshot_))) {
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