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

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: add test 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 or backed off types.
188 void NotifyThrottledTypesChanged(ModelTypeSet types); 168 void NotifyBlockedTypesChanged(ModelTypeSet types);
189 169
190 // Looks for pending work and, if it finds any, run this work at "canary" 170 // Looks for pending work and, if it finds any, run this work at "canary"
191 // priority. 171 // priority.
192 void TryCanaryJob(); 172 void TryCanaryJob();
193 173
194 // At the moment TrySyncCycleJob just posts call to TrySyncCycleJobImpl on 174 // At the moment TrySyncCycleJob just posts call to TrySyncCycleJobImpl on
195 // current thread. In the future it will request access token here. 175 // current thread. In the future it will request access token here.
196 void TrySyncCycleJob(); 176 void TrySyncCycleJob();
197 void TrySyncCycleJobImpl(); 177 void TrySyncCycleJobImpl();
198 178
199 // Transitions out of the THROTTLED WaitInterval then calls TryCanaryJob(). 179 // Transitions out of the THROTTLED WaitInterval then calls TryCanaryJob().
180 // This function is for global throttling.
200 void Unthrottle(); 181 void Unthrottle();
201 182
202 // Called when a per-type throttling interval expires. 183 // Called when a per-type throttling or backing off interval expires.
203 void TypeUnthrottle(base::TimeTicks unthrottle_time); 184 void OnTypesUnblocked();
204 185
205 // Runs a normal nudge job when the scheduled timer expires. 186 // Runs a normal nudge job when the scheduled timer expires.
206 void PerformDelayedNudge(); 187 void PerformDelayedNudge();
207 188
208 // Attempts to exit EXPONENTIAL_BACKOFF by calling TryCanaryJob(). 189 // Attempts to exit EXPONENTIAL_BACKOFF by calling TryCanaryJob().
190 // This function is for global backoff.
209 void ExponentialBackoffRetry(); 191 void ExponentialBackoffRetry();
210 192
211 // Called when the root cause of the current connection error is fixed. 193 // Called when the root cause of the current connection error is fixed.
212 void OnServerConnectionErrorFixed(); 194 void OnServerConnectionErrorFixed();
213 195
214 // Creates a cycle for a poll and performs the sync. 196 // Creates a cycle for a poll and performs the sync.
215 void PollTimerCallback(); 197 void PollTimerCallback();
216 198
217 // Creates a cycle for a retry and performs the sync. 199 // Creates a cycle for a retry and performs the sync.
218 void RetryTimerCallback(); 200 void RetryTimerCallback();
219 201
220 // Returns the set of types that are enabled and not currently throttled. 202 // Returns the set of types that are enabled and not currently throttled and
221 ModelTypeSet GetEnabledAndUnthrottledTypes(); 203 // backed off.
204 ModelTypeSet GetEnabledAndUnblockedTypes();
222 205
223 // Called as we are started to broadcast an initial cycle snapshot 206 // Called as we are started to broadcast an initial cycle snapshot
224 // containing data like initial_sync_ended. Important when the client starts 207 // containing data like initial_sync_ended. Important when the client starts
225 // up and does not need to perform an initial sync. 208 // up and does not need to perform an initial sync.
226 void SendInitialSnapshot(); 209 void SendInitialSnapshot();
227 210
228 // This is used for histogramming and analysis of ScheduleNudge* APIs. 211 // This is used for histogramming and analysis of ScheduleNudge* APIs.
229 // SyncScheduler is the ultimate choke-point for all such invocations (with 212 // SyncScheduler is the ultimate choke-point for all such invocations (with
230 // and without InvalidationState variants, all NudgeSources, etc) and as such 213 // and without InvalidationState variants, all NudgeSources, etc) and as such
231 // is the most flexible place to do this bookkeeping. 214 // is the most flexible place to do this bookkeeping.
(...skipping 20 matching lines...) Expand all
252 235
253 // The mode of operation. 236 // The mode of operation.
254 Mode mode_; 237 Mode mode_;
255 238
256 // Current wait state. Null if we're not in backoff and not throttled. 239 // Current wait state. Null if we're not in backoff and not throttled.
257 std::unique_ptr<WaitInterval> wait_interval_; 240 std::unique_ptr<WaitInterval> wait_interval_;
258 241
259 std::unique_ptr<BackoffDelayProvider> delay_provider_; 242 std::unique_ptr<BackoffDelayProvider> delay_provider_;
260 243
261 // The event that will wake us up. 244 // The event that will wake us up.
245 // When the whole client got throttling or backoff, we will delay this timer
246 // as well.
262 base::OneShotTimer pending_wakeup_timer_; 247 base::OneShotTimer pending_wakeup_timer_;
263 248
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 249 // Storage for variables related to an in-progress configure request. Note
268 // that (mode_ != CONFIGURATION_MODE) \implies !pending_configure_params_. 250 // that (mode_ != CONFIGURATION_MODE) \implies !pending_configure_params_.
269 std::unique_ptr<ConfigurationParams> pending_configure_params_; 251 std::unique_ptr<ConfigurationParams> pending_configure_params_;
270 252
271 std::unique_ptr<ClearParams> pending_clear_params_; 253 std::unique_ptr<ClearParams> pending_clear_params_;
272 254
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. 255 // Keeps track of work that the syncer needs to handle.
277 NudgeTracker nudge_tracker_; 256 NudgeTracker nudge_tracker_;
278 257
279 // Invoked to run through the sync cycle. 258 // Invoked to run through the sync cycle.
280 std::unique_ptr<Syncer> syncer_; 259 std::unique_ptr<Syncer> syncer_;
281 260
282 SyncCycleContext* cycle_context_; 261 SyncCycleContext* cycle_context_;
283 262
284 // A map tracking LOCAL NudgeSource invocations of ScheduleNudge* APIs, 263 // A map tracking LOCAL NudgeSource invocations of ScheduleNudge* APIs,
285 // organized by datatype. Each datatype that was part of the types requested 264 // 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 294 // A second factory specially for weak_handle_this_, to allow the handle
316 // to be const and alleviate threading concerns. 295 // to be const and alleviate threading concerns.
317 base::WeakPtrFactory<SyncSchedulerImpl> weak_ptr_factory_for_weak_handle_; 296 base::WeakPtrFactory<SyncSchedulerImpl> weak_ptr_factory_for_weak_handle_;
318 297
319 DISALLOW_COPY_AND_ASSIGN(SyncSchedulerImpl); 298 DISALLOW_COPY_AND_ASSIGN(SyncSchedulerImpl);
320 }; 299 };
321 300
322 } // namespace syncer 301 } // namespace syncer
323 302
324 #endif // COMPONENTS_SYNC_ENGINE_IMPL_SYNC_SCHEDULER_IMPL_H_ 303 #endif // COMPONENTS_SYNC_ENGINE_IMPL_SYNC_SCHEDULER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698