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

Making the maximum number of Scheduler initialization attempts configurable #363

Merged
merged 1 commit into from
Aug 13, 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 @@ -75,7 +75,7 @@
@Accessors(fluent = true)
@Slf4j
public class Scheduler implements Runnable {
static final int MAX_INITIALIZATION_ATTEMPTS = 20;

private SchedulerLog slog = new SchedulerLog();

private final CheckpointConfig checkpointConfig;
Expand Down Expand Up @@ -197,7 +197,7 @@ public void run() {
initialize();
log.info("Initialization complete. Starting worker loop.");
} catch (RuntimeException e) {
log.error("Unable to initialize after {} attempts. Shutting down.", MAX_INITIALIZATION_ATTEMPTS, e);
log.error("Unable to initialize after {} attempts. Shutting down.", lifecycleConfig.maxInitializationAttempts(), e);
shutdown();
}

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

for (int i = 0; (!isDone) && (i < MAX_INITIALIZATION_ATTEMPTS); i++) {
for (int i = 0; (!isDone) && (i < lifecycleConfig.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 @@ -45,4 +45,9 @@ public class LifecycleConfig {
* AggregatorUtil is responsible for deaggregating KPL records.
*/
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,7 +240,21 @@ public final void testInitializationFailureWithRetries() throws Exception {

scheduler.run();

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

@Test
public final void testInitializationFailureWithRetriesWithConfiguredMaxInitializationAttempts() throws Exception {
final int maxInitializationAttempts = 5;
lifecycleConfig.maxInitializationAttempts(maxInitializationAttempts);

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

scheduler.run();

// verify initialization was retried for maxInitializationAttempts times
verify(shardDetector, times(maxInitializationAttempts)).listShards();
}


Expand Down