use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.
the class TestDistributionGroup method testLeafNode.
/**
* Test a distribution region with only one level
*/
@Test(timeout = 60000)
public void testLeafNode() {
final DistributionRegion distributionRegion = createDistributionGroup(2);
Assert.assertTrue(distributionRegion.isLeafRegion());
Assert.assertEquals(0, distributionRegion.getLevel());
Assert.assertEquals(1, distributionRegion.getTotalLevel());
}
use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.
the class StatisticsUpdateRunnable method updateRegionStatistics.
/**
* Update region statistics
*
* @param distributionGroup
* @param regionId
* @throws ZookeeperException
* @throws StorageManagerException
* @throws InterruptedException
*/
private void updateRegionStatistics(final String distributionGroup, final long regionId) throws BBoxDBException, ZookeeperException, StorageManagerException, InterruptedException {
final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
final DistributionRegion distributionRegion = spacePartitioner.getRootNode();
final DistributionRegion regionToSplit = DistributionRegionHelper.getDistributionRegionForNamePrefix(distributionRegion, regionId);
final long totalSize = TupleStoreUtil.getSizeOfDistributionGroupAndRegionId(storageRegistry, distributionGroup, regionId);
final long totalTuples = TupleStoreUtil.getTuplesInDistributionGroupAndRegionId(storageRegistry, distributionGroup, regionId);
final long totalSizeInMb = totalSize / (1024 * 1024);
logger.info("Updating region statistics: {} / {}. Size in MB: {} / Tuples: {}", distributionGroup, regionId, totalSizeInMb, totalTuples);
regionAdapter.updateRegionStatistics(regionToSplit, ZookeeperClientFactory.getLocalInstanceName(), totalSizeInMb, totalTuples);
}
use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.
the class DistributionRegionAdapter method getNodeForPath.
/**
* Get the node for the given zookeeper path
* @param distributionRegion
* @param path
* @return
*/
public DistributionRegion getNodeForPath(final DistributionRegion distributionRegion, final String path) {
final String name = distributionRegion.getDistributionGroupName();
final String distributionGroupPath = zookeeperClient.getDistributionGroupAdapter().getDistributionGroupRootElementPath(name);
if (!path.startsWith(distributionGroupPath)) {
throw new IllegalArgumentException("Path " + path + " does not start with " + distributionGroupPath);
}
final StringBuilder sb = new StringBuilder(path);
sb.delete(0, distributionGroupPath.length());
DistributionRegion resultElement = distributionRegion;
final StringTokenizer tokenizer = new StringTokenizer(sb.toString(), "/");
while (tokenizer.hasMoreTokens()) {
// Element is removed
if (resultElement == null) {
return null;
}
final String token = tokenizer.nextToken();
if (!token.startsWith(ZookeeperNodeNames.NAME_CHILDREN)) {
throw new IllegalArgumentException("Unable to decode " + sb);
}
final String[] split = token.split("-");
final int childNumber = Integer.parseInt(split[1]);
if (resultElement.getDirectChildren().size() <= childNumber) {
return null;
}
resultElement = resultElement.getDirectChildren().get(childNumber);
}
return resultElement;
}
use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.
the class RegionMergeHelper method getTotalRegionSize.
/**
* Get the total size of the child regions
* @param region
* @return
*/
public static OptionalDouble getTotalRegionSize(final List<DistributionRegion> sources) {
if (sources.isEmpty()) {
return OptionalDouble.empty();
}
// Update statistics
sources.forEach(r -> StatisticsHelper.getAndUpdateStatistics(r));
for (final DistributionRegion region : sources) {
if (!StatisticsHelper.isEnoughHistoryDataAvailable(region.getIdentifier())) {
return OptionalDouble.empty();
}
}
// Get statistics
final double value = sources.stream().filter(Objects::nonNull).mapToDouble(r -> StatisticsHelper.getAverageStatistics(r.getIdentifier())).sum();
return OptionalDouble.of(value);
}
use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.
the class RegionMerger method mergeRegion.
/**
* Merge the given region
* @param region
* @param distributionGroupZookeeperAdapter
* @param spacePartitioner
* @param diskStorage
*/
public void mergeRegion(final List<DistributionRegion> source, final SpacePartitioner spacePartitioner, final TupleStoreManagerRegistry tupleStoreManagerRegistry) {
assert (!source.isEmpty());
logger.info("Performing merge for: {}", source.get(0).getIdentifier());
final DistributionRegionAdapter distributionGroupZookeeperAdapter = ZookeeperClientFactory.getZookeeperClient().getDistributionRegionAdapter();
DistributionRegion destination = null;
try {
destination = spacePartitioner.getDestinationForMerge(source);
if (destination == null) {
logger.error("Got null when calling getDestinationForMerge from space partitoner {}", source);
return;
}
final String identifier = destination.getIdentifier();
// Try to set region state to merging. If this fails, another node is already
// merges the region
final boolean setToMergeResult = distributionGroupZookeeperAdapter.setToSplitMerging(destination);
if (!setToMergeResult) {
logger.info("Unable to set state to split merge for region: {}, stopping merge", identifier);
logger.info("Old state was {}", distributionGroupZookeeperAdapter.getStateForDistributionRegion(destination));
return;
}
spacePartitioner.prepareMerge(source, destination);
redistributeDataMerge(source, destination);
spacePartitioner.mergeComplete(source, destination);
} catch (Throwable e) {
logger.warn("Got uncought exception during merge: " + source.get(0).getIdentifier(), e);
handleMergeFailed(source, destination, spacePartitioner);
}
}
Aggregations