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