Search in sources :

Example 1 with BranchedDataPolicy

use of org.neo4j.kernel.ha.BranchedDataPolicy 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());
}
Also used : PagedFile(org.neo4j.io.pagecache.PagedFile) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) InOrder(org.mockito.InOrder) MasterClient(org.neo4j.kernel.ha.com.slave.MasterClient) URI(java.net.URI) TransactionId(org.neo4j.kernel.impl.store.TransactionId) StoreId(org.neo4j.kernel.impl.store.StoreId) StoreCopyClient(org.neo4j.com.storecopy.StoreCopyClient) BranchedDataPolicy(org.neo4j.kernel.ha.BranchedDataPolicy) PagedFile(org.neo4j.io.pagecache.PagedFile) File(java.io.File) BranchedDataException(org.neo4j.kernel.ha.BranchedDataException) MoveAfterCopy(org.neo4j.com.storecopy.MoveAfterCopy) CancellationRequest(org.neo4j.helpers.CancellationRequest) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 2 with BranchedDataPolicy

use of org.neo4j.kernel.ha.BranchedDataPolicy 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);
}
Also used : BranchedDataPolicy(org.neo4j.kernel.ha.BranchedDataPolicy) StoreId(org.neo4j.kernel.impl.store.StoreId) MoveAfterCopy(org.neo4j.com.storecopy.MoveAfterCopy) NeoStoreDataSource(org.neo4j.kernel.NeoStoreDataSource) MasterClientResolver(org.neo4j.kernel.ha.com.slave.MasterClientResolver) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) Monitors(org.neo4j.kernel.monitoring.Monitors) DelegateInvocationHandler(org.neo4j.kernel.ha.DelegateInvocationHandler) StoreUnableToParticipateInClusterException(org.neo4j.kernel.ha.StoreUnableToParticipateInClusterException) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Function(java.util.function.Function) Supplier(java.util.function.Supplier) PullerFactory(org.neo4j.kernel.ha.PullerFactory) MasterClient(org.neo4j.kernel.ha.com.slave.MasterClient) SlaveServer(org.neo4j.kernel.ha.com.slave.SlaveServer) HaIdGeneratorFactory(org.neo4j.kernel.ha.id.HaIdGeneratorFactory) CancellationRequest(org.neo4j.helpers.CancellationRequest) URI(java.net.URI) MismatchingStoreIdException(org.neo4j.kernel.impl.store.MismatchingStoreIdException) BASE_TX_ID(org.neo4j.kernel.impl.transaction.log.TransactionIdStore.BASE_TX_ID) PageCache(org.neo4j.io.pagecache.PageCache) Config(org.neo4j.kernel.configuration.Config) IOException(java.io.IOException) LogService(org.neo4j.kernel.impl.logging.LogService) HaSettings(org.neo4j.kernel.ha.HaSettings) File(java.io.File) UpdatePuller(org.neo4j.kernel.ha.UpdatePuller) ForeignStoreException(org.neo4j.kernel.ha.store.ForeignStoreException) UnableToCopyStoreFromOldMasterException(org.neo4j.kernel.ha.store.UnableToCopyStoreFromOldMasterException) ClusterMemberAvailability(org.neo4j.cluster.member.ClusterMemberAvailability) KernelExtensionFactory(org.neo4j.kernel.extension.KernelExtensionFactory) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Slave(org.neo4j.kernel.ha.com.master.Slave) StoreCopyClient(org.neo4j.com.storecopy.StoreCopyClient) TransactionStats(org.neo4j.kernel.impl.transaction.TransactionStats) RequestContextFactory(org.neo4j.kernel.ha.com.RequestContextFactory) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Master(org.neo4j.kernel.ha.com.master.Master) MoveAfterCopy(org.neo4j.com.storecopy.MoveAfterCopy)

Aggregations

File (java.io.File)2 URI (java.net.URI)2 MoveAfterCopy (org.neo4j.com.storecopy.MoveAfterCopy)2 StoreCopyClient (org.neo4j.com.storecopy.StoreCopyClient)2 CancellationRequest (org.neo4j.helpers.CancellationRequest)2 PageCache (org.neo4j.io.pagecache.PageCache)2 BranchedDataPolicy (org.neo4j.kernel.ha.BranchedDataPolicy)2 MasterClient (org.neo4j.kernel.ha.com.slave.MasterClient)2 StoreId (org.neo4j.kernel.impl.store.StoreId)2 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)2 IOException (java.io.IOException)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1 Test (org.junit.Test)1 InOrder (org.mockito.InOrder)1 ClusterMemberAvailability (org.neo4j.cluster.member.ClusterMemberAvailability)1 DependencyResolver (org.neo4j.graphdb.DependencyResolver)1 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)1 PagedFile (org.neo4j.io.pagecache.PagedFile)1 NeoStoreDataSource (org.neo4j.kernel.NeoStoreDataSource)1