Search in sources :

Example 26 with SpacePartitioner

use of org.bboxdb.distribution.partitioner.SpacePartitioner in project bboxdb by jnidzwetzki.

the class CreateDistributionGroupHandler method handleRequest.

@Override
public /**
 * Create a new distribution group
 */
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
    try {
        final CreateDistributionGroupRequest createPackage = CreateDistributionGroupRequest.decodeTuple(encodedPackage);
        final String distributionGroup = createPackage.getDistributionGroup();
        logger.info("Create distribution group: {}", distributionGroup);
        final DistributionGroupAdapter distributionGroupAdapter = ZookeeperClientFactory.getZookeeperClient().getDistributionGroupAdapter();
        final DistributionRegionAdapter distributionRegionAdapter = ZookeeperClientFactory.getZookeeperClient().getDistributionRegionAdapter();
        final List<String> knownGroups = distributionGroupAdapter.getDistributionGroups();
        if (knownGroups.contains(distributionGroup)) {
            logger.error("Untable to create distributon group {}, already exists", distributionGroup);
            final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_DGROUP_EXISTS);
            clientConnectionHandler.writeResultPackage(responsePackage);
            return true;
        }
        distributionGroupAdapter.createDistributionGroup(distributionGroup, createPackage.getDistributionGroupConfiguration());
        final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
        final DistributionRegion region = spacePartitioner.getRootNode();
        distributionRegionAdapter.setStateForDistributionRegion(region, DistributionRegionState.ACTIVE);
        clientConnectionHandler.writeResultPackage(new SuccessResponse(packageSequence));
    } catch (Exception e) {
        logger.warn("Error while create distribution group", e);
        final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
        clientConnectionHandler.writeResultPackage(responsePackage);
    }
    return true;
}
Also used : DistributionGroupAdapter(org.bboxdb.distribution.zookeeper.DistributionGroupAdapter) SuccessResponse(org.bboxdb.network.packages.response.SuccessResponse) CreateDistributionGroupRequest(org.bboxdb.network.packages.request.CreateDistributionGroupRequest) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionRegionAdapter(org.bboxdb.distribution.zookeeper.DistributionRegionAdapter) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) IOException(java.io.IOException) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 27 with SpacePartitioner

use of org.bboxdb.distribution.partitioner.SpacePartitioner in project bboxdb by jnidzwetzki.

the class InsertTupleHandler method processInsertPackage.

/**
 * Insert the table into the local storage
 * @param tuple
 * @param requestTable
 * @param storageRegistry
 * @param routingHeader
 * @throws StorageManagerException
 * @throws RejectedException
 * @throws BBoxDBException
 */
protected void processInsertPackage(final Tuple tuple, final TupleStoreName requestTable, final TupleStoreManagerRegistry storageRegistry, final List<Long> distributionRegions) throws RejectedException {
    try {
        final String fullname = requestTable.getDistributionGroup();
        final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(fullname);
        final DistributionRegionIdMapper regionIdMapper = spacePartitioner.getDistributionRegionIdMapper();
        final Collection<TupleStoreName> localTables = regionIdMapper.convertRegionIdToTableNames(requestTable, distributionRegions);
        if (localTables.isEmpty()) {
            throw new BBoxDBException("Got no local tables for routed package");
        }
        // Are some tables unknown and needs to be created?
        final boolean unknownTables = localTables.stream().anyMatch((t) -> !storageRegistry.isStorageManagerKnown(t));
        // Expensive call (involves Zookeeper interaction)
        if (unknownTables) {
            createMissingTables(requestTable, storageRegistry, localTables);
        }
        // Insert tuples
        for (final TupleStoreName tupleStoreName : localTables) {
            final TupleStoreManager storageManager = storageRegistry.getTupleStoreManager(tupleStoreName);
            storageManager.put(tuple);
        }
    } catch (RejectedException e) {
        throw e;
    } catch (Throwable e) {
        throw new RejectedException(e);
    }
}
Also used : RejectedException(org.bboxdb.commons.RejectedException) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager)

Example 28 with SpacePartitioner

use of org.bboxdb.distribution.partitioner.SpacePartitioner in project bboxdb by jnidzwetzki.

the class CompactorHelper method isRegionActive.

/**
 * Is the region for the table active?
 *
 * @param tupleStoreName
 * @return
 * @throws StorageManagerException
 * @throws InterruptedException
 */
public static boolean isRegionActive(final TupleStoreName tupleStoreName) throws StorageManagerException, InterruptedException {
    try {
        if (!tupleStoreName.isDistributedTable()) {
            logger.error("Tuple store {} is not a distributed table, untable to split", tupleStoreName);
            return false;
        }
        final long regionId = tupleStoreName.getRegionId().getAsLong();
        final String distributionGroup = tupleStoreName.getDistributionGroup();
        final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
        final DistributionRegion distributionRegion = spacePartitioner.getRootNode();
        final DistributionRegion regionToSplit = DistributionRegionHelper.getDistributionRegionForNamePrefix(distributionRegion, regionId);
        // Region does not exist
        if (regionToSplit == null) {
            logger.error("Unable to get distribution region {} {}", distributionRegion, regionId);
            return false;
        }
        if (regionToSplit.isRootElement()) {
            return true;
        }
        return regionToSplit.getState() == DistributionRegionState.ACTIVE;
    } catch (BBoxDBException e) {
        throw new StorageManagerException(e);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw e;
    }
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) StorageManagerException(org.bboxdb.storage.StorageManagerException) BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 29 with SpacePartitioner

use of org.bboxdb.distribution.partitioner.SpacePartitioner in project bboxdb by jnidzwetzki.

the class DistributedRecoveryService method runRecoveryForDistributionGroup.

/**
 * Run recovery for distribution group
 * @param distributionGroupName
 * @throws ZookeeperException
 */
protected void runRecoveryForDistributionGroup(final String distributionGroupName) {
    try {
        final ZookeeperClient zookeeperClient = ZookeeperClientFactory.getZookeeperClient();
        final BBoxDBInstance localInstance = ZookeeperClientFactory.getLocalInstanceName();
        for (final DiskStorage storage : storageRegistry.getAllStorages()) {
            checkGroupVersion(storage, distributionGroupName, zookeeperClient);
        }
        final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroupName);
        final DistributionRegion distributionGroup = spacePartitioner.getRootNode();
        final List<OutdatedDistributionRegion> outdatedRegions = DistributionRegionHelper.getOutdatedRegions(distributionGroup, localInstance);
        handleOutdatedRegions(distributionGroupName, outdatedRegions);
    } catch (Throwable e) {
        logger.error("Got exception while running recovery for distribution group: " + distributionGroupName, e);
    }
}
Also used : ZookeeperClient(org.bboxdb.distribution.zookeeper.ZookeeperClient) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) DiskStorage(org.bboxdb.storage.tuplestore.DiskStorage) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Aggregations

SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)29 BBoxDBException (org.bboxdb.misc.BBoxDBException)16 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)15 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)14 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)10 StorageManagerException (org.bboxdb.storage.StorageManagerException)9 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)8 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 RejectedException (org.bboxdb.commons.RejectedException)3 KDtreeSpacePartitioner (org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner)3 SpacePartitionerCache (org.bboxdb.distribution.partitioner.SpacePartitionerCache)3 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)3 DistributionRegionAdapter (org.bboxdb.distribution.zookeeper.DistributionRegionAdapter)3 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)3 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)3 TupleStoreManagerRegistry (org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry)3 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2