use of org.neo4j.kernel.ha.BranchedDataException in project neo4j by neo4j.
the class SwitchToSlaveBranchThenCopyTest method shouldHandleBranchedStoreWhenHandshakeFailsWithBranchedDataException.
@Test
public void shouldHandleBranchedStoreWhenHandshakeFailsWithBranchedDataException() throws Throwable {
// Given
SwitchToSlaveBranchThenCopy switchToSlave = newSwitchToSlaveSpy();
URI masterUri = new URI("cluster://localhost?serverId=1");
URI me = new URI("cluster://localhost?serverId=2");
MasterClient masterClient = mock(MasterClient.class);
when(masterClient.handshake(anyLong(), any(StoreId.class))).thenThrow(new BranchedDataException(""));
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, masterUri, me, CancellationRequest.NEVER_CANCELLED);
fail("Should have thrown " + BranchedDataException.class.getSimpleName() + " exception");
} catch (BranchedDataException e) {
// good we got the expected exception
}
// Then
verify(switchToSlave).stopServicesAndHandleBranchedStore(any(BranchedDataPolicy.class));
}
use of org.neo4j.kernel.ha.BranchedDataException in project neo4j by neo4j.
the class SwitchToSlaveCopyThenBranchTest method shouldNotBranchStoreUnlessWeHaveCopiedDownAReplacement.
@Test
public void shouldNotBranchStoreUnlessWeHaveCopiedDownAReplacement() throws Throwable {
// Given
StoreCopyClient storeCopyClient = mock(StoreCopyClient.class);
doAnswer(invocation -> {
MoveAfterCopy moveAfterCopy = invocation.getArgumentAt(2, MoveAfterCopy.class);
moveAfterCopy.move(Stream.empty(), new File(""), new File(""));
return null;
}).when(storeCopyClient).copyStore(any(StoreCopyClient.StoreCopyRequester.class), any(CancellationRequest.class), any(MoveAfterCopy.class));
PageCache pageCacheMock = mock(PageCache.class);
PagedFile pagedFileMock = mock(PagedFile.class);
when(pagedFileMock.getLastPageId()).thenReturn(1L);
when(pageCacheMock.map(any(File.class), anyInt())).thenReturn(pagedFileMock);
SwitchToSlaveCopyThenBranch switchToSlave = newSwitchToSlaveSpy(pageCacheMock, storeCopyClient);
URI masterUri = new URI("cluster://localhost?serverId=1");
URI me = new URI("cluster://localhost?serverId=2");
CancellationRequest cancellationRequest = CancellationRequest.NEVER_CANCELLED;
MasterClient masterClient = mock(MasterClient.class);
when(masterClient.handshake(anyLong(), any(StoreId.class))).thenThrow(new BranchedDataException(""));
TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
when(transactionIdStore.getLastCommittedTransaction()).thenReturn(new TransactionId(42, 42, 42));
when(transactionIdStore.getLastCommittedTransactionId()).thenReturn(TransactionIdStore.BASE_TX_ID);
// When
BranchedDataPolicy branchPolicy = mock(BranchedDataPolicy.class);
switchToSlave.stopServicesAndHandleBranchedStore(branchPolicy, masterUri, me, cancellationRequest);
// Then
InOrder inOrder = Mockito.inOrder(storeCopyClient, branchPolicy);
inOrder.verify(storeCopyClient).copyStore(any(StoreCopyClient.StoreCopyRequester.class), any(CancellationRequest.class), any(MoveAfterCopy.class));
inOrder.verify(branchPolicy).handle(new File(""), pageCacheMock, NullLogService.getInstance());
}
use of org.neo4j.kernel.ha.BranchedDataException in project neo4j by neo4j.
the class SwitchToSlaveCopyThenBranchTest method shouldHandleBranchedStoreWhenHandshakeFailsWithBranchedDataException.
@Test
public void shouldHandleBranchedStoreWhenHandshakeFailsWithBranchedDataException() throws Throwable {
// Given
SwitchToSlaveCopyThenBranch switchToSlave = newSwitchToSlaveSpy();
URI masterUri = new URI("cluster://localhost?serverId=1");
URI me = new URI("cluster://localhost?serverId=2");
MasterClient masterClient = mock(MasterClient.class);
when(masterClient.handshake(anyLong(), any(StoreId.class))).thenThrow(new BranchedDataException(""));
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, masterUri, me, CancellationRequest.NEVER_CANCELLED);
fail("Should have thrown " + BranchedDataException.class.getSimpleName() + " exception");
} catch (BranchedDataException e) {
// good we got the expected exception
}
// Then
verify(switchToSlave).stopServicesAndHandleBranchedStore(any(BranchedDataPolicy.class), any(URI.class), any(URI.class), any(CancellationRequest.class));
}
use of org.neo4j.kernel.ha.BranchedDataException in project graphdb by neo4j-attic.
the class HighlyAvailableGraphDatabase method tryToEnsureIAmNotABrokenMachine.
private void tryToEnsureIAmNotABrokenMachine(Pair<Master, Machine> master) {
if (master.other().getMachineId() == machineId) {
return;
} else if (master.first() == null) {
// Temporarily disconnected from ZK
RuntimeException cause = new RuntimeException("Unable to get master from ZK");
shutdown(cause, false);
throw cause;
}
XaDataSource nioneoDataSource = getConfig().getTxModule().getXaDataSourceManager().getXaDataSource(Config.DEFAULT_DATA_SOURCE_NAME);
long myLastCommittedTx = nioneoDataSource.getLastCommittedTxId();
long highestCommonTxId = Math.min(myLastCommittedTx, master.other().getLastCommittedTxId());
int masterForMyHighestCommonTxId = -1;
try {
masterForMyHighestCommonTxId = nioneoDataSource.getMasterForCommittedTx(highestCommonTxId);
;
} catch (IOException e) {
// This is quite dangerous to just catch here... but the special case is
// where this db was just now copied from the master where there's data,
// but no logical logs were transfered and hence no masterId info is here
msgLog.logMessage("Couldn't get master ID for txId " + highestCommonTxId + ". It may be that a log file is missing due to the db being copied from master?", e);
return;
}
int masterForMastersHighestCommonTxId = master.first().getMasterIdForCommittedTx(highestCommonTxId).response();
// Compare those two, if equal -> good
if (masterForMyHighestCommonTxId == masterForMastersHighestCommonTxId) {
msgLog.logMessage("Master id for last committed tx ok with highestCommonTxId=" + highestCommonTxId + " with masterId=" + masterForMyHighestCommonTxId, true);
return;
} else {
String msg = "Broken store, I (machineId:" + machineId + ") think machineId for txId (" + highestCommonTxId + ") is " + masterForMyHighestCommonTxId + ", but master (machineId:" + master.other().getMachineId() + ") says that it's " + masterForMastersHighestCommonTxId;
msgLog.logMessage(msg, true);
RuntimeException exception = new BranchedDataException(msg);
shutdown(exception, false);
throw exception;
}
}
use of org.neo4j.kernel.ha.BranchedDataException 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);
}
}
Aggregations