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

Side by Side Diff: components/sync/engine_impl/sync_scheduler_impl.h

Issue 2475043002: [Sync] Sync client should to exponential backoff when receive partial failure (Closed)
Patch Set: code review Created 4 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 #ifndef COMPONENTS_SYNC_ENGINE_IMPL_SYNC_SCHEDULER_IMPL_H_ 5 #ifndef COMPONENTS_SYNC_ENGINE_IMPL_SYNC_SCHEDULER_IMPL_H_
6 #define COMPONENTS_SYNC_ENGINE_IMPL_SYNC_SCHEDULER_IMPL_H_ 6 #define COMPONENTS_SYNC_ENGINE_IMPL_SYNC_SCHEDULER_IMPL_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 void ScheduleInitialSyncNudge(ModelType model_type) override; 63 void ScheduleInitialSyncNudge(ModelType model_type) override;
64 void SetNotificationsEnabled(bool notifications_enabled) override; 64 void SetNotificationsEnabled(bool notifications_enabled) override;
65 65
66 void OnCredentialsUpdated() override; 66 void OnCredentialsUpdated() override;
67 void OnConnectionStatusChange() override; 67 void OnConnectionStatusChange() override;
68 68
69 // SyncCycle::Delegate implementation. 69 // SyncCycle::Delegate implementation.
70 void OnThrottled(const base::TimeDelta& throttle_duration) override; 70 void OnThrottled(const base::TimeDelta& throttle_duration) override;
71 void OnTypesThrottled(ModelTypeSet types, 71 void OnTypesThrottled(ModelTypeSet types,
72 const base::TimeDelta& throttle_duration) override; 72 const base::TimeDelta& throttle_duration) override;
73 void OnTypesBackedOff(ModelTypeSet types) override;
73 bool IsCurrentlyThrottled() override; 74 bool IsCurrentlyThrottled() override;
74 void OnReceivedShortPollIntervalUpdate( 75 void OnReceivedShortPollIntervalUpdate(
75 const base::TimeDelta& new_interval) override; 76 const base::TimeDelta& new_interval) override;
76 void OnReceivedLongPollIntervalUpdate( 77 void OnReceivedLongPollIntervalUpdate(
77 const base::TimeDelta& new_interval) override; 78 const base::TimeDelta& new_interval) override;
78 void OnReceivedCustomNudgeDelays( 79 void OnReceivedCustomNudgeDelays(
79 const std::map<ModelType, base::TimeDelta>& nudge_delays) override; 80 const std::map<ModelType, base::TimeDelta>& nudge_delays) override;
80 void OnReceivedClientInvalidationHintBufferSize(int size) override; 81 void OnReceivedClientInvalidationHintBufferSize(int size) override;
81 void OnSyncProtocolError( 82 void OnSyncProtocolError(
82 const SyncProtocolError& sync_protocol_error) override; 83 const SyncProtocolError& sync_protocol_error) override;
(...skipping 26 matching lines...) Expand all
109 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest, 110 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest,
110 ServerConnectionChangeDuringBackoff); 111 ServerConnectionChangeDuringBackoff);
111 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest, 112 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest,
112 ConnectionChangeCanaryPreemptedByNudge); 113 ConnectionChangeCanaryPreemptedByNudge);
113 FRIEND_TEST_ALL_PREFIXES(BackoffTriggersSyncSchedulerTest, 114 FRIEND_TEST_ALL_PREFIXES(BackoffTriggersSyncSchedulerTest,
114 FailGetEncryptionKey); 115 FailGetEncryptionKey);
115 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest, SuccessfulRetry); 116 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest, SuccessfulRetry);
116 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest, FailedRetry); 117 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest, FailedRetry);
117 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest, ReceiveNewRetryDelay); 118 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest, ReceiveNewRetryDelay);
118 119
119 struct WaitInterval {
120 enum Mode {
121 // Uninitialized state, should not be set in practice.
122 UNKNOWN = -1,
123 // We enter a series of increasingly longer WaitIntervals if we experience
124 // repeated transient failures. We retry at the end of each interval.
125 EXPONENTIAL_BACKOFF,
126 // A server-initiated throttled interval. We do not allow any syncing
127 // during such an interval.
128 THROTTLED,
129 };
130 WaitInterval();
131 ~WaitInterval();
132 WaitInterval(Mode mode, base::TimeDelta length);
133
134 static const char* GetModeString(Mode mode);
135
136 Mode mode;
137 base::TimeDelta length;
138 };
139
140 static const char* GetModeString(Mode mode); 120 static const char* GetModeString(Mode mode);
141 121
142 void SetDefaultNudgeDelay(base::TimeDelta delay_ms); 122 void SetDefaultNudgeDelay(base::TimeDelta delay_ms);
143 123
144 // Invoke the syncer to perform a nudge job. 124 // Invoke the syncer to perform a nudge job.
145 void DoNudgeSyncCycleJob(JobPriority priority); 125 void DoNudgeSyncCycleJob(JobPriority priority);
146 126
147 // Invoke the syncer to perform a configuration job. 127 // Invoke the syncer to perform a configuration job.
148 void DoConfigurationSyncCycleJob(JobPriority priority); 128 void DoConfigurationSyncCycleJob(JobPriority priority);
149 129
150 void DoClearServerDataSyncCycleJob(JobPriority priority); 130 void DoClearServerDataSyncCycleJob(JobPriority priority);
151 131
152 // Helper function for Do{Nudge,Configuration,Poll}SyncCycleJob. 132 // Helper function for Do{Nudge,Configuration,Poll}SyncCycleJob.
153 void HandleSuccess(); 133 void HandleSuccess();
154 134
155 // Helper function for Do{Nudge,Configuration,Poll}SyncCycleJob. 135 // Helper function for Do{Nudge,Configuration,Poll}SyncCycleJob.
156 void HandleFailure(const ModelNeutralState& model_neutral_state); 136 void HandleFailure(const ModelNeutralState& model_neutral_state);
157 137
158 // Invoke the Syncer to perform a poll job. 138 // Invoke the Syncer to perform a poll job.
159 void DoPollSyncCycleJob(); 139 void DoPollSyncCycleJob();
160 140
161 // Helper function to calculate poll interval. 141 // Helper function to calculate poll interval.
162 base::TimeDelta GetPollInterval(); 142 base::TimeDelta GetPollInterval();
163 143
164 // Adjusts the poll timer to account for new poll interval, and possibly 144 // Adjusts the poll timer to account for new poll interval, and possibly
165 // resets the poll interval, depedning on the flag's value. 145 // resets the poll interval, depedning on the flag's value.
166 void AdjustPolling(PollAdjustType type); 146 void AdjustPolling(PollAdjustType type);
167 147
168 // Helper to restart waiting with |wait_interval_|'s timer. 148 // Helper to restart pending_wakeup_timer_.
169 void RestartWaiting(); 149 void RestartWaiting();
170 150
171 // Determines if we're allowed to contact the server right now. 151 // Determines if we're allowed to contact the server right now.
172 bool CanRunJobNow(JobPriority priority); 152 bool CanRunJobNow(JobPriority priority);
173 153
174 // Determines if we're allowed to contact the server right now. 154 // Determines if we're allowed to contact the server right now.
175 bool CanRunNudgeJobNow(JobPriority priority); 155 bool CanRunNudgeJobNow(JobPriority priority);
176 156
177 // If the scheduler's current state supports it, this will create a job based 157 // If the scheduler's current state supports it, this will create a job based
178 // on the passed in parameters and coalesce it with any other pending jobs, 158 // on the passed in parameters and coalesce it with any other pending jobs,
179 // then post a delayed task to run it. It may also choose to drop the job or 159 // then post a delayed task to run it. It may also choose to drop the job or
180 // save it for later, depending on the scheduler's current state. 160 // save it for later, depending on the scheduler's current state.
181 void ScheduleNudgeImpl(const base::TimeDelta& delay, 161 void ScheduleNudgeImpl(const base::TimeDelta& delay,
182 const tracked_objects::Location& nudge_location); 162 const tracked_objects::Location& nudge_location);
183 163
184 // Helper to signal listeners about changed retry time. 164 // Helper to signal listeners about changed retry time.
185 void NotifyRetryTime(base::Time retry_time); 165 void NotifyRetryTime(base::Time retry_time);
186 166
187 // Helper to signal listeners about changed throttled types. 167 // Helper to signal listeners about changed throttled types.
188 void NotifyThrottledTypesChanged(ModelTypeSet types); 168 void NotifyThrottledTypesChanged(ModelTypeSet types);
189 169
170 // Helper to signal listeners about changed backed off types.
171 void NotifyBackedOffTypesChanged(ModelTypeSet types);
172
190 // Looks for pending work and, if it finds any, run this work at "canary" 173 // Looks for pending work and, if it finds any, run this work at "canary"
191 // priority. 174 // priority.
192 void TryCanaryJob(); 175 void TryCanaryJob();
193 176
194 // At the moment TrySyncCycleJob just posts call to TrySyncCycleJobImpl on 177 // At the moment TrySyncCycleJob just posts call to TrySyncCycleJobImpl on
195 // current thread. In the future it will request access token here. 178 // current thread. In the future it will request access token here.
196 void TrySyncCycleJob(); 179 void TrySyncCycleJob();
197 void TrySyncCycleJobImpl(); 180 void TrySyncCycleJobImpl();
198 181
199 // Transitions out of the THROTTLED WaitInterval then calls TryCanaryJob(). 182 // Transitions out of the THROTTLED WaitInterval then calls TryCanaryJob().
183 // This function is for global throttling.
200 void Unthrottle(); 184 void Unthrottle();
201 185
202 // Called when a per-type throttling interval expires. 186 // Called when a per-type throttling or backing off interval expires.
203 void TypeUnthrottle(base::TimeTicks unthrottle_time); 187 void OnTypesUnblocked();
204 188
205 // Runs a normal nudge job when the scheduled timer expires. 189 // Runs a normal nudge job when the scheduled timer expires.
206 void PerformDelayedNudge(); 190 void PerformDelayedNudge();
207 191
208 // Attempts to exit EXPONENTIAL_BACKOFF by calling TryCanaryJob(). 192 // Attempts to exit EXPONENTIAL_BACKOFF by calling TryCanaryJob().
193 // This function is for global backoff.
209 void ExponentialBackoffRetry(); 194 void ExponentialBackoffRetry();
210 195
211 // Called when the root cause of the current connection error is fixed. 196 // Called when the root cause of the current connection error is fixed.
212 void OnServerConnectionErrorFixed(); 197 void OnServerConnectionErrorFixed();
213 198
214 // Creates a cycle for a poll and performs the sync. 199 // Creates a cycle for a poll and performs the sync.
215 void PollTimerCallback(); 200 void PollTimerCallback();
216 201
217 // Creates a cycle for a retry and performs the sync. 202 // Creates a cycle for a retry and performs the sync.
218 void RetryTimerCallback(); 203 void RetryTimerCallback();
219 204
220 // Returns the set of types that are enabled and not currently throttled. 205 // Returns the set of types that are enabled and not currently throttled and
221 ModelTypeSet GetEnabledAndUnthrottledTypes(); 206 // backed off.
207 ModelTypeSet GetEnabledAndUnblockedTypes();
222 208
223 // Called as we are started to broadcast an initial cycle snapshot 209 // Called as we are started to broadcast an initial cycle snapshot
224 // containing data like initial_sync_ended. Important when the client starts 210 // containing data like initial_sync_ended. Important when the client starts
225 // up and does not need to perform an initial sync. 211 // up and does not need to perform an initial sync.
226 void SendInitialSnapshot(); 212 void SendInitialSnapshot();
227 213
228 // This is used for histogramming and analysis of ScheduleNudge* APIs. 214 // This is used for histogramming and analysis of ScheduleNudge* APIs.
229 // SyncScheduler is the ultimate choke-point for all such invocations (with 215 // SyncScheduler is the ultimate choke-point for all such invocations (with
230 // and without InvalidationState variants, all NudgeSources, etc) and as such 216 // and without InvalidationState variants, all NudgeSources, etc) and as such
231 // is the most flexible place to do this bookkeeping. 217 // is the most flexible place to do this bookkeeping.
(...skipping 20 matching lines...) Expand all
252 238
253 // The mode of operation. 239 // The mode of operation.
254 Mode mode_; 240 Mode mode_;
255 241
256 // Current wait state. Null if we're not in backoff and not throttled. 242 // Current wait state. Null if we're not in backoff and not throttled.
257 std::unique_ptr<WaitInterval> wait_interval_; 243 std::unique_ptr<WaitInterval> wait_interval_;
258 244
259 std::unique_ptr<BackoffDelayProvider> delay_provider_; 245 std::unique_ptr<BackoffDelayProvider> delay_provider_;
260 246
261 // The event that will wake us up. 247 // The event that will wake us up.
248 // When the whole client got throttling or backoff, we will delay this timer
249 // as well.
262 base::OneShotTimer pending_wakeup_timer_; 250 base::OneShotTimer pending_wakeup_timer_;
263 251
264 // An event that fires when data type throttling expires.
265 base::OneShotTimer type_unthrottle_timer_;
266
267 // Storage for variables related to an in-progress configure request. Note 252 // Storage for variables related to an in-progress configure request. Note
268 // that (mode_ != CONFIGURATION_MODE) \implies !pending_configure_params_. 253 // that (mode_ != CONFIGURATION_MODE) \implies !pending_configure_params_.
269 std::unique_ptr<ConfigurationParams> pending_configure_params_; 254 std::unique_ptr<ConfigurationParams> pending_configure_params_;
270 255
271 std::unique_ptr<ClearParams> pending_clear_params_; 256 std::unique_ptr<ClearParams> pending_clear_params_;
272 257
273 // If we have a nudge pending to run soon, it will be listed here.
274 base::TimeTicks scheduled_nudge_time_;
275
276 // Keeps track of work that the syncer needs to handle. 258 // Keeps track of work that the syncer needs to handle.
277 NudgeTracker nudge_tracker_; 259 NudgeTracker nudge_tracker_;
278 260
279 // Invoked to run through the sync cycle. 261 // Invoked to run through the sync cycle.
280 std::unique_ptr<Syncer> syncer_; 262 std::unique_ptr<Syncer> syncer_;
281 263
282 SyncCycleContext* cycle_context_; 264 SyncCycleContext* cycle_context_;
283 265
284 // A map tracking LOCAL NudgeSource invocations of ScheduleNudge* APIs, 266 // A map tracking LOCAL NudgeSource invocations of ScheduleNudge* APIs,
285 // organized by datatype. Each datatype that was part of the types requested 267 // organized by datatype. Each datatype that was part of the types requested
(...skipping 29 matching lines...) Expand all
315 // A second factory specially for weak_handle_this_, to allow the handle 297 // A second factory specially for weak_handle_this_, to allow the handle
316 // to be const and alleviate threading concerns. 298 // to be const and alleviate threading concerns.
317 base::WeakPtrFactory<SyncSchedulerImpl> weak_ptr_factory_for_weak_handle_; 299 base::WeakPtrFactory<SyncSchedulerImpl> weak_ptr_factory_for_weak_handle_;
318 300
319 DISALLOW_COPY_AND_ASSIGN(SyncSchedulerImpl); 301 DISALLOW_COPY_AND_ASSIGN(SyncSchedulerImpl);
320 }; 302 };
321 303
322 } // namespace syncer 304 } // namespace syncer
323 305
324 #endif // COMPONENTS_SYNC_ENGINE_IMPL_SYNC_SCHEDULER_IMPL_H_ 306 #endif // COMPONENTS_SYNC_ENGINE_IMPL_SYNC_SCHEDULER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698