Search in sources :

Example 6 with TupleRedistributor

use of org.bboxdb.distribution.partitioner.regionsplit.tuplesink.TupleRedistributor 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 7 with TupleRedistributor

use of org.bboxdb.distribution.partitioner.regionsplit.tuplesink.TupleRedistributor in project bboxdb by jnidzwetzki.

the class RegionSplitter method distributeData.

/**
 * Redistribute the given sstable
 * @param ssTableName
 * @param source
 * @param destination
 * @throws StorageManagerException
 */
private void distributeData(final TupleStoreName ssTableName, final DistributionRegion source, final List<DistributionRegion> destination) throws BBoxDBException, StorageManagerException {
    logger.info("Redistributing table {}", ssTableName.getFullname());
    final TupleStoreManager ssTableManager = registry.getTupleStoreManager(ssTableName);
    // Spread data
    final TupleRedistributor tupleRedistributor = getTupleRedistributor(source, destination, ssTableName);
    spreadTupleStores(ssTableManager, tupleRedistributor);
    logger.info("Redistributing table {} is DONE", ssTableName.getFullname());
}
Also used : TupleRedistributor(org.bboxdb.distribution.partitioner.regionsplit.tuplesink.TupleRedistributor) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager)

Example 8 with TupleRedistributor

use of org.bboxdb.distribution.partitioner.regionsplit.tuplesink.TupleRedistributor in project bboxdb by jnidzwetzki.

the class TestTupleSink method testTupleRedistribution2.

/**
 * Test the tuple redistribution
 * @throws Exception
 */
@Test(timeout = 60000)
public void testTupleRedistribution2() throws Exception {
    final DistributionRegion distributionRegion1 = new DistributionRegion(TEST_GROUP, DistributionRegion.ROOT_NODE_ROOT_POINTER, new BoundingBox(0.0, 1.0, 0.0, 1.0, 0.0, 1.0), 1);
    final DistributionRegion distributionRegion2 = new DistributionRegion(TEST_GROUP, DistributionRegion.ROOT_NODE_ROOT_POINTER, new BoundingBox(5.0, 6.0, 5.0, 6.0, 5.0, 6.0), 1);
    final TupleRedistributor tupleRedistributor = createTupleRedistributor();
    final AbstractTupleSink tupleSink1 = Mockito.mock(AbstractTupleSink.class);
    tupleRedistributor.registerRegion(distributionRegion1, Arrays.asList(tupleSink1));
    final AbstractTupleSink tupleSink2 = Mockito.mock(AbstractTupleSink.class);
    tupleRedistributor.registerRegion(distributionRegion2, Arrays.asList(tupleSink2));
    final Tuple tuple1 = new Tuple("abc", new BoundingBox(0.0, 1.0, 0.0, 1.0, 0.0, 1.0), "".getBytes());
    tupleRedistributor.redistributeTuple(tuple1);
    (Mockito.verify(tupleSink1, Mockito.times(1))).sinkTuple(Mockito.any(Tuple.class));
    (Mockito.verify(tupleSink2, Mockito.never())).sinkTuple(Mockito.any(Tuple.class));
    final Tuple tuple2 = new Tuple("abc", new BoundingBox(5.0, 6.0, 5.0, 6.0, 5.0, 6.0), "".getBytes());
    tupleRedistributor.redistributeTuple(tuple2);
    (Mockito.verify(tupleSink1, Mockito.times(1))).sinkTuple(Mockito.any(Tuple.class));
    (Mockito.verify(tupleSink2, Mockito.times(1))).sinkTuple(Mockito.any(Tuple.class));
    final Tuple tuple3 = new Tuple("abc", new BoundingBox(0.0, 6.0, 0.0, 6.0, 0.0, 6.0), "".getBytes());
    tupleRedistributor.redistributeTuple(tuple3);
    (Mockito.verify(tupleSink1, Mockito.atLeast(2))).sinkTuple(Mockito.any(Tuple.class));
    (Mockito.verify(tupleSink2, Mockito.atLeast(2))).sinkTuple(Mockito.any(Tuple.class));
    final Tuple tuple4 = new DeletedTuple("abc");
    tupleRedistributor.redistributeTuple(tuple4);
    (Mockito.verify(tupleSink1, Mockito.atLeast(3))).sinkTuple(Mockito.any(Tuple.class));
    (Mockito.verify(tupleSink2, Mockito.atLeast(3))).sinkTuple(Mockito.any(Tuple.class));
    System.out.println(tupleRedistributor.getStatistics());
}
Also used : TupleRedistributor(org.bboxdb.distribution.partitioner.regionsplit.tuplesink.TupleRedistributor) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BoundingBox(org.bboxdb.commons.math.BoundingBox) AbstractTupleSink(org.bboxdb.distribution.partitioner.regionsplit.tuplesink.AbstractTupleSink) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Aggregations

TupleRedistributor (org.bboxdb.distribution.partitioner.regionsplit.tuplesink.TupleRedistributor)8 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)5 Test (org.junit.Test)5 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)4 Tuple (org.bboxdb.storage.entity.Tuple)4 BoundingBox (org.bboxdb.commons.math.BoundingBox)3 AbstractTupleSink (org.bboxdb.distribution.partitioner.regionsplit.tuplesink.AbstractTupleSink)3 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)3 TupleStoreManagerRegistry (org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)1 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)1 SpacePartitionerCache (org.bboxdb.distribution.partitioner.SpacePartitionerCache)1 LocalTupleSink (org.bboxdb.distribution.partitioner.regionsplit.tuplesink.LocalTupleSink)1 NetworkTupleSink (org.bboxdb.distribution.partitioner.regionsplit.tuplesink.NetworkTupleSink)1 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)1 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)1