Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving the max number of Scheduler initialization attempts parameter … #368

Merged
merged 2 commits into from
Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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