Search in sources :

Example 11 with ZookeeperDiscoverySpi

use of org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi in project ignite by apache.

the class ZookeeperDiscoveryTopologyChangeAndReconnectTest method testPing.

/**
 * @throws Exception If failed.
 */
@Test
public void testPing() throws Exception {
    sesTimeout = 5000;
    startGrids(3);
    final ZookeeperDiscoverySpi spi = helper.waitSpi(getTestIgniteInstanceName(1), spis);
    final UUID nodeId = ignite(2).cluster().localNode().id();
    IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Runnable() {

        @Override
        public void run() {
            assertTrue(spi.pingNode(nodeId));
        }
    }, 32, "ping");
    fut.get();
    fut = GridTestUtils.runMultiThreadedAsync(new Runnable() {

        @Override
        public void run() {
            spi.pingNode(nodeId);
        }
    }, 32, "ping");
    U.sleep(100);
    stopGrid(2);
    fut.get();
    fut = GridTestUtils.runMultiThreadedAsync(new Runnable() {

        @Override
        public void run() {
            assertFalse(spi.pingNode(nodeId));
        }
    }, 32, "ping");
    fut.get();
}
Also used : ZookeeperDiscoverySpi(org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi) UUID(java.util.UUID) GridCacheAbstractFullApiSelfTest(org.apache.ignite.internal.processors.cache.GridCacheAbstractFullApiSelfTest) Test(org.junit.Test)

Example 12 with ZookeeperDiscoverySpi

use of org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi in project ignite by apache.

the class ZookeeperDiscoveryTopologyChangeAndReconnectTest method reconnectClientNodes.

/**
 * Reconnect client node.
 *
 * @param log  Logger.
 * @param clients Clients.
 * @param closeSock {@code True} to simulate reconnect by closing zk client's socket.
 * @throws Exception If failed.
 */
private static void reconnectClientNodes(final IgniteLogger log, List<Ignite> clients, boolean closeSock) throws Exception {
    final CountDownLatch disconnectLatch = new CountDownLatch(clients.size());
    final CountDownLatch reconnectLatch = new CountDownLatch(clients.size());
    IgnitePredicate<Event> p = new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            if (evt.type() == EVT_CLIENT_NODE_DISCONNECTED) {
                log.info("Disconnected: " + evt);
                disconnectLatch.countDown();
            } else if (evt.type() == EVT_CLIENT_NODE_RECONNECTED) {
                log.info("Reconnected: " + evt);
                reconnectLatch.countDown();
            }
            return true;
        }
    };
    List<String> zkNodes = new ArrayList<>();
    for (Ignite client : clients) {
        client.events().localListen(p, EVT_CLIENT_NODE_DISCONNECTED, EVT_CLIENT_NODE_RECONNECTED);
        zkNodes.add(ZookeeperDiscoverySpiTestHelper.aliveZkNodePath(client));
    }
    long timeout = 15_000;
    if (closeSock) {
        for (Ignite client : clients) {
            ZookeeperDiscoverySpi spi = (ZookeeperDiscoverySpi) client.configuration().getDiscoverySpi();
            ZkTestClientCnxnSocketNIO.forNode(client.name()).closeSocket(true);
            timeout = Math.max(timeout, (long) (spi.getSessionTimeout() * 1.5f));
        }
    } else {
        /*
             * Use hack to simulate session expire without waiting session timeout:
             * create and close ZooKeeper with the same session ID as ignite node's ZooKeeper.
             */
        List<ZooKeeper> dummyClients = new ArrayList<>();
        for (Ignite client : clients) {
            ZookeeperDiscoverySpi spi = (ZookeeperDiscoverySpi) client.configuration().getDiscoverySpi();
            ZooKeeper zk = ZookeeperDiscoverySpiTestHelper.zkClient(spi);
            for (String s : spi.getZkConnectionString().split(",")) {
                try {
                    ZooKeeper dummyZk = new ZooKeeper(s, 10_000, null, zk.getSessionId(), zk.getSessionPasswd());
                    dummyZk.exists("/a", false);
                    dummyClients.add(dummyZk);
                    break;
                } catch (Exception e) {
                    log.warning("Can't connect to server " + s + " [err=" + e + ']');
                }
            }
        }
        for (ZooKeeper zk : dummyClients) zk.close();
    }
    ZookeeperDiscoverySpiTestHelper.waitNoAliveZkNodes(log, ((ZookeeperDiscoverySpi) clients.get(0).configuration().getDiscoverySpi()).getZkConnectionString(), zkNodes, timeout);
    if (closeSock) {
        for (Ignite client : clients) ZkTestClientCnxnSocketNIO.forNode(client.name()).allowConnect();
    }
    ZookeeperDiscoverySpiTestHelper.waitReconnectEvent(log, disconnectLatch);
    ZookeeperDiscoverySpiTestHelper.waitReconnectEvent(log, reconnectLatch);
    for (Ignite client : clients) client.events().stopLocalListen(p);
}
Also used : IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) ArrayList(java.util.ArrayList) ZookeeperDiscoverySpi(org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) ZooKeeper(org.apache.zookeeper.ZooKeeper) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite)

Example 13 with ZookeeperDiscoverySpi

use of org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi in project ignite by apache.

the class ZookeeperDiscoveryCommunicationFailureTest method testCommunicationFailureResolve_ConcurrentDiscoveyEvents.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
@Test
public void testCommunicationFailureResolve_ConcurrentDiscoveyEvents() throws Exception {
    sesTimeout = 5000;
    commFailureRslvr = NoOpCommunicationFailureResolver.FACTORY;
    final int INIT_NODES = 5;
    startGridsMultiThreaded(INIT_NODES);
    final CyclicBarrier b = new CyclicBarrier(4);
    GridCompoundFuture<?, ?> fut = new GridCompoundFuture<>();
    final AtomicBoolean stop = new AtomicBoolean();
    fut.add((IgniteInternalFuture) GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            b.await();
            ThreadLocalRandom rnd = ThreadLocalRandom.current();
            for (int i = 0; i < 10; i++) {
                startGrid(i + INIT_NODES);
                // noinspection BusyWait
                Thread.sleep(rnd.nextLong(1000) + 10);
                if (stop.get())
                    break;
            }
            return null;
        }
    }, "test-node-start"));
    fut.add((IgniteInternalFuture) GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            b.await();
            ThreadLocalRandom rnd = ThreadLocalRandom.current();
            while (!stop.get()) {
                startGrid(100);
                // noinspection BusyWait
                Thread.sleep(rnd.nextLong(1000) + 10);
                stopGrid(100);
                // noinspection BusyWait
                Thread.sleep(rnd.nextLong(1000) + 10);
            }
            return null;
        }
    }, "test-node-restart"));
    fut.add((IgniteInternalFuture) GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            b.await();
            ThreadLocalRandom rnd = ThreadLocalRandom.current();
            int idx = 0;
            while (!stop.get()) {
                CacheConfiguration ccfg = new CacheConfiguration("c-" + idx++);
                ccfg.setBackups(rnd.nextInt(5));
                ignite(rnd.nextInt(INIT_NODES)).createCache(ccfg);
                // noinspection BusyWait
                Thread.sleep(rnd.nextLong(1000) + 10);
                ignite(rnd.nextInt(INIT_NODES)).destroyCache(ccfg.getName());
                // noinspection BusyWait
                Thread.sleep(rnd.nextLong(1000) + 10);
            }
            return null;
        }
    }, "test-create-cache"));
    fut.add((IgniteInternalFuture) GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            try {
                b.await();
                ThreadLocalRandom rnd = ThreadLocalRandom.current();
                for (int i = 0; i < 5; i++) {
                    info("resolveCommunicationFailure: " + i);
                    ZookeeperDiscoverySpi spi = spi(ignite(rnd.nextInt(INIT_NODES)));
                    spi.resolveCommunicationFailure(ignite(rnd.nextInt(INIT_NODES)).cluster().localNode(), new Exception("test"));
                }
                return null;
            } finally {
                stop.set(true);
            }
        }
    }, 5, "test-resolve-failure"));
    fut.markInitialized();
    fut.get();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ZookeeperDiscoverySpi(org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) CyclicBarrier(java.util.concurrent.CyclicBarrier) Test(org.junit.Test)

Example 14 with ZookeeperDiscoverySpi

use of org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi in project ignite by apache.

the class ZookeeperDiscoveryCommunicationFailureTest method testNoOpCommunicationErrorResolve_5.

/**
 * Tests that nodes join is delayed while resolve is in progress.
 *
 * @throws Exception If failed.
 */
@Test
public void testNoOpCommunicationErrorResolve_5() throws Exception {
    testCommSpi = true;
    sesTimeout = 2000;
    commFailureRslvr = NoOpCommunicationFailureResolver.FACTORY;
    startGrid(0);
    startGridsMultiThreaded(1, 3);
    ZkTestCommunicationSpi commSpi = ZkTestCommunicationSpi.testSpi(ignite(3));
    commSpi.pingStartLatch = new CountDownLatch(1);
    commSpi.pingLatch = new CountDownLatch(1);
    IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Object>() {

        @Override
        public Object call() {
            ZookeeperDiscoverySpi spi = spi(ignite(1));
            spi.resolveCommunicationFailure(ignite(2).cluster().localNode(), new Exception("test"));
            return null;
        }
    });
    assertTrue(commSpi.pingStartLatch.await(10, SECONDS));
    try {
        assertFalse(fut.isDone());
        final AtomicInteger nodeIdx = new AtomicInteger(3);
        IgniteInternalFuture<?> startFut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                startGrid(nodeIdx.incrementAndGet());
                return null;
            }
        }, 3, "start-node");
        U.sleep(1000);
        assertFalse(startFut.isDone());
        assertEquals(4, ignite(0).cluster().nodes().size());
        commSpi.pingLatch.countDown();
        startFut.get();
        fut.get();
        waitForTopology(7);
    } finally {
        commSpi.pingLatch.countDown();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ZookeeperDiscoverySpi(org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) Test(org.junit.Test)

Example 15 with ZookeeperDiscoverySpi

use of org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi in project ignite by apache.

the class ZookeeperDiscoveryCommunicationFailureTest method testDefaultCommunicationFailureResolver1.

/**
 * @throws Exception If failed.
 */
@Test
public void testDefaultCommunicationFailureResolver1() throws Exception {
    testCommSpi = true;
    sesTimeout = 5000;
    startGrids(3);
    ZkTestCommunicationSpi.testSpi(ignite(0)).initCheckResult(3, 0, 1);
    ZkTestCommunicationSpi.testSpi(ignite(1)).initCheckResult(3, 0, 1);
    ZkTestCommunicationSpi.testSpi(ignite(2)).initCheckResult(3, 2);
    UUID killedId = nodeId(2);
    assertNotNull(ignite(0).cluster().node(killedId));
    ZookeeperDiscoverySpi spi = spi(ignite(0));
    spi.resolveCommunicationFailure(spi.getNode(ignite(1).cluster().localNode().id()), new Exception("test"));
    waitForTopology(2);
    assertNull(ignite(0).cluster().node(killedId));
}
Also used : ZookeeperDiscoverySpi(org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi) UUID(java.util.UUID) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) Test(org.junit.Test)

Aggregations

ZookeeperDiscoverySpi (org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi)21 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)13 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)12 Test (org.junit.Test)10 Ignite (org.apache.ignite.Ignite)9 UUID (java.util.UUID)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)4 ArrayList (java.util.ArrayList)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 ZkTestClientCnxnSocketNIO (org.apache.zookeeper.ZkTestClientCnxnSocketNIO)3 HashMap (java.util.HashMap)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)2 Event (org.apache.ignite.events.Event)2 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)2 IgnitePredicate (org.apache.ignite.lang.IgnitePredicate)2 BitSet (java.util.BitSet)1