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

Side by Side Diff: chrome/browser/sync/engine/process_updates_command.cc

Issue 8533024: sync: Use a single transaction in ProcessUpdates rather than one per entry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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
« no previous file with comments | « chrome/browser/sync/engine/process_updates_command.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/sync/engine/process_updates_command.h" 5 #include "chrome/browser/sync/engine/process_updates_command.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 27 matching lines...) Expand all
38 void ProcessUpdatesCommand::ModelChangingExecuteImpl(SyncSession* session) { 38 void ProcessUpdatesCommand::ModelChangingExecuteImpl(SyncSession* session) {
39 syncable::ScopedDirLookup dir(session->context()->directory_manager(), 39 syncable::ScopedDirLookup dir(session->context()->directory_manager(),
40 session->context()->account_name()); 40 session->context()->account_name());
41 if (!dir.good()) { 41 if (!dir.good()) {
42 LOG(ERROR) << "Scoped dir lookup failed!"; 42 LOG(ERROR) << "Scoped dir lookup failed!";
43 return; 43 return;
44 } 44 }
45 45
46 StatusController* status = session->status_controller(); 46 StatusController* status = session->status_controller();
47 47
48 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir);
48 const sessions::UpdateProgress& progress(status->update_progress()); 49 const sessions::UpdateProgress& progress(status->update_progress());
49 vector<sessions::VerifiedUpdate>::const_iterator it; 50 vector<sessions::VerifiedUpdate>::const_iterator it;
50 for (it = progress.VerifiedUpdatesBegin(); 51 for (it = progress.VerifiedUpdatesBegin();
51 it != progress.VerifiedUpdatesEnd(); 52 it != progress.VerifiedUpdatesEnd();
52 ++it) { 53 ++it) {
53 const sync_pb::SyncEntity& update = it->second; 54 const sync_pb::SyncEntity& update = it->second;
54 55
55 if (it->first != VERIFY_SUCCESS && it->first != VERIFY_UNDELETE) 56 if (it->first != VERIFY_SUCCESS && it->first != VERIFY_UNDELETE)
56 continue; 57 continue;
57 switch (ProcessUpdate(dir, update)) { 58 switch (ProcessUpdate(dir, update, &trans)) {
58 case SUCCESS_PROCESSED: 59 case SUCCESS_PROCESSED:
59 case SUCCESS_STORED: 60 case SUCCESS_STORED:
60 break; 61 break;
61 default: 62 default:
62 NOTREACHED(); 63 NOTREACHED();
63 break; 64 break;
64 } 65 }
65 } 66 }
66 67
67 status->set_num_consecutive_errors(0); 68 status->set_num_consecutive_errors(0);
(...skipping 16 matching lines...) Expand all
84 same_id, 85 same_id,
85 deleted, 86 deleted,
86 is_directory, 87 is_directory,
87 model_type); 88 model_type);
88 } 89 }
89 } // namespace 90 } // namespace
90 91
91 // Process a single update. Will avoid touching global state. 92 // Process a single update. Will avoid touching global state.
92 ServerUpdateProcessingResult ProcessUpdatesCommand::ProcessUpdate( 93 ServerUpdateProcessingResult ProcessUpdatesCommand::ProcessUpdate(
93 const syncable::ScopedDirLookup& dir, 94 const syncable::ScopedDirLookup& dir,
94 const sync_pb::SyncEntity& proto_update) { 95 const sync_pb::SyncEntity& proto_update,
96 syncable::WriteTransaction* const trans) {
rlarocque 2011/11/15 00:52:23 Was there a reason you decided to use a pointer he
95 97
96 const SyncEntity& update = *static_cast<const SyncEntity*>(&proto_update); 98 const SyncEntity& update = *static_cast<const SyncEntity*>(&proto_update);
97 syncable::Id server_id = update.id(); 99 syncable::Id server_id = update.id();
98 const std::string name = SyncerProtoUtil::NameFromSyncEntity(update); 100 const std::string name = SyncerProtoUtil::NameFromSyncEntity(update);
99 101
100 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir);
101
102 // Look to see if there's a local item that should recieve this update, 102 // Look to see if there's a local item that should recieve this update,
103 // maybe due to a duplicate client tag or a lost commit response. 103 // maybe due to a duplicate client tag or a lost commit response.
104 syncable::Id local_id = SyncerUtil::FindLocalIdToUpdate(&trans, update); 104 syncable::Id local_id = SyncerUtil::FindLocalIdToUpdate(trans, update);
105 105
106 // FindLocalEntryToUpdate has veto power. 106 // FindLocalEntryToUpdate has veto power.
107 if (local_id.IsNull()) { 107 if (local_id.IsNull()) {
108 return SUCCESS_PROCESSED; // The entry has become irrelevant. 108 return SUCCESS_PROCESSED; // The entry has become irrelevant.
109 } 109 }
110 110
111 SyncerUtil::CreateNewEntry(&trans, local_id); 111 SyncerUtil::CreateNewEntry(trans, local_id);
112 112
113 // We take a two step approach. First we store the entries data in the 113 // We take a two step approach. First we store the entries data in the
114 // server fields of a local entry and then move the data to the local fields 114 // server fields of a local entry and then move the data to the local fields
115 syncable::MutableEntry target_entry(&trans, syncable::GET_BY_ID, local_id); 115 syncable::MutableEntry target_entry(trans, syncable::GET_BY_ID, local_id);
116 116
117 // We need to run the Verify checks again; the world could have changed 117 // We need to run the Verify checks again; the world could have changed
118 // since VerifyUpdatesCommand. 118 // since VerifyUpdatesCommand.
119 if (!ReverifyEntry(&trans, update, &target_entry)) { 119 if (!ReverifyEntry(trans, update, &target_entry)) {
120 return SUCCESS_PROCESSED; // The entry has become irrelevant. 120 return SUCCESS_PROCESSED; // The entry has become irrelevant.
121 } 121 }
122 122
123 // If we're repurposing an existing local entry with a new server ID, 123 // If we're repurposing an existing local entry with a new server ID,
124 // change the ID now, after we're sure that the update can succeed. 124 // change the ID now, after we're sure that the update can succeed.
125 if (local_id != server_id) { 125 if (local_id != server_id) {
126 DCHECK(!update.deleted()); 126 DCHECK(!update.deleted());
127 SyncerUtil::ChangeEntryIDAndUpdateChildren(&trans, &target_entry, 127 SyncerUtil::ChangeEntryIDAndUpdateChildren(trans, &target_entry,
128 server_id); 128 server_id);
129 // When IDs change, versions become irrelevant. Forcing BASE_VERSION 129 // When IDs change, versions become irrelevant. Forcing BASE_VERSION
130 // to zero would ensure that this update gets applied, but would indicate 130 // to zero would ensure that this update gets applied, but would indicate
131 // creation or undeletion if it were committed that way. Instead, prefer 131 // creation or undeletion if it were committed that way. Instead, prefer
132 // forcing BASE_VERSION to entry.version() while also forcing 132 // forcing BASE_VERSION to entry.version() while also forcing
133 // IS_UNAPPLIED_UPDATE to true. If the item is UNSYNCED, it's committable 133 // IS_UNAPPLIED_UPDATE to true. If the item is UNSYNCED, it's committable
134 // from the new state; it may commit before the conflict resolver gets 134 // from the new state; it may commit before the conflict resolver gets
135 // a crack at it. 135 // a crack at it.
136 if (target_entry.Get(syncable::IS_UNSYNCED) || 136 if (target_entry.Get(syncable::IS_UNSYNCED) ||
137 target_entry.Get(syncable::BASE_VERSION) > 0) { 137 target_entry.Get(syncable::BASE_VERSION) > 0) {
(...skipping 17 matching lines...) Expand all
155 // If these don't match, it means that we have a different view of the 155 // If these don't match, it means that we have a different view of the
156 // truth from other clients. That's a sync bug, though we may be able 156 // truth from other clients. That's a sync bug, though we may be able
157 // to recover the next time this item commits. 157 // to recover the next time this item commits.
158 LOG_IF(ERROR, !SyncerUtil::ServerAndLocalEntriesMatch(&target_entry)) 158 LOG_IF(ERROR, !SyncerUtil::ServerAndLocalEntriesMatch(&target_entry))
159 << target_entry; 159 << target_entry;
160 } 160 }
161 return SUCCESS_PROCESSED; 161 return SUCCESS_PROCESSED;
162 } 162 }
163 163
164 } // namespace browser_sync 164 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/process_updates_command.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698