Search in sources :

Example 6 with BranchedDataException

use of org.neo4j.kernel.ha.BranchedDataException in project neo4j by neo4j.

the class SwitchToSlave method checkDataConsistencyWithMaster.

void checkDataConsistencyWithMaster(URI availableMasterId, Master master, StoreId storeId, TransactionIdStore transactionIdStore) {
    TransactionId myLastCommittedTxData = transactionIdStore.getLastCommittedTransaction();
    long myLastCommittedTx = myLastCommittedTxData.transactionId();
    HandshakeResult handshake;
    try (Response<HandshakeResult> response = master.handshake(myLastCommittedTx, storeId)) {
        handshake = response.response();
        requestContextFactory.setEpoch(handshake.epoch());
    } catch (BranchedDataException e) {
        // Rethrow wrapped in a branched data exception on our side, to clarify where the problem originates.
        throw new BranchedDataException("The database stored on this machine has diverged from that " + "of the master. This will be automatically resolved.", e);
    } catch (RuntimeException e) {
        // server-side exception
        if (e.getCause() instanceof MissingLogDataException) {
            /*
                 * This means the master was unable to find a log entry for the txid we just asked. This
                 * probably means the thing we asked for is too old or too new. Anyway, since it doesn't
                 * have the tx it is better if we just throw our store away and ask for a new copy. Next
                 * time around it shouldn't have to even pass from here.
                 */
            throw new StoreOutOfDateException("The master is missing the log required to complete the " + "consistency check", e.getCause());
        }
        throw e;
    }
    long myChecksum = myLastCommittedTxData.checksum();
    if (myChecksum != handshake.txChecksum()) {
        String msg = "The cluster contains two logically different versions of the database.. This will be " + "automatically resolved. Details: I (server_id:" + config.get(ClusterSettings.server_id) + ") think checksum for txId (" + myLastCommittedTx + ") is " + myChecksum + ", but master (server_id:" + getServerId(availableMasterId) + ") says that it's " + handshake.txChecksum() + ", where handshake is " + handshake;
        throw new BranchedDataException(msg);
    }
    msgLog.info("Checksum for last committed tx ok with lastTxId=" + myLastCommittedTx + " with checksum=" + myChecksum, true);
}
Also used : HandshakeResult(org.neo4j.kernel.ha.com.master.HandshakeResult) StoreOutOfDateException(org.neo4j.kernel.ha.StoreOutOfDateException) BranchedDataException(org.neo4j.kernel.ha.BranchedDataException) MissingLogDataException(org.neo4j.kernel.impl.transaction.log.MissingLogDataException) TransactionId(org.neo4j.kernel.impl.store.TransactionId)

Aggregations

BranchedDataException (org.neo4j.kernel.ha.BranchedDataException)6 StoreId (org.neo4j.kernel.impl.store.StoreId)4 TransactionId (org.neo4j.kernel.impl.store.TransactionId)4 URI (java.net.URI)3 Test (org.junit.Test)3 BranchedDataPolicy (org.neo4j.kernel.ha.BranchedDataPolicy)3 MasterClient (org.neo4j.kernel.ha.com.slave.MasterClient)3 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)3 CancellationRequest (org.neo4j.helpers.CancellationRequest)2 File (java.io.File)1 IOException (java.io.IOException)1 InOrder (org.mockito.InOrder)1 InstanceId (org.neo4j.cluster.InstanceId)1 MoveAfterCopy (org.neo4j.com.storecopy.MoveAfterCopy)1 StoreCopyClient (org.neo4j.com.storecopy.StoreCopyClient)1 PageCache (org.neo4j.io.pagecache.PageCache)1 PagedFile (org.neo4j.io.pagecache.PagedFile)1 StoreOutOfDateException (org.neo4j.kernel.ha.StoreOutOfDateException)1 ClusterMember (org.neo4j.kernel.ha.cluster.member.ClusterMember)1 ClusterMembers (org.neo4j.kernel.ha.cluster.member.ClusterMembers)1