use of org.bboxdb.distribution.OutdatedDistributionRegion 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.distribution.OutdatedDistributionRegion 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;
}
Aggregations