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