Search in sources :

Example 46 with DistributionRegion

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

the class TreeJPanel method paintComponent.

@Override
protected void paintComponent(final Graphics g) {
    super.paintComponent(g);
    setBackground(Color.WHITE);
    // Group is not set
    if (guiModel.getTreeAdapter() == null) {
        return;
    }
    final Graphics2D graphics2D = (Graphics2D) g;
    graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    graphics2D.scale(zoomFactor, zoomFactor);
    try {
        final DistributionRegion distributionRegion = guiModel.getTreeAdapter().getRootNode();
        regions.clear();
        if (distributionRegion == null) {
            logger.error("Got null root node");
            return;
        }
        final int maxChildren = distributionRegion.getThisAndChildRegions().stream().mapToInt(r -> r.getDirectChildren().size()).max().orElse(0);
        // Fake position to calculate the real width
        rootPosX = 100000;
        createDistribtionRegionComponents(distributionRegion, maxChildren);
        calculateRootNodeXPos();
        final BoundingBox drawBox = drawDistributionRegion(graphics2D);
        updateComponentSize(drawBox);
    } catch (BBoxDBException e) {
        logger.error("Got an exception", e);
    }
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BoundingBox(org.bboxdb.commons.math.BoundingBox) BBoxDBException(org.bboxdb.misc.BBoxDBException) Graphics2D(java.awt.Graphics2D)

Example 47 with DistributionRegion

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

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

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

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

the class BBoxDBCluster method deleteTuple.

@Override
public EmptyResultFuture deleteTuple(final String table, final String key, final long timestamp) throws BBoxDBException {
    final DeletedTuple tuple = new DeletedTuple(key);
    final DistributionRegion distributionRegion = getRootNode(table);
    final Supplier<List<NetworkOperationFuture>> supplier = () -> {
        final List<RoutingHop> hops = RoutingHopHelper.getRoutingHopsForWrite(distributionRegion, tuple.getBoundingBox());
        final List<NetworkOperationFuture> futures = new ArrayList<>();
        for (final RoutingHop hop : hops) {
            final BBoxDBInstance instance = hop.getDistributedInstance();
            final BBoxDBConnection connection = membershipConnectionService.getConnectionForInstance(instance);
            final RoutingHeader routingHeader = new RoutingHeader((short) 0, Arrays.asList(hop));
            final NetworkOperationFuture future = connection.getBboxDBClient().getInsertTupleFuture(table, tuple, routingHeader);
            futures.add(future);
        }
        return futures;
    };
    return new EmptyResultFuture(supplier);
}
Also used : DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) ArrayList(java.util.ArrayList) List(java.util.List) RoutingHop(org.bboxdb.network.routing.RoutingHop) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

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