use of org.neo4j.causalclustering.catchup.storecopy.StoreCopyFailedException in project neo4j by neo4j.
the class CoreStateDownloaderTest method shouldNotOverwriteNonEmptyMismatchingStore.
@Test
public void shouldNotOverwriteNonEmptyMismatchingStore() throws Exception {
// given
when(localDatabase.isEmpty()).thenReturn(false);
StoreId remoteStoreId = new StoreId(5, 6, 7, 8);
when(remoteStore.getStoreId(remoteMember)).thenReturn(remoteStoreId);
// when
try {
downloader.downloadSnapshot(remoteMember, coreState);
fail();
} catch (StoreCopyFailedException e) {
// expected
}
// then
verify(remoteStore, never()).copy(any(), any(), any());
verify(remoteStore, never()).tryCatchingUp(any(), any(), any());
}
use of org.neo4j.causalclustering.catchup.storecopy.StoreCopyFailedException in project neo4j by neo4j.
the class ReadReplicaStartupProcess method start.
@Override
public void start() throws IOException {
boolean syncedWithUpstream = false;
RetryStrategy.Timeout timeout = retryStrategy.newTimeout();
int attempt = 0;
while (!syncedWithUpstream) {
attempt++;
MemberId source = null;
try {
source = selectionStrategyPipeline.bestUpstreamDatabase();
syncStoreWithUpstream(source);
syncedWithUpstream = true;
} catch (UpstreamDatabaseSelectionException e) {
lastIssue = issueOf("finding upstream member", attempt);
debugLog.warn(lastIssue);
} catch (StoreCopyFailedException e) {
lastIssue = issueOf(format("copying store files from %s", source), attempt);
debugLog.warn(lastIssue);
} catch (StreamingTransactionsFailedException e) {
lastIssue = issueOf(format("streaming transactions from %s", source), attempt);
debugLog.warn(lastIssue);
} catch (StoreIdDownloadFailedException e) {
lastIssue = issueOf(format("getting store id from %s", source), attempt);
debugLog.warn(lastIssue);
}
try {
Thread.sleep(timeout.getMillis());
timeout.increment();
} catch (InterruptedException e) {
Thread.interrupted();
lastIssue = "Interrupted while trying to start read replica";
debugLog.warn(lastIssue);
break;
}
}
if (!syncedWithUpstream) {
userLog.error(lastIssue);
throw new RuntimeException(lastIssue);
}
try {
localDatabase.start();
txPulling.start();
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
use of org.neo4j.causalclustering.catchup.storecopy.StoreCopyFailedException in project neo4j by neo4j.
the class CoreStateDownloader method downloadSnapshot.
public synchronized void downloadSnapshot(MemberId source, CoreState coreState) throws StoreCopyFailedException {
try {
/* Extract some key properties before shutting it down. */
boolean isEmptyStore = localDatabase.isEmpty();
if (!isEmptyStore) {
/* make sure it's recovered before we start messing with catchup */
localDatabase.start();
localDatabase.stop();
}
StoreId remoteStoreId = remoteStore.getStoreId(source);
if (!isEmptyStore && !remoteStoreId.equals(localDatabase.storeId())) {
throw new StoreCopyFailedException("StoreId mismatch and not empty");
}
startStopOnStoreCopy.stop();
localDatabase.stopForStoreCopy();
log.info("Downloading snapshot from core server at %s", source);
/* The core snapshot must be copied before the store, because the store has a dependency on
* the state of the state machines. The store will thus be at or ahead of the state machines,
* in consensus log index, and application of commands will bring them in sync. Any such commands
* that carry transactions will thus be ignored by the transaction/token state machines, since they
* are ahead, and the correct decisions for their applicability have already been taken as encapsulated
* in the copied store. */
CoreSnapshot coreSnapshot = catchUpClient.makeBlockingRequest(source, new CoreSnapshotRequest(), new CatchUpResponseAdaptor<CoreSnapshot>() {
@Override
public void onCoreSnapshot(CompletableFuture<CoreSnapshot> signal, CoreSnapshot response) {
signal.complete(response);
}
});
if (isEmptyStore) {
storeCopyProcess.replaceWithStoreFrom(source, remoteStoreId);
} else {
StoreId localStoreId = localDatabase.storeId();
CatchupResult catchupResult = remoteStore.tryCatchingUp(source, localStoreId, localDatabase.storeDir());
if (catchupResult == E_TRANSACTION_PRUNED) {
log.info("Failed to pull transactions from " + source + ". They may have been pruned away.");
localDatabase.delete();
storeCopyProcess.replaceWithStoreFrom(source, localStoreId);
} else if (catchupResult != SUCCESS_END_OF_STREAM) {
throw new StoreCopyFailedException("Failed to download store: " + catchupResult);
}
}
/* We install the snapshot after the store has been downloaded,
* so that we are not left with a state ahead of the store. */
coreState.installSnapshot(coreSnapshot);
log.info("Core snapshot installed: " + coreSnapshot);
/* Starting the database will invoke the commit process factory in
* the EnterpriseCoreEditionModule, which has important side-effects. */
log.info("Starting local database");
localDatabase.start();
coreStateMachines.installCommitProcess(localDatabase.getCommitProcess());
startStopOnStoreCopy.start();
} catch (StoreCopyFailedException e) {
throw e;
} catch (Throwable e) {
throw new StoreCopyFailedException(e);
}
}
Aggregations