Search in sources :

Example 11 with BBoxDBException

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

the class CLI method actionDeleteTuple.

/**
 * Delete a tuple
 * @param line
 */
protected void actionDeleteTuple(final CommandLine line) {
    if (!line.hasOption(CLIParameter.KEY) || !line.hasOption(CLIParameter.TABLE)) {
        System.err.println("Key or table are missing");
        printHelpAndExit();
    }
    final String key = line.getOptionValue(CLIParameter.KEY);
    final String table = line.getOptionValue(CLIParameter.TABLE);
    System.out.println("Deleting tuple for key: " + key);
    try {
        final EmptyResultFuture resultFuture = bboxDbConnection.deleteTuple(table, key);
        pendingFutures.put(resultFuture);
        pendingFutures.waitForCompletion();
    } catch (BBoxDBException e) {
        System.err.println("Got an error during delete: " + e);
        System.exit(-1);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return;
    }
}
Also used : BBoxDBException(org.bboxdb.misc.BBoxDBException) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 12 with BBoxDBException

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

the class DataRedistributionLoader method loadFile.

/**
 * Load the given file
 * @param id
 * @return
 * @throws InterruptedException
 */
private boolean loadFile(final int fileid) throws InterruptedException {
    final String filename = files[fileid];
    if (loadedFiles.contains(filename)) {
        System.err.println("File " + filename + " is already loaded");
        return false;
    }
    System.out.println("Loading 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();
            final Tuple tuple = tupleBuilder.buildTuple(key, l);
            try {
                if (tuple != null) {
                    final EmptyResultFuture insertFuture = bboxDBCluster.insertTuple(TABLE, tuple);
                    pendingFutures.put(insertFuture);
                }
            } catch (BBoxDBException e) {
                logger.error("Got error while inserting tuple", e);
            }
            if (lineNumber.get() % 1000 == 0) {
                System.out.format("Loaded %d elements\n", lineNumber.get());
            }
        });
    } catch (IOException e) {
        System.err.println("Got an exeption while reading file: " + e);
        System.exit(-1);
    }
    pendingFutures.waitForCompletion();
    loadedFiles.add(filename);
    System.out.println("Loaded content from: " + filename);
    return true;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IOException(java.io.IOException) BBoxDBException(org.bboxdb.misc.BBoxDBException) Tuple(org.bboxdb.storage.entity.Tuple) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 13 with BBoxDBException

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

the class DistributionRegionHelper method getOutdatedRegions.

/**
 * Find the outdated regions for the distributed instance
 * @param region
 * @param distributedInstance
 * @return
 * @throws BBoxDBException
 */
public static List<OutdatedDistributionRegion> getOutdatedRegions(final DistributionRegion region, final BBoxDBInstance distributedInstance) throws BBoxDBException {
    final List<OutdatedDistributionRegion> result = new ArrayList<>();
    if (region == null) {
        return result;
    }
    final List<DistributionRegion> regions = region.getThisAndChildRegions().stream().filter(r -> r.getSystems().contains(distributedInstance)).collect(Collectors.toList());
    for (final DistributionRegion regionToInspect : regions) {
        try {
            final OutdatedDistributionRegion regionResult = processRegion(distributedInstance, ZookeeperClientFactory.getZookeeperClient(), regionToInspect);
            if (regionResult != null) {
                result.add(regionResult);
            }
        } catch (ZookeeperException e) {
            throw new BBoxDBException(e);
        }
    }
    return result;
}
Also used : Arrays(java.util.Arrays) OutdatedDistributionRegion(org.bboxdb.distribution.OutdatedDistributionRegion) Multiset(com.google.common.collect.Multiset) RoutingHop(org.bboxdb.network.routing.RoutingHop) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) DistributionRegionState(org.bboxdb.distribution.partitioner.DistributionRegionState) BoundingBox(org.bboxdb.commons.math.BoundingBox) ZookeeperClient(org.bboxdb.distribution.zookeeper.ZookeeperClient) ArrayList(java.util.ArrayList) Const(org.bboxdb.misc.Const) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) HashMultiset(com.google.common.collect.HashMultiset) Map(java.util.Map) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) ZookeeperClientFactory(org.bboxdb.distribution.zookeeper.ZookeeperClientFactory) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Retryer(org.bboxdb.commons.Retryer) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) List(java.util.List) Entry(java.util.Map.Entry) Optional(java.util.Optional) BBoxDBException(org.bboxdb.misc.BBoxDBException) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) OutdatedDistributionRegion(org.bboxdb.distribution.OutdatedDistributionRegion) OutdatedDistributionRegion(org.bboxdb.distribution.OutdatedDistributionRegion) ArrayList(java.util.ArrayList) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Example 14 with BBoxDBException

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

the class RegionMergeHelper method getMergingCandidates.

/**
 * Is the merging by the space partitioner allowed?
 * @param region
 * @return
 */
public static List<List<DistributionRegion>> getMergingCandidates(final DistributionRegion region) {
    try {
        final String distributionGroupName = region.getDistributionGroupName();
        final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroupName);
        return spacePartitioner.getMergeCandidates(region);
    } catch (BBoxDBException e) {
        logger.error("Got exception while testing for merge", e);
        return new ArrayList<>();
    }
}
Also used : BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 15 with BBoxDBException

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

the class RegionSplitHelper method isSplittingSupported.

/**
 * Is the splitting of the region supported?
 * @param regionToSplit
 * @return
 */
public static boolean isSplittingSupported(final DistributionRegion region) {
    try {
        final String distributionGroupName = region.getDistributionGroupName();
        final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroupName);
        return spacePartitioner.isSplitable(region);
    } catch (BBoxDBException e) {
        logger.error("Got exception while testing for merge", e);
        return false;
    }
}
Also used : BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

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