use of org.bboxdb.distribution.partitioner.SpacePartitioner in project bboxdb by jnidzwetzki.
the class CreateDistributionGroupHandler method handleRequest.
@Override
public /**
* Create a new distribution group
*/
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
try {
final CreateDistributionGroupRequest createPackage = CreateDistributionGroupRequest.decodeTuple(encodedPackage);
final String distributionGroup = createPackage.getDistributionGroup();
logger.info("Create distribution group: {}", distributionGroup);
final DistributionGroupAdapter distributionGroupAdapter = ZookeeperClientFactory.getZookeeperClient().getDistributionGroupAdapter();
final DistributionRegionAdapter distributionRegionAdapter = ZookeeperClientFactory.getZookeeperClient().getDistributionRegionAdapter();
final List<String> knownGroups = distributionGroupAdapter.getDistributionGroups();
if (knownGroups.contains(distributionGroup)) {
logger.error("Untable to create distributon group {}, already exists", distributionGroup);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_DGROUP_EXISTS);
clientConnectionHandler.writeResultPackage(responsePackage);
return true;
}
distributionGroupAdapter.createDistributionGroup(distributionGroup, createPackage.getDistributionGroupConfiguration());
final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
final DistributionRegion region = spacePartitioner.getRootNode();
distributionRegionAdapter.setStateForDistributionRegion(region, DistributionRegionState.ACTIVE);
clientConnectionHandler.writeResultPackage(new SuccessResponse(packageSequence));
} catch (Exception e) {
logger.warn("Error while create distribution group", e);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
clientConnectionHandler.writeResultPackage(responsePackage);
}
return true;
}
use of org.bboxdb.distribution.partitioner.SpacePartitioner 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.distribution.partitioner.SpacePartitioner 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.distribution.partitioner.SpacePartitioner in project bboxdb by jnidzwetzki.
the class DistributedRecoveryService method runRecoveryForDistributionGroup.
/**
* Run recovery for distribution group
* @param distributionGroupName
* @throws ZookeeperException
*/
protected void runRecoveryForDistributionGroup(final String distributionGroupName) {
try {
final ZookeeperClient zookeeperClient = ZookeeperClientFactory.getZookeeperClient();
final BBoxDBInstance localInstance = ZookeeperClientFactory.getLocalInstanceName();
for (final DiskStorage storage : storageRegistry.getAllStorages()) {
checkGroupVersion(storage, distributionGroupName, zookeeperClient);
}
final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroupName);
final DistributionRegion distributionGroup = spacePartitioner.getRootNode();
final List<OutdatedDistributionRegion> outdatedRegions = DistributionRegionHelper.getOutdatedRegions(distributionGroup, localInstance);
handleOutdatedRegions(distributionGroupName, outdatedRegions);
} catch (Throwable e) {
logger.error("Got exception while running recovery for distribution group: " + distributionGroupName, e);
}
}
Aggregations