Skip to content

Commit

Permalink
Moving the max number of Scheduler initialization attempts parameter … (
Browse files Browse the repository at this point in the history
#368)

* Moving the max number of Scheduler initialization attempts parameter to CoordinatorConfig

* Changing the max initialization attempts variable name
  • Loading branch information
muktiranjan authored and sahilpalvia committed Aug 15, 2018
1 parent 205cf05 commit e694ab7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ public class CoordinatorConfig {
@NonNull
private final String applicationName;

/**
* The maximum number of attempts to initialize the Scheduler
*
* <p>Default value: 20</p>
*/
private int maxInitializationAttempts = 20;

/**
* Interval in milliseconds between polling to check for parent shard completion.
* Polling frequently will take up more DynamoDB IOPS (when there are leases for shards waiting on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public class Scheduler implements Runnable {
private final RetrievalConfig retrievalConfig;

private final String applicationName;
private final int maxInitializationAttempts;
private final Checkpointer checkpoint;
private final long shardConsumerDispatchPollIntervalMillis;
// Backoff time when polling to check if application has finished processing
Expand Down Expand Up @@ -144,6 +145,7 @@ public Scheduler(@NonNull final CheckpointConfig checkpointConfig,
this.retrievalConfig = retrievalConfig;

this.applicationName = this.coordinatorConfig.applicationName();
this.maxInitializationAttempts = this.coordinatorConfig.maxInitializationAttempts();
this.metricsFactory = this.metricsConfig.metricsFactory();
this.leaseCoordinator = this.leaseManagementConfig.leaseManagementFactory()
.createLeaseCoordinator(this.metricsFactory);
Expand Down Expand Up @@ -197,7 +199,7 @@ public void run() {
initialize();
log.info("Initialization complete. Starting worker loop.");
} catch (RuntimeException e) {
log.error("Unable to initialize after {} attempts. Shutting down.", lifecycleConfig.maxInitializationAttempts(), e);
log.error("Unable to initialize after {} attempts. Shutting down.", maxInitializationAttempts, e);
shutdown();
}

Expand All @@ -214,7 +216,7 @@ private void initialize() {
boolean isDone = false;
Exception lastException = null;

for (int i = 0; (!isDone) && (i < lifecycleConfig.maxInitializationAttempts()); i++) {
for (int i = 0; (!isDone) && (i < maxInitializationAttempts); i++) {
try {
log.info("Initialization attempt {}", (i + 1));
log.info("Initializing LeaseCoordinator");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,4 @@ public class LifecycleConfig {
*/
private AggregatorUtil aggregatorUtil = new AggregatorUtil();

/**
* The maximum number of attempts to initialize the Scheduler
*/
private int maxInitializationAttempts = 20;
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,15 @@ public final void testInitializationFailureWithRetries() throws Exception {

scheduler.run();

verify(shardDetector, times(lifecycleConfig.maxInitializationAttempts())).listShards();
verify(shardDetector, times(coordinatorConfig.maxInitializationAttempts())).listShards();
}

@Test
public final void testInitializationFailureWithRetriesWithConfiguredMaxInitializationAttempts() throws Exception {
final int maxInitializationAttempts = 5;
lifecycleConfig.maxInitializationAttempts(maxInitializationAttempts);
coordinatorConfig.maxInitializationAttempts(maxInitializationAttempts);
scheduler = new Scheduler(checkpointConfig, coordinatorConfig, leaseManagementConfig, lifecycleConfig,
metricsConfig, processorConfig, retrievalConfig);

doNothing().when(leaseCoordinator).initialize();
when(shardDetector.listShards()).thenThrow(new RuntimeException());
Expand Down

0 comments on commit e694ab7

Please sign in to comment.