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);
}
}
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();
}
}
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;
}
Aggregations