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

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

Issue 2712713005: Revert of IndexedDB: Optimize range deletion operations (e.g. clearing a store) (Closed)
Patch Set: Created 3 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
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 #include <utility> 8 #include <utility>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 PutInt(transaction, MaxDatabaseIdKey::Encode(), database_id); 692 PutInt(transaction, MaxDatabaseIdKey::Encode(), database_id);
693 *new_id = database_id; 693 *new_id = database_id;
694 return Status::OK(); 694 return Status::OK();
695 } 695 }
696 696
697 // If you're deleting a range that contains user keys that have blob info, this 697 // If you're deleting a range that contains user keys that have blob info, this
698 // won't clean up the blobs. 698 // won't clean up the blobs.
699 Status DeleteRangeBasic(LevelDBTransaction* transaction, 699 Status DeleteRangeBasic(LevelDBTransaction* transaction,
700 const std::string& begin, 700 const std::string& begin,
701 const std::string& end, 701 const std::string& end,
702 bool upper_open) { 702 bool upper_open,
703 return transaction->RemoveRange(begin, end, upper_open); 703 size_t* delete_count) {
704 DCHECK(delete_count);
705 std::unique_ptr<LevelDBIterator> it = transaction->CreateIterator();
706 Status s;
707 *delete_count = 0;
708 for (s = it->Seek(begin); s.ok() && it->IsValid() &&
709 (upper_open ? CompareKeys(it->Key(), end) < 0
710 : CompareKeys(it->Key(), end) <= 0);
711 s = it->Next()) {
712 if (transaction->Remove(it->Key()))
713 (*delete_count)++;
714 }
715 return s;
704 } 716 }
705 717
706 Status DeleteBlobsInRange(IndexedDBBackingStore::Transaction* transaction, 718 Status DeleteBlobsInRange(IndexedDBBackingStore::Transaction* transaction,
707 int64_t database_id, 719 int64_t database_id,
708 int64_t object_store_id, 720 int64_t object_store_id,
709 const std::string& start_key, 721 const std::string& start_key,
710 const std::string& end_key, 722 const std::string& end_key,
711 bool upper_open) { 723 bool upper_open) {
712 std::unique_ptr<LevelDBIterator> it = 724 std::unique_ptr<LevelDBIterator> it =
713 transaction->transaction()->CreateIterator(); 725 transaction->transaction()->CreateIterator();
(...skipping 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1981 Status IndexedDBBackingStore::DeleteObjectStore( 1993 Status IndexedDBBackingStore::DeleteObjectStore(
1982 IndexedDBBackingStore::Transaction* transaction, 1994 IndexedDBBackingStore::Transaction* transaction,
1983 int64_t database_id, 1995 int64_t database_id,
1984 int64_t object_store_id) { 1996 int64_t object_store_id) {
1985 IDB_TRACE("IndexedDBBackingStore::DeleteObjectStore"); 1997 IDB_TRACE("IndexedDBBackingStore::DeleteObjectStore");
1986 if (!KeyPrefix::ValidIds(database_id, object_store_id)) 1998 if (!KeyPrefix::ValidIds(database_id, object_store_id))
1987 return InvalidDBKeyStatus(); 1999 return InvalidDBKeyStatus();
1988 LevelDBTransaction* leveldb_transaction = transaction->transaction(); 2000 LevelDBTransaction* leveldb_transaction = transaction->transaction();
1989 2001
1990 base::string16 object_store_name; 2002 base::string16 object_store_name;
2003 size_t delete_count = 0;
1991 bool found = false; 2004 bool found = false;
1992 Status s = GetString(leveldb_transaction, ObjectStoreMetaDataKey::Encode( 2005 Status s = GetString(leveldb_transaction, ObjectStoreMetaDataKey::Encode(
1993 database_id, object_store_id, 2006 database_id, object_store_id,
1994 ObjectStoreMetaDataKey::NAME), 2007 ObjectStoreMetaDataKey::NAME),
1995 &object_store_name, &found); 2008 &object_store_name, &found);
1996 if (!s.ok()) { 2009 if (!s.ok()) {
1997 INTERNAL_READ_ERROR_UNTESTED(DELETE_OBJECT_STORE); 2010 INTERNAL_READ_ERROR_UNTESTED(DELETE_OBJECT_STORE);
1998 return s; 2011 return s;
1999 } 2012 }
2000 if (!found) { 2013 if (!found) {
2001 INTERNAL_CONSISTENCY_ERROR_UNTESTED(DELETE_OBJECT_STORE); 2014 INTERNAL_CONSISTENCY_ERROR_UNTESTED(DELETE_OBJECT_STORE);
2002 return InternalInconsistencyStatus(); 2015 return InternalInconsistencyStatus();
2003 } 2016 }
2004 2017
2005 s = DeleteBlobsInObjectStore(transaction, database_id, object_store_id); 2018 s = DeleteBlobsInObjectStore(transaction, database_id, object_store_id);
2006 if (!s.ok()) { 2019 if (!s.ok()) {
2007 INTERNAL_CONSISTENCY_ERROR_UNTESTED(DELETE_OBJECT_STORE); 2020 INTERNAL_CONSISTENCY_ERROR_UNTESTED(DELETE_OBJECT_STORE);
2008 return s; 2021 return s;
2009 } 2022 }
2010 2023
2011 s = DeleteRangeBasic( 2024 s = DeleteRangeBasic(
2012 leveldb_transaction, 2025 leveldb_transaction,
2013 ObjectStoreMetaDataKey::Encode(database_id, object_store_id, 0), 2026 ObjectStoreMetaDataKey::Encode(database_id, object_store_id, 0),
2014 ObjectStoreMetaDataKey::EncodeMaxKey(database_id, object_store_id), true); 2027 ObjectStoreMetaDataKey::EncodeMaxKey(database_id, object_store_id), true,
2028 &delete_count);
2015 2029
2016 if (s.ok()) { 2030 if (s.ok()) {
2017 leveldb_transaction->Remove( 2031 leveldb_transaction->Remove(
2018 ObjectStoreNamesKey::Encode(database_id, object_store_name)); 2032 ObjectStoreNamesKey::Encode(database_id, object_store_name));
2019 2033
2020 s = DeleteRangeBasic( 2034 s = DeleteRangeBasic(
2021 leveldb_transaction, 2035 leveldb_transaction,
2022 IndexFreeListKey::Encode(database_id, object_store_id, 0), 2036 IndexFreeListKey::Encode(database_id, object_store_id, 0),
2023 IndexFreeListKey::EncodeMaxKey(database_id, object_store_id), true); 2037 IndexFreeListKey::EncodeMaxKey(database_id, object_store_id), true,
2038 &delete_count);
2024 } 2039 }
2025 2040
2026 if (s.ok()) { 2041 if (s.ok()) {
2027 s = DeleteRangeBasic( 2042 s = DeleteRangeBasic(
2028 leveldb_transaction, 2043 leveldb_transaction,
2029 IndexMetaDataKey::Encode(database_id, object_store_id, 0, 0), 2044 IndexMetaDataKey::Encode(database_id, object_store_id, 0, 0),
2030 IndexMetaDataKey::EncodeMaxKey(database_id, object_store_id), true); 2045 IndexMetaDataKey::EncodeMaxKey(database_id, object_store_id), true,
2046 &delete_count);
2031 } 2047 }
2032 2048
2033 if (!s.ok()) { 2049 if (!s.ok()) {
2034 INTERNAL_WRITE_ERROR_UNTESTED(DELETE_OBJECT_STORE); 2050 INTERNAL_WRITE_ERROR_UNTESTED(DELETE_OBJECT_STORE);
2035 return s; 2051 return s;
2036 } 2052 }
2037 2053
2038 return ClearObjectStore(transaction, database_id, object_store_id); 2054 return ClearObjectStore(transaction, database_id, object_store_id);
2039 } 2055 }
2040 2056
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
2167 IndexedDBBackingStore::Transaction* transaction, 2183 IndexedDBBackingStore::Transaction* transaction,
2168 int64_t database_id, 2184 int64_t database_id,
2169 int64_t object_store_id) { 2185 int64_t object_store_id) {
2170 IDB_TRACE("IndexedDBBackingStore::ClearObjectStore"); 2186 IDB_TRACE("IndexedDBBackingStore::ClearObjectStore");
2171 if (!KeyPrefix::ValidIds(database_id, object_store_id)) 2187 if (!KeyPrefix::ValidIds(database_id, object_store_id))
2172 return InvalidDBKeyStatus(); 2188 return InvalidDBKeyStatus();
2173 const std::string start_key = 2189 const std::string start_key =
2174 KeyPrefix(database_id, object_store_id).Encode(); 2190 KeyPrefix(database_id, object_store_id).Encode();
2175 const std::string stop_key = 2191 const std::string stop_key =
2176 KeyPrefix(database_id, object_store_id + 1).Encode(); 2192 KeyPrefix(database_id, object_store_id + 1).Encode();
2177 Status s = 2193 size_t delete_count = 0;
2178 DeleteRangeBasic(transaction->transaction(), start_key, stop_key, true); 2194 Status s = DeleteRangeBasic(transaction->transaction(), start_key, stop_key,
2195 true, &delete_count);
2179 if (!s.ok()) { 2196 if (!s.ok()) {
2180 INTERNAL_WRITE_ERROR(CLEAR_OBJECT_STORE); 2197 INTERNAL_WRITE_ERROR(CLEAR_OBJECT_STORE);
2181 return s; 2198 return s;
2182 } 2199 }
2183 return DeleteBlobsInObjectStore(transaction, database_id, object_store_id); 2200 return DeleteBlobsInObjectStore(transaction, database_id, object_store_id);
2184 } 2201 }
2185 2202
2186 Status IndexedDBBackingStore::DeleteRecord( 2203 Status IndexedDBBackingStore::DeleteRecord(
2187 IndexedDBBackingStore::Transaction* transaction, 2204 IndexedDBBackingStore::Transaction* transaction,
2188 int64_t database_id, 2205 int64_t database_id,
(...skipping 15 matching lines...) Expand all
2204 const std::string exists_entry_key = ExistsEntryKey::Encode( 2221 const std::string exists_entry_key = ExistsEntryKey::Encode(
2205 database_id, object_store_id, record_identifier.primary_key()); 2222 database_id, object_store_id, record_identifier.primary_key());
2206 leveldb_transaction->Remove(exists_entry_key); 2223 leveldb_transaction->Remove(exists_entry_key);
2207 return Status::OK(); 2224 return Status::OK();
2208 } 2225 }
2209 2226
2210 Status IndexedDBBackingStore::DeleteRange( 2227 Status IndexedDBBackingStore::DeleteRange(
2211 IndexedDBBackingStore::Transaction* transaction, 2228 IndexedDBBackingStore::Transaction* transaction,
2212 int64_t database_id, 2229 int64_t database_id,
2213 int64_t object_store_id, 2230 int64_t object_store_id,
2214 const IndexedDBKeyRange& key_range) { 2231 const IndexedDBKeyRange& key_range,
2232 size_t* exists_delete_count) {
2233 DCHECK(exists_delete_count);
2215 Status s; 2234 Status s;
2235 *exists_delete_count = 0;
2216 std::unique_ptr<IndexedDBBackingStore::Cursor> start_cursor = 2236 std::unique_ptr<IndexedDBBackingStore::Cursor> start_cursor =
2217 OpenObjectStoreCursor(transaction, database_id, object_store_id, 2237 OpenObjectStoreCursor(transaction, database_id, object_store_id,
2218 key_range, blink::WebIDBCursorDirectionNext, &s); 2238 key_range, blink::WebIDBCursorDirectionNext, &s);
2219 if (!s.ok()) 2239 if (!s.ok())
2220 return s; 2240 return s;
2221 if (!start_cursor) 2241 if (!start_cursor)
2222 return Status::OK(); // Empty range == delete success. 2242 return Status::OK(); // Empty range == delete success.
2223 std::unique_ptr<IndexedDBBackingStore::Cursor> end_cursor = 2243 std::unique_ptr<IndexedDBBackingStore::Cursor> end_cursor =
2224 OpenObjectStoreCursor(transaction, database_id, object_store_id, 2244 OpenObjectStoreCursor(transaction, database_id, object_store_id,
2225 key_range, blink::WebIDBCursorDirectionPrev, &s); 2245 key_range, blink::WebIDBCursorDirectionPrev, &s);
(...skipping 16 matching lines...) Expand all
2242 return InternalInconsistencyStatus(); 2262 return InternalInconsistencyStatus();
2243 2263
2244 s = DeleteBlobsInRange(transaction, 2264 s = DeleteBlobsInRange(transaction,
2245 database_id, 2265 database_id,
2246 object_store_id, 2266 object_store_id,
2247 start_blob_key.Encode(), 2267 start_blob_key.Encode(),
2248 end_blob_key.Encode(), 2268 end_blob_key.Encode(),
2249 false); 2269 false);
2250 if (!s.ok()) 2270 if (!s.ok())
2251 return s; 2271 return s;
2252 s = DeleteRangeBasic(transaction->transaction(), start_key, stop_key, false); 2272 size_t data_delete_count = 0;
2273 s = DeleteRangeBasic(transaction->transaction(), start_key, stop_key, false,
2274 &data_delete_count);
2253 if (!s.ok()) 2275 if (!s.ok())
2254 return s; 2276 return s;
2255 start_key = 2277 start_key =
2256 ExistsEntryKey::Encode(database_id, object_store_id, start_cursor->key()); 2278 ExistsEntryKey::Encode(database_id, object_store_id, start_cursor->key());
2257 stop_key = 2279 stop_key =
2258 ExistsEntryKey::Encode(database_id, object_store_id, end_cursor->key()); 2280 ExistsEntryKey::Encode(database_id, object_store_id, end_cursor->key());
2259 2281
2260 s = DeleteRangeBasic(transaction->transaction(), start_key, stop_key, false); 2282 s = DeleteRangeBasic(transaction->transaction(), start_key, stop_key, false,
2283 exists_delete_count);
2284 DCHECK_EQ(data_delete_count, *exists_delete_count);
2261 return s; 2285 return s;
2262 } 2286 }
2263 2287
2264 Status IndexedDBBackingStore::GetKeyGeneratorCurrentNumber( 2288 Status IndexedDBBackingStore::GetKeyGeneratorCurrentNumber(
2265 IndexedDBBackingStore::Transaction* transaction, 2289 IndexedDBBackingStore::Transaction* transaction,
2266 int64_t database_id, 2290 int64_t database_id,
2267 int64_t object_store_id, 2291 int64_t object_store_id,
2268 int64_t* key_generator_current_number) { 2292 int64_t* key_generator_current_number) {
2269 if (!KeyPrefix::ValidIds(database_id, object_store_id)) 2293 if (!KeyPrefix::ValidIds(database_id, object_store_id))
2270 return InvalidDBKeyStatus(); 2294 return InvalidDBKeyStatus();
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
2998 Status IndexedDBBackingStore::DeleteIndex( 3022 Status IndexedDBBackingStore::DeleteIndex(
2999 IndexedDBBackingStore::Transaction* transaction, 3023 IndexedDBBackingStore::Transaction* transaction,
3000 int64_t database_id, 3024 int64_t database_id,
3001 int64_t object_store_id, 3025 int64_t object_store_id,
3002 int64_t index_id) { 3026 int64_t index_id) {
3003 IDB_TRACE("IndexedDBBackingStore::DeleteIndex"); 3027 IDB_TRACE("IndexedDBBackingStore::DeleteIndex");
3004 if (!KeyPrefix::ValidIds(database_id, object_store_id, index_id)) 3028 if (!KeyPrefix::ValidIds(database_id, object_store_id, index_id))
3005 return InvalidDBKeyStatus(); 3029 return InvalidDBKeyStatus();
3006 LevelDBTransaction* leveldb_transaction = transaction->transaction(); 3030 LevelDBTransaction* leveldb_transaction = transaction->transaction();
3007 3031
3032 size_t delete_count = 0;
3008 const std::string index_meta_data_start = 3033 const std::string index_meta_data_start =
3009 IndexMetaDataKey::Encode(database_id, object_store_id, index_id, 0); 3034 IndexMetaDataKey::Encode(database_id, object_store_id, index_id, 0);
3010 const std::string index_meta_data_end = 3035 const std::string index_meta_data_end =
3011 IndexMetaDataKey::EncodeMaxKey(database_id, object_store_id, index_id); 3036 IndexMetaDataKey::EncodeMaxKey(database_id, object_store_id, index_id);
3012 Status s = DeleteRangeBasic(leveldb_transaction, index_meta_data_start, 3037 Status s = DeleteRangeBasic(leveldb_transaction, index_meta_data_start,
3013 index_meta_data_end, true); 3038 index_meta_data_end, true, &delete_count);
3014 3039
3015 if (s.ok()) { 3040 if (s.ok()) {
3016 const std::string index_data_start = 3041 const std::string index_data_start =
3017 IndexDataKey::EncodeMinKey(database_id, object_store_id, index_id); 3042 IndexDataKey::EncodeMinKey(database_id, object_store_id, index_id);
3018 const std::string index_data_end = 3043 const std::string index_data_end =
3019 IndexDataKey::EncodeMaxKey(database_id, object_store_id, index_id); 3044 IndexDataKey::EncodeMaxKey(database_id, object_store_id, index_id);
3020 s = DeleteRangeBasic(leveldb_transaction, index_data_start, index_data_end, 3045 s = DeleteRangeBasic(leveldb_transaction, index_data_start, index_data_end,
3021 true); 3046 true, &delete_count);
3022 } 3047 }
3023 3048
3024 if (!s.ok()) 3049 if (!s.ok())
3025 INTERNAL_WRITE_ERROR_UNTESTED(DELETE_INDEX); 3050 INTERNAL_WRITE_ERROR_UNTESTED(DELETE_INDEX);
3026 3051
3027 return s; 3052 return s;
3028 } 3053 }
3029 3054
3030 Status IndexedDBBackingStore::RenameIndex( 3055 Status IndexedDBBackingStore::RenameIndex(
3031 IndexedDBBackingStore::Transaction* transaction, 3056 IndexedDBBackingStore::Transaction* transaction,
(...skipping 1418 matching lines...) Expand 10 before | Expand all | Expand 10 after
4450 4475
4451 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( 4476 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor(
4452 const WriteDescriptor& other) = default; 4477 const WriteDescriptor& other) = default;
4453 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = 4478 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() =
4454 default; 4479 default;
4455 IndexedDBBackingStore::Transaction::WriteDescriptor& 4480 IndexedDBBackingStore::Transaction::WriteDescriptor&
4456 IndexedDBBackingStore::Transaction::WriteDescriptor:: 4481 IndexedDBBackingStore::Transaction::WriteDescriptor::
4457 operator=(const WriteDescriptor& other) = default; 4482 operator=(const WriteDescriptor& other) = default;
4458 4483
4459 } // namespace content 4484 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_backing_store.h ('k') | content/browser/indexed_db/indexed_db_backing_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698