use of org.neo4j.kernel.ha.com.master.InvalidEpochException in project neo4j by neo4j.
the class SlaveUpdatePullerTest method shouldCapExcessiveInvalidEpochExceptionLogging.
@Test
public void shouldCapExcessiveInvalidEpochExceptionLogging() throws Exception {
OngoingStubbing<Response<Void>> updatePullStubbing = when(master.pullUpdates(any(RequestContext.class)));
updatePullStubbing.thenThrow(new InvalidEpochException(2, 1));
for (int i = 0; i < SlaveUpdatePuller.LOG_CAP + 20; i++) {
updatePuller.pullUpdates();
}
logProvider.assertContainsThrowablesMatching(0, repeat(new InvalidEpochException(2, 1), SlaveUpdatePuller.LOG_CAP));
// And we should be able to recover afterwards
updatePullStubbing.thenReturn(Response.EMPTY).thenThrow(new InvalidEpochException(2, 1));
// This one will succeed and unlock the circuit breaker
updatePuller.pullUpdates();
// And then we log another exception
updatePuller.pullUpdates();
logProvider.assertContainsThrowablesMatching(0, repeat(new InvalidEpochException(2, 1), SlaveUpdatePuller.LOG_CAP + 1));
}
use of org.neo4j.kernel.ha.com.master.InvalidEpochException in project neo4j by neo4j.
the class MasterEpochTest method shouldFailSubsequentRequestsAfterAllocateIdsAfterMasterSwitch.
@Test
public void shouldFailSubsequentRequestsAfterAllocateIdsAfterMasterSwitch() throws Throwable {
// GIVEN
SPI spi = MasterImplTest.mockedSpi();
IdAllocation servedIdAllocation = idAllocation(0, 999);
when(spi.allocateIds(any(IdType.class))).thenReturn(servedIdAllocation);
when(spi.getTransactionChecksum(anyLong())).thenReturn(10L);
StoreId storeId = newStoreIdForCurrentVersion();
MasterImpl master = new MasterImpl(spi, mock(ConversationManager.class), mock(MasterImpl.Monitor.class), Config.embeddedDefaults(stringMap(ClusterSettings.server_id.name(), "1")));
HandshakeResult handshake = master.handshake(1, storeId).response();
master.start();
// WHEN/THEN
IdAllocation idAllocation = master.allocateIds(context(handshake.epoch()), IdType.NODE).response();
assertEquals(servedIdAllocation.getHighestIdInUse(), idAllocation.getHighestIdInUse());
try {
master.allocateIds(context(handshake.epoch() + 1), IdType.NODE);
fail("Should fail with invalid epoch");
} catch (InvalidEpochException e) {
// Good
}
}
use of org.neo4j.kernel.ha.com.master.InvalidEpochException in project neo4j by neo4j.
the class MasterClientResolver method handle.
@Override
public void handle(ComException exception) {
exception.traceComException(log, "MasterClientResolver.handle");
if (exception instanceof IllegalProtocolVersionException) {
log.info("Handling " + exception + ", will pick new master client");
IllegalProtocolVersionException illegalProtocolVersion = (IllegalProtocolVersionException) exception;
ProtocolVersion requiredProtocolVersion = new ProtocolVersion(illegalProtocolVersion.getReceived(), ProtocolVersion.INTERNAL_PROTOCOL_VERSION);
getFor(requiredProtocolVersion);
} else if (exception instanceof InvalidEpochException) {
log.info("Handling " + exception + ", will go to PENDING and ask for election");
invalidEpochHandler.handle();
} else {
log.debug("Ignoring " + exception + ".");
}
}
use of org.neo4j.kernel.ha.com.master.InvalidEpochException in project neo4j by neo4j.
the class SlaveUpdatePuller method doPullUpdates.
private void doPullUpdates() {
try {
RequestContext context = requestContextFactory.newRequestContext();
try (Response<Void> ignored = master.pullUpdates(context)) {
// Updates would be applied as part of response processing
monitor.pulledUpdates(context.lastAppliedTransaction());
}
invalidEpochCappedLogger.reset();
comExceptionCappedLogger.reset();
} catch (InvalidEpochException e) {
invalidEpochHandler.handle();
invalidEpochCappedLogger.warn("Pull updates by " + this + " failed at the epoch check", e);
} catch (ComException e) {
invalidEpochCappedLogger.warn("Pull updates by " + this + " failed due to network error.", e);
} catch (Throwable e) {
logger.error("Pull updates by " + this + " failed", e);
}
lastUpdateTime.setLastUpdateTime(currentTimeMillis());
}
Aggregations