Source/WebCore/ChangeLog

 12012-09-06 Joshua Bell <jsbell@chromium.org>
 2
 3 IndexedDB: IDBFactory.deleteDatabase() is slow
 4 https://bugs.webkit.org/show_bug.cgi?id=96036
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 The deleteDatabase() operation is implemented by creating a LevelDBTansaction to accumulate
 9 the records to delete, then committing it. The transaction is a tree of key/operation pairs.
 10 As each (key, delete) entry is added to the tree compares need to be made, potentially
 11 requiring full key decodes. Since this temporary transaction is never read from, this is
 12 overkill.
 13
 14 Instead, expose a new LevelDB::removeRange() method that only creates a LevelDBWriteBatch.
 15 This is lighter weight than a LevelDBTransaction, has transactional integrity, and appears
 16 faster than calling into leveldb to remove each individual record directly.
 17
 18 No new tests - no functional changes, only perf improvement.
 19
 20 * Modules/indexeddb/IDBLevelDBBackingStore.cpp:
 21 (WebCore::IDBLevelDBBackingStore::deleteDatabase):
 22 * platform/leveldb/LevelDBDatabase.cpp:
 23 (WebCore::LevelDBDatabase::removeRange):
 24 (WebCore):
 25 * platform/leveldb/LevelDBDatabase.h:
 26 (LevelDBDatabase):
 27
1282012-09-03 Sam Weinig <sam@webkit.org>
229
330 Part 1 of removing PlatformString.h, move remaining functions to new homes

Source/WebCore/Modules/indexeddb/IDBLevelDBBackingStore.cpp

@@static bool deleteRange(LevelDBTransaction* transaction, const Vector<char>& beg
360360bool IDBLevelDBBackingStore::deleteDatabase(const String& name)
361361{
362362 IDB_TRACE("IDBLevelDBBackingStore::deleteDatabase");
363  RefPtr<LevelDBTransaction> transaction = LevelDBTransaction::create(m_db.get());
364363
365364 int64_t databaseId;
366365 String version;
367366 int64_t intVersion;
368367 if (!getIDBDatabaseMetaData(name, version, intVersion, databaseId)) {
369  transaction->rollback();
370368 return true;
371369 }
372370
373371 const Vector<char> startKey = DatabaseMetaDataKey::encode(databaseId, DatabaseMetaDataKey::OriginName);
374372 const Vector<char> stopKey = DatabaseMetaDataKey::encode(databaseId + 1, DatabaseMetaDataKey::OriginName);
375  if (!deleteRange(transaction.get(), startKey, stopKey)) {
376  transaction->rollback();
 373 if (!m_db->removeRange(startKey, stopKey)) {
377374 return false;
378375 }
379376
380377 const Vector<char> key = DatabaseNameKey::encode(m_identifier, name);
381  transaction->remove(key);
382 
383  return transaction->commit();
 378 return m_db->remove(key);
384379}
385380
386381static bool checkObjectStoreAndMetaDataType(const LevelDBIterator* it, const Vector<char>& stopKey, int64_t objectStoreId, int64_t metaDataType)

Source/WebCore/platform/leveldb/LevelDBDatabase.cpp

@@bool LevelDBDatabase::remove(const LevelDBSlice& key)
187187 return false;
188188}
189189
 190bool LevelDBDatabase::removeRange(const LevelDBSlice& start, const LevelDBSlice& limit)
 191{
 192
 193 OwnPtr<LevelDBIterator> it = createIterator();
 194 OwnPtr<LevelDBWriteBatch> writeBatch = LevelDBWriteBatch::create();
 195 for (it->seek(start); it->isValid() && m_comparator->compare(it->key(), limit) < 0; it->next())
 196 writeBatch->remove(it->key());
 197
 198 leveldb::WriteOptions writeOptions;
 199 writeOptions.sync = true;
 200 const leveldb::Status s = m_db->Write(writeOptions, writeBatch->m_writeBatch.get());
 201 if (s.ok())
 202 return true;
 203 LOG_ERROR("LevelDB write failed: %s", s.ToString().c_str());
 204 return false;
 205}
 206
190207bool LevelDBDatabase::get(const LevelDBSlice& key, Vector<char>& value)
191208{
192209 std::string result;

Source/WebCore/platform/leveldb/LevelDBDatabase.h

@@public:
5555
5656 bool put(const LevelDBSlice& key, const Vector<char>& value);
5757 bool remove(const LevelDBSlice& key);
 58 bool removeRange(const LevelDBSlice& start, const LevelDBSlice& limit);
5859 bool get(const LevelDBSlice& key, Vector<char>& value);
5960 bool write(LevelDBWriteBatch&);
6061 PassOwnPtr<LevelDBIterator> createIterator();