Search in sources :

Example 66 with DistributionRegion

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

the class TestZookeeperIntegration method testStatistics1.

/**
 * Test the statistics for a given region
 * @throws ZookeeperException
 * @throws ZookeeperNotFoundException
 * @throws BBoxDBException
 */
@Test(timeout = 60000)
public void testStatistics1() throws ZookeeperException, ZookeeperNotFoundException, BBoxDBException {
    final BBoxDBInstance system1 = new BBoxDBInstance("192.168.1.10:5050");
    final BBoxDBInstance system2 = new BBoxDBInstance("192.168.1.11:5050");
    final DistributionRegion region = getSpacePartitioner().getRootNode();
    final OptionalDouble size1 = StatisticsHelper.getAndUpdateStatistics(region);
    Assert.assertFalse(size1.isPresent());
    final Map<BBoxDBInstance, Map<String, Long>> statistics1 = distributionRegionAdapter.getRegionStatistics(region);
    Assert.assertTrue(statistics1.isEmpty());
    distributionRegionAdapter.updateRegionStatistics(region, system1, 12, 999);
    final Map<BBoxDBInstance, Map<String, Long>> statistics2 = distributionRegionAdapter.getRegionStatistics(region);
    Assert.assertEquals(1, statistics2.size());
    Assert.assertEquals(12, statistics2.get(system1).get(ZookeeperNodeNames.NAME_STATISTICS_TOTAL_SIZE).longValue());
    Assert.assertEquals(999, statistics2.get(system1).get(ZookeeperNodeNames.NAME_STATISTICS_TOTAL_TUPLES).longValue());
    final OptionalDouble size2 = StatisticsHelper.getAndUpdateStatistics(region);
    Assert.assertEquals(12, size2.getAsDouble(), DELTA);
    distributionRegionAdapter.updateRegionStatistics(region, system2, 33, 1234);
    final Map<BBoxDBInstance, Map<String, Long>> statistics3 = distributionRegionAdapter.getRegionStatistics(region);
    Assert.assertEquals(2, statistics3.size());
    Assert.assertEquals(12, statistics3.get(system1).get(ZookeeperNodeNames.NAME_STATISTICS_TOTAL_SIZE).longValue());
    Assert.assertEquals(999, statistics3.get(system1).get(ZookeeperNodeNames.NAME_STATISTICS_TOTAL_TUPLES).longValue());
    Assert.assertEquals(33, statistics3.get(system2).get(ZookeeperNodeNames.NAME_STATISTICS_TOTAL_SIZE).longValue());
    Assert.assertEquals(1234, statistics3.get(system2).get(ZookeeperNodeNames.NAME_STATISTICS_TOTAL_TUPLES).longValue());
    final OptionalDouble size3 = StatisticsHelper.getAndUpdateStatistics(region);
    Assert.assertEquals(33, size3.getAsDouble(), DELTA);
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) Map(java.util.Map) OptionalDouble(java.util.OptionalDouble) Test(org.junit.Test)

Example 67 with DistributionRegion

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

the class CLI method printDistributionRegionRecursive.

/**
 * Print the content of the distribution region recursive
 * @param distributionRegion
 */
protected void printDistributionRegionRecursive(final DistributionRegion distributionRegion) {
    if (distributionRegion == null) {
        return;
    }
    final BoundingBox boundingBox = distributionRegion.getConveringBox();
    final String bboxString = IntStream.range(0, boundingBox.getDimension()).mapToObj(i -> "Dimension:" + i + " " + boundingBox.getIntervalForDimension(i).toString()).collect(Collectors.joining(", "));
    final String systemsString = distributionRegion.getSystems().stream().map(s -> s.getIp() + ":" + s.getPort()).collect(Collectors.joining(", ", "[", "]"));
    System.out.format("Region %d, Bounding Box=%s, State=%s, Systems=%s%n", distributionRegion.getRegionId(), bboxString, distributionRegion.getState(), systemsString);
    for (final DistributionRegion region : distributionRegion.getDirectChildren()) {
        printDistributionRegionRecursive(region);
    }
}
Also used : IntStream(java.util.stream.IntStream) BBoxDBInstanceManager(org.bboxdb.distribution.membership.BBoxDBInstanceManager) Arrays(java.util.Arrays) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner) TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) DistributionGroupConfigurationCache(org.bboxdb.distribution.DistributionGroupConfigurationCache) Options(org.apache.commons.cli.Options) Tuple(org.bboxdb.storage.entity.Tuple) LoggerFactory(org.slf4j.LoggerFactory) HelpFormatter(org.apache.commons.cli.HelpFormatter) BBoxDB(org.bboxdb.network.client.BBoxDB) BoundingBox(org.bboxdb.commons.math.BoundingBox) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) DefaultParser(org.apache.commons.cli.DefaultParser) Const(org.bboxdb.misc.Const) BBoxDBCluster(org.bboxdb.network.client.BBoxDBCluster) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) CommandLine(org.apache.commons.cli.CommandLine) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) Option(org.apache.commons.cli.Option) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) Logger(org.slf4j.Logger) CommandLineParser(org.apache.commons.cli.CommandLineParser) DistributionGroupConfigurationBuilder(org.bboxdb.storage.entity.DistributionGroupConfigurationBuilder) IOException(java.io.IOException) TupleStoreConfigurationBuilder(org.bboxdb.storage.entity.TupleStoreConfigurationBuilder) Collectors(java.util.stream.Collectors) JoinedTupleListFuture(org.bboxdb.network.client.future.JoinedTupleListFuture) FixedSizeFutureStore(org.bboxdb.network.client.tools.FixedSizeFutureStore) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) ParseException(org.apache.commons.cli.ParseException) TupleFileReader(org.bboxdb.tools.TupleFileReader) TupleBuilderFactory(org.bboxdb.tools.converter.tuple.TupleBuilderFactory) BBoxDBException(org.bboxdb.misc.BBoxDBException) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) SpacePartitionerCache(org.bboxdb.distribution.partitioner.SpacePartitionerCache) MathUtil(org.bboxdb.commons.MathUtil) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BoundingBox(org.bboxdb.commons.math.BoundingBox)

Example 68 with DistributionRegion

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

the class TestDistributionGroup method createDistributionGroup.

/**
 * @param dimensions
 * @return
 */
private DistributionRegion createDistributionGroup(final int dimensions) {
    final String name = "foo";
    DistributionGroupConfigurationCache.getInstance().clear();
    final DistributionGroupConfiguration config = new DistributionGroupConfiguration();
    config.setDimensions(dimensions);
    DistributionGroupConfigurationCache.getInstance().addNewConfiguration(name, config);
    final DistributionRegion level0 = new DistributionRegion(name, BoundingBox.createFullCoveringDimensionBoundingBox(dimensions));
    return level0;
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration)

Example 69 with DistributionRegion

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

the class TestZookeeperIntegration method testStatistics2.

/**
 * Test the statistics of child regions
 * @throws Exception
 */
@Test(timeout = 60000)
public void testStatistics2() throws Exception {
    final BBoxDBInstance system1 = new BBoxDBInstance("192.168.1.10:5050");
    final KDtreeSpacePartitioner spaceparitioner = (KDtreeSpacePartitioner) getSpacePartitioner();
    final DistributionRegion region = spaceparitioner.getRootNode();
    final OptionalDouble totalSize1 = RegionMergeHelper.getTotalRegionSize(region.getDirectChildren());
    Assert.assertFalse(totalSize1.isPresent());
    spaceparitioner.splitNode(region, 12);
    spaceparitioner.waitForSplitCompleteZookeeperCallback(region, 2);
    distributionRegionAdapter.updateRegionStatistics(region.getDirectChildren().get(0), system1, 12, 999);
    distributionRegionAdapter.updateRegionStatistics(region.getDirectChildren().get(1), system1, 33, 999);
    StatisticsHelper.clearHistory();
    final OptionalDouble totalSizeAfterClear = RegionMergeHelper.getTotalRegionSize(region.getDirectChildren());
    Assert.assertFalse(totalSizeAfterClear.isPresent());
    // Update complete history
    for (int i = 0; i < StatisticsHelper.HISTORY_LENGTH; i++) {
        RegionMergeHelper.getTotalRegionSize(region.getDirectChildren());
    }
    final OptionalDouble totalSize2 = RegionMergeHelper.getTotalRegionSize(region.getDirectChildren());
    Assert.assertEquals(45, totalSize2.getAsDouble(), DELTA);
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) KDtreeSpacePartitioner(org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner) OptionalDouble(java.util.OptionalDouble) Test(org.junit.Test)

Example 70 with DistributionRegion

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

the class TestZookeeperIntegration method testSystemRegisterAndUnregister.

/**
 * Test the system register and unregister methods
 * @throws ZookeeperException
 * @throws ZookeeperNotFoundException
 * @throws BBoxDBException
 */
@Test(timeout = 60000)
public void testSystemRegisterAndUnregister() throws ZookeeperException, ZookeeperNotFoundException, BBoxDBException {
    final BBoxDBInstance systemName = new BBoxDBInstance("192.168.1.10:5050");
    final DistributionRegion region = getSpacePartitioner().getRootNode();
    final Collection<BBoxDBInstance> systems1 = distributionRegionAdapter.getSystemsForDistributionRegion(region);
    Assert.assertEquals(1, systems1.size());
    // Add a system
    final String path = distributionRegionAdapter.getZookeeperPathForDistributionRegion(region);
    distributionRegionAdapter.addSystemToDistributionRegion(path, systemName);
    final Collection<BBoxDBInstance> systems2 = distributionRegionAdapter.getSystemsForDistributionRegion(region);
    Assert.assertEquals(2, systems2.size());
    Assert.assertTrue(systems2.contains(systemName));
    distributionRegionAdapter.deleteSystemFromDistributionRegion(region, systemName);
    final Collection<BBoxDBInstance> systems3 = distributionRegionAdapter.getSystemsForDistributionRegion(region);
    Assert.assertEquals(1, systems3.size());
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) Test(org.junit.Test)

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