Search in sources :

Example 51 with BBoxDBException

use of org.bboxdb.misc.BBoxDBException 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 52 with BBoxDBException

use of org.bboxdb.misc.BBoxDBException in project bboxdb by jnidzwetzki.

the class KeepAliveHandler method handleGossip.

/**
 * Handle keep alive gossip
 * @param keepAliveRequst
 * @param clientConnectionHandler
 * @return
 */
private boolean handleGossip(final KeepAliveRequest keepAliveRequst, final ClientConnectionHandler clientConnectionHandler) {
    final String table = keepAliveRequst.getTablename();
    final TupleStoreName tupleStoreName = new TupleStoreName(table);
    final List<Tuple> tuples = keepAliveRequst.getTuples();
    final TupleStoreManagerRegistry storageRegistry = clientConnectionHandler.getStorageRegistry();
    try {
        for (final Tuple tuple : tuples) {
            final boolean result = checkLocalTuples(storageRegistry, tupleStoreName, tuple);
            if (!result) {
                return false;
            }
        }
    } catch (BBoxDBException e) {
        logger.error("Got exception while handling gossip", e);
    }
    return true;
}
Also used : TupleStoreManagerRegistry(org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) BBoxDBException(org.bboxdb.misc.BBoxDBException) Tuple(org.bboxdb.storage.entity.Tuple)

Example 53 with BBoxDBException

use of org.bboxdb.misc.BBoxDBException 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 54 with BBoxDBException

use of org.bboxdb.misc.BBoxDBException in project bboxdb by jnidzwetzki.

the class DataRedistributionLoader method deleteFile.

/**
 * Remove the given file
 * @param fileid
 * @throws InterruptedException
 */
private void deleteFile(final int fileid) throws InterruptedException {
    final String filename = files[fileid];
    if (!loadedFiles.contains(filename)) {
        System.err.println("File " + filename + " is not loaded");
        return;
    }
    System.out.println("Removing content from: " + filename);
    final AtomicInteger lineNumber = new AtomicInteger(0);
    final String prefix = Integer.toString(fileid) + "_";
    try (final Stream<String> lines = Files.lines(Paths.get(filename))) {
        lines.forEach(l -> {
            final String key = prefix + lineNumber.getAndIncrement();
            try {
                final EmptyResultFuture resultFuture = bboxDBCluster.deleteTuple(TABLE, key);
                pendingFutures.put(resultFuture);
                if (lineNumber.get() % 1000 == 0) {
                    System.out.format("Deleted %d elements\n", lineNumber.get());
                }
            } catch (BBoxDBException e) {
                logger.error("Got error while deleting tuple", e);
            }
        });
    } catch (IOException e) {
        System.err.println("Got an exeption while reading file: " + e);
        System.exit(-1);
    }
    pendingFutures.waitForCompletion();
    loadedFiles.remove(filename);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IOException(java.io.IOException) BBoxDBException(org.bboxdb.misc.BBoxDBException) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 55 with BBoxDBException

use of org.bboxdb.misc.BBoxDBException in project bboxdb by jnidzwetzki.

the class RegionMergeHelper method isRegionUnderflow.

/**
 * Needs the region a merge?
 * @param region
 * @return
 * @throws BBoxDBException
 */
public static boolean isRegionUnderflow(final List<DistributionRegion> sources) throws BBoxDBException {
    assert (!sources.isEmpty()) : "Sources can not be empty";
    final List<String> sourceIds = getRegionIdsFromRegionList(sources);
    logger.info("Testing for underflow: {}", sourceIds);
    final boolean inactiveChilds = sources.stream().anyMatch(c -> c.getState() != DistributionRegionState.ACTIVE);
    if (inactiveChilds) {
        logger.info("Not all children ready, skip merge test for {}", sourceIds);
        return false;
    }
    // We are not responsible to this region
    final BBoxDBInstance localInstanceName = ZookeeperClientFactory.getLocalInstanceName();
    final boolean localSystemContained = sources.stream().anyMatch(r -> r.getSystems().contains(localInstanceName));
    if (!localSystemContained) {
        logger.info("Not testing for underflow for {} on {}", sourceIds, localInstanceName);
        return false;
    }
    final OptionalDouble childRegionSize = getTotalRegionSize(sources);
    if (!childRegionSize.isPresent()) {
        logger.info("Got invalid statistics for {}", sourceIds);
        return false;
    }
    try {
        final String fullname = sources.get(0).getDistributionGroupName();
        final long minSize = getConfiguredRegionMinSizeInMB(fullname);
        final double childDoubleSize = childRegionSize.getAsDouble();
        logger.info("Testing for region {} underflow curent size is {} / min is {}", sourceIds, childDoubleSize, minSize);
        return (childDoubleSize < minSize);
    } catch (ZookeeperException | ZookeeperNotFoundException e) {
        throw new BBoxDBException(e);
    }
}
Also used : ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) BBoxDBException(org.bboxdb.misc.BBoxDBException) OptionalDouble(java.util.OptionalDouble)

Aggregations

BBoxDBException (org.bboxdb.misc.BBoxDBException)64 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)24 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)22 BoundingBox (org.bboxdb.commons.math.BoundingBox)17 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)14 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)13 ArrayList (java.util.ArrayList)12 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)12 StorageManagerException (org.bboxdb.storage.StorageManagerException)12 List (java.util.List)11 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)11 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)10 Tuple (org.bboxdb.storage.entity.Tuple)9 ResourceAllocationException (org.bboxdb.distribution.placement.ResourceAllocationException)7 RoutingHop (org.bboxdb.network.routing.RoutingHop)7 JoinedTupleListFuture (org.bboxdb.network.client.future.JoinedTupleListFuture)6 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)6 RejectedException (org.bboxdb.commons.RejectedException)5 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)5 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)5