Search in sources :

Example 76 with BBoxDBInstance

use of org.bboxdb.distribution.membership.BBoxDBInstance in project bboxdb by jnidzwetzki.

the class DynamicgridSpacePartitioner method splitNode.

/**
 * Split the node at the given split point
 * @param regionToSplit
 * @param splitPosition
 * @throws BBoxDBException
 * @throws ResourceAllocationException
 */
public void splitNode(final DistributionRegion regionToSplit, final double splitPosition) throws BBoxDBException, ResourceAllocationException {
    try {
        logger.debug("Write split at pos {} into zookeeper", splitPosition);
        final DistributionRegion parent = regionToSplit.getParent();
        final String sourcePath = distributionRegionZookeeperAdapter.getZookeeperPathForDistributionRegion(regionToSplit);
        final String parentPath = distributionRegionZookeeperAdapter.getZookeeperPathForDistributionRegion(parent);
        // Calculate the covering bounding boxes
        final BoundingBox parentBox = regionToSplit.getConveringBox();
        final BoundingBox leftBoundingBox = parentBox.splitAndGetLeft(splitPosition, 0, true);
        final BoundingBox rightBoundingBox = parentBox.splitAndGetRight(splitPosition, 0, false);
        final String fullname = distributionGroupName;
        // Only one system executes the split, therefore we can determine the child ids
        final int oldNumberOfhildren = parent.getDirectChildren().size();
        final long childNumber = parent.getHighestChildNumber();
        final String child1Path = distributionRegionZookeeperAdapter.createNewChild(parentPath, (int) childNumber + 1, leftBoundingBox, fullname);
        final String child2Path = distributionRegionZookeeperAdapter.createNewChild(parentPath, (int) childNumber + 2, rightBoundingBox, fullname);
        // Update state
        distributionRegionZookeeperAdapter.setStateForDistributionGroup(sourcePath, DistributionRegionState.SPLITTING);
        final Predicate<DistributionRegion> predicate = (r) -> r.getDirectChildren().size() == oldNumberOfhildren + 2;
        DistributionRegionSyncerHelper.waitForPredicate(predicate, regionToSplit, distributionRegionSyncer);
        // The first child is stored on the same systems as the parent
        SpacePartitionerHelper.copySystemsToRegion(regionToSplit.getSystems(), child1Path, zookeeperClient);
        final List<BBoxDBInstance> blacklistSystems = regionToSplit.getSystems();
        SpacePartitionerHelper.allocateSystemsToRegion(child2Path, fullname, blacklistSystems, zookeeperClient);
    } catch (ZookeeperException | ZookeeperNotFoundException e) {
        throw new BBoxDBException(e);
    }
}
Also used : SamplingBasedSplitStrategy(org.bboxdb.distribution.partitioner.regionsplit.SamplingBasedSplitStrategy) DistributionRegionSyncerHelper(org.bboxdb.distribution.region.DistributionRegionSyncerHelper) Arrays(java.util.Arrays) Predicate(java.util.function.Predicate) Collection(java.util.Collection) SplitpointStrategy(org.bboxdb.distribution.partitioner.regionsplit.SplitpointStrategy) BoundingBox(org.bboxdb.commons.math.BoundingBox) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) ArrayList(java.util.ArrayList) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) List(java.util.List) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) InputParseException(org.bboxdb.commons.InputParseException) ResourceAllocationException(org.bboxdb.distribution.placement.ResourceAllocationException) BBoxDBException(org.bboxdb.misc.BBoxDBException) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) MathUtil(org.bboxdb.commons.MathUtil) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BBoxDBException(org.bboxdb.misc.BBoxDBException) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) BoundingBox(org.bboxdb.commons.math.BoundingBox) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance)

Example 77 with BBoxDBInstance

use of org.bboxdb.distribution.membership.BBoxDBInstance in project bboxdb by jnidzwetzki.

the class StatisticsHelper method getAndUpdateStatistics.

/**
 * Get the max total size from the statistics map
 * @param statistics
 * @return
 * @throws ZookeeperNotFoundException
 * @throws ZookeeperException
 */
public static OptionalDouble getAndUpdateStatistics(final DistributionRegion region) {
    try {
        final Map<BBoxDBInstance, Map<String, Long>> statistics = distributionGroupZookeeperAdapter.getRegionStatistics(region);
        final OptionalDouble regionSize = statistics.values().stream().mapToDouble(p -> p.get(ZookeeperNodeNames.NAME_STATISTICS_TOTAL_SIZE)).filter(Objects::nonNull).max();
        if (regionSize.isPresent()) {
            final String regionIdentifier = region.getIdentifier();
            updateStatisticsHistory(regionIdentifier, regionSize.getAsDouble());
        }
        return regionSize;
    } catch (Exception e) {
        logger.error("Got an exception while reading statistics", e);
        return OptionalDouble.empty();
    }
}
Also used : BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) HashMap(java.util.HashMap) Map(java.util.Map) OptionalDouble(java.util.OptionalDouble) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException)

Example 78 with BBoxDBInstance

use of org.bboxdb.distribution.membership.BBoxDBInstance in project bboxdb by jnidzwetzki.

the class ZookeeperClientFactory method getLocalInstanceName.

/**
 * Get the name of the local instance
 * @param bboxdbConfiguration
 * @return
 */
public static synchronized BBoxDBInstance getLocalInstanceName() {
    if (localInstanceName == null) {
        final BBoxDBConfiguration configuration = BBoxDBConfigurationManager.getConfiguration();
        final String localIp = configuration.getLocalip();
        final int localPort = configuration.getNetworkListenPort();
        localInstanceName = new BBoxDBInstance(localIp, localPort, Const.VERSION);
    }
    return localInstanceName;
}
Also used : BBoxDBConfiguration(org.bboxdb.misc.BBoxDBConfiguration) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance)

Aggregations

BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)78 Test (org.junit.Test)36 ArrayList (java.util.ArrayList)28 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)25 BBoxDBException (org.bboxdb.misc.BBoxDBException)16 ZookeeperClient (org.bboxdb.distribution.zookeeper.ZookeeperClient)14 List (java.util.List)13 RoutingHop (org.bboxdb.network.routing.RoutingHop)13 BBoxDBInstanceManager (org.bboxdb.distribution.membership.BBoxDBInstanceManager)11 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)11 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)11 BoundingBox (org.bboxdb.commons.math.BoundingBox)9 NetworkOperationFuture (org.bboxdb.network.client.future.NetworkOperationFuture)8 Map (java.util.Map)7 HashMap (java.util.HashMap)6 ZookeeperBBoxDBInstanceAdapter (org.bboxdb.distribution.membership.ZookeeperBBoxDBInstanceAdapter)6 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)6 JoinedTupleListFuture (org.bboxdb.network.client.future.JoinedTupleListFuture)6 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)6 OptionalDouble (java.util.OptionalDouble)4