use of org.bboxdb.distribution.placement.ResourceAllocationException in project bboxdb by jnidzwetzki.
the class SpacePartitionerHelper method allocateSystemsToRegion.
/**
* Allocate the required amount of systems to the given region
*
* @param region
* @param zookeeperClient
* @throws ZookeeperException
* @throws ResourceAllocationException
* @throws ZookeeperNotFoundException
*/
public static void allocateSystemsToRegion(final String regionPath, final String distributionGroupName, final Collection<BBoxDBInstance> blacklist, final ZookeeperClient zookeeperClient) throws ZookeeperException, ResourceAllocationException, ZookeeperNotFoundException {
final DistributionGroupConfiguration config = DistributionGroupConfigurationCache.getInstance().getDistributionGroupConfiguration(distributionGroupName);
final short replicationFactor = config.getReplicationFactor();
final BBoxDBInstanceManager distributedInstanceManager = BBoxDBInstanceManager.getInstance();
final List<BBoxDBInstance> availableSystems = distributedInstanceManager.getInstances();
final String placementStrategy = config.getPlacementStrategy();
final ResourcePlacementStrategy resourcePlacementStrategy = ResourcePlacementStrategyFactory.getInstance(placementStrategy);
if (resourcePlacementStrategy == null) {
throw new ResourceAllocationException("Unable to instanciate the ressource " + "placement strategy");
}
// The blacklist, to prevent duplicate allocations
final Set<BBoxDBInstance> allocationSystems = new HashSet<>();
final Set<BBoxDBInstance> blacklistedSystems = new HashSet<>();
blacklistedSystems.addAll(blacklist);
for (short i = 0; i < replicationFactor; i++) {
final BBoxDBInstance instance = resourcePlacementStrategy.getInstancesForNewRessource(availableSystems, blacklistedSystems);
allocationSystems.add(instance);
blacklistedSystems.add(instance);
}
logger.info("Allocated new ressource to {} with blacklist {}", allocationSystems, blacklist);
zookeeperClient.getDistributionRegionAdapter().allocateSystemsToRegion(regionPath, allocationSystems);
}
use of org.bboxdb.distribution.placement.ResourceAllocationException in project bboxdb by jnidzwetzki.
the class KDtreeSpacePartitioner method splitRegion.
/**
* Split the node at the given position
* @param regionToSplit
* @param splitPosition
* @throws ZookeeperException
* @throws ResourceAllocationException
* @throws ZookeeperNotFoundException
*/
@Override
public List<DistributionRegion> splitRegion(final DistributionRegion regionToSplit, final Collection<BoundingBox> samples) throws BBoxDBException {
try {
final SplitpointStrategy splitpointStrategy = new SamplingBasedSplitStrategy(samples);
final int splitDimension = getSplitDimension(regionToSplit);
final BoundingBox regionBox = regionToSplit.getConveringBox();
final double splitPosition = splitpointStrategy.getSplitPoint(splitDimension, regionBox);
splitNode(regionToSplit, splitPosition);
return regionToSplit.getDirectChildren();
} catch (Exception e) {
throw new BBoxDBException(e);
}
}
use of org.bboxdb.distribution.placement.ResourceAllocationException in project bboxdb by jnidzwetzki.
the class BBoxDBCluster method getSystemForNewRessources.
/**
* Find a system with free resources
* @return
* @throws ResourceAllocationException
*/
private BBoxDBConnection getSystemForNewRessources() throws ResourceAllocationException {
final List<BBoxDBInstance> serverConnections = membershipConnectionService.getAllInstances();
if (serverConnections == null) {
throw new ResourceAllocationException("Server connections are null");
}
final BBoxDBInstance system = resourcePlacementStrategy.getInstancesForNewRessource(serverConnections);
return membershipConnectionService.getConnectionForInstance(system);
}
use of org.bboxdb.distribution.placement.ResourceAllocationException in project bboxdb by jnidzwetzki.
the class AbstractTreeSpacePartitoner method createRootNode.
@Override
public void createRootNode(final DistributionGroupConfiguration configuration) throws BBoxDBException {
try {
final String distributionGroup = spacePartitionerContext.getDistributionGroupName();
final String rootPath = distributionGroupZookeeperAdapter.getDistributionGroupRootElementPath(distributionGroup);
zookeeperClient.createDirectoryStructureRecursive(rootPath);
final int nameprefix = distributionGroupZookeeperAdapter.getNextTableIdForDistributionGroup(distributionGroup);
zookeeperClient.createPersistentNode(rootPath + "/" + ZookeeperNodeNames.NAME_NAMEPREFIX, Integer.toString(nameprefix).getBytes());
zookeeperClient.createPersistentNode(rootPath + "/" + ZookeeperNodeNames.NAME_SYSTEMS, "".getBytes());
final BoundingBox rootBox = getRootBox(configuration);
distributionRegionZookeeperAdapter.setBoundingBoxForPath(rootPath, rootBox);
zookeeperClient.createPersistentNode(rootPath + "/" + ZookeeperNodeNames.NAME_REGION_STATE, DistributionRegionState.ACTIVE.getStringValue().getBytes());
SpacePartitionerHelper.allocateSystemsToRegion(rootPath, distributionGroup, new HashSet<>(), zookeeperClient);
NodeMutationHelper.markNodeMutationAsComplete(zookeeperClient, rootPath);
} catch (ZookeeperException | ResourceAllocationException | ZookeeperNotFoundException e) {
throw new BBoxDBException(e);
}
}
use of org.bboxdb.distribution.placement.ResourceAllocationException 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);
}
}
Aggregations