Index: sync/syncable/directory_backing_store.cc |
diff --git a/sync/syncable/directory_backing_store.cc b/sync/syncable/directory_backing_store.cc |
index 9b8e0dba855edc22128e0cb4aab84d96ec485da5..70d92986cd2506c1f62296a71ad45a4be01e89fc 100644 |
--- a/sync/syncable/directory_backing_store.cc |
+++ b/sync/syncable/directory_backing_store.cc |
@@ -27,6 +27,8 @@ |
#include "sync/syncable/syncable-inl.h" |
#include "sync/syncable/syncable_columns.h" |
#include "sync/util/time.h" |
+#include "sync/internal_api/public/base/ordinal.h" |
rlarocque
2012/10/01 21:45:55
These should be in alphabetical order.
vishwath
2012/10/02 01:06:33
Done.
|
+#include "sync/internal_api/public/base/node_ordinal.h" |
using std::string; |
@@ -39,7 +41,7 @@ static const string::size_type kUpdateStatementBufferSize = 2048; |
// Increment this version whenever updating DB tables. |
extern const int32 kCurrentDBVersion; // Global visibility for our unittest. |
-const int32 kCurrentDBVersion = 80; |
+const int32 kCurrentDBVersion = 81; |
// Iterate over the fields of |entry| and bind each to |statement| for |
// updating. Returns the number of args bound. |
@@ -48,7 +50,16 @@ void BindFields(const EntryKernel& entry, |
int index = 0; |
int i = 0; |
for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) { |
- statement->BindInt64(index++, entry.ref(static_cast<Int64Field>(i))); |
+ // Store SERVER_POSITION_IN_PARENT as a blob for eventual shift |
+ // to using ordinals instead of int64's |
rlarocque
2012/10/01 21:45:55
Comments should end with a period.
akalin
2012/10/01 23:13:35
int64's int64s
vishwath
2012/10/02 01:06:33
Done.
vishwath
2012/10/02 01:06:33
Done.
|
+ // See crbug.com/145412 |
+ if (i == SERVER_POSITION_IN_PARENT) { |
+ std::string ordinal = Int64ToNodeOrdinal( |
+ entry.ref(SERVER_POSITION_IN_PARENT)).ToInternalValue(); |
+ statement->BindBlob(index++, ordinal.data(), ordinal.size()); |
+ } |
+ else |
rlarocque
2012/10/01 21:45:55
That's unusual formatting. You should put the els
vishwath
2012/10/02 01:06:33
An unfortunate take-away from too much python prog
|
+ statement->BindInt64(index++, entry.ref(static_cast<Int64Field>(i))); |
} |
for ( ; i < TIME_FIELDS_END; ++i) { |
statement->BindInt64(index++, |
@@ -78,7 +89,20 @@ EntryKernel* UnpackEntry(sql::Statement* statement) { |
DCHECK_EQ(statement->ColumnCount(), static_cast<int>(FIELD_COUNT)); |
int i = 0; |
for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) { |
- kernel->put(static_cast<Int64Field>(i), statement->ColumnInt64(i)); |
+ // Store SERVER_POSITION_IN_PARENT as a string for eventual shift |
+ // to using ordinals instead of int64's //VISH_TODO: CONTINUE HERE |
rlarocque
2012/10/01 21:45:55
Did you intend to leave this comment here?
vishwath
2012/10/02 01:06:33
That would be an embarrassed no.
On 2012/10/01 21:
|
+ if(i == SERVER_POSITION_IN_PARENT && |
+ statement->ColumnType(i) == sql::COLUMN_TYPE_BLOB) { |
rlarocque
2012/10/01 21:45:55
Make this second expression a DCHECK? We shouldn'
vishwath
2012/10/02 01:06:33
I changed the check to a test for a non-null colum
|
+ std::string ordinal_blob; |
+ DCHECK(statement->ColumnBlobAsString(i, &ordinal_blob)); |
+ int64 server_position = NodeOrdinalToInt64( |
+ NodeOrdinal(ordinal_blob)); |
+ kernel->put( |
+ static_cast<Int64Field>(SERVER_POSITION_IN_PARENT), |
rlarocque
2012/10/01 21:45:55
The parameters to put() should be aligned.
vishwath
2012/10/02 01:06:33
Done.
|
+ server_position); |
+ } |
+ else |
rlarocque
2012/10/01 21:45:55
Change this formatting, too.
vishwath
2012/10/02 01:06:33
Done.
|
+ kernel->put(static_cast<Int64Field>(i), statement->ColumnInt64(i)); |
} |
for ( ; i < TIME_FIELDS_END; ++i) { |
kernel->put(static_cast<TimeField>(i), |
@@ -323,6 +347,13 @@ bool DirectoryBackingStore::InitializeTables() { |
version_on_disk = 80; |
} |
+ // Version 81 changes the server_position_in_parent_field from an int64 |
+ // to a string. |
+ if (version_on_disk == 80) { |
+ if (MigrateVersion80To81()) |
+ version_on_disk = 81; |
+ } |
+ |
// If one of the migrations requested it, drop columns that aren't current. |
// It's only safe to do this after migrating all the way to the current |
// version. |
@@ -968,6 +999,7 @@ bool DirectoryBackingStore::MigrateVersion78To79() { |
SetVersion(79); |
return true; |
} |
+ |
bool DirectoryBackingStore::MigrateVersion79To80() { |
if (!db_->Execute( |
"ALTER TABLE share_info ADD COLUMN bag_of_chips BLOB")) |
@@ -982,6 +1014,77 @@ bool DirectoryBackingStore::MigrateVersion79To80() { |
return true; |
} |
+bool DirectoryBackingStore::MigrateVersion80To81() { |
+ // Version 81 changes server_position_in_parent from a potentially lossy |
+ // int64 to an unbounded fidelity ordinal (stored as a blob) |
rlarocque
2012/10/01 21:45:55
Append period here.
vishwath
2012/10/02 01:06:33
Done.
|
+ // We make the current metas table temporary, create a new table where |
+ // server_position_in_parent is of the right type, and transfer values |
+ // after converting from int64's to Ordinals. |
+ SafeDropTable("temp_metas"); |
+ if(!db_->Execute( |
rlarocque
2012/10/01 21:45:55
Does this not fit on one line?
vishwath
2012/10/02 01:06:33
Done.
|
+ "ALTER TABLE metas RENAME TO temp_metas")) { |
+ return false; |
+ } |
+ if(!CreateMetasTable(false)) |
+ return false; |
+ |
rlarocque
2012/10/01 21:45:55
Remove extra whitespace.
vishwath
2012/10/02 01:06:33
Done.
|
+ |
+ std::string old_info_string = "SELECT "; |
+ AppendColumnList(&old_info_string); |
rlarocque
2012/10/01 21:45:55
This is dangerous. Someone might update g_metas_c
vishwath
2012/10/02 01:06:33
Done.
|
+ old_info_string.append(" FROM temp_metas"); |
+ |
+ std::string new_info_string = "INSERT INTO metas ("; |
+ AppendColumnList(&new_info_string); |
rlarocque
2012/10/01 21:45:55
Same warning here, except that this call expects t
vishwath
2012/10/02 01:06:33
Done.
|
+ new_info_string.append(") VALUES ("); |
+ for(int i = BEGIN_FIELDS; i < BEGIN_FIELDS + FIELD_COUNT - 1; ++i) { |
rlarocque
2012/10/01 21:45:55
Similar warnings apply to this loop, too. And oth
vishwath
2012/10/02 01:06:33
Done.
|
+ new_info_string.append("?, "); |
+ } |
+ new_info_string.append("?)"); |
+ |
+ sql::Statement old_info(db_->GetUniqueStatement( |
+ old_info_string.c_str())); |
+ sql::Statement new_info(db_->GetUniqueStatement( |
+ new_info_string.c_str())); |
+ |
+ while(old_info.Step()) { |
+ int64 int_ordinal = old_info.ColumnInt(3); |
+ std::string new_ordinal = |
+ Int64ToNodeOrdinal(int_ordinal).ToInternalValue(); |
+ //Loop and bind each new column based on the old column type |
+ for(int i = 0; i < FIELD_COUNT; ++i) { |
+ if (i == SERVER_POSITION_IN_PARENT) { |
+ new_info.BindBlob(i, new_ordinal.data(), new_ordinal.length()); |
+ continue; |
+ } |
+ switch(old_info.ColumnType(i)) { |
+ case sql::COLUMN_TYPE_INTEGER: |
+ new_info.BindInt64(i, old_info.ColumnInt64(i)); |
+ break; |
+ case sql::COLUMN_TYPE_FLOAT: |
+ new_info.BindDouble(i, old_info.ColumnDouble(i)); |
+ break; |
+ case sql::COLUMN_TYPE_TEXT: |
+ new_info.BindString(i, old_info.ColumnString(i)); |
+ break; |
+ case sql::COLUMN_TYPE_BLOB: |
+ new_info.BindBlob(i, |
+ old_info.ColumnBlob(i), |
+ old_info.ColumnByteLength(i)); |
+ break; |
+ case sql::COLUMN_TYPE_NULL: |
+ new_info.BindNull(i); |
+ } |
+ } |
+ |
+ if(!new_info.Run()) |
+ return false; |
+ new_info.Reset(true); |
+ } |
+ |
+ SetVersion(81); |
+ return true; |
+} |
+ |
bool DirectoryBackingStore::CreateTables() { |
DVLOG(1) << "First run, creating tables"; |
// Create two little tables share_version and share_info |