Search in sources :

Example 1 with DistributionRegionAdapter

use of org.bboxdb.distribution.zookeeper.DistributionRegionAdapter 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 2 with DistributionRegionAdapter

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

the class RegionMerger method mergeRegion.

/**
 * Merge the given region
 * @param region
 * @param distributionGroupZookeeperAdapter
 * @param spacePartitioner
 * @param diskStorage
 */
public void mergeRegion(final List<DistributionRegion> source, final SpacePartitioner spacePartitioner, final TupleStoreManagerRegistry tupleStoreManagerRegistry) {
    assert (!source.isEmpty());
    logger.info("Performing merge for: {}", source.get(0).getIdentifier());
    final DistributionRegionAdapter distributionGroupZookeeperAdapter = ZookeeperClientFactory.getZookeeperClient().getDistributionRegionAdapter();
    DistributionRegion destination = null;
    try {
        destination = spacePartitioner.getDestinationForMerge(source);
        if (destination == null) {
            logger.error("Got null when calling getDestinationForMerge from space partitoner {}", source);
            return;
        }
        final String identifier = destination.getIdentifier();
        // Try to set region state to merging. If this fails, another node is already
        // merges the region
        final boolean setToMergeResult = distributionGroupZookeeperAdapter.setToSplitMerging(destination);
        if (!setToMergeResult) {
            logger.info("Unable to set state to split merge for region: {}, stopping merge", identifier);
            logger.info("Old state was {}", distributionGroupZookeeperAdapter.getStateForDistributionRegion(destination));
            return;
        }
        spacePartitioner.prepareMerge(source, destination);
        redistributeDataMerge(source, destination);
        spacePartitioner.mergeComplete(source, destination);
    } catch (Throwable e) {
        logger.warn("Got uncought exception during merge: " + source.get(0).getIdentifier(), e);
        handleMergeFailed(source, destination, spacePartitioner);
    }
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionRegionAdapter(org.bboxdb.distribution.zookeeper.DistributionRegionAdapter)

Example 3 with DistributionRegionAdapter

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

the class TupleStoreFlushZookeeperAdapter method accept.

@Override
public void accept(final TupleStoreName ssTableName, final Long flushTimestamp) {
    // Fetch the local instance
    final BBoxDBInstance localInstance = ZookeeperClientFactory.getLocalInstanceName();
    try {
        final String distributionGroup = ssTableName.getDistributionGroup();
        final SpacePartitioner spacepartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
        final DistributionRegion distributionGroupRoot = spacepartitioner.getRootNode();
        if (distributionGroupRoot == null) {
            logger.error("Root for {} is null, not executing callback", ssTableName);
            return;
        }
        final long regionId = ssTableName.getRegionId().getAsLong();
        final DistributionRegion distributionRegion = DistributionRegionHelper.getDistributionRegionForNamePrefix(distributionGroupRoot, regionId);
        logger.debug("Updating checkpoint for: {} to {}", ssTableName.getFullname(), flushTimestamp);
        final DistributionRegionAdapter distributionRegionAdapter = ZookeeperClientFactory.getZookeeperClient().getDistributionRegionAdapter();
        if (distributionRegionAdapter != null && distributionRegion != null) {
            distributionRegionAdapter.setCheckpointForDistributionRegion(distributionRegion, localInstance, flushTimestamp);
        }
    } catch (ZookeeperException | BBoxDBException e) {
        if (Thread.currentThread().isInterrupted()) {
            return;
        }
        logger.warn("Unable to find distribution region: ", e);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return;
    }
}
Also used : ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionRegionAdapter(org.bboxdb.distribution.zookeeper.DistributionRegionAdapter) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 4 with DistributionRegionAdapter

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

the class DistributionRegionComponent method addStatisticsToTooltip.

/**
 * Add the statistics to the tooltip
 * @param sb
 * @return
 * @throws ZookeeperException
 * @throws ZookeeperNotFoundException
 */
private Map<BBoxDBInstance, Map<String, Long>> addStatisticsToTooltip(final StringBuilder sb) throws ZookeeperException, ZookeeperNotFoundException {
    final DistributionRegionAdapter adapter = ZookeeperClientFactory.getZookeeperClient().getDistributionRegionAdapter();
    final Map<BBoxDBInstance, Map<String, Long>> statistics = adapter.getRegionStatistics(distributionRegion);
    for (final BBoxDBInstance instance : statistics.keySet()) {
        final Map<String, Long> statisticData = statistics.get(instance);
        sb.append("Node: ");
        sb.append(instance.toGUIString(guiModel.isScreenshotMode()));
        sb.append(" Tuples: ");
        sb.append(statisticData.get(ZookeeperNodeNames.NAME_STATISTICS_TOTAL_TUPLES));
        sb.append(", Size: ");
        sb.append(statisticData.get(ZookeeperNodeNames.NAME_STATISTICS_TOTAL_SIZE));
        sb.append(" MB <br>");
    }
    return statistics;
}
Also used : DistributionRegionAdapter(org.bboxdb.distribution.zookeeper.DistributionRegionAdapter) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) Map(java.util.Map)

Example 5 with DistributionRegionAdapter

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

the class CreateInitialPartitioning method run.

@Override
public void run() {
    final TupleFileReader tupleFile = new TupleFileReader(filename, format);
    final List<BoundingBox> samples = new ArrayList<>();
    tupleFile.addTupleListener(t -> {
        final BoundingBox polygonBoundingBox = t.getBoundingBox();
        samples.add(polygonBoundingBox);
    });
    try {
        tupleFile.processFile();
        final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
        final DistributionRegionAdapter adapter = ZookeeperClientFactory.getZookeeperClient().getDistributionRegionAdapter();
        while (getActiveRegions(spacePartitioner).size() < partitions) {
            logger.info("We have now {} of {} active partitons, executing split", getActiveRegions(spacePartitioner).size() < partitions);
            final List<DistributionRegion> activeRegions = getActiveRegions(spacePartitioner);
            final DistributionRegion regionToSplit = ListHelper.getElementRandom(activeRegions);
            logger.info("Splitting region {}", regionToSplit.getRegionId());
            final List<DistributionRegion> destination = spacePartitioner.splitRegion(regionToSplit, samples);
            spacePartitioner.splitComplete(regionToSplit, destination);
        }
        // Prevent merging of nodes
        for (DistributionRegion region : spacePartitioner.getRootNode().getAllChildren()) {
            adapter.setMergingSupported(region, false);
        }
    } catch (Exception e) {
        logger.error("Got an exception", e);
        System.exit(-1);
    }
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) TupleFileReader(org.bboxdb.tools.TupleFileReader) BoundingBox(org.bboxdb.commons.math.BoundingBox) ArrayList(java.util.ArrayList) DistributionRegionAdapter(org.bboxdb.distribution.zookeeper.DistributionRegionAdapter) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Aggregations

DistributionRegionAdapter (org.bboxdb.distribution.zookeeper.DistributionRegionAdapter)7 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)6 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)3 ArrayList (java.util.ArrayList)2 BoundingBox (org.bboxdb.commons.math.BoundingBox)2 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)2 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)2 BBoxDBException (org.bboxdb.misc.BBoxDBException)2 IOException (java.io.IOException)1 Map (java.util.Map)1 DistributionRegionState (org.bboxdb.distribution.partitioner.DistributionRegionState)1 KDtreeSpacePartitioner (org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner)1 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)1 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)1 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)1 CreateDistributionGroupRequest (org.bboxdb.network.packages.request.CreateDistributionGroupRequest)1 ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)1 SuccessResponse (org.bboxdb.network.packages.response.SuccessResponse)1 TupleFileReader (org.bboxdb.tools.TupleFileReader)1 Test (org.junit.Test)1