Search in sources :

Example 71 with BBoxDBInstance

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

the class RegionMerger method mergeDataByNetworkRead.

/**
 * Merge the region by a network read
 *
 * @param region
 * @param tupleStoreName
 * @param tupleRedistributor
 * @param childRegion
 * @throws InterruptedException
 * @throws StorageManagerException
 * @throws Exception
 */
private void mergeDataByNetworkRead(final DistributionRegion region, final TupleStoreName tupleStoreName, final TupleRedistributor tupleRedistributor, final DistributionRegion childRegion) throws InterruptedException, StorageManagerException {
    final List<BBoxDBInstance> systems = childRegion.getSystems();
    assert (!systems.isEmpty()) : "Systems can not be empty";
    final BBoxDBInstance firstSystem = systems.get(0);
    final BBoxDBConnection connection = MembershipConnectionService.getInstance().getConnectionForInstance(firstSystem);
    assert (connection != null) : "Connection can not be null: " + firstSystem.getStringValue();
    final BoundingBox bbox = childRegion.getConveringBox();
    final String fullname = tupleStoreName.getFullname();
    final BBoxDBClient bboxDBClient = connection.getBboxDBClient();
    final TupleListFuture result = bboxDBClient.queryBoundingBox(fullname, bbox);
    result.waitForAll();
    if (result.isFailed()) {
        throw new StorageManagerException("Exception while fetching tuples: " + result.getAllMessages());
    }
    for (final Tuple tuple : result) {
        tupleRedistributor.redistributeTuple(tuple);
    }
}
Also used : BBoxDBClient(org.bboxdb.network.client.BBoxDBClient) BoundingBox(org.bboxdb.commons.math.BoundingBox) TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection) StorageManagerException(org.bboxdb.storage.StorageManagerException) Tuple(org.bboxdb.storage.entity.Tuple)

Example 72 with BBoxDBInstance

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

the class DistributionRegionHelper method processRegion.

/**
 * Test if there is an outdated region
 *
 * @param distributedInstance
 * @param result
 * @param distributionGroupZookeeperAdapter
 * @param regionToInspect
 * @return
 * @throws ZookeeperException
 * @throws BBoxDBException
 */
private static OutdatedDistributionRegion processRegion(final BBoxDBInstance distributedInstance, final ZookeeperClient zookeeperClient, final DistributionRegion regionToInspect) throws ZookeeperException, BBoxDBException {
    final Map<BBoxDBInstance, Long> versions = new HashMap<>();
    for (final BBoxDBInstance instance : regionToInspect.getSystems()) {
        final long version = zookeeperClient.getDistributionRegionAdapter().getCheckpointForDistributionRegion(regionToInspect, instance);
        versions.put(instance, version);
    }
    if (!versions.containsKey(distributedInstance)) {
        throw new BBoxDBException("Unable to find local instance for region: " + distributedInstance + " / " + regionToInspect);
    }
    final Optional<Entry<BBoxDBInstance, Long>> newestInstanceOptional = versions.entrySet().stream().reduce((a, b) -> a.getValue() > b.getValue() ? a : b);
    if (!newestInstanceOptional.isPresent()) {
        return null;
    }
    final long localVersion = versions.get(distributedInstance);
    final Entry<BBoxDBInstance, Long> newestInstance = newestInstanceOptional.get();
    if (!newestInstance.getKey().equals(distributedInstance)) {
        return new OutdatedDistributionRegion(regionToInspect, newestInstance.getKey(), localVersion);
    }
    return null;
}
Also used : Entry(java.util.Map.Entry) HashMap(java.util.HashMap) OutdatedDistributionRegion(org.bboxdb.distribution.OutdatedDistributionRegion) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Example 73 with BBoxDBInstance

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

the class StatisticsUpdateRunnable method updateNodeStats.

/**
 * Update the local node stats (diskspace, memory)
 * @throws ZookeeperException
 */
private void updateNodeStats() {
    try {
        final BBoxDBInstance instance = ZookeeperClientFactory.getLocalInstanceName();
        logger.debug("Update zookeeper node stats");
        final ZookeeperClient zookeeperClient = ZookeeperClientFactory.getZookeeperClient();
        final ZookeeperBBoxDBInstanceAdapter zookeeperBBoxDBInstanceAdapter = new ZookeeperBBoxDBInstanceAdapter(zookeeperClient);
        zookeeperBBoxDBInstanceAdapter.updateNodeInfo(instance);
    } catch (ZookeeperException e) {
        logger.error("Got exception while updating local node stats", e);
    }
}
Also used : ZookeeperClient(org.bboxdb.distribution.zookeeper.ZookeeperClient) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) ZookeeperBBoxDBInstanceAdapter(org.bboxdb.distribution.membership.ZookeeperBBoxDBInstanceAdapter)

Example 74 with BBoxDBInstance

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

the class DistributionRegionAdapter method allocateSystemsToRegion.

/**
 * Allocate the given list of systems to a region
 * @param region
 * @param allocationSystems
 * @throws ZookeeperException
 */
public void allocateSystemsToRegion(final String regionPath, final Set<BBoxDBInstance> allocationSystems) throws ZookeeperException {
    final List<String> systemNames = allocationSystems.stream().map(s -> s.getStringValue()).collect(Collectors.toList());
    logger.info("Allocating region {} to {}", regionPath, systemNames);
    // Resource allocation successfully, write data to zookeeper
    for (final BBoxDBInstance instance : allocationSystems) {
        addSystemToDistributionRegion(regionPath, instance);
    }
}
Also used : Logger(org.slf4j.Logger) Watcher(org.apache.zookeeper.Watcher) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) HashMap(java.util.HashMap) DistributionRegionState(org.bboxdb.distribution.partitioner.DistributionRegionState) Collectors(java.util.stream.Collectors) BoundingBox(org.bboxdb.commons.math.BoundingBox) List(java.util.List) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) InputParseException(org.bboxdb.commons.InputParseException) StringTokenizer(java.util.StringTokenizer) Map(java.util.Map) BBoxDBException(org.bboxdb.misc.BBoxDBException) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) MathUtil(org.bboxdb.commons.MathUtil) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance)

Example 75 with BBoxDBInstance

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

the class AbstractSpacePartitioner method allocateSystems.

/**
 * Allocate systems to the children
 * @param regionToSplit
 * @param numberOfChilden
 * @throws ZookeeperException
 * @throws ResourceAllocationException
 * @throws ZookeeperNotFoundException
 */
protected void allocateSystems(final DistributionRegion regionToSplit, final int numberOfChilden) throws ZookeeperException, ZookeeperNotFoundException, ResourceAllocationException {
    // The first child is stored on the same systems as the parent
    final DistributionRegion firstRegion = regionToSplit.getDirectChildren().get(0);
    final String firstRegionPath = distributionRegionZookeeperAdapter.getZookeeperPathForDistributionRegion(firstRegion);
    SpacePartitionerHelper.copySystemsToRegion(regionToSplit.getSystems(), firstRegionPath, zookeeperClient);
    final List<BBoxDBInstance> blacklistSystems = regionToSplit.getSystems();
    // For the remaining node, a new resource allocation is performed
    for (int i = 1; i < numberOfChilden; i++) {
        final DistributionRegion region = regionToSplit.getDirectChildren().get(i);
        final String path = distributionRegionZookeeperAdapter.getZookeeperPathForDistributionRegion(region);
        final String fullname = region.getDistributionGroupName();
        SpacePartitionerHelper.allocateSystemsToRegion(path, fullname, blacklistSystems, zookeeperClient);
    }
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) 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