Search in sources :

Example 26 with DistributionRegion

use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.

the class TestDistributionGroup method testLeafNode.

/**
 * Test a distribution region with only one level
 */
@Test(timeout = 60000)
public void testLeafNode() {
    final DistributionRegion distributionRegion = createDistributionGroup(2);
    Assert.assertTrue(distributionRegion.isLeafRegion());
    Assert.assertEquals(0, distributionRegion.getLevel());
    Assert.assertEquals(1, distributionRegion.getTotalLevel());
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) Test(org.junit.Test)

Example 27 with DistributionRegion

use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.

the class StatisticsUpdateRunnable method updateRegionStatistics.

/**
 * Update region statistics
 *
 * @param distributionGroup
 * @param regionId
 * @throws ZookeeperException
 * @throws StorageManagerException
 * @throws InterruptedException
 */
private void updateRegionStatistics(final String distributionGroup, final long regionId) throws BBoxDBException, ZookeeperException, StorageManagerException, InterruptedException {
    final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
    final DistributionRegion distributionRegion = spacePartitioner.getRootNode();
    final DistributionRegion regionToSplit = DistributionRegionHelper.getDistributionRegionForNamePrefix(distributionRegion, regionId);
    final long totalSize = TupleStoreUtil.getSizeOfDistributionGroupAndRegionId(storageRegistry, distributionGroup, regionId);
    final long totalTuples = TupleStoreUtil.getTuplesInDistributionGroupAndRegionId(storageRegistry, distributionGroup, regionId);
    final long totalSizeInMb = totalSize / (1024 * 1024);
    logger.info("Updating region statistics: {} / {}. Size in MB: {} / Tuples: {}", distributionGroup, regionId, totalSizeInMb, totalTuples);
    regionAdapter.updateRegionStatistics(regionToSplit, ZookeeperClientFactory.getLocalInstanceName(), totalSizeInMb, totalTuples);
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 28 with DistributionRegion

use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.

the class DistributionRegionAdapter method getNodeForPath.

/**
 * Get the node for the given zookeeper path
 * @param distributionRegion
 * @param path
 * @return
 */
public DistributionRegion getNodeForPath(final DistributionRegion distributionRegion, final String path) {
    final String name = distributionRegion.getDistributionGroupName();
    final String distributionGroupPath = zookeeperClient.getDistributionGroupAdapter().getDistributionGroupRootElementPath(name);
    if (!path.startsWith(distributionGroupPath)) {
        throw new IllegalArgumentException("Path " + path + " does not start with " + distributionGroupPath);
    }
    final StringBuilder sb = new StringBuilder(path);
    sb.delete(0, distributionGroupPath.length());
    DistributionRegion resultElement = distributionRegion;
    final StringTokenizer tokenizer = new StringTokenizer(sb.toString(), "/");
    while (tokenizer.hasMoreTokens()) {
        // Element is removed
        if (resultElement == null) {
            return null;
        }
        final String token = tokenizer.nextToken();
        if (!token.startsWith(ZookeeperNodeNames.NAME_CHILDREN)) {
            throw new IllegalArgumentException("Unable to decode " + sb);
        }
        final String[] split = token.split("-");
        final int childNumber = Integer.parseInt(split[1]);
        if (resultElement.getDirectChildren().size() <= childNumber) {
            return null;
        }
        resultElement = resultElement.getDirectChildren().get(childNumber);
    }
    return resultElement;
}
Also used : StringTokenizer(java.util.StringTokenizer) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion)

Example 29 with DistributionRegion

use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.

the class RegionMergeHelper method getTotalRegionSize.

/**
 * Get the total size of the child regions
 * @param region
 * @return
 */
public static OptionalDouble getTotalRegionSize(final List<DistributionRegion> sources) {
    if (sources.isEmpty()) {
        return OptionalDouble.empty();
    }
    // Update statistics
    sources.forEach(r -> StatisticsHelper.getAndUpdateStatistics(r));
    for (final DistributionRegion region : sources) {
        if (!StatisticsHelper.isEnoughHistoryDataAvailable(region.getIdentifier())) {
            return OptionalDouble.empty();
        }
    }
    // Get statistics
    final double value = sources.stream().filter(Objects::nonNull).mapToDouble(r -> StatisticsHelper.getAverageStatistics(r.getIdentifier())).sum();
    return OptionalDouble.of(value);
}
Also used : SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner) ZookeeperClientFactory(org.bboxdb.distribution.zookeeper.ZookeeperClientFactory) Logger(org.slf4j.Logger) DistributionGroupConfigurationCache(org.bboxdb.distribution.DistributionGroupConfigurationCache) OptionalDouble(java.util.OptionalDouble) LoggerFactory(org.slf4j.LoggerFactory) DistributionRegionState(org.bboxdb.distribution.partitioner.DistributionRegionState) Collectors(java.util.stream.Collectors) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) ArrayList(java.util.ArrayList) Objects(java.util.Objects) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) List(java.util.List) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitionerCache(org.bboxdb.distribution.partitioner.SpacePartitionerCache) DistributionRegionAdapter(org.bboxdb.distribution.zookeeper.DistributionRegionAdapter) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) Objects(java.util.Objects)

Example 30 with DistributionRegion

use of org.bboxdb.distribution.region.DistributionRegion 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)

Aggregations

DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)91 Test (org.junit.Test)45 BBoxDBException (org.bboxdb.misc.BBoxDBException)34 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)33 BoundingBox (org.bboxdb.commons.math.BoundingBox)27 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)23 ArrayList (java.util.ArrayList)17 List (java.util.List)17 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)16 DistributionRegionAdapter (org.bboxdb.distribution.zookeeper.DistributionRegionAdapter)15 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)15 KDtreeSpacePartitioner (org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner)14 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)11 ZookeeperClientFactory (org.bboxdb.distribution.zookeeper.ZookeeperClientFactory)11 DistributionRegionState (org.bboxdb.distribution.partitioner.DistributionRegionState)10 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)10 DistributionRegionSyncer (org.bboxdb.distribution.region.DistributionRegionSyncer)10 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)10 RoutingHop (org.bboxdb.network.routing.RoutingHop)10 DistributionGroupConfigurationBuilder (org.bboxdb.storage.entity.DistributionGroupConfigurationBuilder)10