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