Search in sources :

Example 1 with MismatchingStoreIdException

use of org.neo4j.kernel.impl.store.MismatchingStoreIdException in project neo4j by neo4j.

the class SwitchToSlaveCopyThenBranchTest method shouldHandleBranchedStoreWhenMyStoreIdDiffersFromMasterStoreId.

@Test
@SuppressWarnings("unchecked")
public void shouldHandleBranchedStoreWhenMyStoreIdDiffersFromMasterStoreId() throws Throwable {
    // Given
    SwitchToSlaveCopyThenBranch switchToSlave = newSwitchToSlaveSpy();
    URI me = new URI("cluster://localhost?serverId=2");
    MasterClient masterClient = mock(MasterClient.class);
    Response<HandshakeResult> response = mock(Response.class);
    when(response.response()).thenReturn(new HandshakeResult(1, 2));
    when(masterClient.handshake(anyLong(), any(StoreId.class))).thenReturn(response);
    StoreId storeId = newStoreIdForCurrentVersion(1, 2, 3, 4);
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    when(transactionIdStore.getLastCommittedTransaction()).thenReturn(new TransactionId(42, 42, 42));
    when(transactionIdStore.getLastCommittedTransactionId()).thenReturn(TransactionIdStore.BASE_TX_ID);
    // When
    try {
        switchToSlave.checkDataConsistency(masterClient, transactionIdStore, storeId, new URI("cluster://localhost?serverId=1"), me, CancellationRequest.NEVER_CANCELLED);
        fail("Should have thrown " + MismatchingStoreIdException.class.getSimpleName() + " exception");
    } catch (MismatchingStoreIdException e) {
    // good we got the expected exception
    }
    // Then
    verify(switchToSlave).stopServicesAndHandleBranchedStore(any(BranchedDataPolicy.class), any(URI.class), any(URI.class), any(CancellationRequest.class));
}
Also used : HandshakeResult(org.neo4j.kernel.ha.com.master.HandshakeResult) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) StoreId(org.neo4j.kernel.impl.store.StoreId) MasterClient(org.neo4j.kernel.ha.com.slave.MasterClient) MismatchingStoreIdException(org.neo4j.kernel.impl.store.MismatchingStoreIdException) BranchedDataPolicy(org.neo4j.kernel.ha.BranchedDataPolicy) URI(java.net.URI) CancellationRequest(org.neo4j.helpers.CancellationRequest) TransactionId(org.neo4j.kernel.impl.store.TransactionId) Test(org.junit.Test)

Example 2 with MismatchingStoreIdException

use of org.neo4j.kernel.impl.store.MismatchingStoreIdException in project neo4j by neo4j.

the class BackupTool method executeBackup.

BackupOutcome executeBackup(HostnamePort hostnamePort, File to, ConsistencyCheck consistencyCheck, Config config, long timeout, boolean forensics) throws ToolFailureException {
    try {
        systemOut.println("Performing backup from '" + hostnamePort + "'");
        String host = hostnamePort.getHost();
        int port = hostnamePort.getPort();
        BackupOutcome outcome = backupService.doIncrementalBackupOrFallbackToFull(host, port, to, consistencyCheck, config, timeout, forensics);
        systemOut.println("Done");
        return outcome;
    } catch (UnexpectedStoreVersionException e) {
        throw new ToolFailureException(e.getMessage(), e);
    } catch (MismatchingStoreIdException e) {
        throw new ToolFailureException(String.format(MISMATCHED_STORE_ID, e.getExpected(), e.getEncountered()));
    } catch (ComException e) {
        throw new ToolFailureException("Couldn't connect to '" + hostnamePort + "'", e);
    } catch (IncrementalBackupNotPossibleException e) {
        throw new ToolFailureException(e.getMessage(), e);
    }
}
Also used : ComException(org.neo4j.com.ComException) UnexpectedStoreVersionException(org.neo4j.kernel.impl.store.UnexpectedStoreVersionException) BackupOutcome(org.neo4j.backup.BackupService.BackupOutcome) MismatchingStoreIdException(org.neo4j.kernel.impl.store.MismatchingStoreIdException)

Example 3 with MismatchingStoreIdException

use of org.neo4j.kernel.impl.store.MismatchingStoreIdException in project neo4j by neo4j.

the class SwitchToSlaveCopyThenBranch method checkDataConsistency.

void checkDataConsistency(MasterClient masterClient, TransactionIdStore txIdStore, StoreId storeId, URI masterUri, URI me, CancellationRequest cancellationRequest) throws Throwable {
    try {
        userLog.info("Checking store consistency with master");
        checkMyStoreIdAndMastersStoreId(storeId, masterUri, resolver);
        checkDataConsistencyWithMaster(masterUri, masterClient, storeId, txIdStore);
        userLog.info("Store is consistent");
    } catch (StoreUnableToParticipateInClusterException upe) {
        userLog.info("The store is inconsistent. Will treat it as branched and fetch a new one from the master");
        msgLog.warn("Current store is unable to participate in the cluster; fetching new store from master", upe);
        try {
            stopServicesAndHandleBranchedStore(config.get(HaSettings.branched_data_policy), masterUri, me, cancellationRequest);
        } catch (IOException e) {
            msgLog.warn("Failed while trying to handle branched data", e);
        }
        throw upe;
    } catch (MismatchingStoreIdException e) {
        userLog.info("The store does not represent the same database as master. Will remove and fetch a new one from " + "master");
        if (txIdStore.getLastCommittedTransactionId() == BASE_TX_ID) {
            msgLog.warn("Found and deleting empty store with mismatching store id", e);
            stopServicesAndHandleBranchedStore(BranchedDataPolicy.keep_none, masterUri, me, cancellationRequest);
            throw e;
        }
        msgLog.error("Store cannot participate in cluster due to mismatching store IDs", e);
        throw new ForeignStoreException(e.getExpected(), e.getEncountered());
    }
}
Also used : ForeignStoreException(org.neo4j.kernel.ha.store.ForeignStoreException) StoreUnableToParticipateInClusterException(org.neo4j.kernel.ha.StoreUnableToParticipateInClusterException) MismatchingStoreIdException(org.neo4j.kernel.impl.store.MismatchingStoreIdException) IOException(java.io.IOException)

Example 4 with MismatchingStoreIdException

use of org.neo4j.kernel.impl.store.MismatchingStoreIdException in project neo4j by neo4j.

the class SwitchToSlave method checkMyStoreIdAndMastersStoreId.

void checkMyStoreIdAndMastersStoreId(StoreId myStoreId, URI masterUri, DependencyResolver resolver) {
    ClusterMembers clusterMembers = resolver.resolveDependency(ClusterMembers.class);
    InstanceId serverId = HighAvailabilityModeSwitcher.getServerId(masterUri);
    Iterable<ClusterMember> members = clusterMembers.getMembers();
    ClusterMember master = firstOrNull(filter(hasInstanceId(serverId), members));
    if (master == null) {
        throw new IllegalStateException("Cannot find the master among " + members + " with master serverId=" + serverId + " and uri=" + masterUri);
    }
    StoreId masterStoreId = master.getStoreId();
    if (!myStoreId.equals(masterStoreId)) {
        throw new MismatchingStoreIdException(myStoreId, master.getStoreId());
    } else if (!myStoreId.equalsByUpgradeId(master.getStoreId())) {
        throw new BranchedDataException("My store with " + myStoreId + " was updated independently from " + "master's store " + masterStoreId);
    }
}
Also used : ClusterMember(org.neo4j.kernel.ha.cluster.member.ClusterMember) StoreId(org.neo4j.kernel.impl.store.StoreId) InstanceId(org.neo4j.cluster.InstanceId) ClusterMembers.hasInstanceId(org.neo4j.kernel.ha.cluster.member.ClusterMembers.hasInstanceId) MismatchingStoreIdException(org.neo4j.kernel.impl.store.MismatchingStoreIdException) ClusterMembers(org.neo4j.kernel.ha.cluster.member.ClusterMembers) BranchedDataException(org.neo4j.kernel.ha.BranchedDataException)

Example 5 with MismatchingStoreIdException

use of org.neo4j.kernel.impl.store.MismatchingStoreIdException in project neo4j by neo4j.

the class SwitchToSlaveBranchThenCopyTest method shouldHandleBranchedStoreWhenMyStoreIdDiffersFromMasterStoreId.

@Test
@SuppressWarnings("unchecked")
public void shouldHandleBranchedStoreWhenMyStoreIdDiffersFromMasterStoreId() throws Throwable {
    // Given
    SwitchToSlaveBranchThenCopy switchToSlave = newSwitchToSlaveSpy();
    URI me = new URI("cluster://localhost?serverId=2");
    MasterClient masterClient = mock(MasterClient.class);
    Response<HandshakeResult> response = mock(Response.class);
    when(response.response()).thenReturn(new HandshakeResult(1, 2));
    when(masterClient.handshake(anyLong(), any(StoreId.class))).thenReturn(response);
    StoreId storeId = newStoreIdForCurrentVersion(1, 2, 3, 4);
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    when(transactionIdStore.getLastCommittedTransaction()).thenReturn(new TransactionId(42, 42, 42));
    when(transactionIdStore.getLastCommittedTransactionId()).thenReturn(TransactionIdStore.BASE_TX_ID);
    // When
    try {
        switchToSlave.checkDataConsistency(masterClient, transactionIdStore, storeId, new URI("cluster://localhost?serverId=1"), me, CancellationRequest.NEVER_CANCELLED);
        fail("Should have thrown " + MismatchingStoreIdException.class.getSimpleName() + " exception");
    } catch (MismatchingStoreIdException e) {
    // good we got the expected exception
    }
    // Then
    verify(switchToSlave).stopServicesAndHandleBranchedStore(any(BranchedDataPolicy.class));
}
Also used : HandshakeResult(org.neo4j.kernel.ha.com.master.HandshakeResult) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) StoreId(org.neo4j.kernel.impl.store.StoreId) MasterClient(org.neo4j.kernel.ha.com.slave.MasterClient) MismatchingStoreIdException(org.neo4j.kernel.impl.store.MismatchingStoreIdException) BranchedDataPolicy(org.neo4j.kernel.ha.BranchedDataPolicy) URI(java.net.URI) TransactionId(org.neo4j.kernel.impl.store.TransactionId) Test(org.junit.Test)

Aggregations

MismatchingStoreIdException (org.neo4j.kernel.impl.store.MismatchingStoreIdException)9 URI (java.net.URI)4 StoreId (org.neo4j.kernel.impl.store.StoreId)4 IOException (java.io.IOException)3 Test (org.junit.Test)3 InstanceId (org.neo4j.cluster.InstanceId)2 ClusterClient (org.neo4j.cluster.client.ClusterClient)2 ComException (org.neo4j.com.ComException)2 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)2 NullLogProvider (org.neo4j.logging.NullLogProvider)2 ConnectException (java.net.ConnectException)1 Callable (java.util.concurrent.Callable)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 Future (java.util.concurrent.Future)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1