use of org.bboxdb.distribution.membership.BBoxDBInstance in project bboxdb by jnidzwetzki.
the class RegionMerger method mergeDataByNetworkRead.
/**
* Merge the region by a network read
*
* @param region
* @param tupleStoreName
* @param tupleRedistributor
* @param childRegion
* @throws InterruptedException
* @throws StorageManagerException
* @throws Exception
*/
private void mergeDataByNetworkRead(final DistributionRegion region, final TupleStoreName tupleStoreName, final TupleRedistributor tupleRedistributor, final DistributionRegion childRegion) throws InterruptedException, StorageManagerException {
final List<BBoxDBInstance> systems = childRegion.getSystems();
assert (!systems.isEmpty()) : "Systems can not be empty";
final BBoxDBInstance firstSystem = systems.get(0);
final BBoxDBConnection connection = MembershipConnectionService.getInstance().getConnectionForInstance(firstSystem);
assert (connection != null) : "Connection can not be null: " + firstSystem.getStringValue();
final BoundingBox bbox = childRegion.getConveringBox();
final String fullname = tupleStoreName.getFullname();
final BBoxDBClient bboxDBClient = connection.getBboxDBClient();
final TupleListFuture result = bboxDBClient.queryBoundingBox(fullname, bbox);
result.waitForAll();
if (result.isFailed()) {
throw new StorageManagerException("Exception while fetching tuples: " + result.getAllMessages());
}
for (final Tuple tuple : result) {
tupleRedistributor.redistributeTuple(tuple);
}
}
use of org.bboxdb.distribution.membership.BBoxDBInstance in project bboxdb by jnidzwetzki.
the class DistributionRegionHelper method processRegion.
/**
* Test if there is an outdated region
*
* @param distributedInstance
* @param result
* @param distributionGroupZookeeperAdapter
* @param regionToInspect
* @return
* @throws ZookeeperException
* @throws BBoxDBException
*/
private static OutdatedDistributionRegion processRegion(final BBoxDBInstance distributedInstance, final ZookeeperClient zookeeperClient, final DistributionRegion regionToInspect) throws ZookeeperException, BBoxDBException {
final Map<BBoxDBInstance, Long> versions = new HashMap<>();
for (final BBoxDBInstance instance : regionToInspect.getSystems()) {
final long version = zookeeperClient.getDistributionRegionAdapter().getCheckpointForDistributionRegion(regionToInspect, instance);
versions.put(instance, version);
}
if (!versions.containsKey(distributedInstance)) {
throw new BBoxDBException("Unable to find local instance for region: " + distributedInstance + " / " + regionToInspect);
}
final Optional<Entry<BBoxDBInstance, Long>> newestInstanceOptional = versions.entrySet().stream().reduce((a, b) -> a.getValue() > b.getValue() ? a : b);
if (!newestInstanceOptional.isPresent()) {
return null;
}
final long localVersion = versions.get(distributedInstance);
final Entry<BBoxDBInstance, Long> newestInstance = newestInstanceOptional.get();
if (!newestInstance.getKey().equals(distributedInstance)) {
return new OutdatedDistributionRegion(regionToInspect, newestInstance.getKey(), localVersion);
}
return null;
}
use of org.bboxdb.distribution.membership.BBoxDBInstance in project bboxdb by jnidzwetzki.
the class StatisticsUpdateRunnable method updateNodeStats.
/**
* Update the local node stats (diskspace, memory)
* @throws ZookeeperException
*/
private void updateNodeStats() {
try {
final BBoxDBInstance instance = ZookeeperClientFactory.getLocalInstanceName();
logger.debug("Update zookeeper node stats");
final ZookeeperClient zookeeperClient = ZookeeperClientFactory.getZookeeperClient();
final ZookeeperBBoxDBInstanceAdapter zookeeperBBoxDBInstanceAdapter = new ZookeeperBBoxDBInstanceAdapter(zookeeperClient);
zookeeperBBoxDBInstanceAdapter.updateNodeInfo(instance);
} catch (ZookeeperException e) {
logger.error("Got exception while updating local node stats", e);
}
}
use of org.bboxdb.distribution.membership.BBoxDBInstance in project bboxdb by jnidzwetzki.
the class DistributionRegionAdapter method allocateSystemsToRegion.
/**
* Allocate the given list of systems to a region
* @param region
* @param allocationSystems
* @throws ZookeeperException
*/
public void allocateSystemsToRegion(final String regionPath, final Set<BBoxDBInstance> allocationSystems) throws ZookeeperException {
final List<String> systemNames = allocationSystems.stream().map(s -> s.getStringValue()).collect(Collectors.toList());
logger.info("Allocating region {} to {}", regionPath, systemNames);
// Resource allocation successfully, write data to zookeeper
for (final BBoxDBInstance instance : allocationSystems) {
addSystemToDistributionRegion(regionPath, instance);
}
}
use of org.bboxdb.distribution.membership.BBoxDBInstance in project bboxdb by jnidzwetzki.
the class AbstractSpacePartitioner method allocateSystems.
/**
* Allocate systems to the children
* @param regionToSplit
* @param numberOfChilden
* @throws ZookeeperException
* @throws ResourceAllocationException
* @throws ZookeeperNotFoundException
*/
protected void allocateSystems(final DistributionRegion regionToSplit, final int numberOfChilden) throws ZookeeperException, ZookeeperNotFoundException, ResourceAllocationException {
// The first child is stored on the same systems as the parent
final DistributionRegion firstRegion = regionToSplit.getDirectChildren().get(0);
final String firstRegionPath = distributionRegionZookeeperAdapter.getZookeeperPathForDistributionRegion(firstRegion);
SpacePartitionerHelper.copySystemsToRegion(regionToSplit.getSystems(), firstRegionPath, zookeeperClient);
final List<BBoxDBInstance> blacklistSystems = regionToSplit.getSystems();
// For the remaining node, a new resource allocation is performed
for (int i = 1; i < numberOfChilden; i++) {
final DistributionRegion region = regionToSplit.getDirectChildren().get(i);
final String path = distributionRegionZookeeperAdapter.getZookeeperPathForDistributionRegion(region);
final String fullname = region.getDistributionGroupName();
SpacePartitionerHelper.allocateSystemsToRegion(path, fullname, blacklistSystems, zookeeperClient);
}
}
Aggregations