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);
}
Aggregations