use of org.infinispan.xsite.status.TakeOfflineManager in project infinispan by infinispan.
the class XSiteAutoStateTransferTest method testSingleManualModeDoNotTriggerStateTransfer.
public void testSingleManualModeDoNotTriggerStateTransfer() throws InterruptedException, TimeoutException, ExecutionException {
// site1 is the async one
String remoteSite = siteName(1);
// make the remote site offline.
for (int i = 0; i < defaultNumberOfNodes(); ++i) {
TakeOfflineManager manager = takeOfflineManager(i);
assertNotSame(TakeSiteOfflineResponse.NO_SUCH_SITE, manager.takeSiteOffline(remoteSite));
assertSame(SiteState.OFFLINE, manager.getSiteState(remoteSite));
}
SiteMasterController controller = findSiteMaster();
boolean manualModeSet = false;
for (int i = 0; i < defaultNumberOfNodes(); ++i) {
if (i == controller.managerIndex) {
stateTransferManager(i).setAutomaticStateTransfer(remoteSite, XSiteStateTransferMode.AUTO);
} else if (!manualModeSet) {
stateTransferManager(i).setAutomaticStateTransfer(remoteSite, XSiteStateTransferMode.MANUAL);
manualModeSet = true;
}
// else, does not mather if the 3rd node is MANUAL or AUTO since it shouldn't start any state transfer if at least one node is MANUAL
}
// block sites up event and wait until received
SiteUpEvent event = controller.getStateTransferManager().blockSiteUpEvent();
triggerSiteUpEvent(controller, remoteSite);
Collection<String> sitesUp = event.waitForEvent();
// check if it is the correct event
assertEquals(1, sitesUp.size());
assertEquals(remoteSite, sitesUp.iterator().next());
CompletableFuture<ControlledRpcManager.BlockedRequest<XSiteAutoTransferStatusCommand>> req = controller.getRpcManager().expectCommandAsync(XSiteAutoTransferStatusCommand.class);
// let the event continue, it will be handled in this thread, which is fine
event.continueRunnable();
// we expect the coordinator to send a command
ControlledRpcManager.BlockedRequest<XSiteAutoTransferStatusCommand> cmd = req.get(30, TimeUnit.SECONDS);
cmd.send().receiveAll();
// site status must not change
for (int i = 0; i < defaultNumberOfNodes(); ++i) {
TakeOfflineManager manager = takeOfflineManager(i);
assertSame(SiteState.OFFLINE, manager.getSiteState(remoteSite));
}
}
use of org.infinispan.xsite.status.TakeOfflineManager in project infinispan by infinispan.
the class XSiteAutoStateTransferTest method testAutoStateTransfer.
public void testAutoStateTransfer(Method method) throws InterruptedException, TimeoutException, ExecutionException {
// site1 is the async one
String remoteSite = siteName(1);
// we make all of them to put some data
for (int i = 0; i < defaultNumberOfNodes(); ++i) {
TakeOfflineManager manager = takeOfflineManager(i);
assertNotSame(TakeSiteOfflineResponse.NO_SUCH_SITE, manager.takeSiteOffline(remoteSite));
assertSame(SiteState.OFFLINE, manager.getSiteState(remoteSite));
// site2 is disabled as well just to avoid replicating there
manager.takeSiteOffline(siteName(2));
assertTrue(stateTransferManager(i).setAutomaticStateTransfer(remoteSite, XSiteStateTransferMode.AUTO));
}
// lets put some data
for (int i = 0; i < defaultNumberOfNodes() * 5; ++i) {
cache(0, 0).put(TestingUtil.k(method, i), TestingUtil.v(method, i));
}
// make sure data didn't go through
for (int i = 0; i < defaultNumberOfNodes() * 5; ++i) {
assertNull(cache(1, 0).get(TestingUtil.k(method, i)));
}
SiteMasterController controller = findSiteMaster();
// let the state command go through
controller.getRpcManager().excludeCommands(XSiteStatePushCommand.class, IracCleanupKeyCommand.class, IracTombstoneStateResponseCommand.class, StateTransferCancelCommand.class);
CompletableFuture<ControlledRpcManager.BlockedRequest<XSiteAutoTransferStatusCommand>> req1 = controller.getRpcManager().expectCommandAsync(XSiteAutoTransferStatusCommand.class);
CompletableFuture<ControlledRpcManager.BlockedRequest<XSiteBringOnlineCommand>> req2 = controller.getRpcManager().expectCommandAsync(XSiteBringOnlineCommand.class);
CompletableFuture<ControlledRpcManager.BlockedRequest<XSiteStateTransferStartSendCommand>> req3 = controller.getRpcManager().expectCommandAsync(XSiteStateTransferStartSendCommand.class);
// block sites up event and wait until received
SiteUpEvent event = controller.getStateTransferManager().blockSiteUpEvent();
triggerSiteUpEvent(controller, remoteSite);
Collection<String> sitesUp = event.waitForEvent();
// check if it is the correct event
assertEquals(1, sitesUp.size());
assertEquals(remoteSite, sitesUp.iterator().next());
// let the event continue
event.continueRunnable();
// make sure the commands are blocked
req1.get(10, TimeUnit.SECONDS).send().receiveAll();
req2.get(10, TimeUnit.SECONDS).send().receiveAll();
req3.get(10, TimeUnit.SECONDS).send().receiveAll();
controller.getRpcManager().stopBlocking();
// site1 must be online now
for (int i = 0; i < defaultNumberOfNodes(); ++i) {
TakeOfflineManager manager = takeOfflineManager(i);
assertSame(SiteState.ONLINE, manager.getSiteState(remoteSite));
assertSame(SiteState.OFFLINE, manager.getSiteState(siteName(2)));
}
// wait for state transfer to finish
eventuallyEquals(StateTransferStatus.SEND_OK, () -> controller.getStateTransferManager().getStatus().get(remoteSite));
// check data
for (int i = 0; i < defaultNumberOfNodes() * 5; ++i) {
String key = TestingUtil.k(method, i);
String value = TestingUtil.v(method, i);
assertEquals(value, cache(0, 0).get(key));
assertEquals(value, cache(1, 0).get(key));
}
}
use of org.infinispan.xsite.status.TakeOfflineManager in project infinispan by infinispan.
the class XSiteAutoStateTransferTest method testManualModeDoNotTriggerStateTransfer.
public void testManualModeDoNotTriggerStateTransfer() throws InterruptedException {
// site1 is the async one
String remoteSite = siteName(1);
// make the remote site offline.
for (int i = 0; i < defaultNumberOfNodes(); ++i) {
TakeOfflineManager manager = takeOfflineManager(i);
assertNotSame(TakeSiteOfflineResponse.NO_SUCH_SITE, manager.takeSiteOffline(remoteSite));
assertSame(SiteState.OFFLINE, manager.getSiteState(remoteSite));
stateTransferManager(i).setAutomaticStateTransfer(remoteSite, XSiteStateTransferMode.MANUAL);
}
SiteMasterController controller = findSiteMaster();
// block sites up event and wait until received
SiteUpEvent event = controller.getStateTransferManager().blockSiteUpEvent();
triggerSiteUpEvent(controller, remoteSite);
Collection<String> sitesUp = event.waitForEvent();
// check if it is the correct event
assertEquals(1, sitesUp.size());
assertEquals(remoteSite, sitesUp.iterator().next());
// let the event continue, it will be handled in this thread, which is fine
event.continueRunnable();
// coordinator don't even query other nodes state
controller.getRpcManager().expectNoCommand(10, TimeUnit.SECONDS);
// site status must not change
for (int i = 0; i < defaultNumberOfNodes(); ++i) {
TakeOfflineManager manager = takeOfflineManager(i);
assertSame(SiteState.OFFLINE, manager.getSiteState(remoteSite));
}
}
use of org.infinispan.xsite.status.TakeOfflineManager in project infinispan by infinispan.
the class XSiteAutoStateTransferTest method testNewSiteMasterStartsStateTransfer.
public void testNewSiteMasterStartsStateTransfer(Method method) throws Exception {
// site1 is the async one
String remoteSite = siteName(1);
// we make all of them to put some data
for (int i = 0; i < defaultNumberOfNodes(); ++i) {
TakeOfflineManager manager = takeOfflineManager(i);
assertNotSame(TakeSiteOfflineResponse.NO_SUCH_SITE, manager.takeSiteOffline(remoteSite));
assertSame(SiteState.OFFLINE, manager.getSiteState(remoteSite));
// site2 is disabled as well just to avoid replicating there
manager.takeSiteOffline(siteName(2));
assertTrue(stateTransferManager(i).setAutomaticStateTransfer(remoteSite, XSiteStateTransferMode.AUTO));
}
// lets put some data
for (int i = 0; i < defaultNumberOfNodes() * 5; ++i) {
cache(0, 0).put(TestingUtil.k(method, i), TestingUtil.v(method, i));
}
// make sure data didn't go through
for (int i = 0; i < defaultNumberOfNodes() * 5; ++i) {
assertNull(cache(1, 0).get(TestingUtil.k(method, i)));
}
SiteMasterController oldSiteMaster = findSiteMaster();
SiteMasterController newSiteMaster = getSiteMasterController(oldSiteMaster.managerIndex + 1 % defaultNumberOfNodes());
// reset current site master
oldSiteMaster.getRpcManager().stopBlocking();
// let the state command go through
newSiteMaster.getRpcManager().excludeCommands(XSiteStatePushCommand.class, StateTransferStartCommand.class, StateResponseCommand.class, StateTransferCancelCommand.class, IracRequestStateCommand.class, IracStateResponseCommand.class, IracUpdateVersionCommand.class, IracCleanupKeyCommand.class, IracTombstoneStateResponseCommand.class);
// the JGroups events triggers this command where NodeB checks if it needs to starts the transfer
CompletableFuture<ControlledRpcManager.BlockedRequest<XSiteAutoTransferStatusCommand>> req1 = newSiteMaster.getRpcManager().expectCommandAsync(XSiteAutoTransferStatusCommand.class);
// and we have a second command coming from NodeC. NodeB broadcast the RELAY2 events to all nodes
CompletableFuture<ControlledRpcManager.BlockedRequest<XSiteAutoTransferStatusCommand>> req2 = newSiteMaster.getRpcManager().expectCommandAsync(XSiteAutoTransferStatusCommand.class);
CompletableFuture<ControlledRpcManager.BlockedRequest<XSiteBringOnlineCommand>> req3 = newSiteMaster.getRpcManager().expectCommandAsync(XSiteBringOnlineCommand.class);
CompletableFuture<ControlledRpcManager.BlockedRequest<XSiteStateTransferStartSendCommand>> req4 = newSiteMaster.getRpcManager().expectCommandAsync(XSiteStateTransferStartSendCommand.class);
// block sites up event and wait until received
SiteUpEvent event = newSiteMaster.getStateTransferManager().blockSiteUpEvent();
site(0).kill(0);
site(0).waitForClusterToForm(null);
// new view should be installed
Collection<String> sitesUp = event.waitForEvent();
// check if it is the correct event, it creates a new connection so the event contains the 3 sites
assertEquals(3, sitesUp.size());
assertTrue(sitesUp.contains(siteName(0)));
assertTrue(sitesUp.contains(siteName(1)));
assertTrue(sitesUp.contains(siteName(2)));
// let the event continue
event.continueRunnable();
// make sure the commands are blocked
// we only need req1 or req2 to succeed,it does not matter which one
req1.get(10, TimeUnit.SECONDS).fail();
req2.get(10, TimeUnit.SECONDS).send().receiveAll();
req3.get(10, TimeUnit.SECONDS).send().receiveAll();
req4.get(10, TimeUnit.SECONDS).send().receiveAll();
newSiteMaster.getRpcManager().stopBlocking();
// site1 must be online now
for (int i = 0; i < defaultNumberOfNodes() - 1; ++i) {
TakeOfflineManager manager = takeOfflineManager(i);
assertSame(SiteState.ONLINE, manager.getSiteState(remoteSite));
assertSame(SiteState.OFFLINE, manager.getSiteState(siteName(2)));
}
// wait for state transfer to finish
eventuallyEquals(StateTransferStatus.SEND_OK, () -> newSiteMaster.getStateTransferManager().getStatus().get(remoteSite));
// check data
for (int i = 0; i < defaultNumberOfNodes() * 5; ++i) {
String key = TestingUtil.k(method, i);
String value = TestingUtil.v(method, i);
assertEquals(value, cache(0, newSiteMaster.managerIndex).get(key));
assertEquals(value, cache(1, 0).get(key));
}
}
use of org.infinispan.xsite.status.TakeOfflineManager in project infinispan by infinispan.
the class XSiteAmendOfflineStatusCommand method invokeAsync.
@Override
public CompletionStage<?> invokeAsync(ComponentRegistry registry) throws Throwable {
TakeOfflineManager takeOfflineManager = registry.getTakeOfflineManager().running();
takeOfflineManager.amendConfiguration(siteName, afterFailures, minTimeToWait);
return CompletableFutures.completedNull();
}
Aggregations