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

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: rebase 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest, 115 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest,
115 ServerConnectionChangeDuringBackoff); 116 ServerConnectionChangeDuringBackoff);
116 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest, 117 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest,
117 ConnectionChangeCanaryPreemptedByNudge); 118 ConnectionChangeCanaryPreemptedByNudge);
118 FRIEND_TEST_ALL_PREFIXES(BackoffTriggersSyncSchedulerTest, 119 FRIEND_TEST_ALL_PREFIXES(BackoffTriggersSyncSchedulerTest,
119 FailGetEncryptionKey); 120 FailGetEncryptionKey);
120 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest, SuccessfulRetry); 121 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest, SuccessfulRetry);
121 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest, FailedRetry); 122 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest, FailedRetry);
122 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest, ReceiveNewRetryDelay); 123 FRIEND_TEST_ALL_PREFIXES(SyncSchedulerTest, ReceiveNewRetryDelay);
123 124
124 struct WaitInterval {
125 enum Mode {
126 // Uninitialized state, should not be set in practice.
127 UNKNOWN = -1,
128 // We enter a series of increasingly longer WaitIntervals if we experience
129 // repeated transient failures. We retry at the end of each interval.
130 EXPONENTIAL_BACKOFF,
131 // A server-initiated throttled interval. We do not allow any syncing
132 // during such an interval.
133 THROTTLED,
134 };
135 WaitInterval();
136 ~WaitInterval();
137 WaitInterval(Mode mode, base::TimeDelta length);
138
139 static const char* GetModeString(Mode mode);
140
141 Mode mode;
142 base::TimeDelta length;
143 };
144
145 static const char* GetModeString(Mode mode); 125 static const char* GetModeString(Mode mode);
146 126
147 // Invoke the syncer to perform a nudge job. 127 // Invoke the syncer to perform a nudge job.
148 void DoNudgeSyncCycleJob(JobPriority priority); 128 void DoNudgeSyncCycleJob(JobPriority priority);
149 129
150 // Invoke the syncer to perform a configuration job. 130 // Invoke the syncer to perform a configuration job.
151 void DoConfigurationSyncCycleJob(JobPriority priority); 131 void DoConfigurationSyncCycleJob(JobPriority priority);
152 132
153 void DoClearServerDataSyncCycleJob(JobPriority priority); 133 void DoClearServerDataSyncCycleJob(JobPriority priority);
154 134
155 // Helper function for Do{Nudge,Configuration,Poll}SyncCycleJob. 135 // Helper function for Do{Nudge,Configuration,Poll}SyncCycleJob.
156 void HandleSuccess(); 136 void HandleSuccess();
157 137
158 // Helper function for Do{Nudge,Configuration,Poll}SyncCycleJob. 138 // Helper function for Do{Nudge,Configuration,Poll}SyncCycleJob.
159 void HandleFailure(const ModelNeutralState& model_neutral_state); 139 void HandleFailure(const ModelNeutralState& model_neutral_state);
160 140
161 // Invoke the Syncer to perform a poll job. 141 // Invoke the Syncer to perform a poll job.
162 void DoPollSyncCycleJob(); 142 void DoPollSyncCycleJob();
163 143
164 // Helper function to calculate poll interval. 144 // Helper function to calculate poll interval.
165 base::TimeDelta GetPollInterval(); 145 base::TimeDelta GetPollInterval();
166 146
167 // Adjusts the poll timer to account for new poll interval, and possibly 147 // Adjusts the poll timer to account for new poll interval, and possibly
168 // resets the poll interval, depedning on the flag's value. 148 // resets the poll interval, depedning on the flag's value.
169 void AdjustPolling(PollAdjustType type); 149 void AdjustPolling(PollAdjustType type);
170 150
171 // Helper to restart waiting with |wait_interval_|'s timer. 151 // Helper to restart pending_wakeup_timer_.
172 void RestartWaiting(); 152 void RestartWaiting();
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 CanRunJobNow(JobPriority priority); 155 bool CanRunJobNow(JobPriority priority);
176 156
177 // Determines if we're allowed to contact the server right now. 157 // Determines if we're allowed to contact the server right now.
178 bool CanRunNudgeJobNow(JobPriority priority); 158 bool CanRunNudgeJobNow(JobPriority priority);
179 159
180 // If the scheduler's current state supports it, this will create a job based 160 // If the scheduler's current state supports it, this will create a job based
181 // on the passed in parameters and coalesce it with any other pending jobs, 161 // on the passed in parameters and coalesce it with any other pending jobs,
182 // then post a delayed task to run it. It may also choose to drop the job or 162 // then post a delayed task to run it. It may also choose to drop the job or
183 // save it for later, depending on the scheduler's current state. 163 // save it for later, depending on the scheduler's current state.
184 void ScheduleNudgeImpl(const base::TimeDelta& delay, 164 void ScheduleNudgeImpl(const base::TimeDelta& delay,
185 const tracked_objects::Location& nudge_location); 165 const tracked_objects::Location& nudge_location);
186 166
187 // Helper to signal listeners about changed retry time. 167 // Helper to signal listeners about changed retry time.
188 void NotifyRetryTime(base::Time retry_time); 168 void NotifyRetryTime(base::Time retry_time);
189 169
190 // Helper to signal listeners about changed throttled types. 170 // Helper to signal listeners about changed throttled or backed off types.
191 void NotifyThrottledTypesChanged(ModelTypeSet types); 171 void NotifyBlockedTypesChanged(ModelTypeSet types);
192 172
193 // 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"
194 // priority. 174 // priority.
195 void TryCanaryJob(); 175 void TryCanaryJob();
196 176
197 // At the moment TrySyncCycleJob just posts call to TrySyncCycleJobImpl on 177 // At the moment TrySyncCycleJob just posts call to TrySyncCycleJobImpl on
198 // current thread. In the future it will request access token here. 178 // current thread. In the future it will request access token here.
199 void TrySyncCycleJob(); 179 void TrySyncCycleJob();
200 void TrySyncCycleJobImpl(); 180 void TrySyncCycleJobImpl();
201 181
202 // 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.
203 void Unthrottle(); 184 void Unthrottle();
204 185
205 // Called when a per-type throttling interval expires. 186 // Called when a per-type throttling or backing off interval expires.
206 void TypeUnthrottle(base::TimeTicks unthrottle_time); 187 void OnTypesUnblocked();
207 188
208 // Runs a normal nudge job when the scheduled timer expires. 189 // Runs a normal nudge job when the scheduled timer expires.
209 void PerformDelayedNudge(); 190 void PerformDelayedNudge();
210 191
211 // Attempts to exit EXPONENTIAL_BACKOFF by calling TryCanaryJob(). 192 // Attempts to exit EXPONENTIAL_BACKOFF by calling TryCanaryJob().
193 // This function is for global backoff.
212 void ExponentialBackoffRetry(); 194 void ExponentialBackoffRetry();
213 195
214 // 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.
215 void OnServerConnectionErrorFixed(); 197 void OnServerConnectionErrorFixed();
216 198
217 // Creates a cycle for a poll and performs the sync. 199 // Creates a cycle for a poll and performs the sync.
218 void PollTimerCallback(); 200 void PollTimerCallback();
219 201
220 // Creates a cycle for a retry and performs the sync. 202 // Creates a cycle for a retry and performs the sync.
221 void RetryTimerCallback(); 203 void RetryTimerCallback();
222 204
223 // 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
224 ModelTypeSet GetEnabledAndUnthrottledTypes(); 206 // backed off.
207 ModelTypeSet GetEnabledAndUnblockedTypes();
225 208
226 // Called as we are started to broadcast an initial cycle snapshot 209 // Called as we are started to broadcast an initial cycle snapshot
227 // containing data like initial_sync_ended. Important when the client starts 210 // containing data like initial_sync_ended. Important when the client starts
228 // up and does not need to perform an initial sync. 211 // up and does not need to perform an initial sync.
229 void SendInitialSnapshot(); 212 void SendInitialSnapshot();
230 213
231 // This is used for histogramming and analysis of ScheduleNudge* APIs. 214 // This is used for histogramming and analysis of ScheduleNudge* APIs.
232 // SyncScheduler is the ultimate choke-point for all such invocations (with 215 // SyncScheduler is the ultimate choke-point for all such invocations (with
233 // and without InvalidationState variants, all NudgeSources, etc) and as such 216 // and without InvalidationState variants, all NudgeSources, etc) and as such
234 // 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
255 238
256 // The mode of operation. 239 // The mode of operation.
257 Mode mode_; 240 Mode mode_;
258 241
259 // 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.
260 std::unique_ptr<WaitInterval> wait_interval_; 243 std::unique_ptr<WaitInterval> wait_interval_;
261 244
262 std::unique_ptr<BackoffDelayProvider> delay_provider_; 245 std::unique_ptr<BackoffDelayProvider> delay_provider_;
263 246
264 // 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.
265 base::OneShotTimer pending_wakeup_timer_; 250 base::OneShotTimer pending_wakeup_timer_;
266 251
267 // An event that fires when data type throttling expires.
268 base::OneShotTimer type_unthrottle_timer_;
269
270 // Storage for variables related to an in-progress configure request. Note 252 // Storage for variables related to an in-progress configure request. Note
271 // that (mode_ != CONFIGURATION_MODE) \implies !pending_configure_params_. 253 // that (mode_ != CONFIGURATION_MODE) \implies !pending_configure_params_.
272 std::unique_ptr<ConfigurationParams> pending_configure_params_; 254 std::unique_ptr<ConfigurationParams> pending_configure_params_;
273 255
274 std::unique_ptr<ClearParams> pending_clear_params_; 256 std::unique_ptr<ClearParams> pending_clear_params_;
275 257
276 // If we have a nudge pending to run soon, it will be listed here.
277 base::TimeTicks scheduled_nudge_time_;
278
279 // Keeps track of work that the syncer needs to handle. 258 // Keeps track of work that the syncer needs to handle.
280 NudgeTracker nudge_tracker_; 259 NudgeTracker nudge_tracker_;
281 260
282 // Invoked to run through the sync cycle. 261 // Invoked to run through the sync cycle.
283 std::unique_ptr<Syncer> syncer_; 262 std::unique_ptr<Syncer> syncer_;
284 263
285 SyncCycleContext* cycle_context_; 264 SyncCycleContext* cycle_context_;
286 265
287 // A map tracking LOCAL NudgeSource invocations of ScheduleNudge* APIs, 266 // A map tracking LOCAL NudgeSource invocations of ScheduleNudge* APIs,
288 // 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
318 // 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
319 // to be const and alleviate threading concerns. 298 // to be const and alleviate threading concerns.
320 base::WeakPtrFactory<SyncSchedulerImpl> weak_ptr_factory_for_weak_handle_; 299 base::WeakPtrFactory<SyncSchedulerImpl> weak_ptr_factory_for_weak_handle_;
321 300
322 DISALLOW_COPY_AND_ASSIGN(SyncSchedulerImpl); 301 DISALLOW_COPY_AND_ASSIGN(SyncSchedulerImpl);
323 }; 302 };
324 303
325 } // namespace syncer 304 } // namespace syncer
326 305
327 #endif // COMPONENTS_SYNC_ENGINE_IMPL_SYNC_SCHEDULER_IMPL_H_ 306 #endif // COMPONENTS_SYNC_ENGINE_IMPL_SYNC_SCHEDULER_IMPL_H_
OLDNEW
« no previous file with comments | « components/sync/engine_impl/sync_manager_impl.cc ('k') | components/sync/engine_impl/sync_scheduler_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698