use of org.neo4j.causalclustering.identity.StoreId 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);
}
}
use of org.neo4j.causalclustering.identity.StoreId in project neo4j by neo4j.
the class RemoteStoreTest method shouldSetLastPulledTransactionId.
@Test
public void shouldSetLastPulledTransactionId() throws Exception {
// given
long lastFlushedTxId = 12;
StoreId wantedStoreId = new StoreId(1, 2, 3, 4);
MemberId localhost = new MemberId(UUID.randomUUID());
StoreCopyClient storeCopyClient = mock(StoreCopyClient.class);
when(storeCopyClient.copyStoreFiles(eq(localhost), eq(wantedStoreId), any(StoreFileStreams.class))).thenReturn(lastFlushedTxId);
TxPullClient txPullClient = mock(TxPullClient.class);
when(txPullClient.pullTransactions(eq(localhost), eq(wantedStoreId), anyLong(), any(TxPullResponseListener.class))).thenReturn(new TxPullRequestResult(SUCCESS_END_OF_STREAM, 13));
TransactionLogCatchUpWriter writer = mock(TransactionLogCatchUpWriter.class);
RemoteStore remoteStore = new RemoteStore(NullLogProvider.getInstance(), mock(FileSystemAbstraction.class), null, storeCopyClient, txPullClient, factory(writer), new Monitors());
// when
remoteStore.copy(localhost, wantedStoreId, new File("destination"));
// then
// the interface is defined as asking for the one preceding
long previousTxId = lastFlushedTxId - 1;
verify(txPullClient).pullTransactions(eq(localhost), eq(wantedStoreId), eq(previousTxId), any(TxPullResponseListener.class));
}
use of org.neo4j.causalclustering.identity.StoreId in project neo4j by neo4j.
the class RemoteStoreTest method shouldCloseDownTxLogWriterIfTxStreamingFails.
@Test
public void shouldCloseDownTxLogWriterIfTxStreamingFails() throws Exception {
// given
StoreId storeId = new StoreId(1, 2, 3, 4);
StoreCopyClient storeCopyClient = mock(StoreCopyClient.class);
TxPullClient txPullClient = mock(TxPullClient.class);
TransactionLogCatchUpWriter writer = mock(TransactionLogCatchUpWriter.class);
RemoteStore remoteStore = new RemoteStore(NullLogProvider.getInstance(), mock(FileSystemAbstraction.class), null, storeCopyClient, txPullClient, factory(writer), new Monitors());
doThrow(StoreCopyFailedException.class).when(txPullClient).pullTransactions(any(MemberId.class), eq(storeId), anyLong(), any(TransactionLogCatchUpWriter.class));
// when
try {
remoteStore.copy(null, storeId, null);
} catch (StoreCopyFailedException e) {
// expected
}
// then
verify(writer).close();
}
use of org.neo4j.causalclustering.identity.StoreId in project neo4j by neo4j.
the class StoreFilesTest method mustReadStoreId.
@Test
public void mustReadStoreId() throws Exception {
File dir = getBaseDir();
File neostore = new File(dir, MetaDataStore.DEFAULT_NAME);
ThreadLocalRandom rng = ThreadLocalRandom.current();
long time = rng.nextLong();
long randomNumber = rng.nextLong();
long upgradeTime = rng.nextLong();
long upgradeTransactionId = rng.nextLong();
createOnPageCache(neostore);
MetaDataStore.setRecord(pageCache, neostore, Position.TIME, time);
MetaDataStore.setRecord(pageCache, neostore, Position.RANDOM_NUMBER, randomNumber);
MetaDataStore.setRecord(pageCache, neostore, Position.STORE_VERSION, rng.nextLong());
MetaDataStore.setRecord(pageCache, neostore, Position.UPGRADE_TIME, upgradeTime);
MetaDataStore.setRecord(pageCache, neostore, Position.UPGRADE_TRANSACTION_ID, upgradeTransactionId);
StoreId storeId = storeFiles.readStoreId(dir);
assertThat(storeId.getCreationTime(), is(time));
assertThat(storeId.getRandomId(), is(randomNumber));
assertThat(storeId.getUpgradeTime(), is(upgradeTime));
assertThat(storeId.getUpgradeId(), is(upgradeTransactionId));
}
use of org.neo4j.causalclustering.identity.StoreId in project neo4j by neo4j.
the class TestStoreId method doReadStoreId.
private static StoreId doReadStoreId(File coreStoreDir, PageCache pageCache) throws IOException {
File metadataStore = new File(coreStoreDir, MetaDataStore.DEFAULT_NAME);
long creationTime = MetaDataStore.getRecord(pageCache, metadataStore, TIME);
long randomNumber = MetaDataStore.getRecord(pageCache, metadataStore, RANDOM_NUMBER);
long upgradeTime = MetaDataStore.getRecord(pageCache, metadataStore, UPGRADE_TIME);
long upgradeId = MetaDataStore.getRecord(pageCache, metadataStore, UPGRADE_TRANSACTION_ID);
return new StoreId(creationTime, randomNumber, upgradeTime, upgradeId);
}
Aggregations