Search in sources :

Example 1 with UpdatePullerScheduler

use of org.neo4j.kernel.ha.UpdatePullerScheduler in project neo4j by neo4j.

the class SwitchToSlave method startHaCommunication.

private URI startHaCommunication(LifeSupport haCommunicationLife, NeoStoreDataSource neoDataSource, URI me, URI masterUri, StoreId storeId, CancellationRequest cancellationRequest) throws IllegalArgumentException, InterruptedException {
    MasterClient master = newMasterClient(masterUri, me, neoDataSource.getStoreId(), haCommunicationLife);
    TransactionObligationFulfiller obligationFulfiller = resolver.resolveDependency(TransactionObligationFulfiller.class);
    UpdatePullerScheduler updatePullerScheduler = updatePullerFactory.createUpdatePullerScheduler(updatePuller);
    Slave slaveImpl = new SlaveImpl(obligationFulfiller);
    SlaveServer server = slaveServerFactory.apply(slaveImpl);
    if (cancellationRequest.cancellationRequested()) {
        msgLog.info("Switch to slave cancelled, unable to start HA-communication");
        return null;
    }
    masterDelegateHandler.setDelegate(master);
    haCommunicationLife.add(updatePullerScheduler);
    haCommunicationLife.add(server);
    haCommunicationLife.start();
    /*
         * Take the opportunity to catch up with master, now that we're alone here, right before we
         * drop the availability guard, so that other transactions might start.
         */
    if (!catchUpWithMaster(updatePuller)) {
        return null;
    }
    URI slaveHaURI = createHaURI(me, server);
    clusterMemberAvailability.memberIsAvailable(HighAvailabilityModeSwitcher.SLAVE, slaveHaURI, storeId);
    return slaveHaURI;
}
Also used : Slave(org.neo4j.kernel.ha.com.master.Slave) TransactionObligationFulfiller(org.neo4j.com.storecopy.TransactionObligationFulfiller) UpdatePullerScheduler(org.neo4j.kernel.ha.UpdatePullerScheduler) MasterClient(org.neo4j.kernel.ha.com.slave.MasterClient) SlaveServer(org.neo4j.kernel.ha.com.slave.SlaveServer) URI(java.net.URI) SlaveImpl(org.neo4j.kernel.ha.com.slave.SlaveImpl)

Example 2 with UpdatePullerScheduler

use of org.neo4j.kernel.ha.UpdatePullerScheduler in project neo4j by neo4j.

the class SwitchToSlaveBranchThenCopyTest method updatesPulledAndPullingScheduledOnSwitchToSlave.

@Test
public void updatesPulledAndPullingScheduledOnSwitchToSlave() throws Throwable {
    SwitchToSlaveBranchThenCopy switchToSlave = newSwitchToSlaveSpy();
    when(fs.fileExists(any(File.class))).thenReturn(true);
    JobScheduler jobScheduler = mock(JobScheduler.class);
    LifeSupport communicationLife = mock(LifeSupport.class);
    URI localhost = getLocalhostUri();
    final UpdatePullerScheduler pullerScheduler = new UpdatePullerScheduler(jobScheduler, NullLogProvider.getInstance(), updatePuller, 10L);
    when(pullerFactory.createUpdatePullerScheduler(updatePuller)).thenReturn(pullerScheduler);
    // emulate lifecycle start call on scheduler
    doAnswer(invocationOnMock -> {
        pullerScheduler.init();
        return null;
    }).when(communicationLife).start();
    switchToSlave.switchToSlave(communicationLife, localhost, localhost, mock(CancellationRequest.class));
    verify(updatePuller).tryPullUpdates();
    verify(communicationLife).add(pullerScheduler);
    verify(jobScheduler).scheduleRecurring(eq(JobScheduler.Groups.pullUpdates), any(Runnable.class), eq(10L), eq(10L), eq(TimeUnit.MILLISECONDS));
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) UpdatePullerScheduler(org.neo4j.kernel.ha.UpdatePullerScheduler) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) PagedFile(org.neo4j.io.pagecache.PagedFile) File(java.io.File) URI(java.net.URI) CancellationRequest(org.neo4j.helpers.CancellationRequest) Test(org.junit.Test)

Example 3 with UpdatePullerScheduler

use of org.neo4j.kernel.ha.UpdatePullerScheduler in project neo4j by neo4j.

the class SwitchToSlaveCopyThenBranchTest method updatesPulledAndPullingScheduledOnSwitchToSlave.

@Test
public void updatesPulledAndPullingScheduledOnSwitchToSlave() throws Throwable {
    SwitchToSlaveCopyThenBranch switchToSlave = newSwitchToSlaveSpy();
    when(fs.fileExists(any(File.class))).thenReturn(true);
    JobScheduler jobScheduler = mock(JobScheduler.class);
    LifeSupport communicationLife = mock(LifeSupport.class);
    URI localhost = getLocalhostUri();
    final UpdatePullerScheduler pullerScheduler = new UpdatePullerScheduler(jobScheduler, NullLogProvider.getInstance(), updatePuller, 10L);
    when(pullerFactory.createUpdatePullerScheduler(updatePuller)).thenReturn(pullerScheduler);
    // emulate lifecycle start call on scheduler
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            pullerScheduler.init();
            return null;
        }
    }).when(communicationLife).start();
    switchToSlave.switchToSlave(communicationLife, localhost, localhost, mock(CancellationRequest.class));
    verify(updatePuller).tryPullUpdates();
    verify(communicationLife).add(pullerScheduler);
    verify(jobScheduler).scheduleRecurring(eq(JobScheduler.Groups.pullUpdates), any(Runnable.class), eq(10L), eq(10L), eq(TimeUnit.MILLISECONDS));
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) UpdatePullerScheduler(org.neo4j.kernel.ha.UpdatePullerScheduler) URI(java.net.URI) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) PagedFile(org.neo4j.io.pagecache.PagedFile) File(java.io.File) CancellationRequest(org.neo4j.helpers.CancellationRequest) Test(org.junit.Test)

Aggregations

URI (java.net.URI)3 UpdatePullerScheduler (org.neo4j.kernel.ha.UpdatePullerScheduler)3 File (java.io.File)2 Test (org.junit.Test)2 CancellationRequest (org.neo4j.helpers.CancellationRequest)2 PagedFile (org.neo4j.io.pagecache.PagedFile)2 JobScheduler (org.neo4j.kernel.impl.util.JobScheduler)2 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)2 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1 TransactionObligationFulfiller (org.neo4j.com.storecopy.TransactionObligationFulfiller)1 Slave (org.neo4j.kernel.ha.com.master.Slave)1 MasterClient (org.neo4j.kernel.ha.com.slave.MasterClient)1 SlaveImpl (org.neo4j.kernel.ha.com.slave.SlaveImpl)1 SlaveServer (org.neo4j.kernel.ha.com.slave.SlaveServer)1