Search in sources :

Example 1 with KDtreeSpacePartitioner

use of org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner in project bboxdb by jnidzwetzki.

the class TestZookeeperIntegration method testSystemCheckpoint2.

/**
 * Test the set and get checkpoint methods
 * @throws Exception
 */
@Test(timeout = 60000)
public void testSystemCheckpoint2() throws Exception {
    final BBoxDBInstance systemName1 = new BBoxDBInstance("192.168.1.10:5050");
    final BBoxDBInstance systemName2 = new BBoxDBInstance("192.168.1.20:5050");
    final KDtreeSpacePartitioner distributionGroupAdapter = (KDtreeSpacePartitioner) getSpacePartitioner();
    final DistributionRegion region = distributionGroupAdapter.getRootNode();
    distributionGroupAdapter.splitNode(region, 50);
    final DistributionRegion region1 = region.getDirectChildren().get(0);
    final String path1 = distributionRegionAdapter.getZookeeperPathForDistributionRegion(region1);
    final DistributionRegion region2 = region.getDirectChildren().get(1);
    final String path2 = distributionRegionAdapter.getZookeeperPathForDistributionRegion(region2);
    distributionRegionAdapter.addSystemToDistributionRegion(path1, systemName1);
    distributionRegionAdapter.addSystemToDistributionRegion(path1, systemName2);
    distributionRegionAdapter.addSystemToDistributionRegion(path2, systemName1);
    distributionRegionAdapter.addSystemToDistributionRegion(path2, systemName2);
    distributionRegionAdapter.setCheckpointForDistributionRegion(region1, systemName1, 1);
    distributionRegionAdapter.setCheckpointForDistributionRegion(region1, systemName2, 2);
    distributionRegionAdapter.setCheckpointForDistributionRegion(region2, systemName1, 3);
    distributionRegionAdapter.setCheckpointForDistributionRegion(region2, systemName2, 4);
    final long checkpoint1 = distributionRegionAdapter.getCheckpointForDistributionRegion(region1, systemName1);
    final long checkpoint2 = distributionRegionAdapter.getCheckpointForDistributionRegion(region1, systemName2);
    final long checkpoint3 = distributionRegionAdapter.getCheckpointForDistributionRegion(region2, systemName1);
    final long checkpoint4 = distributionRegionAdapter.getCheckpointForDistributionRegion(region2, systemName2);
    Assert.assertEquals(1, checkpoint1);
    Assert.assertEquals(2, checkpoint2);
    Assert.assertEquals(3, checkpoint3);
    Assert.assertEquals(4, checkpoint4);
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) KDtreeSpacePartitioner(org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner) Test(org.junit.Test)

Example 2 with KDtreeSpacePartitioner

use of org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner in project bboxdb by jnidzwetzki.

the class TestZookeeperIntegration method testNameprefix2.

/**
 * Test the generation of the nameprefix
 * @throws Exception
 */
@Test(timeout = 60000)
public void testNameprefix2() throws Exception {
    final KDtreeSpacePartitioner distributionGroupAdapter = (KDtreeSpacePartitioner) getSpacePartitioner();
    final DistributionRegion region = distributionGroupAdapter.getRootNode();
    distributionGroupAdapter.splitNode(region, 10);
    final DistributionRegion leftChild = region.getDirectChildren().get(0);
    final DistributionRegion rightChild = region.getDirectChildren().get(1);
    Assert.assertEquals(DistributionRegionState.REDISTRIBUTION_ACTIVE, leftChild.getState());
    Assert.assertEquals(DistributionRegionState.REDISTRIBUTION_ACTIVE, rightChild.getState());
    Assert.assertEquals(0, region.getRegionId());
    Assert.assertEquals(1, leftChild.getRegionId());
    Assert.assertEquals(2, rightChild.getRegionId());
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) KDtreeSpacePartitioner(org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner) Test(org.junit.Test)

Example 3 with KDtreeSpacePartitioner

use of org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner in project bboxdb by jnidzwetzki.

the class TestZookeeperIntegration method testPathDecodeAndEncode.

/**
 * Test the path decoding and encoding
 * @throws ZookeeperException
 * @throws BBoxDBException
 * @throws ZookeeperNotFoundException
 * @throws ResourceAllocationException
 */
@Test(timeout = 60000)
public void testPathDecodeAndEncode() throws ZookeeperException, BBoxDBException, ZookeeperNotFoundException, ResourceAllocationException {
    final KDtreeSpacePartitioner spacepartitionier = (KDtreeSpacePartitioner) getSpacePartitioner();
    final DistributionRegion level0 = spacepartitionier.getRootNode();
    spacepartitionier.splitNode(level0, 50);
    level0.makeChildsActive();
    // Level 1
    final DistributionRegion level1l = level0.getDirectChildren().get(0);
    spacepartitionier.splitNode(level1l, 40);
    level1l.makeChildsActive();
    final DistributionRegion level1r = level0.getDirectChildren().get(1);
    spacepartitionier.splitNode(level1r, 50);
    level1r.makeChildsActive();
    // Level 2
    final DistributionRegion level2ll = level1l.getDirectChildren().get(0);
    spacepartitionier.splitNode(level2ll, 30);
    level2ll.makeChildsActive();
    final DistributionRegion level2rl = level1r.getDirectChildren().get(0);
    spacepartitionier.splitNode(level2rl, 60);
    level2rl.makeChildsActive();
    final DistributionRegion level2lr = level1l.getDirectChildren().get(1);
    spacepartitionier.splitNode(level2lr, 30);
    level2lr.makeChildsActive();
    final DistributionRegion level2rr = level1r.getDirectChildren().get(1);
    spacepartitionier.splitNode(level2rr, 60);
    level2rr.makeChildsActive();
    // Level 3
    final DistributionRegion level3lll = level2ll.getDirectChildren().get(0);
    spacepartitionier.splitNode(level3lll, 35);
    level3lll.makeChildsActive();
    final String path0 = distributionRegionAdapter.getZookeeperPathForDistributionRegion(level0);
    final String path1 = distributionRegionAdapter.getZookeeperPathForDistributionRegion(level1l);
    final String path2 = distributionRegionAdapter.getZookeeperPathForDistributionRegion(level1r);
    final String path3 = distributionRegionAdapter.getZookeeperPathForDistributionRegion(level2ll);
    final String path4 = distributionRegionAdapter.getZookeeperPathForDistributionRegion(level2rl);
    final String path5 = distributionRegionAdapter.getZookeeperPathForDistributionRegion(level2lr);
    final String path6 = distributionRegionAdapter.getZookeeperPathForDistributionRegion(level2rr);
    final String path7 = distributionRegionAdapter.getZookeeperPathForDistributionRegion(level3lll);
    Assert.assertEquals(level0, distributionRegionAdapter.getNodeForPath(level0, path0));
    Assert.assertEquals(level1l, distributionRegionAdapter.getNodeForPath(level0, path1));
    Assert.assertEquals(level1r, distributionRegionAdapter.getNodeForPath(level0, path2));
    Assert.assertEquals(level2ll, distributionRegionAdapter.getNodeForPath(level0, path3));
    Assert.assertEquals(level2rl, distributionRegionAdapter.getNodeForPath(level0, path4));
    Assert.assertEquals(level2lr, distributionRegionAdapter.getNodeForPath(level0, path5));
    Assert.assertEquals(level2rr, distributionRegionAdapter.getNodeForPath(level0, path6));
    Assert.assertEquals(level3lll, distributionRegionAdapter.getNodeForPath(level0, path7));
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) KDtreeSpacePartitioner(org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner) Test(org.junit.Test)

Example 4 with KDtreeSpacePartitioner

use of org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner in project bboxdb by jnidzwetzki.

the class TestKDtreeSpacePartitioner method testDistributionRegionSplitAndMerge.

/**
 * Test the split of a distribution region
 * @throws Exception
 */
@Test(timeout = 60000)
public void testDistributionRegionSplitAndMerge() throws Exception {
    final DistributionRegionAdapter distributionRegionAdapter = ZookeeperClientFactory.getZookeeperClient().getDistributionRegionAdapter();
    // Split and update
    System.out.println("---> Get space partitioner");
    final KDtreeSpacePartitioner spacePartitioner = (KDtreeSpacePartitioner) getSpacePartitioner();
    System.out.println("---> Get space partitioner - DONE");
    final DistributionRegion rootNode = spacePartitioner.getRootNode();
    System.out.println("---> Get root node - DONE");
    Assert.assertEquals(0, rootNode.getRegionId());
    Assert.assertEquals(TEST_GROUP, rootNode.getDistributionGroupName());
    final DistributionRegionState stateForDistributionRegion1 = distributionRegionAdapter.getStateForDistributionRegion(rootNode);
    Assert.assertEquals(DistributionRegionState.ACTIVE, stateForDistributionRegion1);
    System.out.println("--> Set split for node");
    spacePartitioner.splitNode(rootNode, 10);
    spacePartitioner.waitForSplitCompleteZookeeperCallback(rootNode, 2);
    final DistributionRegion firstChild = rootNode.getDirectChildren().get(0);
    Assert.assertEquals(10.0, firstChild.getConveringBox().getCoordinateHigh(0), DELTA);
    final DistributionRegionState stateForDistributionRegion2 = distributionRegionAdapter.getStateForDistributionRegion(rootNode);
    Assert.assertEquals(DistributionRegionState.SPLITTING, stateForDistributionRegion2);
    // Reread group from zookeeper
    final DistributionRegion newDistributionGroup = spacePartitioner.getRootNode();
    final DistributionRegion firstChildNew = newDistributionGroup.getDirectChildren().get(0);
    Assert.assertEquals(10.0, firstChildNew.getConveringBox().getCoordinateHigh(0), DELTA);
    final DistributionRegionState stateForDistributionRegion3 = distributionRegionAdapter.getStateForDistributionRegion(newDistributionGroup);
    Assert.assertEquals(DistributionRegionState.SPLITTING, stateForDistributionRegion3);
    Assert.assertEquals(1, rootNode.getDirectChildren().get(0).getRegionId());
    Assert.assertEquals(2, rootNode.getDirectChildren().get(1).getRegionId());
    // Delete children
    System.out.println("---> Calling prepare merge");
    spacePartitioner.prepareMerge(spacePartitioner.getRootNode().getDirectChildren(), spacePartitioner.getRootNode());
    System.out.println("---> Calling merge complete");
    spacePartitioner.mergeComplete(spacePartitioner.getRootNode().getDirectChildren(), spacePartitioner.getRootNode());
    final DistributionRegion newDistributionGroup2 = spacePartitioner.getRootNode();
    final DistributionRegionState stateForDistributionRegion4 = distributionRegionAdapter.getStateForDistributionRegion(newDistributionGroup2);
    Assert.assertEquals(DistributionRegionState.ACTIVE, stateForDistributionRegion4);
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionRegionState(org.bboxdb.distribution.partitioner.DistributionRegionState) DistributionRegionAdapter(org.bboxdb.distribution.zookeeper.DistributionRegionAdapter) KDtreeSpacePartitioner(org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner) Test(org.junit.Test)

Example 5 with KDtreeSpacePartitioner

use of org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner in project bboxdb by jnidzwetzki.

the class TestKDtreeSpacePartitioner method testDimensionsOfRootNode.

/**
 * Test the root node dimensions
 * @throws ZookeeperException
 * @throws InterruptedException
 * @throws ZookeeperNotFoundException
 * @throws BBoxDBException
 */
@Test(timeout = 60000)
public void testDimensionsOfRootNode() throws ZookeeperException, InterruptedException, ZookeeperNotFoundException, BBoxDBException {
    for (int i = 1; i < 2; i++) {
        createNewDistributionGroup(i);
        final KDtreeSpacePartitioner spacepartitionier = getSpacePartitioner();
        final DistributionRegion rootNode = spacepartitionier.getRootNode();
        Assert.assertEquals(i, rootNode.getConveringBox().getDimension());
    }
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) KDtreeSpacePartitioner(org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner) Test(org.junit.Test)

Aggregations

KDtreeSpacePartitioner (org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner)12 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)12 Test (org.junit.Test)12 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)2 List (java.util.List)1 OptionalDouble (java.util.OptionalDouble)1 DistributionRegionState (org.bboxdb.distribution.partitioner.DistributionRegionState)1 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)1 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)1 DistributionRegionAdapter (org.bboxdb.distribution.zookeeper.DistributionRegionAdapter)1 BBoxDBException (org.bboxdb.misc.BBoxDBException)1 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)1