Search in sources :

Example 66 with BBoxDBInstance

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

the class TestStorageUtilizationRessourcePlacement method testUtilPlacement.

/**
 * Test round robin placement 1
 * @throws ResourceAllocationException
 */
@Test(timeout = 60000)
public void testUtilPlacement() throws ResourceAllocationException {
    final ResourcePlacementStrategy resourcePlacementStrategy = getPlacementStrategy();
    final List<BBoxDBInstance> systems = new ArrayList<>();
    final BBoxDBInstance instance1 = new BBoxDBInstance("node1:123", "0.1", BBoxDBInstanceState.READY);
    systems.add(instance1);
    instance1.addFreeSpace("/tmp", 10);
    instance1.addTotalSpace("/tmp", 10);
    final BBoxDBInstance instance2 = new BBoxDBInstance("node2:123", "0.1", BBoxDBInstanceState.READY);
    systems.add(instance2);
    instance2.addFreeSpace("/tmp", 10);
    instance2.addTotalSpace("/tmp", 10);
    instance2.addFreeSpace("/tmp2", 10);
    instance2.addTotalSpace("/tmp2", 10);
    final BBoxDBInstance instance3 = new BBoxDBInstance("node3:123", "0.1", BBoxDBInstanceState.READY);
    systems.add(instance3);
    instance3.addFreeSpace("/tmp", 10);
    instance3.addTotalSpace("/tmp", 10);
    instance3.addFreeSpace("/tmp2", 10);
    instance3.addTotalSpace("/tmp2", 10);
    instance3.addFreeSpace("/tmp3", 10);
    instance3.addTotalSpace("/tmp3", 10);
    final BBoxDBInstance instance4 = new BBoxDBInstance("node4:123", "0.1", BBoxDBInstanceState.READY);
    systems.add(instance4);
    instance4.addFreeSpace("/tmp", 10);
    instance4.addTotalSpace("/tmp", 10);
    instance4.addFreeSpace("/tmp2", 10);
    instance4.addTotalSpace("/tmp2", 10);
    instance4.addFreeSpace("/tmp3", 10);
    instance4.addTotalSpace("/tmp3", 10);
    instance4.addFreeSpace("/tmp4", 10);
    instance4.addTotalSpace("/tmp4", 10);
    utilization.clear();
    utilization.setCount(systems.get(0), 1);
    utilization.setCount(systems.get(1), 1);
    utilization.setCount(systems.get(2), 1);
    Assert.assertEquals(systems.get(3), resourcePlacementStrategy.getInstancesForNewRessource(systems));
    utilization.clear();
    utilization.setCount(systems.get(0), 1);
    utilization.setCount(systems.get(1), 1);
    utilization.setCount(systems.get(2), 1);
    utilization.setCount(systems.get(3), 1);
    Assert.assertEquals(systems.get(3), resourcePlacementStrategy.getInstancesForNewRessource(systems));
    utilization.setCount(systems.get(3), 100);
    Assert.assertEquals(systems.get(2), resourcePlacementStrategy.getInstancesForNewRessource(systems));
}
Also used : ArrayList(java.util.ArrayList) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) Test(org.junit.Test)

Example 67 with BBoxDBInstance

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

the class BBoxDBMain method createMembershipService.

/**
 * Returns a new instance of the membership service
 * @param storageRegistry
 * @return
 */
public MembershipConnectionService createMembershipService(final TupleStoreManagerRegistry storageRegistry) {
    final MembershipConnectionService membershipService = MembershipConnectionService.getInstance();
    // Prevent network connections to ourself
    final BBoxDBInstance localhost = ZookeeperClientFactory.getLocalInstanceName();
    membershipService.addSystemToBlacklist(localhost);
    // The storage registry for gossip
    membershipService.setTupleStoreManagerRegistry(storageRegistry);
    return membershipService;
}
Also used : MembershipConnectionService(org.bboxdb.distribution.membership.MembershipConnectionService) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance)

Example 68 with BBoxDBInstance

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

the class DistributedRecoveryService method runRecoveryForDistributionGroup.

/**
 * Run recovery for distribution group
 * @param distributionGroupName
 * @throws ZookeeperException
 */
protected void runRecoveryForDistributionGroup(final String distributionGroupName) {
    try {
        final ZookeeperClient zookeeperClient = ZookeeperClientFactory.getZookeeperClient();
        final BBoxDBInstance localInstance = ZookeeperClientFactory.getLocalInstanceName();
        for (final DiskStorage storage : storageRegistry.getAllStorages()) {
            checkGroupVersion(storage, distributionGroupName, zookeeperClient);
        }
        final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroupName);
        final DistributionRegion distributionGroup = spacePartitioner.getRootNode();
        final List<OutdatedDistributionRegion> outdatedRegions = DistributionRegionHelper.getOutdatedRegions(distributionGroup, localInstance);
        handleOutdatedRegions(distributionGroupName, outdatedRegions);
    } catch (Throwable e) {
        logger.error("Got exception while running recovery for distribution group: " + distributionGroupName, e);
    }
}
Also used : ZookeeperClient(org.bboxdb.distribution.zookeeper.ZookeeperClient) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) DiskStorage(org.bboxdb.storage.tuplestore.DiskStorage) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 69 with BBoxDBInstance

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

the class StaticgridSpacePartitioner method createGridInDimension.

/**
 * Create the grid in the given dimension
 * @param splitConfig
 * @param rootPath
 * @param rootBox
 * @param dimension
 * @throws ZookeeperException
 * @throws InputParseException
 * @throws ResourceAllocationException
 * @throws ZookeeperNotFoundException
 */
private void createGridInDimension(final String[] splitConfig, final String parentPath, final BoundingBox box, final int dimension) throws ZookeeperException, InputParseException, ZookeeperNotFoundException, ResourceAllocationException {
    logger.info("Processing dimension {}", dimension);
    final String fullname = distributionGroupName;
    final String stepIntervalString = splitConfig[dimension + 1];
    final double stepInterval = MathUtil.tryParseDouble(stepIntervalString, () -> "Unable to parse" + stepIntervalString);
    BoundingBox boundingBoxToSplit = box;
    int childNumber = 0;
    while (boundingBoxToSplit != null) {
        final double splitPos = boundingBoxToSplit.getCoordinateLow(dimension) + stepInterval;
        BoundingBox nodeBox;
        if (splitPos >= boundingBoxToSplit.getCoordinateHigh(dimension)) {
            nodeBox = boundingBoxToSplit;
            boundingBoxToSplit = null;
        } else {
            nodeBox = boundingBoxToSplit.splitAndGetRight(splitPos, dimension, false);
            boundingBoxToSplit = boundingBoxToSplit.splitAndGetRight(splitPos, dimension, true);
        }
        final String childPath = distributionRegionZookeeperAdapter.createNewChild(parentPath, childNumber, nodeBox, fullname);
        if (dimension == 0) {
            SpacePartitionerHelper.allocateSystemsToRegion(childPath, distributionGroupName, new ArrayList<BBoxDBInstance>(), zookeeperClient);
            distributionRegionZookeeperAdapter.setStateForDistributionGroup(childPath, DistributionRegionState.ACTIVE);
        } else {
            distributionRegionZookeeperAdapter.setStateForDistributionGroup(childPath, DistributionRegionState.SPLIT);
            createGridInDimension(splitConfig, childPath, nodeBox, dimension - 1);
        }
        childNumber++;
    }
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance)

Example 70 with BBoxDBInstance

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

the class RegionMergeHelper method isRegionUnderflow.

/**
 * Needs the region a merge?
 * @param region
 * @return
 * @throws BBoxDBException
 */
public static boolean isRegionUnderflow(final List<DistributionRegion> sources) throws BBoxDBException {
    assert (!sources.isEmpty()) : "Sources can not be empty";
    final List<String> sourceIds = getRegionIdsFromRegionList(sources);
    logger.info("Testing for underflow: {}", sourceIds);
    final boolean inactiveChilds = sources.stream().anyMatch(c -> c.getState() != DistributionRegionState.ACTIVE);
    if (inactiveChilds) {
        logger.info("Not all children ready, skip merge test for {}", sourceIds);
        return false;
    }
    // We are not responsible to this region
    final BBoxDBInstance localInstanceName = ZookeeperClientFactory.getLocalInstanceName();
    final boolean localSystemContained = sources.stream().anyMatch(r -> r.getSystems().contains(localInstanceName));
    if (!localSystemContained) {
        logger.info("Not testing for underflow for {} on {}", sourceIds, localInstanceName);
        return false;
    }
    final OptionalDouble childRegionSize = getTotalRegionSize(sources);
    if (!childRegionSize.isPresent()) {
        logger.info("Got invalid statistics for {}", sourceIds);
        return false;
    }
    try {
        final String fullname = sources.get(0).getDistributionGroupName();
        final long minSize = getConfiguredRegionMinSizeInMB(fullname);
        final double childDoubleSize = childRegionSize.getAsDouble();
        logger.info("Testing for region {} underflow curent size is {} / min is {}", sourceIds, childDoubleSize, minSize);
        return (childDoubleSize < minSize);
    } catch (ZookeeperException | ZookeeperNotFoundException e) {
        throw new BBoxDBException(e);
    }
}
Also used : ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) BBoxDBException(org.bboxdb.misc.BBoxDBException) OptionalDouble(java.util.OptionalDouble)

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