use of com.hazelcast.jet.impl.MasterContext in project hazelcast-jet by hazelcast.
the class SplitBrainTest method when_quorumIsLostOnMinority_then_jobRestartsUntilMerge.
@Test
public void when_quorumIsLostOnMinority_then_jobRestartsUntilMerge() {
int firstSubClusterSize = 3;
int secondSubClusterSize = 2;
int clusterSize = firstSubClusterSize + secondSubClusterSize;
StuckProcessor.executionStarted = new CountDownLatch(clusterSize * PARALLELISM);
Job[] jobRef = new Job[1];
Consumer<JetInstance[]> beforeSplit = instances -> {
MockPS processorSupplier = new MockPS(StuckProcessor::new, clusterSize);
DAG dag = new DAG().vertex(new Vertex("test", processorSupplier));
jobRef[0] = instances[0].newJob(dag, new JobConfig().setSplitBrainProtection(true));
assertOpenEventually(StuckProcessor.executionStarted);
};
Future[] minorityJobFutureRef = new Future[1];
BiConsumer<JetInstance[], JetInstance[]> onSplit = (firstSubCluster, secondSubCluster) -> {
StuckProcessor.proceedLatch.countDown();
assertTrueEventually(() -> assertEquals(clusterSize + firstSubClusterSize, MockPS.initCount.get()));
long jobId = jobRef[0].getId();
assertTrueEventually(() -> {
JetService service = getJetService(firstSubCluster[0]);
assertEquals(COMPLETED, service.getJobCoordinationService().getJobStatus(jobId));
});
JetService service2 = getJetService(secondSubCluster[0]);
assertTrueEventually(() -> {
assertEquals(STARTING, service2.getJobCoordinationService().getJobStatus(jobId));
});
MasterContext masterContext = service2.getJobCoordinationService().getMasterContext(jobId);
assertNotNull(masterContext);
minorityJobFutureRef[0] = masterContext.completionFuture();
assertTrueAllTheTime(() -> {
assertEquals(STARTING, service2.getJobCoordinationService().getJobStatus(jobId));
}, 20);
};
Consumer<JetInstance[]> afterMerge = instances -> {
assertTrueEventually(() -> {
assertEquals(clusterSize + firstSubClusterSize, MockPS.initCount.get());
assertEquals(clusterSize + firstSubClusterSize, MockPS.closeCount.get());
});
assertEquals(clusterSize, MockPS.receivedCloseErrors.size());
MockPS.receivedCloseErrors.forEach(t -> assertTrue(t instanceof TopologyChangedException));
try {
minorityJobFutureRef[0].get();
fail();
} catch (CancellationException ignored) {
} catch (Exception e) {
throw new AssertionError(e);
}
};
testSplitBrain(firstSubClusterSize, secondSubClusterSize, beforeSplit, onSplit, afterMerge);
}
use of com.hazelcast.jet.impl.MasterContext in project hazelcast by hazelcast.
the class SplitBrainTest method when_newMemberJoinsToCluster_then_jobQuorumSizeIsUpdated.
@Test
public void when_newMemberJoinsToCluster_then_jobQuorumSizeIsUpdated() {
int clusterSize = 3;
HazelcastInstance[] instances = new HazelcastInstance[clusterSize];
for (int i = 0; i < clusterSize; i++) {
instances[i] = createHazelcastInstance(createConfig());
}
NoOutputSourceP.executionStarted = new CountDownLatch(clusterSize * PARALLELISM);
MockPS processorSupplier = new MockPS(NoOutputSourceP::new, clusterSize);
DAG dag = new DAG().vertex(new Vertex("test", processorSupplier).localParallelism(PARALLELISM));
Job job = instances[0].getJet().newJob(dag, new JobConfig().setSplitBrainProtection(true));
assertOpenEventually(NoOutputSourceP.executionStarted);
createHazelcastInstance(createConfig());
assertTrueEventually(() -> {
JetServiceBackend service = getJetServiceBackend(instances[0]);
JobRepository jobRepository = service.getJobRepository();
JobExecutionRecord record = jobRepository.getJobExecutionRecord(job.getId());
assertEquals(3, record.getQuorumSize());
MasterContext masterContext = service.getJobCoordinationService().getMasterContext(job.getId());
assertEquals(3, masterContext.jobExecutionRecord().getQuorumSize());
});
NoOutputSourceP.proceedLatch.countDown();
}
use of com.hazelcast.jet.impl.MasterContext in project hazelcast by hazelcast.
the class SplitBrainTest method when_quorumIsLostOnMinority_then_jobDoesNotRestartOnMinorityAndCancelledAfterMerge.
@Test
public void when_quorumIsLostOnMinority_then_jobDoesNotRestartOnMinorityAndCancelledAfterMerge() {
int firstSubClusterSize = 3;
int secondSubClusterSize = 2;
int clusterSize = firstSubClusterSize + secondSubClusterSize;
NoOutputSourceP.executionStarted = new CountDownLatch(clusterSize * PARALLELISM);
Job[] jobRef = new Job[1];
Consumer<HazelcastInstance[]> beforeSplit = instances -> {
MockPS processorSupplier = new MockPS(NoOutputSourceP::new, clusterSize);
DAG dag = new DAG().vertex(new Vertex("test", processorSupplier));
jobRef[0] = instances[0].getJet().newJob(dag, new JobConfig().setSplitBrainProtection(true));
assertOpenEventually(NoOutputSourceP.executionStarted);
};
Future[] minorityJobFutureRef = new Future[1];
BiConsumer<HazelcastInstance[], HazelcastInstance[]> onSplit = (firstSubCluster, secondSubCluster) -> {
NoOutputSourceP.proceedLatch.countDown();
assertTrueEventually(() -> assertEquals(clusterSize + firstSubClusterSize, MockPS.initCount.get()));
long jobId = jobRef[0].getId();
assertTrueEventually(() -> {
JetServiceBackend service = getJetServiceBackend(firstSubCluster[0]);
assertEquals(COMPLETED, service.getJobCoordinationService().getJobStatus(jobId).get());
});
JetServiceBackend service2 = getJetServiceBackend(secondSubCluster[0]);
assertTrueEventually(() -> {
MasterContext masterContext = service2.getJobCoordinationService().getMasterContext(jobId);
assertNotNull(masterContext);
minorityJobFutureRef[0] = masterContext.jobContext().jobCompletionFuture();
});
assertTrueAllTheTime(() -> {
assertStatusNotRunningOrStarting(service2.getJobCoordinationService().getJobStatus(jobId).get());
}, 20);
};
Consumer<HazelcastInstance[]> afterMerge = instances -> {
assertTrueEventually(() -> {
assertEquals(clusterSize + firstSubClusterSize, MockPS.initCount.get());
assertEquals(clusterSize + firstSubClusterSize, MockPS.closeCount.get());
});
assertEquals(clusterSize, MockPS.receivedCloseErrors.size());
MockPS.receivedCloseErrors.forEach(t -> assertTrue("received " + t, t instanceof CancellationException));
try {
minorityJobFutureRef[0].get();
fail();
} catch (CancellationException expected) {
} catch (Exception e) {
throw new AssertionError(e);
}
};
testSplitBrain(firstSubClusterSize, secondSubClusterSize, beforeSplit, onSplit, afterMerge);
}
use of com.hazelcast.jet.impl.MasterContext in project hazelcast-jet by hazelcast.
the class TopologyChangeTest method when_jobParticipantReceivesStaleInitOperation_then_jobRestarts.
@Test
public void when_jobParticipantReceivesStaleInitOperation_then_jobRestarts() {
// Given
JetInstance newInstance = createJetMember(config);
for (JetInstance instance : instances) {
assertClusterSizeEventually(NODE_COUNT + 1, instance.getHazelcastInstance());
}
rejectOperationsBetween(instances[0].getHazelcastInstance(), instances[2].getHazelcastInstance(), JetInitDataSerializerHook.FACTORY_ID, singletonList(INIT_EXECUTION_OP));
DAG dag = new DAG().vertex(new Vertex("test", new MockPS(TestProcessors.Identity::new, nodeCount + 1)));
Job job = instances[0].newJob(dag);
JetService jetService = getJetService(instances[0]);
assertTrueEventually(() -> assertFalse(jetService.getJobCoordinationService().getMasterContexts().isEmpty()));
MasterContext masterContext = jetService.getJobCoordinationService().getMasterContext(job.getId());
assertTrueEventually(() -> {
assertEquals(STARTING, masterContext.jobStatus());
assertNotEquals(0, masterContext.getExecutionId());
});
// When
long executionId = masterContext.getExecutionId();
assertTrueEventually(() -> {
Arrays.stream(instances).filter(instance -> !instance.getHazelcastInstance().getCluster().getLocalMember().isLiteMember()).filter(instance -> instance != instances[2]).map(JetTestSupport::getJetService).map(service -> service.getJobExecutionService().getExecutionContext(executionId)).forEach(Assert::assertNotNull);
});
newInstance.getHazelcastInstance().getLifecycleService().terminate();
for (JetInstance instance : instances) {
assertClusterSizeEventually(NODE_COUNT, instance.getHazelcastInstance());
}
resetPacketFiltersFrom(instances[0].getHazelcastInstance());
// Then
job.join();
assertNotEquals(executionId, masterContext.getExecutionId());
}
use of com.hazelcast.jet.impl.MasterContext in project hazelcast by hazelcast.
the class TopologyChangeTest method when_jobParticipantReceivesStaleInitOperation_then_jobRestarts.
@Test
public void when_jobParticipantReceivesStaleInitOperation_then_jobRestarts() {
// Given
HazelcastInstance newInstance = createHazelcastInstance(config);
for (HazelcastInstance instance : instances) {
assertClusterSizeEventually(NODE_COUNT + 1, instance);
}
rejectOperationsBetween(instances[0], instances[2], JetInitDataSerializerHook.FACTORY_ID, singletonList(INIT_EXECUTION_OP));
DAG dag = new DAG().vertex(new Vertex("test", new MockPS(TestProcessors.Identity::new, nodeCount + 1)));
Job job = instances[0].getJet().newJob(dag);
JetServiceBackend jetServiceBackend = getJetServiceBackend(instances[0]);
assertTrueEventually(() -> assertFalse(jetServiceBackend.getJobCoordinationService().getMasterContexts().isEmpty()));
MasterContext masterContext = jetServiceBackend.getJobCoordinationService().getMasterContext(job.getId());
assertTrueEventually(() -> {
assertEquals(STARTING, masterContext.jobStatus());
assertNotEquals(0, masterContext.executionId());
});
// When
long executionId = masterContext.executionId();
assertTrueEventually(() -> {
Arrays.stream(instances).filter(instance -> !instance.getCluster().getLocalMember().isLiteMember()).filter(instance -> instance != instances[2]).map(JetTestSupport::getJetServiceBackend).map(service -> service.getJobExecutionService().getExecutionContext(executionId)).forEach(Assert::assertNotNull);
});
newInstance.getLifecycleService().terminate();
for (HazelcastInstance instance : instances) {
assertClusterSizeEventually(NODE_COUNT, instance);
}
resetPacketFiltersFrom(instances[0]);
// Then
job.join();
assertNotEquals(executionId, masterContext.executionId());
}
Aggregations