Search in sources :

Example 56 with TupleStoreName

use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.

the class TupleStoreUtil method getSizeOfDistributionGroupAndRegionId.

/**
 * Get the size of all sstables in the distribution group and region id
 * @param distributionGroupName
 * @param regionId
 * @return
 * @throws StorageManagerException
 */
public static long getSizeOfDistributionGroupAndRegionId(final TupleStoreManagerRegistry registry, final String distributionGroupName, final long regionId) throws StorageManagerException {
    final List<TupleStoreName> tables = getAllTablesForDistributionGroupAndRegionId(registry, distributionGroupName, regionId);
    long totalSize = 0;
    for (TupleStoreName ssTableName : tables) {
        totalSize = totalSize + registry.getTupleStoreManager(ssTableName).getSize();
    }
    return totalSize;
}
Also used : TupleStoreName(org.bboxdb.storage.entity.TupleStoreName)

Example 57 with TupleStoreName

use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.

the class TupleStoreZookeeperObserver method registerTable.

/**
 * Register a new table, a callback is registered on the space partitioner
 * to delete the table when it is split or merged
 *
 * @param tupleStoreName
 */
public void registerTable(final TupleStoreName tupleStoreName) {
    if (!tupleStoreName.isDistributedTable()) {
        return;
    }
    final String distributionGroup = tupleStoreName.getDistributionGroup();
    final DistributionRegionEntity tableEntity = new DistributionRegionEntity(distributionGroup, tupleStoreName.getRegionId().getAsLong());
    synchronized (knownRegions) {
        if (knownRegions.contains(tableEntity)) {
            return;
        }
        // Register callback
        final DistributionRegionCallback callback = (e, r) -> {
            handleCallback(tableEntity, e, r);
        };
        try {
            final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
            spacePartitioner.registerCallback(callback);
            knownRegions.add(tableEntity);
        } catch (BBoxDBException e) {
            logger.error("Unable to register callback", e);
        }
    }
}
Also used : DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner) ZookeeperClientFactory(org.bboxdb.distribution.zookeeper.ZookeeperClientFactory) Logger(org.slf4j.Logger) TupleStoreAdapter(org.bboxdb.distribution.zookeeper.TupleStoreAdapter) Collection(java.util.Collection) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) TupleStoreConfigurationCache(org.bboxdb.distribution.TupleStoreConfigurationCache) DistributionRegionState(org.bboxdb.distribution.partitioner.DistributionRegionState) WatchedEvent(org.apache.zookeeper.WatchedEvent) ZookeeperClient(org.bboxdb.distribution.zookeeper.ZookeeperClient) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) HashSet(java.util.HashSet) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) List(java.util.List) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionRegionEvent(org.bboxdb.distribution.region.DistributionRegionEvent) BBoxDBException(org.bboxdb.misc.BBoxDBException) DistributionGroupAdapter(org.bboxdb.distribution.zookeeper.DistributionGroupAdapter) SpacePartitionerCache(org.bboxdb.distribution.partitioner.SpacePartitionerCache) StorageManagerException(org.bboxdb.storage.StorageManagerException) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 58 with TupleStoreName

use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.

the class TupleStoreZookeeperObserver method deleteAllDeletedTables.

/**
 * Delete all deleted tables
 *
 * @param distributionGroup
 * @param allZookeeperTables
 * @throws BBoxDBException
 * @throws StorageManagerException
 */
private void deleteAllDeletedTables(final String distributionGroup, final List<String> allZookeeperTables) throws BBoxDBException, StorageManagerException {
    final List<TupleStoreName> allLocalTables = registry.getAllTablesForDistributionGroup(distributionGroup);
    final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
    final DistributionRegionIdMapper regionIdMapper = spacePartitioner.getDistributionRegionIdMapper();
    for (final TupleStoreName localTable : allLocalTables) {
        final String localTableName = localTable.getFullnameWithoutPrefix();
        if (!allZookeeperTables.contains(localTableName)) {
            logger.info("Table {} is not known in zookeeper, deleting local", localTableName);
            final Collection<TupleStoreName> localTables = regionIdMapper.getAllLocalTables(localTable);
            for (final TupleStoreName ssTableName : localTables) {
                registry.deleteTable(ssTableName, false);
            }
        }
    }
}
Also used : TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 59 with TupleStoreName

use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.

the class TestNetworkClasses method testDecodePackage.

/**
 * Decode an encoded package
 * @throws IOException
 * @throws PackageEncodeException
 */
@Test(timeout = 60000)
public void testDecodePackage() throws IOException, PackageEncodeException {
    final Tuple tuple = new Tuple("key", BoundingBox.FULL_SPACE, "abc".getBytes(), 12);
    final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
    final InsertTupleRequest insertPackage = new InsertTupleRequest(sequenceNumber, ROUTING_HEADER_UNROUTED, new TupleStoreName("test"), tuple);
    byte[] encodedPackage = networkPackageToByte(insertPackage);
    Assert.assertNotNull(encodedPackage);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
    boolean result = NetworkPackageDecoder.validateRequestPackageHeader(bb, NetworkConst.REQUEST_TYPE_INSERT_TUPLE);
    Assert.assertTrue(result);
}
Also used : TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ByteBuffer(java.nio.ByteBuffer) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) InsertTupleRequest(org.bboxdb.network.packages.request.InsertTupleRequest) Test(org.junit.Test)

Example 60 with TupleStoreName

use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.

the class TestNetworkClasses method testGetSequenceNumber.

/**
 * Get the sequence number from a package
 * @throws IOException
 * @throws PackageEncodeException
 */
@Test(timeout = 60000)
public void testGetSequenceNumber() throws IOException, PackageEncodeException {
    final Tuple tuple = new Tuple("key", BoundingBox.FULL_SPACE, "abc".getBytes(), 12);
    // Increment to avoid sequenceNumber = 0
    sequenceNumberGenerator.getNextSequenceNummber();
    sequenceNumberGenerator.getNextSequenceNummber();
    final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
    final InsertTupleRequest insertPackage = new InsertTupleRequest(sequenceNumber, ROUTING_HEADER_UNROUTED, new TupleStoreName("test"), tuple);
    final byte[] encodedPackage = networkPackageToByte(insertPackage);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
    final short packageSequencenNumber = NetworkPackageDecoder.getRequestIDFromRequestPackage(bb);
    Assert.assertEquals(sequenceNumber, packageSequencenNumber);
}
Also used : TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ByteBuffer(java.nio.ByteBuffer) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) InsertTupleRequest(org.bboxdb.network.packages.request.InsertTupleRequest) Test(org.junit.Test)

Aggregations

TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)77 Test (org.junit.Test)25 Tuple (org.bboxdb.storage.entity.Tuple)18 StorageManagerException (org.bboxdb.storage.StorageManagerException)15 ArrayList (java.util.ArrayList)14 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)14 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)13 ByteBuffer (java.nio.ByteBuffer)12 BoundingBox (org.bboxdb.commons.math.BoundingBox)12 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)12 BBoxDBException (org.bboxdb.misc.BBoxDBException)12 InsertTupleRequest (org.bboxdb.network.packages.request.InsertTupleRequest)12 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)12 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)12 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)11 List (java.util.List)10 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)10 TupleStoreManagerRegistry (org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry)10 ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)9 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)9