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

Side by Side Diff: content/browser/indexed_db/indexed_db_backing_store.cc

Issue 902503003: IndexedDB: Address performance regression with blob journals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « no previous file | content/test/data/indexeddb/corrupted_open_db_detection.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/indexed_db_backing_store.h" 5 #include "content/browser/indexed_db/indexed_db_backing_store.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 4113 matching lines...) Expand 10 before | Expand all | Expand 10 after
4124 4124
4125 leveldb::Status IndexedDBBackingStore::Transaction::CommitPhaseTwo() { 4125 leveldb::Status IndexedDBBackingStore::Transaction::CommitPhaseTwo() {
4126 IDB_TRACE("IndexedDBBackingStore::Transaction::CommitPhaseTwo"); 4126 IDB_TRACE("IndexedDBBackingStore::Transaction::CommitPhaseTwo");
4127 leveldb::Status s; 4127 leveldb::Status s;
4128 4128
4129 DCHECK(committing_); 4129 DCHECK(committing_);
4130 committing_ = false; 4130 committing_ = false;
4131 DCHECK_GT(backing_store_->committing_transaction_count_, 0UL); 4131 DCHECK_GT(backing_store_->committing_transaction_count_, 0UL);
4132 --backing_store_->committing_transaction_count_; 4132 --backing_store_->committing_transaction_count_;
4133 4133
4134 // Read the persisted states of the primary/live blob journals, 4134 BlobJournalType primary_journal, live_journal, saved_primary_journal,
4135 // so that they can be updated correctly by the transaction. 4135 dead_blobs;
4136 BlobJournalType primary_journal, live_journal; 4136 if (!blob_change_map_.empty()) {
4137 { 4137 // Read the persisted states of the primary/live blob journals,
4138 // so that they can be updated correctly by the transaction.
4138 scoped_refptr<LevelDBTransaction> journal_transaction = 4139 scoped_refptr<LevelDBTransaction> journal_transaction =
4139 IndexedDBClassFactory::Get()->CreateLevelDBTransaction( 4140 IndexedDBClassFactory::Get()->CreateLevelDBTransaction(
4140 backing_store_->db_.get()); 4141 backing_store_->db_.get());
4141 s = GetPrimaryBlobJournal(journal_transaction.get(), &primary_journal); 4142 s = GetPrimaryBlobJournal(journal_transaction.get(), &primary_journal);
4142 if (!s.ok()) 4143 if (!s.ok())
4143 return s; 4144 return s;
4144 s = GetLiveBlobJournal(journal_transaction.get(), &live_journal); 4145 s = GetLiveBlobJournal(journal_transaction.get(), &live_journal);
4145 if (!s.ok()) 4146 if (!s.ok())
4146 return s; 4147 return s;
4147 }
4148 4148
4149 // Remove newly added blobs from the journal - they will be accounted 4149 // Remove newly added blobs from the journal - they will be accounted
4150 // for in blob entry tables in the transaction. 4150 // for in blob entry tables in the transaction.
4151 {
4152 std::sort(primary_journal.begin(), primary_journal.end()); 4151 std::sort(primary_journal.begin(), primary_journal.end());
4153 std::sort(blobs_to_write_.begin(), blobs_to_write_.end()); 4152 std::sort(blobs_to_write_.begin(), blobs_to_write_.end());
4154 BlobJournalType new_journal = base::STLSetDifference<BlobJournalType>( 4153 BlobJournalType new_journal = base::STLSetDifference<BlobJournalType>(
4155 primary_journal, blobs_to_write_); 4154 primary_journal, blobs_to_write_);
4156 primary_journal.swap(new_journal); 4155 primary_journal.swap(new_journal);
4156
4157 // Append newly deleted blobs to appropriate primary/live journals.
4158 saved_primary_journal = primary_journal;
4159 BlobJournalType live_blobs;
4160 if (!blobs_to_remove_.empty()) {
4161 DCHECK(!backing_store_->is_incognito());
4162 PartitionBlobsToRemove(&dead_blobs, &live_blobs);
4163 }
4164 primary_journal.insert(primary_journal.end(), dead_blobs.begin(),
4165 dead_blobs.end());
4166 live_journal.insert(live_journal.end(), live_blobs.begin(),
4167 live_blobs.end());
4168 UpdatePrimaryBlobJournal(transaction_.get(), primary_journal);
4169 UpdateLiveBlobJournal(transaction_.get(), live_journal);
4157 } 4170 }
4158 4171
4159 // Append newly deleted blobs to appropriate primary/live journals.
4160 BlobJournalType saved_primary_journal = primary_journal;
4161 BlobJournalType dead_blobs, live_blobs;
4162 if (!blobs_to_remove_.empty()) {
4163 DCHECK(!backing_store_->is_incognito());
4164 PartitionBlobsToRemove(&dead_blobs, &live_blobs);
4165 }
4166 primary_journal.insert(primary_journal.end(), dead_blobs.begin(),
4167 dead_blobs.end());
4168 live_journal.insert(live_journal.end(), live_blobs.begin(), live_blobs.end());
4169 UpdatePrimaryBlobJournal(transaction_.get(), primary_journal);
4170 UpdateLiveBlobJournal(transaction_.get(), live_journal);
4171
4172 // Actually commit. If this succeeds, the journals will appropriately 4172 // Actually commit. If this succeeds, the journals will appropriately
4173 // reflect pending blob work - dead files that should be deleted 4173 // reflect pending blob work - dead files that should be deleted
4174 // immediately, and live files to monitor. 4174 // immediately, and live files to monitor.
4175 s = transaction_->Commit(); 4175 s = transaction_->Commit();
4176 transaction_ = NULL; 4176 transaction_ = NULL;
4177 4177
4178 if (!s.ok()) { 4178 if (!s.ok()) {
4179 INTERNAL_WRITE_ERROR(TRANSACTION_COMMIT_METHOD); 4179 INTERNAL_WRITE_ERROR(TRANSACTION_COMMIT_METHOD);
4180 return s; 4180 return s;
4181 } 4181 }
(...skipping 14 matching lines...) Expand all
4196 } 4196 }
4197 } 4197 }
4198 return leveldb::Status::OK(); 4198 return leveldb::Status::OK();
4199 } 4199 }
4200 4200
4201 // Actually delete dead blob files, then remove those entries 4201 // Actually delete dead blob files, then remove those entries
4202 // from the persisted primary journal. 4202 // from the persisted primary journal.
4203 if (dead_blobs.empty()) 4203 if (dead_blobs.empty())
4204 return leveldb::Status::OK(); 4204 return leveldb::Status::OK();
4205 4205
4206 DCHECK(!blob_change_map_.empty());
4207
4206 s = backing_store_->CleanUpBlobJournalEntries(dead_blobs); 4208 s = backing_store_->CleanUpBlobJournalEntries(dead_blobs);
4207 if (!s.ok()) { 4209 if (!s.ok()) {
4208 INTERNAL_WRITE_ERROR_UNTESTED(TRANSACTION_COMMIT_METHOD); 4210 INTERNAL_WRITE_ERROR_UNTESTED(TRANSACTION_COMMIT_METHOD);
4209 return s; 4211 return s;
4210 } 4212 }
4211 4213
4212 scoped_refptr<LevelDBTransaction> update_journal_transaction = 4214 scoped_refptr<LevelDBTransaction> update_journal_transaction =
4213 IndexedDBClassFactory::Get()->CreateLevelDBTransaction( 4215 IndexedDBClassFactory::Get()->CreateLevelDBTransaction(
4214 backing_store_->db_.get()); 4216 backing_store_->db_.get());
4215 UpdatePrimaryBlobJournal(update_journal_transaction.get(), 4217 UpdatePrimaryBlobJournal(update_journal_transaction.get(),
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
4394 int64_t size, 4396 int64_t size,
4395 base::Time last_modified) 4397 base::Time last_modified)
4396 : is_file_(true), 4398 : is_file_(true),
4397 file_path_(file_path), 4399 file_path_(file_path),
4398 key_(key), 4400 key_(key),
4399 size_(size), 4401 size_(size),
4400 last_modified_(last_modified) { 4402 last_modified_(last_modified) {
4401 } 4403 }
4402 4404
4403 } // namespace content 4405 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/test/data/indexeddb/corrupted_open_db_detection.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698