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;
}
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));
}
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));
}
Aggregations