OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/engine/directory_commit_contribution.h" | 5 #include "sync/engine/directory_commit_contribution.h" |
6 | 6 |
7 #include "sync/engine/commit_util.h" | 7 #include "sync/engine/commit_util.h" |
8 #include "sync/engine/get_commit_ids.h" | 8 #include "sync/engine/get_commit_ids.h" |
9 #include "sync/engine/syncer_util.h" | 9 #include "sync/engine/syncer_util.h" |
| 10 #include "sync/internal_api/public/sessions/commit_counters.h" |
10 #include "sync/syncable/model_neutral_mutable_entry.h" | 11 #include "sync/syncable/model_neutral_mutable_entry.h" |
11 #include "sync/syncable/syncable_model_neutral_write_transaction.h" | 12 #include "sync/syncable/syncable_model_neutral_write_transaction.h" |
12 | 13 |
13 namespace syncer { | 14 namespace syncer { |
14 | 15 |
15 using syncable::GET_BY_HANDLE; | 16 using syncable::GET_BY_HANDLE; |
16 using syncable::SYNCER; | 17 using syncable::SYNCER; |
17 | 18 |
18 DirectoryCommitContribution::~DirectoryCommitContribution() { | 19 DirectoryCommitContribution::~DirectoryCommitContribution() { |
19 DCHECK(!syncing_bits_set_); | 20 DCHECK(!syncing_bits_set_); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 void DirectoryCommitContribution::AddToCommitMessage( | 60 void DirectoryCommitContribution::AddToCommitMessage( |
60 sync_pb::ClientToServerMessage* msg) { | 61 sync_pb::ClientToServerMessage* msg) { |
61 DCHECK(syncing_bits_set_); | 62 DCHECK(syncing_bits_set_); |
62 sync_pb::CommitMessage* commit_message = msg->mutable_commit(); | 63 sync_pb::CommitMessage* commit_message = msg->mutable_commit(); |
63 entries_start_index_ = commit_message->entries_size(); | 64 entries_start_index_ = commit_message->entries_size(); |
64 std::copy(entities_.begin(), | 65 std::copy(entities_.begin(), |
65 entities_.end(), | 66 entities_.end(), |
66 RepeatedPtrFieldBackInserter(commit_message->mutable_entries())); | 67 RepeatedPtrFieldBackInserter(commit_message->mutable_entries())); |
67 if (!context_.context().empty()) | 68 if (!context_.context().empty()) |
68 commit_message->add_client_contexts()->Swap(&context_); | 69 commit_message->add_client_contexts()->Swap(&context_); |
| 70 |
| 71 CommitCounters* counters = debug_info_emitter_->GetMutableCommitCounters(); |
| 72 counters->num_commits_attempted += entities_.size(); |
69 } | 73 } |
70 | 74 |
71 SyncerError DirectoryCommitContribution::ProcessCommitResponse( | 75 SyncerError DirectoryCommitContribution::ProcessCommitResponse( |
72 const sync_pb::ClientToServerResponse& response, | 76 const sync_pb::ClientToServerResponse& response, |
73 sessions::StatusController* status) { | 77 sessions::StatusController* status) { |
74 DCHECK(syncing_bits_set_); | 78 DCHECK(syncing_bits_set_); |
75 const sync_pb::CommitResponse& commit_response = response.commit(); | 79 const sync_pb::CommitResponse& commit_response = response.commit(); |
76 | 80 |
77 int transient_error_commits = 0; | 81 int transient_error_commits = 0; |
78 int conflicting_commits = 0; | 82 int conflicting_commits = 0; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 case sync_pb::CommitResponse::TRANSIENT_ERROR: | 117 case sync_pb::CommitResponse::TRANSIENT_ERROR: |
114 ++transient_error_commits; | 118 ++transient_error_commits; |
115 break; | 119 break; |
116 default: | 120 default: |
117 LOG(FATAL) << "Bad return from ProcessSingleCommitResponse"; | 121 LOG(FATAL) << "Bad return from ProcessSingleCommitResponse"; |
118 } | 122 } |
119 } | 123 } |
120 MarkDeletedChildrenSynced(dir_, &trans, &deleted_folders); | 124 MarkDeletedChildrenSynced(dir_, &trans, &deleted_folders); |
121 } | 125 } |
122 | 126 |
| 127 CommitCounters* counters = debug_info_emitter_->GetMutableCommitCounters(); |
| 128 counters->num_commits_success += successes; |
| 129 counters->num_commits_conflict += transient_error_commits; |
| 130 counters->num_commits_error += transient_error_commits; |
| 131 |
123 int commit_count = static_cast<int>(metahandles_.size()); | 132 int commit_count = static_cast<int>(metahandles_.size()); |
124 if (commit_count == successes) { | 133 if (commit_count == successes) { |
125 return SYNCER_OK; | 134 return SYNCER_OK; |
126 } else if (error_commits > 0) { | 135 } else if (error_commits > 0) { |
127 return SERVER_RETURN_UNKNOWN_ERROR; | 136 return SERVER_RETURN_UNKNOWN_ERROR; |
128 } else if (transient_error_commits > 0) { | 137 } else if (transient_error_commits > 0) { |
129 return SERVER_RETURN_TRANSIENT_ERROR; | 138 return SERVER_RETURN_TRANSIENT_ERROR; |
130 } else if (conflicting_commits > 0) { | 139 } else if (conflicting_commits > 0) { |
131 // This means that the server already has an item with this version, but | 140 // This means that the server already has an item with this version, but |
132 // we haven't seen that update yet. | 141 // we haven't seen that update yet. |
133 // | 142 // |
134 // A well-behaved client should respond to this by proceeding to the | 143 // A well-behaved client should respond to this by proceeding to the |
135 // download updates phase, fetching the conflicting items, then attempting | 144 // download updates phase, fetching the conflicting items, then attempting |
136 // to resolve the conflict. That's not what this client does. | 145 // to resolve the conflict. That's not what this client does. |
137 // | 146 // |
138 // We don't currently have any code to support that exceptional control | 147 // We don't currently have any code to support that exceptional control |
139 // flow. Instead, we abort the current sync cycle and start a new one. The | 148 // flow. Instead, we abort the current sync cycle and start a new one. The |
140 // end result is the same. | 149 // end result is the same. |
141 return SERVER_RETURN_CONFLICT; | 150 return SERVER_RETURN_CONFLICT; |
142 } else { | 151 } else { |
143 LOG(FATAL) << "Inconsistent counts when processing commit response"; | 152 LOG(FATAL) << "Inconsistent counts when processing commit response"; |
144 return SYNCER_OK; | 153 return SYNCER_OK; |
145 } | 154 } |
146 } | 155 } |
147 | 156 |
148 void DirectoryCommitContribution::CleanUp() { | 157 void DirectoryCommitContribution::CleanUp() { |
149 DCHECK(syncing_bits_set_); | 158 DCHECK(syncing_bits_set_); |
150 UnsetSyncingBits(); | 159 UnsetSyncingBits(); |
| 160 debug_info_emitter_->EmitCommitCountersUpdate(); |
151 } | 161 } |
152 | 162 |
153 size_t DirectoryCommitContribution::GetNumEntries() const { | 163 size_t DirectoryCommitContribution::GetNumEntries() const { |
154 return metahandles_.size(); | 164 return metahandles_.size(); |
155 } | 165 } |
156 | 166 |
157 DirectoryCommitContribution::DirectoryCommitContribution( | 167 DirectoryCommitContribution::DirectoryCommitContribution( |
158 const std::vector<int64>& metahandles, | 168 const std::vector<int64>& metahandles, |
159 const google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities, | 169 const google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities, |
160 const sync_pb::DataTypeContext& context, | 170 const sync_pb::DataTypeContext& context, |
(...skipping 11 matching lines...) Expand all Loading... |
172 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir_); | 182 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir_); |
173 for (std::vector<int64>::const_iterator it = metahandles_.begin(); | 183 for (std::vector<int64>::const_iterator it = metahandles_.begin(); |
174 it != metahandles_.end(); ++it) { | 184 it != metahandles_.end(); ++it) { |
175 syncable::ModelNeutralMutableEntry entry(&trans, GET_BY_HANDLE, *it); | 185 syncable::ModelNeutralMutableEntry entry(&trans, GET_BY_HANDLE, *it); |
176 entry.PutSyncing(false); | 186 entry.PutSyncing(false); |
177 } | 187 } |
178 syncing_bits_set_ = false; | 188 syncing_bits_set_ = false; |
179 } | 189 } |
180 | 190 |
181 } // namespace syncer | 191 } // namespace syncer |
OLD | NEW |