use of org.neo4j.com.storecopy.MoveAfterCopy 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.com.storecopy.MoveAfterCopy in project neo4j by neo4j.
the class SwitchToSlaveCopyThenBranch method stopServicesAndHandleBranchedStore.
void stopServicesAndHandleBranchedStore(BranchedDataPolicy branchPolicy, URI masterUri, URI me, CancellationRequest cancellationRequest) throws Throwable {
MoveAfterCopy moveWithCopyThenBranch = (moves, fromDirectory, toDirectory) -> {
stopServices();
msgLog.debug("Branching store: " + storeDir);
branchPolicy.handle(storeDir, pageCache, logService);
msgLog.debug("Moving downloaded store from " + fromDirectory + " to " + toDirectory);
MoveAfterCopy.moveReplaceExisting().move(moves, fromDirectory, toDirectory);
msgLog.debug("Moved downloaded store from " + fromDirectory + " to " + toDirectory);
};
copyStore(masterUri, me, cancellationRequest, moveWithCopyThenBranch);
}
use of org.neo4j.com.storecopy.MoveAfterCopy in project neo4j by neo4j.
the class SwitchToSlave method copyStoreFromMaster.
void copyStoreFromMaster(MasterClient masterClient, CancellationRequest cancellationRequest, MoveAfterCopy moveAfterCopy) throws Throwable {
try {
userLog.info("Copying store from master");
StoreCopyClient.StoreCopyRequester requester = new StoreCopyClient.StoreCopyRequester() {
@Override
public Response<?> copyStore(StoreWriter writer) {
return masterClient.copyStore(new RequestContext(0, config.get(ClusterSettings.server_id).toIntegerIndex(), 0, BASE_TX_ID, 0), writer);
}
@Override
public void done() {
// Nothing to clean up here
}
};
MoveAfterCopy moveAfterCopyWithLogging = (moves, fromDirectory, toDirectory) -> {
userLog.info("Copied store from master to " + fromDirectory);
msgLog.info("Starting post copy operation to move store from " + fromDirectory + " to " + storeDir);
moveAfterCopy.move(moves, fromDirectory, toDirectory);
};
storeCopyClient.copyStore(requester, cancellationRequest, moveAfterCopyWithLogging);
startServicesAgain();
userLog.info("Finished copying store from master");
} catch (Throwable t) {
// Delete store so that we can copy from master without conflicts next time
cleanStoreDir();
throw t;
}
}
Aggregations