Search in sources :

Example 11 with DistributionRegionIdMapper

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

the class StatisticsUpdateRunnable method updateRegionStatistics.

/**
 * Update the statistics of the region
 */
private void updateRegionStatistics() {
    try {
        final List<String> allDistributionGroups = groupAdapter.getDistributionGroups();
        for (final String distributionGroup : allDistributionGroups) {
            final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
            final DistributionRegionIdMapper regionIdMapper = spacePartitioner.getDistributionRegionIdMapper();
            final Collection<Long> allIds = regionIdMapper.getRegionIdsForRegion(BoundingBox.FULL_SPACE);
            for (final long id : allIds) {
                updateRegionStatistics(distributionGroup, id);
            }
        }
    } catch (Exception e) {
        logger.error("Got exception while updating statistics", e);
    }
}
Also used : DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) BBoxDBException(org.bboxdb.misc.BBoxDBException) StorageManagerException(org.bboxdb.storage.StorageManagerException) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 12 with DistributionRegionIdMapper

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

the class RegionMerger method redistributeDataMerge.

/**
 * Redistribute the data in region merge
 * @param source
 * @param destination
 * @throws Exception
 */
private void redistributeDataMerge(final List<DistributionRegion> source, final DistributionRegion destination) throws Exception {
    logger.info("Redistributing all data for region (merge): " + destination.getIdentifier());
    final String distributionGroupName = destination.getDistributionGroupName();
    final List<TupleStoreName> localTables = TupleStoreUtil.getAllTablesForDistributionGroupAndRegionId(registry, distributionGroupName, destination.getRegionId());
    // Add the local mapping, new data is written to the region
    final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroupName);
    final DistributionRegionIdMapper mapper = spacePartitioner.getDistributionRegionIdMapper();
    // We have set the region to active, wait until we see this status change
    // from Zookeeper and the space partitioner add this region as active
    mapper.waitUntilMappingAppears(destination.getRegionId());
    // Redistribute data
    for (final TupleStoreName tupleStoreName : localTables) {
        logger.info("Merging data of tuple store {}", tupleStoreName);
        startFlushToDisk(tupleStoreName);
        final TupleRedistributor tupleRedistributor = new TupleRedistributor(registry, tupleStoreName);
        tupleRedistributor.registerRegion(destination);
        for (final DistributionRegion childRegion : source) {
            mergeDataFromChildRegion(destination, tupleStoreName, tupleRedistributor, childRegion);
        }
        logger.info("Final statistics for merge ({}): {}", tupleStoreName, tupleRedistributor.getStatistics());
    }
}
Also used : TupleRedistributor(org.bboxdb.distribution.partitioner.regionsplit.tuplesink.TupleRedistributor) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 13 with DistributionRegionIdMapper

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

the class RegionSplitter method redistributeDataSplit.

/**
 * Redistribute data after region split
 * @param region
 */
private void redistributeDataSplit(final DistributionRegion source, final List<DistributionRegion> destination) {
    final long regionId = source.getRegionId();
    try {
        logger.info("Redistributing all data for region: {}", regionId);
        final String distributionGroupName = source.getDistributionGroupName();
        final List<TupleStoreName> localTables = TupleStoreUtil.getAllTablesForDistributionGroupAndRegionId(registry, distributionGroupName, regionId);
        // Remove the local mapping, no new data is written to the region
        final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroupName);
        final DistributionRegionIdMapper mapper = spacePartitioner.getDistributionRegionIdMapper();
        // We have set the region to splitting, wait until we see this status change
        // from Zookeeper and the space partitioner removed this region as active
        mapper.waitUntilMappingDisappears(regionId);
        // Redistribute data
        for (final TupleStoreName ssTableName : localTables) {
            // Reject new writes and flush to disk
            stopFlushToDisk(ssTableName);
            distributeData(ssTableName, source, destination);
        }
    } catch (InterruptedException e) {
        logger.warn("Thread was interrupted");
        Thread.currentThread().interrupt();
        return;
    } catch (Exception e) {
        logger.error("Got exception when redistribute local data", e);
        return;
    }
    logger.info("Redistributing data for region: {} DONE", regionId);
}
Also used : TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) BBoxDBException(org.bboxdb.misc.BBoxDBException) StorageManagerException(org.bboxdb.storage.StorageManagerException) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 14 with DistributionRegionIdMapper

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

Example 15 with DistributionRegionIdMapper

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

the class TestRegionIdMapper method testMappingAppears1.

/**
 * Wait until mapping appears
 * @throws InterruptedException
 * @throws TimeoutException
 */
@Test(timeout = 10000)
public void testMappingAppears1() throws TimeoutException, InterruptedException {
    final DistributionRegionIdMapper regionIdMapper = new DistributionRegionIdMapper(DISTRIBUTION_REGION_NAME);
    regionIdMapper.addMapping(3, new BoundingBox(15d, 18d, 15d, 18d));
    regionIdMapper.waitUntilMappingAppears(3);
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) Test(org.junit.Test)

Aggregations

DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)25 Test (org.junit.Test)14 BoundingBox (org.bboxdb.commons.math.BoundingBox)11 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)11 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)9 BBoxDBException (org.bboxdb.misc.BBoxDBException)6 StorageManagerException (org.bboxdb.storage.StorageManagerException)5 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)3 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)3 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)2 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)2 DistributionRegionCallback (org.bboxdb.distribution.region.DistributionRegionCallback)2 Tuple (org.bboxdb.storage.entity.Tuple)2 RejectedException (org.bboxdb.commons.RejectedException)1 KDtreeSpacePartitioner (org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner)1 SpacePartitionerContext (org.bboxdb.distribution.partitioner.SpacePartitionerContext)1 TupleRedistributor (org.bboxdb.distribution.partitioner.regionsplit.tuplesink.TupleRedistributor)1 DistributionRegionSyncer (org.bboxdb.distribution.region.DistributionRegionSyncer)1 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)1 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)1