Search in sources :

Example 1 with TakeOfflineManager

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));
    }
}
Also used : TakeOfflineManager(org.infinispan.xsite.status.TakeOfflineManager) ControlledRpcManager(org.infinispan.util.ControlledRpcManager) XSiteAutoTransferStatusCommand(org.infinispan.xsite.commands.XSiteAutoTransferStatusCommand)

Example 2 with TakeOfflineManager

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));
    }
}
Also used : TakeOfflineManager(org.infinispan.xsite.status.TakeOfflineManager)

Example 3 with TakeOfflineManager

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));
    }
}
Also used : TakeOfflineManager(org.infinispan.xsite.status.TakeOfflineManager)

Example 4 with TakeOfflineManager

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));
    }
}
Also used : TakeOfflineManager(org.infinispan.xsite.status.TakeOfflineManager)

Example 5 with TakeOfflineManager

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();
}
Also used : TakeOfflineManager(org.infinispan.xsite.status.TakeOfflineManager)

Aggregations

TakeOfflineManager (org.infinispan.xsite.status.TakeOfflineManager)10 Json (org.infinispan.commons.dataconversion.internal.Json)2 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)2 AbstractMultipleSitesTest (org.infinispan.xsite.AbstractMultipleSitesTest)2 Test (org.testng.annotations.Test)2 RestCacheClient (org.infinispan.client.rest.RestCacheClient)1 RestClient (org.infinispan.client.rest.RestClient)1 TakeOfflineConfigurationBuilder (org.infinispan.configuration.cache.TakeOfflineConfigurationBuilder)1 ControlledRpcManager (org.infinispan.util.ControlledRpcManager)1 XSiteAutoTransferStatusCommand (org.infinispan.xsite.commands.XSiteAutoTransferStatusCommand)1