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

Side by Side Diff: sync/engine/directory_update_handler.cc

Issue 271613006: sync: Populate debug counters for directory types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months 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 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_update_handler.h" 5 #include "sync/engine/directory_update_handler.h"
6 6
7 #include "sync/engine/conflict_resolver.h" 7 #include "sync/engine/conflict_resolver.h"
8 #include "sync/engine/process_updates_util.h" 8 #include "sync/engine/process_updates_util.h"
9 #include "sync/engine/update_applicator.h" 9 #include "sync/engine/update_applicator.h"
10 #include "sync/sessions/directory_type_debug_info_emitter.h" 10 #include "sync/sessions/directory_type_debug_info_emitter.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 // version is higher, it means a local change happened while the mutation 53 // version is higher, it means a local change happened while the mutation
54 // was in flight, and the local context takes priority. 54 // was in flight, and the local context takes priority.
55 if (mutated_context.version() >= local_context.version() && 55 if (mutated_context.version() >= local_context.version() &&
56 local_context.context() != mutated_context.context()) { 56 local_context.context() != mutated_context.context()) {
57 dir_->SetDataTypeContext(&trans, type_, mutated_context); 57 dir_->SetDataTypeContext(&trans, type_, mutated_context);
58 // TODO(zea): trigger the datatype's UpdateDataTypeContext method. 58 // TODO(zea): trigger the datatype's UpdateDataTypeContext method.
59 } else if (mutated_context.version() < local_context.version()) { 59 } else if (mutated_context.version() < local_context.version()) {
60 // A GetUpdates using the old context was in progress when the context was 60 // A GetUpdates using the old context was in progress when the context was
61 // set. Fail this get updates cycle, to force a retry. 61 // set. Fail this get updates cycle, to force a retry.
62 DVLOG(1) << "GU Context conflict detected, forcing GU retry."; 62 DVLOG(1) << "GU Context conflict detected, forcing GU retry.";
63 debug_info_emitter_->EmitUpdateCountersUpdate();
63 return DATATYPE_TRIGGERED_RETRY; 64 return DATATYPE_TRIGGERED_RETRY;
64 } 65 }
65 } 66 }
66 67
67 UpdateSyncEntities(&trans, applicable_updates, status); 68 UpdateSyncEntities(&trans, applicable_updates, status);
68 69
69 if (IsValidProgressMarker(progress_marker)) { 70 if (IsValidProgressMarker(progress_marker)) {
70 ExpireEntriesIfNeeded(&trans, progress_marker); 71 ExpireEntriesIfNeeded(&trans, progress_marker);
71 UpdateProgressMarker(progress_marker); 72 UpdateProgressMarker(progress_marker);
72 } 73 }
74 debug_info_emitter_->EmitUpdateCountersUpdate();
73 return SYNCER_OK; 75 return SYNCER_OK;
74 } 76 }
75 77
76 void DirectoryUpdateHandler::ApplyUpdates(sessions::StatusController* status) { 78 void DirectoryUpdateHandler::ApplyUpdates(sessions::StatusController* status) {
77 if (!IsApplyUpdatesRequired()) { 79 if (!IsApplyUpdatesRequired()) {
78 return; 80 return;
79 } 81 }
80 82
81 // This will invoke handlers that belong to the model and its thread, so we 83 // This will invoke handlers that belong to the model and its thread, so we
82 // switch to the appropriate thread before we start this work. 84 // switch to the appropriate thread before we start this work.
83 WorkCallback c = base::Bind( 85 WorkCallback c = base::Bind(
84 &DirectoryUpdateHandler::ApplyUpdatesImpl, 86 &DirectoryUpdateHandler::ApplyUpdatesImpl,
85 // We wait until the callback is executed. We can safely use Unretained. 87 // We wait until the callback is executed. We can safely use Unretained.
86 base::Unretained(this), 88 base::Unretained(this),
87 base::Unretained(status)); 89 base::Unretained(status));
88 worker_->DoWorkAndWaitUntilDone(c); 90 worker_->DoWorkAndWaitUntilDone(c);
91
92 debug_info_emitter_->EmitUpdateCountersUpdate();
89 } 93 }
90 94
91 void DirectoryUpdateHandler::PassiveApplyUpdates( 95 void DirectoryUpdateHandler::PassiveApplyUpdates(
92 sessions::StatusController* status) { 96 sessions::StatusController* status) {
93 if (!IsApplyUpdatesRequired()) { 97 if (!IsApplyUpdatesRequired()) {
94 return; 98 return;
95 } 99 }
96 100
97 // Just do the work here instead of deferring to another thread. 101 // Just do the work here instead of deferring to another thread.
98 ApplyUpdatesImpl(status); 102 ApplyUpdatesImpl(status);
103
104 debug_info_emitter_->EmitUpdateCountersUpdate();
99 } 105 }
100 106
101 SyncerError DirectoryUpdateHandler::ApplyUpdatesImpl( 107 SyncerError DirectoryUpdateHandler::ApplyUpdatesImpl(
102 sessions::StatusController* status) { 108 sessions::StatusController* status) {
103 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir_); 109 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir_);
104 110
105 std::vector<int64> handles; 111 std::vector<int64> handles;
106 dir_->GetUnappliedUpdateMetaHandles( 112 dir_->GetUnappliedUpdateMetaHandles(
107 &trans, 113 &trans,
108 FullModelTypeSet(type_), 114 FullModelTypeSet(type_),
109 &handles); 115 &handles);
110 116
111 // First set of update application passes. 117 // First set of update application passes.
112 UpdateApplicator applicator(dir_->GetCryptographer(&trans)); 118 UpdateApplicator applicator(dir_->GetCryptographer(&trans));
113 applicator.AttemptApplications(&trans, handles); 119 applicator.AttemptApplications(&trans, handles);
120
121 // The old StatusController counters.
114 status->increment_num_updates_applied_by(applicator.updates_applied()); 122 status->increment_num_updates_applied_by(applicator.updates_applied());
115 status->increment_num_hierarchy_conflicts_by( 123 status->increment_num_hierarchy_conflicts_by(
116 applicator.hierarchy_conflicts()); 124 applicator.hierarchy_conflicts());
117 status->increment_num_encryption_conflicts_by( 125 status->increment_num_encryption_conflicts_by(
118 applicator.encryption_conflicts()); 126 applicator.encryption_conflicts());
119 127
128 // The new UpdateCounter counters.
129 UpdateCounters* counters = debug_info_emitter_->GetMutableUpdateCounters();
130 counters->num_updates_applied += applicator.updates_applied();
131 counters->num_hierarchy_conflict_application_failures =
132 applicator.hierarchy_conflicts();
133 counters->num_encryption_conflict_application_failures +=
134 applicator.encryption_conflicts();
135
120 if (applicator.simple_conflict_ids().size() != 0) { 136 if (applicator.simple_conflict_ids().size() != 0) {
121 // Resolve the simple conflicts we just detected. 137 // Resolve the simple conflicts we just detected.
122 ConflictResolver resolver; 138 ConflictResolver resolver;
123 resolver.ResolveConflicts(&trans, 139 resolver.ResolveConflicts(&trans,
124 dir_->GetCryptographer(&trans), 140 dir_->GetCryptographer(&trans),
125 applicator.simple_conflict_ids(), 141 applicator.simple_conflict_ids(),
126 status); 142 status,
143 counters);
127 144
128 // Conflict resolution sometimes results in more updates to apply. 145 // Conflict resolution sometimes results in more updates to apply.
129 handles.clear(); 146 handles.clear();
130 dir_->GetUnappliedUpdateMetaHandles( 147 dir_->GetUnappliedUpdateMetaHandles(
131 &trans, 148 &trans,
132 FullModelTypeSet(type_), 149 FullModelTypeSet(type_),
133 &handles); 150 &handles);
134 151
135 UpdateApplicator conflict_applicator(dir_->GetCryptographer(&trans)); 152 UpdateApplicator conflict_applicator(dir_->GetCryptographer(&trans));
136 conflict_applicator.AttemptApplications(&trans, handles); 153 conflict_applicator.AttemptApplications(&trans, handles);
137 154
138 // We count the number of updates from both applicator passes. 155 // We count the number of updates from both applicator passes.
139 status->increment_num_updates_applied_by( 156 status->increment_num_updates_applied_by(
140 conflict_applicator.updates_applied()); 157 conflict_applicator.updates_applied());
158 counters->num_updates_applied += conflict_applicator.updates_applied();
141 159
142 // Encryption conflicts should remain unchanged by the resolution of simple 160 // Encryption conflicts should remain unchanged by the resolution of simple
143 // conflicts. Those can only be solved by updating our nigori key bag. 161 // conflicts. Those can only be solved by updating our nigori key bag.
144 DCHECK_EQ(conflict_applicator.encryption_conflicts(), 162 DCHECK_EQ(conflict_applicator.encryption_conflicts(),
145 applicator.encryption_conflicts()); 163 applicator.encryption_conflicts());
146 164
147 // Hierarchy conflicts should also remain unchanged, for reasons that are 165 // Hierarchy conflicts should also remain unchanged, for reasons that are
148 // more subtle. Hierarchy conflicts exist when the application of a pending 166 // more subtle. Hierarchy conflicts exist when the application of a pending
149 // update from the server would make the local folder hierarchy 167 // update from the server would make the local folder hierarchy
150 // inconsistent. The resolution of simple conflicts could never affect the 168 // inconsistent. The resolution of simple conflicts could never affect the
(...skipping 19 matching lines...) Expand all
170 return false; // We don't process control types here. 188 return false; // We don't process control types here.
171 } 189 }
172 190
173 return dir_->TypeHasUnappliedUpdates(type_); 191 return dir_->TypeHasUnappliedUpdates(type_);
174 } 192 }
175 193
176 void DirectoryUpdateHandler::UpdateSyncEntities( 194 void DirectoryUpdateHandler::UpdateSyncEntities(
177 syncable::ModelNeutralWriteTransaction* trans, 195 syncable::ModelNeutralWriteTransaction* trans,
178 const SyncEntityList& applicable_updates, 196 const SyncEntityList& applicable_updates,
179 sessions::StatusController* status) { 197 sessions::StatusController* status) {
180 ProcessDownloadedUpdates(dir_, trans, type_, applicable_updates, status); 198 UpdateCounters* counters = debug_info_emitter_->GetMutableUpdateCounters();
199 counters->num_updates_received += applicable_updates.size();
200 ProcessDownloadedUpdates(dir_, trans, type_,
201 applicable_updates, status, counters);
181 } 202 }
182 203
183 bool DirectoryUpdateHandler::IsValidProgressMarker( 204 bool DirectoryUpdateHandler::IsValidProgressMarker(
184 const sync_pb::DataTypeProgressMarker& progress_marker) const { 205 const sync_pb::DataTypeProgressMarker& progress_marker) const {
185 int field_number = progress_marker.data_type_id(); 206 int field_number = progress_marker.data_type_id();
186 ModelType model_type = GetModelTypeFromSpecificsFieldNumber(field_number); 207 ModelType model_type = GetModelTypeFromSpecificsFieldNumber(field_number);
187 if (!IsRealDataType(model_type) || type_ != model_type) { 208 if (!IsRealDataType(model_type) || type_ != model_type) {
188 NOTREACHED() 209 NOTREACHED()
189 << "Update handler of type " << ModelTypeToString(type_) 210 << "Update handler of type " << ModelTypeToString(type_)
190 << " asked to process progress marker with invalid type " 211 << " asked to process progress marker with invalid type "
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 new_gc_directive.version_watermark())) { 250 new_gc_directive.version_watermark())) {
230 ExpireEntriesByVersion(dir_, trans, type_, 251 ExpireEntriesByVersion(dir_, trans, type_,
231 new_gc_directive.version_watermark()); 252 new_gc_directive.version_watermark());
232 } 253 }
233 254
234 cached_gc_directive_.reset( 255 cached_gc_directive_.reset(
235 new sync_pb::GarbageCollectionDirective(new_gc_directive)); 256 new sync_pb::GarbageCollectionDirective(new_gc_directive));
236 } 257 }
237 258
238 } // namespace syncer 259 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698