Modified: trunk/Source/WebCore/ChangeLog (124857 => 124858)
--- trunk/Source/WebCore/ChangeLog 2012-08-07 06:40:42 UTC (rev 124857)
+++ trunk/Source/WebCore/ChangeLog 2012-08-07 06:54:55 UTC (rev 124858)
@@ -1,3 +1,34 @@
+2012-08-06 David Grogan <[email protected]>
+
+ IndexedDB: Make leveldb store integer versions and migrate old schemas
+ https://bugs.webkit.org/show_bug.cgi?id=92883
+
+ Reviewed by Tony Chang.
+
+ Our first schema change. If an existing DB doesn't have integer
+ versions, this will add one to all object stores in the origin.
+
+ No new tests - chrome test for the migration forthcoming. Will involve
+ starting with a leveldb directory from an old build of chrome, opening
+ it up with the migration code in place, and checking the new database.
+ http://codereview.chromium.org/10826159/
+
+ * Modules/indexeddb/IDBLevelDBBackingStore.cpp:
+ (WebCore::putVarInt):
+ (WebCore):
+ (WebCore::setUpMetadata):
+ Uses the ASSERT-but-still-handle-corruption pattern recently discussed
+ in https://bugs.webkit.org/show_bug.cgi?id=92725#c13.
+
+ (WebCore::IDBLevelDBBackingStore::open):
+ (WebCore::IDBLevelDBBackingStore::getIDBDatabaseMetaData):
+ Because we can't store negative numbers, store 0 instead of -1.
+
+ (WebCore::IDBLevelDBBackingStore::createIDBDatabaseMetaData):
+ (WebCore::IDBLevelDBBackingStore::updateIDBDatabaseIntVersion):
+ * Modules/indexeddb/IDBLevelDBCoding.h:
+ * Modules/indexeddb/IDBMetadata.h:
+
2012-08-06 Sheriff Bot <[email protected]>
Unreviewed, rolling out r124780.
Modified: trunk/Source/WebCore/Modules/indexeddb/IDBLevelDBBackingStore.cpp (124857 => 124858)
--- trunk/Source/WebCore/Modules/indexeddb/IDBLevelDBBackingStore.cpp 2012-08-07 06:40:42 UTC (rev 124857)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBLevelDBBackingStore.cpp 2012-08-07 06:54:55 UTC (rev 124858)
@@ -87,6 +87,12 @@
}
template <typename DBOrTransaction>
+static bool putVarInt(DBOrTransaction* db, const Vector<char>& key, int64_t value)
+{
+ return db->put(key, encodeVarInt(value));
+}
+
+template <typename DBOrTransaction>
static bool getString(DBOrTransaction* db, const Vector<char>& key, String& foundString)
{
Vector<char> result;
@@ -129,7 +135,7 @@
virtual const char* name() const { return "idb_cmp1"; }
};
-static bool setUpMetadata(LevelDBDatabase* db)
+static bool setUpMetadata(LevelDBDatabase* db, const String& origin)
{
const Vector<char> metaDataKey = SchemaVersionKey::encode();
@@ -138,12 +144,40 @@
schemaVersion = 0;
if (!putInt(db, metaDataKey, schemaVersion))
return false;
+ } else {
+ if (!schemaVersion) {
+ schemaVersion = 1;
+ RefPtr<LevelDBTransaction> transaction = LevelDBTransaction::create(db);
+ transaction->put(metaDataKey, encodeInt(schemaVersion));
+
+ const Vector<char> startKey = DatabaseNameKey::encodeMinKeyForOrigin(origin);
+ const Vector<char> stopKey = DatabaseNameKey::encodeStopKeyForOrigin(origin);
+ OwnPtr<LevelDBIterator> it = db->createIterator();
+ for (it->seek(startKey); it->isValid() && compareKeys(it->key(), stopKey) < 0; it->next()) {
+ Vector<char> value;
+ bool ok = transaction->get(it->key(), value);
+ if (!ok) {
+ ASSERT_NOT_REACHED();
+ return false;
+ }
+ int databaseId = decodeInt(value.begin(), value.end());
+ Vector<char> intVersionKey = DatabaseMetaDataKey::encode(databaseId, DatabaseMetaDataKey::UserIntVersion);
+ transaction->put(intVersionKey, encodeVarInt(IDBDatabaseMetadata::DefaultIntVersion));
+ ok = transaction->get(it->key(), value);
+ if (!ok) {
+ ASSERT_NOT_REACHED();
+ return false;
+ }
+ }
+ bool ok = transaction->commit();
+ if (!ok) {
+ ASSERT_NOT_REACHED();
+ return false;
+ }
+ }
+ ASSERT(schemaVersion == 1);
}
- // FIXME: Eventually, we'll need to be able to transition between schemas.
- if (schemaVersion)
- return false; // Don't know what to do with this version.
-
return true;
}
@@ -208,7 +242,7 @@
RefPtr<IDBLevelDBBackingStore> backingStore(adoptRef(new IDBLevelDBBackingStore(fileIdentifier, factory, db.release())));
backingStore->m_comparator = comparator.release();
- if (!setUpMetadata(backingStore->m_db.get()))
+ if (!setUpMetadata(backingStore->m_db.get(), fileIdentifier))
return PassRefPtr<IDBBackingStore>();
return backingStore.release();
@@ -246,6 +280,12 @@
if (!ok)
return false;
+ ok = getInt(m_db.get(), DatabaseMetaDataKey::encode(foundId, DatabaseMetaDataKey::UserIntVersion), foundIntVersion);
+ if (!ok)
+ return false;
+ if (foundIntVersion == IDBDatabaseMetadata::DefaultIntVersion)
+ foundIntVersion = IDBDatabaseMetadata::NoIntVersion;
+
return true;
}
@@ -275,12 +315,22 @@
return false;
if (!putString(m_db.get(), DatabaseMetaDataKey::encode(rowId, DatabaseMetaDataKey::UserVersion), version))
return false;
+ if (intVersion == IDBDatabaseMetadata::NoIntVersion)
+ intVersion = IDBDatabaseMetadata::DefaultIntVersion;
+ if (!putVarInt(m_db.get(), DatabaseMetaDataKey::encode(rowId, DatabaseMetaDataKey::UserIntVersion), intVersion))
+ return false;
return true;
}
bool IDBLevelDBBackingStore::updateIDBDatabaseIntVersion(int64_t rowId, int64_t intVersion)
{
- // FIXME: Make this actually do something. http://wkb.ug/92883
+ ASSERT(m_currentTransaction);
+ // FIXME: Change this to strictly greater than 0 once we throw TypeError for
+ // bad versions.
+ ASSERT_WITH_MESSAGE(intVersion >= 0, "intVersion was %lld", static_cast<long long>(intVersion));
+ if (!putVarInt(m_currentTransaction.get(), DatabaseMetaDataKey::encode(rowId, DatabaseMetaDataKey::UserIntVersion), intVersion))
+ return false;
+
return true;
}
Modified: trunk/Source/WebCore/Modules/indexeddb/IDBLevelDBCoding.h (124857 => 124858)
--- trunk/Source/WebCore/Modules/indexeddb/IDBLevelDBCoding.h 2012-08-07 06:40:42 UTC (rev 124857)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBLevelDBCoding.h 2012-08-07 06:54:55 UTC (rev 124858)
@@ -141,7 +141,8 @@
OriginName = 0,
DatabaseName = 1,
UserVersion = 2,
- MaxObjectStoreId = 3
+ MaxObjectStoreId = 3,
+ UserIntVersion = 4
};
static Vector<char> encode(int64_t databaseId, MetaDataType);
Modified: trunk/Source/WebCore/Modules/indexeddb/IDBMetadata.h (124857 => 124858)
--- trunk/Source/WebCore/Modules/indexeddb/IDBMetadata.h 2012-08-07 06:40:42 UTC (rev 124857)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBMetadata.h 2012-08-07 06:54:55 UTC (rev 124858)
@@ -42,8 +42,10 @@
struct IDBIndexMetadata;
struct IDBDatabaseMetadata {
+ // FIXME: These can probably be collapsed into 0.
enum {
- NoIntVersion = -1
+ NoIntVersion = -1,
+ DefaultIntVersion = 0
};
IDBDatabaseMetadata()