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);
}
}
}
}
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();
}
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;
}
}
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);
}
}
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);
}
}
Aggregations