Search in sources :

Example 81 with DistributionRegion

use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.

the class CompactorHelper method isRegionActive.

/**
 * Is the region for the table active?
 *
 * @param tupleStoreName
 * @return
 * @throws StorageManagerException
 * @throws InterruptedException
 */
public static boolean isRegionActive(final TupleStoreName tupleStoreName) throws StorageManagerException, InterruptedException {
    try {
        if (!tupleStoreName.isDistributedTable()) {
            logger.error("Tuple store {} is not a distributed table, untable to split", tupleStoreName);
            return false;
        }
        final long regionId = tupleStoreName.getRegionId().getAsLong();
        final String distributionGroup = tupleStoreName.getDistributionGroup();
        final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
        final DistributionRegion distributionRegion = spacePartitioner.getRootNode();
        final DistributionRegion regionToSplit = DistributionRegionHelper.getDistributionRegionForNamePrefix(distributionRegion, regionId);
        // Region does not exist
        if (regionToSplit == null) {
            logger.error("Unable to get distribution region {} {}", distributionRegion, regionId);
            return false;
        }
        if (regionToSplit.isRootElement()) {
            return true;
        }
        return regionToSplit.getState() == DistributionRegionState.ACTIVE;
    } catch (BBoxDBException e) {
        throw new StorageManagerException(e);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw e;
    }
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) StorageManagerException(org.bboxdb.storage.StorageManagerException) BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 82 with DistributionRegion

use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.

the class SSTableServiceRunnable method testForUnderflow.

/**
 * Test for region underflow
 *
 * @param spacePartitioner
 * @param regionToMerge
 * @throws BBoxDBException
 */
private void testForUnderflow(final SpacePartitioner spacePartitioner, final DistributionRegion oneSourceNode) throws BBoxDBException {
    final List<List<DistributionRegion>> candidates = spacePartitioner.getMergeCandidates(oneSourceNode);
    for (final List<DistributionRegion> sources : candidates) {
        if (RegionMergeHelper.isRegionUnderflow(sources)) {
            final TupleStoreManagerRegistry tupleStoreManagerRegistry = storage.getTupleStoreManagerRegistry();
            final RegionMerger regionMerger = new RegionMerger(tupleStoreManagerRegistry);
            regionMerger.mergeRegion(sources, spacePartitioner, tupleStoreManagerRegistry);
            return;
        }
    }
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) TupleStoreManagerRegistry(org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry) RegionMerger(org.bboxdb.distribution.partitioner.regionsplit.RegionMerger) ArrayList(java.util.ArrayList) List(java.util.List)

Example 83 with DistributionRegion

use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.

the class DistributedRecoveryService method runRecoveryForDistributionGroup.

/**
 * Run recovery for distribution group
 * @param distributionGroupName
 * @throws ZookeeperException
 */
protected void runRecoveryForDistributionGroup(final String distributionGroupName) {
    try {
        final ZookeeperClient zookeeperClient = ZookeeperClientFactory.getZookeeperClient();
        final BBoxDBInstance localInstance = ZookeeperClientFactory.getLocalInstanceName();
        for (final DiskStorage storage : storageRegistry.getAllStorages()) {
            checkGroupVersion(storage, distributionGroupName, zookeeperClient);
        }
        final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroupName);
        final DistributionRegion distributionGroup = spacePartitioner.getRootNode();
        final List<OutdatedDistributionRegion> outdatedRegions = DistributionRegionHelper.getOutdatedRegions(distributionGroup, localInstance);
        handleOutdatedRegions(distributionGroupName, outdatedRegions);
    } catch (Throwable e) {
        logger.error("Got exception while running recovery for distribution group: " + distributionGroupName, e);
    }
}
Also used : ZookeeperClient(org.bboxdb.distribution.zookeeper.ZookeeperClient) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) DiskStorage(org.bboxdb.storage.tuplestore.DiskStorage) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 84 with DistributionRegion

use of org.bboxdb.distribution.region.DistributionRegion 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)

Example 85 with DistributionRegion

use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.

the class DistributionRegionAdapter method getZookeeperPathForDistributionRegion.

/**
 * Get the zookeeper path for a distribution region
 * @param distributionRegion
 * @return
 */
public String getZookeeperPathForDistributionRegion(final DistributionRegion distributionRegion) {
    final StringBuilder sb = new StringBuilder();
    DistributionRegion tmpRegion = distributionRegion;
    if (tmpRegion != null) {
        while (!tmpRegion.isRootElement()) {
            sb.insert(0, "/" + ZookeeperNodeNames.NAME_CHILDREN + tmpRegion.getChildNumberOfParent());
            tmpRegion = tmpRegion.getParent();
        }
    }
    final String name = distributionRegion.getDistributionGroupName();
    final DistributionGroupAdapter distributionGroupAdapter = zookeeperClient.getDistributionGroupAdapter();
    sb.insert(0, distributionGroupAdapter.getDistributionGroupRootElementPath(name));
    return sb.toString();
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion)

Aggregations

DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)91 Test (org.junit.Test)45 BBoxDBException (org.bboxdb.misc.BBoxDBException)34 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)33 BoundingBox (org.bboxdb.commons.math.BoundingBox)27 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)23 ArrayList (java.util.ArrayList)17 List (java.util.List)17 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)16 DistributionRegionAdapter (org.bboxdb.distribution.zookeeper.DistributionRegionAdapter)15 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)15 KDtreeSpacePartitioner (org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner)14 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)11 ZookeeperClientFactory (org.bboxdb.distribution.zookeeper.ZookeeperClientFactory)11 DistributionRegionState (org.bboxdb.distribution.partitioner.DistributionRegionState)10 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)10 DistributionRegionSyncer (org.bboxdb.distribution.region.DistributionRegionSyncer)10 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)10 RoutingHop (org.bboxdb.network.routing.RoutingHop)10 DistributionGroupConfigurationBuilder (org.bboxdb.storage.entity.DistributionGroupConfigurationBuilder)10