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

Side by Side Diff: sync/syncable/directory_backing_store.cc

Issue 11341048: Populate versions on individual nodes in sync model and native bookmark model. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync to head Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "sync/syncable/directory_backing_store.h" 5 #include "sync/syncable/directory_backing_store.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include <limits> 9 #include <limits>
10 10
(...skipping 22 matching lines...) Expand all
33 33
34 namespace syncer { 34 namespace syncer {
35 namespace syncable { 35 namespace syncable {
36 36
37 // This just has to be big enough to hold an UPDATE or INSERT statement that 37 // This just has to be big enough to hold an UPDATE or INSERT statement that
38 // modifies all the columns in the entry table. 38 // modifies all the columns in the entry table.
39 static const string::size_type kUpdateStatementBufferSize = 2048; 39 static const string::size_type kUpdateStatementBufferSize = 2048;
40 40
41 // Increment this version whenever updating DB tables. 41 // Increment this version whenever updating DB tables.
42 extern const int32 kCurrentDBVersion; // Global visibility for our unittest. 42 extern const int32 kCurrentDBVersion; // Global visibility for our unittest.
43 const int32 kCurrentDBVersion = 82; 43 const int32 kCurrentDBVersion = 83;
44 44
45 // Iterate over the fields of |entry| and bind each to |statement| for 45 // Iterate over the fields of |entry| and bind each to |statement| for
46 // updating. Returns the number of args bound. 46 // updating. Returns the number of args bound.
47 void BindFields(const EntryKernel& entry, 47 void BindFields(const EntryKernel& entry,
48 sql::Statement* statement) { 48 sql::Statement* statement) {
49 int index = 0; 49 int index = 0;
50 int i = 0; 50 int i = 0;
51 for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) { 51 for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) {
52 statement->BindInt64(index++, entry.ref(static_cast<Int64Field>(i))); 52 statement->BindInt64(index++, entry.ref(static_cast<Int64Field>(i)));
53 } 53 }
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 if (MigrateVersion80To81()) 351 if (MigrateVersion80To81())
352 version_on_disk = 81; 352 version_on_disk = 81;
353 } 353 }
354 354
355 // Version 82 migration added transaction_version column per data type. 355 // Version 82 migration added transaction_version column per data type.
356 if (version_on_disk == 81) { 356 if (version_on_disk == 81) {
357 if (MigrateVersion81To82()) 357 if (MigrateVersion81To82())
358 version_on_disk = 82; 358 version_on_disk = 82;
359 } 359 }
360 360
361 // Version 83 migration added transaction_version column per sync entry.
362 if (version_on_disk == 82) {
363 if (MigrateVersion82To83())
364 version_on_disk = 83;
365 }
366
361 // If one of the migrations requested it, drop columns that aren't current. 367 // If one of the migrations requested it, drop columns that aren't current.
362 // It's only safe to do this after migrating all the way to the current 368 // It's only safe to do this after migrating all the way to the current
363 // version. 369 // version.
364 if (version_on_disk == kCurrentDBVersion && needs_column_refresh_) { 370 if (version_on_disk == kCurrentDBVersion && needs_column_refresh_) {
365 if (!RefreshColumns()) 371 if (!RefreshColumns())
366 version_on_disk = 0; 372 version_on_disk = 0;
367 } 373 }
368 374
369 // A final, alternative catch-all migration to simply re-sync everything. 375 // A final, alternative catch-all migration to simply re-sync everything.
370 // 376 //
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 "ALTER TABLE models ADD COLUMN transaction_version BIGINT default 0")) 1071 "ALTER TABLE models ADD COLUMN transaction_version BIGINT default 0"))
1066 return false; 1072 return false;
1067 sql::Statement update(db_->GetUniqueStatement( 1073 sql::Statement update(db_->GetUniqueStatement(
1068 "UPDATE models SET transaction_version = 0")); 1074 "UPDATE models SET transaction_version = 0"));
1069 if (!update.Run()) 1075 if (!update.Run())
1070 return false; 1076 return false;
1071 SetVersion(82); 1077 SetVersion(82);
1072 return true; 1078 return true;
1073 } 1079 }
1074 1080
1081 bool DirectoryBackingStore::MigrateVersion82To83() {
1082 // Version 83 added transaction_version on sync node.
1083 if (!db_->Execute(
1084 "ALTER TABLE metas ADD COLUMN transaction_version BIGINT default 0"))
1085 return false;
1086 sql::Statement update(db_->GetUniqueStatement(
1087 "UPDATE metas SET transaction_version = 0"));
1088 if (!update.Run())
1089 return false;
1090 SetVersion(83);
1091 return true;
1092 }
1093
1075 bool DirectoryBackingStore::CreateTables() { 1094 bool DirectoryBackingStore::CreateTables() {
1076 DVLOG(1) << "First run, creating tables"; 1095 DVLOG(1) << "First run, creating tables";
1077 // Create two little tables share_version and share_info 1096 // Create two little tables share_version and share_info
1078 if (!db_->Execute( 1097 if (!db_->Execute(
1079 "CREATE TABLE share_version (" 1098 "CREATE TABLE share_version ("
1080 "id VARCHAR(128) primary key, data INT)")) { 1099 "id VARCHAR(128) primary key, data INT)")) {
1081 return false; 1100 return false;
1082 } 1101 }
1083 1102
1084 { 1103 {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 bool prev_exists = (ids_set.find(entry->ref(PREV_ID).value()) != end); 1266 bool prev_exists = (ids_set.find(entry->ref(PREV_ID).value()) != end);
1248 bool parent_exists = (ids_set.find(entry->ref(PARENT_ID).value()) != end); 1267 bool parent_exists = (ids_set.find(entry->ref(PARENT_ID).value()) != end);
1249 bool next_exists = (ids_set.find(entry->ref(NEXT_ID).value()) != end); 1268 bool next_exists = (ids_set.find(entry->ref(NEXT_ID).value()) != end);
1250 is_ok = is_ok && prev_exists && parent_exists && next_exists; 1269 is_ok = is_ok && prev_exists && parent_exists && next_exists;
1251 } 1270 }
1252 return is_ok; 1271 return is_ok;
1253 } 1272 }
1254 1273
1255 } // namespace syncable 1274 } // namespace syncable
1256 } // namespace syncer 1275 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/syncable/directory_backing_store.h ('k') | sync/syncable/directory_backing_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698