Search in sources :

Example 21 with ZookeeperException

use of org.bboxdb.distribution.zookeeper.ZookeeperException in project bboxdb by jnidzwetzki.

the class TestRegionSyncer method testMerge.

@Test(timeout = 10000)
public void testMerge() throws ZookeeperException, InterruptedException {
    final DistributionRegionSyncer distributionRegionSyncer = buildSyncer();
    final DistributionRegion root = distributionRegionSyncer.getRootNode();
    createSplittedRoot(distributionRegionSyncer, root);
    // Delete child 1
    System.out.println("=== Delete child 1");
    final CountDownLatch deleteLatch1 = new CountDownLatch(1);
    final DistributionRegionCallback callback1 = (e, r) -> {
        if (root.getAllChildren().size() == 1) {
            deleteLatch1.countDown();
        }
    };
    distributionRegionSyncer.registerCallback(callback1);
    distributionRegionAdapter.deleteChild(root.getChildNumber(1));
    deleteLatch1.await();
    distributionRegionSyncer.unregisterCallback(callback1);
    Assert.assertEquals(1, root.getAllChildren().size());
    // Delete child 2
    System.out.println("=== Delete child 2");
    final CountDownLatch deleteLatch2 = new CountDownLatch(1);
    final DistributionRegionCallback callback2 = (e, r) -> {
        if (root.getAllChildren().size() == 0) {
            deleteLatch2.countDown();
        }
    };
    distributionRegionSyncer.registerCallback(callback2);
    distributionRegionAdapter.deleteChild(root.getChildNumber(0));
    deleteLatch2.await();
    distributionRegionSyncer.unregisterCallback(callback2);
    Assert.assertEquals(0, root.getAllChildren().size());
}
Also used : DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) ZookeeperClientFactory(org.bboxdb.distribution.zookeeper.ZookeeperClientFactory) SpacePartitionerContext(org.bboxdb.distribution.partitioner.SpacePartitionerContext) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) Set(java.util.Set) DistributionGroupConfigurationBuilder(org.bboxdb.storage.entity.DistributionGroupConfigurationBuilder) Test(org.junit.Test) DistributionRegionState(org.bboxdb.distribution.partitioner.DistributionRegionState) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) BoundingBox(org.bboxdb.commons.math.BoundingBox) CountDownLatch(java.util.concurrent.CountDownLatch) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionRegionEvent(org.bboxdb.distribution.region.DistributionRegionEvent) BBoxDBException(org.bboxdb.misc.BBoxDBException) DistributionGroupAdapter(org.bboxdb.distribution.zookeeper.DistributionGroupAdapter) DistributionRegionSyncer(org.bboxdb.distribution.region.DistributionRegionSyncer) DistributionRegionAdapter(org.bboxdb.distribution.zookeeper.DistributionRegionAdapter) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) Assert(org.junit.Assert) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) Before(org.junit.Before) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) CountDownLatch(java.util.concurrent.CountDownLatch) DistributionRegionSyncer(org.bboxdb.distribution.region.DistributionRegionSyncer) Test(org.junit.Test)

Example 22 with ZookeeperException

use of org.bboxdb.distribution.zookeeper.ZookeeperException in project bboxdb by jnidzwetzki.

the class TestRegionSyncer method testSplit.

@Test(timeout = 10000)
public void testSplit() throws ZookeeperException, InterruptedException {
    final DistributionRegionSyncer distributionRegionSyncer = buildSyncer();
    final DistributionRegion root = distributionRegionSyncer.getRootNode();
    final String fullname = createSplittedRoot(distributionRegionSyncer, root);
    System.out.println("==== Creating subchild");
    final DistributionRegion level1Child = root.getChildNumber(0);
    final BoundingBox leftBoundingBoxChild = level1Child.getConveringBox().splitAndGetLeft(0, 1, true);
    final CountDownLatch latchLevel1 = new CountDownLatch(1);
    final String level1ChildPath = distributionRegionAdapter.getZookeeperPathForDistributionRegion(level1Child);
    final DistributionRegionCallback level1Callback = (e, r) -> {
        if (root.getAllChildren().size() == 3) {
            latchLevel1.countDown();
        }
    };
    distributionRegionSyncer.registerCallback(level1Callback);
    distributionRegionAdapter.createNewChild(level1ChildPath, 0, leftBoundingBoxChild, fullname);
    latchLevel1.await();
    distributionRegionSyncer.unregisterCallback(level1Callback);
    Assert.assertTrue(root.getChildNumber(0).getChildNumber(0) != null);
    Assert.assertEquals(0, root.getRegionId());
    Assert.assertEquals(1, root.getChildNumber(0).getRegionId());
    Assert.assertEquals(3, root.getChildNumber(0).getChildNumber(0).getRegionId());
    Assert.assertEquals(3, root.getAllChildren().size());
    Assert.assertEquals(0, root.getLevel());
    Assert.assertEquals(1, level1Child.getLevel());
    Assert.assertEquals(2, root.getChildNumber(0).getChildNumber(0).getLevel());
    // Reread data from zookeeper
    System.out.println("== clear in memory data");
    distributionRegionSyncer.clear();
    final DistributionRegion root2 = distributionRegionSyncer.getRootNode();
    Assert.assertTrue(root2.getChildNumber(0).getChildNumber(0) != null);
    Assert.assertEquals(0, root2.getRegionId());
    Assert.assertEquals(1, root2.getChildNumber(0).getRegionId());
    Assert.assertEquals(3, root2.getChildNumber(0).getChildNumber(0).getRegionId());
    Assert.assertEquals(3, root2.getAllChildren().size());
    Assert.assertEquals(0, root2.getLevel());
    Assert.assertEquals(2, root2.getChildNumber(0).getChildNumber(0).getLevel());
}
Also used : DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) ZookeeperClientFactory(org.bboxdb.distribution.zookeeper.ZookeeperClientFactory) SpacePartitionerContext(org.bboxdb.distribution.partitioner.SpacePartitionerContext) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) Set(java.util.Set) DistributionGroupConfigurationBuilder(org.bboxdb.storage.entity.DistributionGroupConfigurationBuilder) Test(org.junit.Test) DistributionRegionState(org.bboxdb.distribution.partitioner.DistributionRegionState) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) BoundingBox(org.bboxdb.commons.math.BoundingBox) CountDownLatch(java.util.concurrent.CountDownLatch) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionRegionEvent(org.bboxdb.distribution.region.DistributionRegionEvent) BBoxDBException(org.bboxdb.misc.BBoxDBException) DistributionGroupAdapter(org.bboxdb.distribution.zookeeper.DistributionGroupAdapter) DistributionRegionSyncer(org.bboxdb.distribution.region.DistributionRegionSyncer) DistributionRegionAdapter(org.bboxdb.distribution.zookeeper.DistributionRegionAdapter) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) Assert(org.junit.Assert) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) Before(org.junit.Before) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BoundingBox(org.bboxdb.commons.math.BoundingBox) CountDownLatch(java.util.concurrent.CountDownLatch) DistributionRegionSyncer(org.bboxdb.distribution.region.DistributionRegionSyncer) Test(org.junit.Test)

Example 23 with ZookeeperException

use of org.bboxdb.distribution.zookeeper.ZookeeperException in project bboxdb by jnidzwetzki.

the class TestRegionSyncer method testChangeState2.

@Test(timeout = 10000)
public void testChangeState2() throws InterruptedException, ZookeeperException {
    final DistributionRegionSyncer distributionRegionSyncer = buildSyncer();
    final DistributionRegion root = distributionRegionSyncer.getRootNode();
    createSplittedRoot(distributionRegionSyncer, root);
    final CountDownLatch latch = new CountDownLatch(1);
    final DistributionRegionCallback callback = (e, r) -> {
        if (r == root.getChildNumber(1) && r.getState() == DistributionRegionState.MERGING) {
            latch.countDown();
        }
    };
    distributionRegionSyncer.registerCallback(callback);
    distributionRegionAdapter.setStateForDistributionRegion(root.getChildNumber(0), DistributionRegionState.MERGING);
    distributionRegionAdapter.setStateForDistributionRegion(root.getChildNumber(1), DistributionRegionState.MERGING);
    latch.await();
    distributionRegionSyncer.unregisterCallback(callback);
    Assert.assertEquals(2, root.getDirectChildren().size());
    Assert.assertEquals(DistributionRegionState.MERGING, root.getChildNumber(0).getState());
    Assert.assertEquals(DistributionRegionState.MERGING, root.getChildNumber(1).getState());
    // Reread state from zookeeper
    System.out.println("== clear in memory data");
    distributionRegionSyncer.clear();
    final DistributionRegion root2 = distributionRegionSyncer.getRootNode();
    Assert.assertEquals(2, root2.getDirectChildren().size());
    Assert.assertEquals(DistributionRegionState.MERGING, root2.getChildNumber(0).getState());
    Assert.assertEquals(DistributionRegionState.MERGING, root2.getChildNumber(1).getState());
}
Also used : DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) ZookeeperClientFactory(org.bboxdb.distribution.zookeeper.ZookeeperClientFactory) SpacePartitionerContext(org.bboxdb.distribution.partitioner.SpacePartitionerContext) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) Set(java.util.Set) DistributionGroupConfigurationBuilder(org.bboxdb.storage.entity.DistributionGroupConfigurationBuilder) Test(org.junit.Test) DistributionRegionState(org.bboxdb.distribution.partitioner.DistributionRegionState) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) BoundingBox(org.bboxdb.commons.math.BoundingBox) CountDownLatch(java.util.concurrent.CountDownLatch) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionRegionEvent(org.bboxdb.distribution.region.DistributionRegionEvent) BBoxDBException(org.bboxdb.misc.BBoxDBException) DistributionGroupAdapter(org.bboxdb.distribution.zookeeper.DistributionGroupAdapter) DistributionRegionSyncer(org.bboxdb.distribution.region.DistributionRegionSyncer) DistributionRegionAdapter(org.bboxdb.distribution.zookeeper.DistributionRegionAdapter) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) Assert(org.junit.Assert) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) Before(org.junit.Before) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) CountDownLatch(java.util.concurrent.CountDownLatch) DistributionRegionSyncer(org.bboxdb.distribution.region.DistributionRegionSyncer) Test(org.junit.Test)

Example 24 with ZookeeperException

use of org.bboxdb.distribution.zookeeper.ZookeeperException in project bboxdb by jnidzwetzki.

the class TestRegionSyncer method testEventTypes.

@Test(timeout = 10000)
public void testEventTypes() throws InterruptedException, ZookeeperException {
    final DistributionRegionSyncer distributionRegionSyncer = buildSyncer();
    final DistributionRegion root = distributionRegionSyncer.getRootNode();
    // Root node is changed on add and remove children
    final CountDownLatch changedLatch = new CountDownLatch(2);
    final DistributionRegionCallback rootNodeChangedCallback = (e, r) -> {
        if (e == DistributionRegionEvent.CHANGED && r.equals(root)) {
            changedLatch.countDown();
        }
    };
    distributionRegionSyncer.registerCallback(rootNodeChangedCallback);
    // Two new children will be added
    final CountDownLatch addedLatch = new CountDownLatch(2);
    final DistributionRegionCallback adddedCallback = (e, r) -> {
        if (e == DistributionRegionEvent.ADDED && !r.equals(root)) {
            addedLatch.countDown();
        }
    };
    distributionRegionSyncer.registerCallback(adddedCallback);
    // Two children will be removed
    final CountDownLatch removedLatch = new CountDownLatch(2);
    final DistributionRegionCallback removedCallback = (e, r) -> {
        if (e == DistributionRegionEvent.REMOVED && !r.equals(root)) {
            removedLatch.countDown();
        }
    };
    distributionRegionSyncer.registerCallback(removedCallback);
    // Mutate tree
    createSplittedRoot(distributionRegionSyncer, root);
    // Wait
    System.out.println("=== Wait for added latch");
    addedLatch.await();
    distributionRegionAdapter.deleteChild(root.getChildNumber(0));
    distributionRegionAdapter.deleteChild(root.getChildNumber(1));
    System.out.println("=== Wait for removed latch");
    removedLatch.await();
    System.out.println("=== Wait for changed latch");
    changedLatch.await();
    distributionRegionSyncer.unregisterCallback(rootNodeChangedCallback);
    distributionRegionSyncer.unregisterCallback(adddedCallback);
    distributionRegionSyncer.unregisterCallback(removedCallback);
}
Also used : DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) ZookeeperClientFactory(org.bboxdb.distribution.zookeeper.ZookeeperClientFactory) SpacePartitionerContext(org.bboxdb.distribution.partitioner.SpacePartitionerContext) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) Set(java.util.Set) DistributionGroupConfigurationBuilder(org.bboxdb.storage.entity.DistributionGroupConfigurationBuilder) Test(org.junit.Test) DistributionRegionState(org.bboxdb.distribution.partitioner.DistributionRegionState) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) BoundingBox(org.bboxdb.commons.math.BoundingBox) CountDownLatch(java.util.concurrent.CountDownLatch) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionRegionEvent(org.bboxdb.distribution.region.DistributionRegionEvent) BBoxDBException(org.bboxdb.misc.BBoxDBException) DistributionGroupAdapter(org.bboxdb.distribution.zookeeper.DistributionGroupAdapter) DistributionRegionSyncer(org.bboxdb.distribution.region.DistributionRegionSyncer) DistributionRegionAdapter(org.bboxdb.distribution.zookeeper.DistributionRegionAdapter) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) Assert(org.junit.Assert) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) Before(org.junit.Before) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) CountDownLatch(java.util.concurrent.CountDownLatch) DistributionRegionSyncer(org.bboxdb.distribution.region.DistributionRegionSyncer) Test(org.junit.Test)

Example 25 with ZookeeperException

use of org.bboxdb.distribution.zookeeper.ZookeeperException in project bboxdb by jnidzwetzki.

the class GuiModel method updateDistributionRegion.

/**
 * Update the distribution region
 *
 * @throws ZookeeperException
 * @throws ZookeeperNotFoundException
 */
public void updateDistributionRegion() throws ZookeeperException, ZookeeperNotFoundException {
    logger.info("Reread distribution group: {}", distributionGroup);
    if (distributionGroup == null) {
        return;
    }
    // Show wait cursor
    SwingUtilities.invokeLater(() -> {
        if (bboxdbGui.getGlassPane() != null) {
            bboxdbGui.getGlassPane().setVisible(true);
            bboxdbGui.getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        }
    });
    // Read distribution group async
    (new Thread(() -> {
        unregisterTreeChangeListener();
        if (distributionGroup == null) {
            spacePartitioner = null;
            return;
        }
        try {
            spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
            final DistributionGroupConfiguration config = DistributionGroupConfigurationCache.getInstance().getDistributionGroupConfiguration(distributionGroup);
            spacePartitioner.registerCallback(GuiModel.this);
            final StringBuilder sb = new StringBuilder();
            sb.append("Cluster name: " + getClustername());
            sb.append(", Replication factor: " + config.getReplicationFactor());
            sb.append(", Dimensions: " + config.getDimensions());
            sb.append(", Space partitioner: " + config.getSpacePartitioner());
            bboxdbGui.getStatusLabel().setText(sb.toString());
            logger.info("Read distribution group {} done", distributionGroup);
            // Reset cursor
            SwingUtilities.invokeLater(() -> {
                updateModel();
                if (bboxdbGui.getGlassPane() != null) {
                    final Cursor defaultCursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
                    bboxdbGui.getGlassPane().setCursor(defaultCursor);
                    bboxdbGui.getGlassPane().setVisible(false);
                }
            });
        } catch (Exception e) {
            logger.warn("Got exception", e);
        }
    })).start();
}
Also used : DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) Cursor(java.awt.Cursor) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException)

Aggregations

ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)37 BBoxDBException (org.bboxdb.misc.BBoxDBException)24 BoundingBox (org.bboxdb.commons.math.BoundingBox)17 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)17 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)16 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)13 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)13 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)11 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)10 ZookeeperClientFactory (org.bboxdb.distribution.zookeeper.ZookeeperClientFactory)10 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)9 DistributionRegionState (org.bboxdb.distribution.partitioner.DistributionRegionState)9 DistributionRegionCallback (org.bboxdb.distribution.region.DistributionRegionCallback)9 DistributionRegionAdapter (org.bboxdb.distribution.zookeeper.DistributionRegionAdapter)9 DistributionGroupConfigurationBuilder (org.bboxdb.storage.entity.DistributionGroupConfigurationBuilder)9 Assert (org.junit.Assert)9 Test (org.junit.Test)9 Set (java.util.Set)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 SpacePartitionerContext (org.bboxdb.distribution.partitioner.SpacePartitionerContext)8