Search in sources :

Example 16 with SpacePartitioner

use of org.bboxdb.distribution.partitioner.SpacePartitioner in project bboxdb by jnidzwetzki.

the class CreateInitialPartitioning method checkForExistingPartitioning.

/**
 * Is the region already partitioned?
 * @param distributionGroup
 * @throws BBoxDBException
 */
private static void checkForExistingPartitioning(final String distributionGroup) throws BBoxDBException {
    final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
    if (spacePartitioner.getRootNode().getThisAndChildRegions().size() != 1) {
        System.err.println("Region is already splitted unable to use this for inital splitting");
        System.exit(-1);
    }
}
Also used : SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 17 with SpacePartitioner

use of org.bboxdb.distribution.partitioner.SpacePartitioner in project bboxdb by jnidzwetzki.

the class CreateInitialPartitioning method run.

@Override
public void run() {
    final TupleFileReader tupleFile = new TupleFileReader(filename, format);
    final List<BoundingBox> samples = new ArrayList<>();
    tupleFile.addTupleListener(t -> {
        final BoundingBox polygonBoundingBox = t.getBoundingBox();
        samples.add(polygonBoundingBox);
    });
    try {
        tupleFile.processFile();
        final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
        final DistributionRegionAdapter adapter = ZookeeperClientFactory.getZookeeperClient().getDistributionRegionAdapter();
        while (getActiveRegions(spacePartitioner).size() < partitions) {
            logger.info("We have now {} of {} active partitons, executing split", getActiveRegions(spacePartitioner).size() < partitions);
            final List<DistributionRegion> activeRegions = getActiveRegions(spacePartitioner);
            final DistributionRegion regionToSplit = ListHelper.getElementRandom(activeRegions);
            logger.info("Splitting region {}", regionToSplit.getRegionId());
            final List<DistributionRegion> destination = spacePartitioner.splitRegion(regionToSplit, samples);
            spacePartitioner.splitComplete(regionToSplit, destination);
        }
        // Prevent merging of nodes
        for (DistributionRegion region : spacePartitioner.getRootNode().getAllChildren()) {
            adapter.setMergingSupported(region, false);
        }
    } catch (Exception e) {
        logger.error("Got an exception", e);
        System.exit(-1);
    }
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) TupleFileReader(org.bboxdb.tools.TupleFileReader) BoundingBox(org.bboxdb.commons.math.BoundingBox) ArrayList(java.util.ArrayList) DistributionRegionAdapter(org.bboxdb.distribution.zookeeper.DistributionRegionAdapter) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 18 with SpacePartitioner

use of org.bboxdb.distribution.partitioner.SpacePartitioner in project bboxdb by jnidzwetzki.

the class SSTableServiceRunnable method testForRegionOverflow.

/**
 * Does the region needs to be split?
 * @param sstableManager
 * @throws BBoxDBException
 * @throws InterruptedException
 */
private void testForRegionOverflow(final TupleStoreManager sstableManager) throws BBoxDBException, InterruptedException {
    // Don't try to split non-distributed tables
    if (!sstableManager.getTupleStoreName().isDistributedTable()) {
        return;
    }
    try {
        final TupleStoreName ssTableName = sstableManager.getTupleStoreName();
        final long regionId = ssTableName.getRegionId().getAsLong();
        final SpacePartitioner spacePartitioner = getSpacePartitioner(ssTableName);
        final DistributionRegion distributionRegion = spacePartitioner.getRootNode();
        final DistributionRegion regionToSplit = DistributionRegionHelper.getDistributionRegionForNamePrefix(distributionRegion, regionId);
        // Region does not exist
        if (regionToSplit == null) {
            return;
        }
        if (!RegionSplitHelper.isSplittingSupported(regionToSplit)) {
            return;
        }
        if (!RegionSplitHelper.isRegionOverflow(regionToSplit)) {
            return;
        }
        executeSplit(sstableManager, spacePartitioner, regionToSplit);
    } catch (Exception e) {
        throw new BBoxDBException(e);
    }
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) BBoxDBException(org.bboxdb.misc.BBoxDBException) RejectedException(org.bboxdb.commons.RejectedException) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) StorageManagerException(org.bboxdb.storage.StorageManagerException) BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 19 with SpacePartitioner

use of org.bboxdb.distribution.partitioner.SpacePartitioner in project bboxdb by jnidzwetzki.

the class SSTableServiceRunnable method testForMergeInGroup.

/**
 * Test for merge in distribution region
 *
 * @param localinstance
 * @param groupName
 * @throws BBoxDBException
 */
private void testForMergeInGroup(final String groupName) throws BBoxDBException {
    final BBoxDBInstance localinstance = ZookeeperClientFactory.getLocalInstanceName();
    final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(groupName);
    final DistributionRegion rootNode = spacePartitioner.getRootNode();
    if (rootNode == null) {
        return;
    }
    final List<DistributionRegion> mergeCandidates = rootNode.getThisAndChildRegions().stream().filter(r -> r.getSystems().contains(localinstance)).collect(Collectors.toList());
    for (final DistributionRegion region : mergeCandidates) {
        testForUnderflow(spacePartitioner, region);
    }
}
Also used : RegionSplitHelper(org.bboxdb.distribution.partitioner.regionsplit.RegionSplitHelper) SSTableWriter(org.bboxdb.storage.sstable.SSTableWriter) LinkedTransferQueue(java.util.concurrent.LinkedTransferQueue) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner) RejectedException(org.bboxdb.commons.RejectedException) DistributionRegionHelper(org.bboxdb.distribution.region.DistributionRegionHelper) ExceptionSafeRunnable(org.bboxdb.commons.concurrent.ExceptionSafeRunnable) RegionMergeHelper(org.bboxdb.distribution.partitioner.regionsplit.RegionMergeHelper) BBoxDBConfiguration(org.bboxdb.misc.BBoxDBConfiguration) LoggerFactory(org.slf4j.LoggerFactory) SSTableFacade(org.bboxdb.storage.sstable.reader.SSTableFacade) ArrayList(java.util.ArrayList) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) SSTableKeyIndexReader(org.bboxdb.storage.sstable.reader.SSTableKeyIndexReader) StorageManagerException(org.bboxdb.storage.StorageManagerException) DiskStorage(org.bboxdb.storage.tuplestore.DiskStorage) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) ZookeeperClientFactory(org.bboxdb.distribution.zookeeper.ZookeeperClientFactory) Logger(org.slf4j.Logger) RegionSplitter(org.bboxdb.distribution.partitioner.regionsplit.RegionSplitter) Set(java.util.Set) Collectors(java.util.stream.Collectors) TupleStoreManagerState(org.bboxdb.storage.tuplestore.manager.TupleStoreManagerState) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) TupleStoreManagerRegistry(org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry) List(java.util.List) RegionMerger(org.bboxdb.distribution.partitioner.regionsplit.RegionMerger) BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitionerCache(org.bboxdb.distribution.partitioner.SpacePartitionerCache) VisibleForTesting(com.google.common.annotations.VisibleForTesting) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 20 with SpacePartitioner

use of org.bboxdb.distribution.partitioner.SpacePartitioner in project bboxdb by jnidzwetzki.

the class KeepAliveHandler method checkLocalTuples.

/**
 * @param tupleStoreManagerRegistry
 * @param tupleStoreName
 * @param tuple
 * @throws BBoxDBException
 * @throws StorageManagerException
 */
private boolean checkLocalTuples(final TupleStoreManagerRegistry tupleStoreManagerRegistry, final TupleStoreName tupleStoreName, final Tuple tuple) throws BBoxDBException {
    final String fullname = tupleStoreName.getDistributionGroup();
    final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(fullname);
    final DistributionRegionIdMapper regionIdMapper = spacePartitioner.getDistributionRegionIdMapper();
    final Collection<TupleStoreName> localTables = regionIdMapper.getLocalTablesForRegion(tuple.getBoundingBox(), tupleStoreName);
    for (final TupleStoreName localTupleStoreName : localTables) {
        try {
            final TupleStoreManager storageManager = tupleStoreManagerRegistry.getTupleStoreManager(localTupleStoreName);
            final String key = tuple.getKey();
            final List<Tuple> localTuples = storageManager.get(key);
            if (localTables.isEmpty()) {
                logger.error("Got empty tuple list during gossip");
                return false;
            }
            final List<Long> localVersions = getSortedVersionList(localTuples);
            final long gossipTupleVersion = tuple.getVersionTimestamp();
            return checkLocalTupleVersions(localVersions, gossipTupleVersion, key);
        } catch (StorageManagerException e) {
            logger.error("Got exception while reading tuples", e);
        }
    }
    return true;
}
Also used : TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) StorageManagerException(org.bboxdb.storage.StorageManagerException) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) Tuple(org.bboxdb.storage.entity.Tuple) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager)

Aggregations

SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)29 BBoxDBException (org.bboxdb.misc.BBoxDBException)16 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)15 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)14 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)10 StorageManagerException (org.bboxdb.storage.StorageManagerException)9 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)8 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 RejectedException (org.bboxdb.commons.RejectedException)3 KDtreeSpacePartitioner (org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner)3 SpacePartitionerCache (org.bboxdb.distribution.partitioner.SpacePartitionerCache)3 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)3 DistributionRegionAdapter (org.bboxdb.distribution.zookeeper.DistributionRegionAdapter)3 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)3 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)3 TupleStoreManagerRegistry (org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry)3 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2