Search in sources :

Example 6 with BBoxDBException

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

the class TupleStoreManager method scanForExistingTables.

/**
 * Scan the database directory for all existing SSTables and
 * create reader objects
 * @throws StorageManagerException
 * @throws InterruptedException
 */
protected void scanForExistingTables() throws StorageManagerException, InterruptedException {
    logger.info("Scan for existing SSTables: " + tupleStoreName.getFullname());
    final String storageDir = storage.getBasedir().getAbsolutePath();
    final String ssTableDir = SSTableHelper.getSSTableDir(storageDir, tupleStoreName);
    final File directoryHandle = new File(ssTableDir);
    checkSSTableDir(directoryHandle);
    final File[] entries = directoryHandle.listFiles();
    for (final File file : entries) {
        final String filename = file.getName();
        if (SSTableHelper.isFileNameSSTable(filename)) {
            logger.info("Found sstable: {}", filename);
            try {
                final int sequenceNumber = SSTableHelper.extractSequenceFromFilename(tupleStoreName, filename);
                final SSTableFacade facade = new SSTableFacade(storageDir, tupleStoreName, sequenceNumber, configuration.getSstableKeyCacheEntries());
                facade.init();
                tupleStoreInstances.addNewDetectedSSTable(facade);
            } catch (BBoxDBException e) {
                throw new StorageManagerException(e);
            }
        }
    }
}
Also used : SSTableFacade(org.bboxdb.storage.sstable.reader.SSTableFacade) StorageManagerException(org.bboxdb.storage.StorageManagerException) File(java.io.File) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Example 7 with BBoxDBException

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

the class TupleStoreManagerRegistry method init.

/**
 * Init the service
 * @throws BBoxDBException
 */
@Override
public synchronized void init() throws InterruptedException, BBoxDBException {
    if (!serviceState.isInNewState()) {
        throw new BBoxDBException("Unable to init service is in state: " + serviceState.getState());
    }
    serviceState.dipatchToStarting();
    final List<String> storageDirs = configuration.getStorageDirectories();
    if (storageDirs.isEmpty()) {
        throw new IllegalArgumentException("Unable to init storage registry without any data directory");
    }
    // Populate the sstable location map
    for (final String directory : storageDirs) {
        try {
            tupleStoreLocations.putAll(TupleStoreLocator.scanDirectoryForExistingTables(directory));
            final int flushThreadsPerStorage = configuration.getMemtableFlushThreadsPerStorage();
            final DiskStorage storage = new DiskStorage(this, new File(directory), flushThreadsPerStorage);
            storage.init();
            storages.put(directory, storage);
        } catch (StorageManagerException e) {
            final String dataDirString = SSTableHelper.getDataDir(directory);
            logger.error("Directory {} does not exists, exiting...", dataDirString);
            System.exit(-1);
        }
    }
    serviceState.dispatchToRunning();
}
Also used : StorageManagerException(org.bboxdb.storage.StorageManagerException) BBoxDBException(org.bboxdb.misc.BBoxDBException) DiskStorage(org.bboxdb.storage.tuplestore.DiskStorage) File(java.io.File)

Example 8 with BBoxDBException

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

the class CLI method actionInsertTuple.

/**
 * Insert a new tuple
 * @param line
 */
protected void actionInsertTuple(final CommandLine line) {
    final List<String> requiredArgs = Arrays.asList(CLIParameter.TABLE, CLIParameter.KEY, CLIParameter.BOUNDING_BOX, CLIParameter.VALUE);
    checkRequiredArgs(requiredArgs);
    final String table = line.getOptionValue(CLIParameter.TABLE);
    final String key = line.getOptionValue(CLIParameter.KEY);
    final String value = line.getOptionValue(CLIParameter.VALUE);
    final BoundingBox boundingBox = getBoundingBoxFromArgs(line);
    final Tuple tuple = new Tuple(key, boundingBox, value.getBytes());
    System.out.println("Insert new tuple into table: " + table);
    try {
        final EmptyResultFuture future = bboxDbConnection.insertTuple(table, tuple);
        pendingFutures.put(future);
        pendingFutures.waitForCompletion();
    } catch (BBoxDBException e) {
        System.err.println("Got an error during insert: " + e);
        System.exit(-1);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return;
    }
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) BBoxDBException(org.bboxdb.misc.BBoxDBException) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 9 with BBoxDBException

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

the class CLI method actionCreateDgroup.

/**
 * Create a new distribution group
 * @param line
 */
protected void actionCreateDgroup(final CommandLine line) {
    final List<String> requiredArgs = Arrays.asList(CLIParameter.DISTRIBUTION_GROUP, CLIParameter.DIMENSIONS, CLIParameter.REPLICATION_FACTOR);
    checkRequiredArgs(requiredArgs);
    final String maxRegionSizeString = CLIHelper.getParameterOrDefault(line, CLIParameter.MAX_REGION_SIZE, Integer.toString(Const.DEFAULT_MAX_REGION_SIZE));
    final String minRegionSizeString = CLIHelper.getParameterOrDefault(line, CLIParameter.MIN_REGION_SIZE, Integer.toString(Const.DEFAULT_MIN_REGION_SIZE));
    final int maxRegionSize = MathUtil.tryParseIntOrExit(maxRegionSizeString, () -> "Unable to parse the max region size: " + maxRegionSizeString);
    final int minRegionSize = MathUtil.tryParseIntOrExit(minRegionSizeString, () -> "Unable to parse the min region size: " + minRegionSizeString);
    final String resourcePlacement = CLIHelper.getParameterOrDefault(line, CLIParameter.RESOURCE_PLACEMENT, Const.DEFAULT_PLACEMENT_STRATEGY);
    final String resourcePlacementConfig = CLIHelper.getParameterOrDefault(line, CLIParameter.RESOURCE_PLACEMENT_CONFIG, Const.DEFAULT_PLACEMENT_CONFIG);
    final String spacePartitioner = CLIHelper.getParameterOrDefault(line, CLIParameter.SPACE_PARTITIONER, Const.DEFAULT_SPACE_PARTITIONER);
    final String spacePartitionerConfig = CLIHelper.getParameterOrDefault(line, CLIParameter.SPACE_PARTITIONER_CONFIG, Const.DEFAULT_SPACE_PARTITIONER_CONFIG);
    final String distributionGroup = line.getOptionValue(CLIParameter.DISTRIBUTION_GROUP);
    final String replicationFactorString = line.getOptionValue(CLIParameter.REPLICATION_FACTOR);
    final int replicationFactor = MathUtil.tryParseIntOrExit(replicationFactorString, () -> "This is not a valid replication factor: " + replicationFactorString);
    final String dimensionsString = line.getOptionValue(CLIParameter.DIMENSIONS);
    final int dimensions = MathUtil.tryParseIntOrExit(dimensionsString, () -> "This is not a valid dimension: " + dimensionsString);
    System.out.println("Create new distribution group: " + distributionGroup);
    try {
        final DistributionGroupConfiguration configuration = DistributionGroupConfigurationBuilder.create(dimensions).withReplicationFactor((short) replicationFactor).withMaximumRegionSize(maxRegionSize).withMinimumRegionSize(minRegionSize).withPlacementStrategy(resourcePlacement, resourcePlacementConfig).withSpacePartitioner(spacePartitioner, spacePartitionerConfig).build();
        final EmptyResultFuture future = bboxDbConnection.createDistributionGroup(distributionGroup, configuration);
        future.waitForAll();
        if (future.isFailed()) {
            System.err.println("Got an error during distribution group creation: " + future.getAllMessages());
        }
    } catch (BBoxDBException e) {
        System.err.println("Got an exception during distribution group creation: " + e);
        System.exit(-1);
    } catch (InterruptedException e) {
        System.err.println("Waiting was interrupted");
        System.exit(-1);
    }
}
Also used : DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) BBoxDBException(org.bboxdb.misc.BBoxDBException) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 10 with BBoxDBException

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

the class CLI method actionShowDgroup.

/**
 * Show a distribution group
 * @param line
 */
protected void actionShowDgroup(final CommandLine line) {
    final List<String> requiredArgs = Arrays.asList(CLIParameter.DISTRIBUTION_GROUP);
    checkRequiredArgs(requiredArgs);
    final String distributionGroup = line.getOptionValue(CLIParameter.DISTRIBUTION_GROUP);
    System.out.println("Show distribution group: " + distributionGroup);
    try {
        final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
        final DistributionGroupConfiguration config = DistributionGroupConfigurationCache.getInstance().getDistributionGroupConfiguration(distributionGroup);
        final short replicationFactor = config.getReplicationFactor();
        System.out.println("Replication factor is: " + replicationFactor);
        printDistributionRegionRecursive(spacePartitioner.getRootNode());
    } catch (BBoxDBException | ZookeeperNotFoundException e) {
        System.err.println("Got an exception during reading distribution group:" + e);
        System.exit(-1);
    }
}
Also used : ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) 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