use of org.bboxdb.distribution.zookeeper.DistributionGroupAdapter in project bboxdb by jnidzwetzki.
the class CreateInitialPartitioning method doesGroupExist.
/**
* Does the group exist?
* @param distributionGroup
* @throws ZookeeperException
* @throws ZookeeperNotFoundException
*/
private static void doesGroupExist(final String distributionGroup) throws ZookeeperException, ZookeeperNotFoundException {
final DistributionGroupAdapter adapter = ZookeeperClientFactory.getZookeeperClient().getDistributionGroupAdapter();
final List<String> knownGroups = adapter.getDistributionGroups();
if (!knownGroups.contains(distributionGroup)) {
System.err.format("Distribution group %s does not exist%n", distributionGroup);
System.exit(-1);
}
}
use of org.bboxdb.distribution.zookeeper.DistributionGroupAdapter 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.zookeeper.DistributionGroupAdapter in project bboxdb by jnidzwetzki.
the class DeleteDistributionGroupHandler method handleRequest.
@Override
public /**
* Delete an existing distribution group
*/
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
try {
final DeleteDistributionGroupRequest deletePackage = DeleteDistributionGroupRequest.decodeTuple(encodedPackage);
final String distributionGroup = deletePackage.getDistributionGroup();
logger.info("Delete distribution group: {}", distributionGroup);
// Delete in Zookeeper
final DistributionGroupAdapter distributionGroupZookeeperAdapter = ZookeeperClientFactory.getZookeeperClient().getDistributionGroupAdapter();
distributionGroupZookeeperAdapter.deleteDistributionGroup(distributionGroup);
// Delete local stored data
logger.info("Delete distribution group, delete local stored data");
clientConnectionHandler.getStorageRegistry().deleteAllTablesInDistributionGroup(distributionGroup);
// Clear cached data
TupleStoreConfigurationCache.getInstance().clear();
logger.info("Delete distribution group - DONE");
clientConnectionHandler.writeResultPackage(new SuccessResponse(packageSequence));
} catch (Exception e) {
logger.warn("Error while delete distribution group", e);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
clientConnectionHandler.writeResultPackage(responsePackage);
}
return true;
}
use of org.bboxdb.distribution.zookeeper.DistributionGroupAdapter in project bboxdb by jnidzwetzki.
the class DistributedRecoveryService method checkGroupVersion.
/**
* Check the group version
* @param storage
* @param distributionGroupName
* @param zookeeperClient
*/
protected void checkGroupVersion(final DiskStorage storage, final String distributionGroupName, final ZookeeperClient zookeeperClient) {
try {
final DistributionGroupMetadata metaData = DistributionGroupMetadataHelper.getMedatadaForGroup(storage.getBasedir().getAbsolutePath(), distributionGroupName);
if (metaData == null) {
logger.debug("Metadata for storage {} and group {} is null, skipping check", storage.getBasedir(), distributionGroupName);
return;
}
final DistributionGroupAdapter distributionGroupZookeeperAdapter = new DistributionGroupAdapter(zookeeperClient);
final String path = distributionGroupZookeeperAdapter.getDistributionGroupPath(distributionGroupName);
final long remoteVersion = NodeMutationHelper.getNodeMutationVersion(zookeeperClient, path, null);
final long localVersion = metaData.getVersion();
if (remoteVersion != localVersion) {
logger.error("Local version {} of dgroup {} does not match remtote version {}", localVersion, distributionGroupName, remoteVersion);
System.exit(-1);
}
} catch (ZookeeperException | ZookeeperNotFoundException e) {
logger.error("Got an exception while checking group version");
}
}
Aggregations