use of org.bboxdb.distribution.zookeeper.DistributionRegionAdapter in project bboxdb by jnidzwetzki.
the class CreateDistributionGroupHandler method handleRequest.
@Override
public /**
* Create a new distribution group
*/
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
try {
final CreateDistributionGroupRequest createPackage = CreateDistributionGroupRequest.decodeTuple(encodedPackage);
final String distributionGroup = createPackage.getDistributionGroup();
logger.info("Create distribution group: {}", distributionGroup);
final DistributionGroupAdapter distributionGroupAdapter = ZookeeperClientFactory.getZookeeperClient().getDistributionGroupAdapter();
final DistributionRegionAdapter distributionRegionAdapter = ZookeeperClientFactory.getZookeeperClient().getDistributionRegionAdapter();
final List<String> knownGroups = distributionGroupAdapter.getDistributionGroups();
if (knownGroups.contains(distributionGroup)) {
logger.error("Untable to create distributon group {}, already exists", distributionGroup);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_DGROUP_EXISTS);
clientConnectionHandler.writeResultPackage(responsePackage);
return true;
}
distributionGroupAdapter.createDistributionGroup(distributionGroup, createPackage.getDistributionGroupConfiguration());
final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
final DistributionRegion region = spacePartitioner.getRootNode();
distributionRegionAdapter.setStateForDistributionRegion(region, DistributionRegionState.ACTIVE);
clientConnectionHandler.writeResultPackage(new SuccessResponse(packageSequence));
} catch (Exception e) {
logger.warn("Error while create distribution group", e);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
clientConnectionHandler.writeResultPackage(responsePackage);
}
return true;
}
use of org.bboxdb.distribution.zookeeper.DistributionRegionAdapter in project bboxdb by jnidzwetzki.
the class RegionSplitter method splitRegion.
/**
* Perform a distribution region split
*
* @param region
* @param distributionGroupZookeeperAdapter
* @param spacePartitioner
* @param diskStorage
*/
public void splitRegion(final DistributionRegion region, final SpacePartitioner spacePartitioner, final TupleStoreManagerRegistry tupleStoreManagerRegistry) {
assert (region != null);
final DistributionRegionAdapter distributionRegionZookeeperAdapter = ZookeeperClientFactory.getZookeeperClient().getDistributionRegionAdapter();
logger.info("Performing split for: {}", region.getIdentifier());
final boolean setResult = tryToSetToFullSplitting(region, distributionRegionZookeeperAdapter);
if (!setResult) {
return;
}
boolean splitFailed = false;
final List<DistributionRegion> destination = new ArrayList<>();
try {
final Collection<BoundingBox> samples = SamplingHelper.getSamplesForRegion(region, tupleStoreManagerRegistry);
final List<DistributionRegion> splitRegions = spacePartitioner.splitRegion(region, samples);
destination.addAll(splitRegions);
redistributeDataSplit(region, destination);
distributionRegionZookeeperAdapter.deleteRegionStatistics(region);
// Setting the region to split will cause a local data delete (see TupleStoreZookeeperObserver)
spacePartitioner.splitComplete(region, destination);
} catch (Throwable e) {
logger.warn("Got exception during split, retry in a few minutes: " + region.getIdentifier(), e);
splitFailed = true;
}
handleSplitFailed(region, spacePartitioner, splitFailed, destination);
logger.info("Performing split for: {} is done", region.getIdentifier());
}
Aggregations