Search in sources :

Example 1 with InvalidEpochException

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));
}
Also used : Response(org.neo4j.com.Response) InvalidEpochException(org.neo4j.kernel.ha.com.master.InvalidEpochException) Test(org.junit.Test)

Example 2 with InvalidEpochException

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
    }
}
Also used : HandshakeResult(org.neo4j.kernel.ha.com.master.HandshakeResult) MasterImpl(org.neo4j.kernel.ha.com.master.MasterImpl) StoreId(org.neo4j.kernel.impl.store.StoreId) ConversationManager(org.neo4j.kernel.ha.com.master.ConversationManager) IdAllocation(org.neo4j.kernel.ha.id.IdAllocation) InvalidEpochException(org.neo4j.kernel.ha.com.master.InvalidEpochException) SPI(org.neo4j.kernel.ha.com.master.MasterImpl.SPI) IdType(org.neo4j.kernel.impl.store.id.IdType) MasterImplTest(org.neo4j.kernel.ha.com.master.MasterImplTest) Test(org.junit.Test)

Example 3 with InvalidEpochException

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 + ".");
    }
}
Also used : IllegalProtocolVersionException(org.neo4j.com.IllegalProtocolVersionException) InvalidEpochException(org.neo4j.kernel.ha.com.master.InvalidEpochException) ProtocolVersion(org.neo4j.com.ProtocolVersion)

Example 4 with InvalidEpochException

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());
}
Also used : ComException(org.neo4j.com.ComException) InvalidEpochException(org.neo4j.kernel.ha.com.master.InvalidEpochException) RequestContext(org.neo4j.com.RequestContext)

Aggregations

InvalidEpochException (org.neo4j.kernel.ha.com.master.InvalidEpochException)4 Test (org.junit.Test)2 ComException (org.neo4j.com.ComException)1 IllegalProtocolVersionException (org.neo4j.com.IllegalProtocolVersionException)1 ProtocolVersion (org.neo4j.com.ProtocolVersion)1 RequestContext (org.neo4j.com.RequestContext)1 Response (org.neo4j.com.Response)1 ConversationManager (org.neo4j.kernel.ha.com.master.ConversationManager)1 HandshakeResult (org.neo4j.kernel.ha.com.master.HandshakeResult)1 MasterImpl (org.neo4j.kernel.ha.com.master.MasterImpl)1 SPI (org.neo4j.kernel.ha.com.master.MasterImpl.SPI)1 MasterImplTest (org.neo4j.kernel.ha.com.master.MasterImplTest)1 IdAllocation (org.neo4j.kernel.ha.id.IdAllocation)1 StoreId (org.neo4j.kernel.impl.store.StoreId)1 IdType (org.neo4j.kernel.impl.store.id.IdType)1