Search in sources :

Example 6 with DistributionRegionAdapter

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;
}
Also used : DistributionGroupAdapter(org.bboxdb.distribution.zookeeper.DistributionGroupAdapter) SuccessResponse(org.bboxdb.network.packages.response.SuccessResponse) CreateDistributionGroupRequest(org.bboxdb.network.packages.request.CreateDistributionGroupRequest) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionRegionAdapter(org.bboxdb.distribution.zookeeper.DistributionRegionAdapter) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) IOException(java.io.IOException) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 7 with DistributionRegionAdapter

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());
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BoundingBox(org.bboxdb.commons.math.BoundingBox) ArrayList(java.util.ArrayList) DistributionRegionAdapter(org.bboxdb.distribution.zookeeper.DistributionRegionAdapter)

Aggregations

DistributionRegionAdapter (org.bboxdb.distribution.zookeeper.DistributionRegionAdapter)7 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)6 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)3 ArrayList (java.util.ArrayList)2 BoundingBox (org.bboxdb.commons.math.BoundingBox)2 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)2 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)2 BBoxDBException (org.bboxdb.misc.BBoxDBException)2 IOException (java.io.IOException)1 Map (java.util.Map)1 DistributionRegionState (org.bboxdb.distribution.partitioner.DistributionRegionState)1 KDtreeSpacePartitioner (org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner)1 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)1 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)1 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)1 CreateDistributionGroupRequest (org.bboxdb.network.packages.request.CreateDistributionGroupRequest)1 ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)1 SuccessResponse (org.bboxdb.network.packages.response.SuccessResponse)1 TupleFileReader (org.bboxdb.tools.TupleFileReader)1 Test (org.junit.Test)1