Search in sources :

Example 1 with OutdatedDistributionRegion

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;
}
Also used : Arrays(java.util.Arrays) OutdatedDistributionRegion(org.bboxdb.distribution.OutdatedDistributionRegion) Multiset(com.google.common.collect.Multiset) RoutingHop(org.bboxdb.network.routing.RoutingHop) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) DistributionRegionState(org.bboxdb.distribution.partitioner.DistributionRegionState) BoundingBox(org.bboxdb.commons.math.BoundingBox) ZookeeperClient(org.bboxdb.distribution.zookeeper.ZookeeperClient) ArrayList(java.util.ArrayList) Const(org.bboxdb.misc.Const) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) HashMultiset(com.google.common.collect.HashMultiset) Map(java.util.Map) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) ZookeeperClientFactory(org.bboxdb.distribution.zookeeper.ZookeeperClientFactory) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Retryer(org.bboxdb.commons.Retryer) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) List(java.util.List) Entry(java.util.Map.Entry) Optional(java.util.Optional) BBoxDBException(org.bboxdb.misc.BBoxDBException) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) OutdatedDistributionRegion(org.bboxdb.distribution.OutdatedDistributionRegion) OutdatedDistributionRegion(org.bboxdb.distribution.OutdatedDistributionRegion) ArrayList(java.util.ArrayList) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Example 2 with OutdatedDistributionRegion

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;
}
Also used : Entry(java.util.Map.Entry) HashMap(java.util.HashMap) OutdatedDistributionRegion(org.bboxdb.distribution.OutdatedDistributionRegion) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Aggregations

HashMap (java.util.HashMap)2 Entry (java.util.Map.Entry)2 OutdatedDistributionRegion (org.bboxdb.distribution.OutdatedDistributionRegion)2 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)2 BBoxDBException (org.bboxdb.misc.BBoxDBException)2 HashMultiset (com.google.common.collect.HashMultiset)1 Multiset (com.google.common.collect.Multiset)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Callable (java.util.concurrent.Callable)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Retryer (org.bboxdb.commons.Retryer)1 BoundingBox (org.bboxdb.commons.math.BoundingBox)1 DistributionRegionState (org.bboxdb.distribution.partitioner.DistributionRegionState)1