Package org.infinispan.topology

Examples of org.infinispan.topology.CacheTopology$Externalizer


      context.queueRebalance(newMembers);
   }

   @Override
   public void onClusterViewChange(AvailabilityStrategyContext context, List<Address> clusterMembers) {
      CacheTopology currentTopology = context.getCurrentTopology();
      List<Address> newMembers = new ArrayList<>(currentTopology.getMembers());
      if (!newMembers.retainAll(clusterMembers)) {
         log.tracef("Cache %s did not lose any members, skipping rebalance", context.getCacheName());
         return;
      }
View Full Code Here


      context.updateCurrentTopology(newMembers);
      context.queueRebalance(newMembers);
   }

   protected void checkForLostData(AvailabilityStrategyContext context, List<Address> newMembers) {
      CacheTopology stableTopology = context.getStableTopology();
      List<Address> stableMembers = stableTopology.getMembers();
      List<Address> lostMembers = new ArrayList<>(stableMembers);
      lostMembers.removeAll(newMembers);
      if (isDataLost(stableTopology.getCurrentCH(), newMembers)) {
         log.lostDataBecauseOfAbruptLeavers(context.getCacheName(), lostMembers);
      } else if (lostMembers.size() >= Math.ceil(stableMembers.size() / 2d)) {
         log.minorityPartition(context.getCacheName(), lostMembers.size(), stableMembers.size());
      }
   }
View Full Code Here

   }

   @Override
   public void onPartitionMerge(AvailabilityStrategyContext context, Collection<CacheStatusResponse> statusResponses) {
      // Pick the biggest stable topology (i.e. the one with most members)
      CacheTopology maxStableTopology = null;
      for (CacheStatusResponse response : statusResponses) {
         CacheTopology stableTopology = response.getStableTopology();
         if (stableTopology == null) {
            // The node hasn't properly joined yet.
            continue;
         }
         if (maxStableTopology == null || maxStableTopology.getMembers().size() < stableTopology.getMembers().size()) {
            maxStableTopology = stableTopology;
         }
      }

      // Now pick the biggest current topology derived from the biggest stable topology
      CacheTopology maxTopology = null;
      for (CacheStatusResponse response : statusResponses) {
         CacheTopology stableTopology = response.getStableTopology();
         if (!Objects.equals(stableTopology, maxStableTopology))
            continue;

         CacheTopology topology = response.getCacheTopology();
         if (topology == null) {
            // The node hasn't properly joined yet.
            continue;
         }
         if (maxTopology == null || maxTopology.getMembers().size() < topology.getMembers().size()) {
            maxTopology = topology;
         }
      }

      if (maxTopology == null) {
         log.debugf("No current topology, recovered only joiners for cache %s", context.getCacheName());
      }

      // Since we picked the biggest topology, its topology id may not be the biggest
      int maxTopologyId = 0;
      for (CacheStatusResponse response : statusResponses) {
         CacheTopology topology = response.getCacheTopology();
         if (topology != null && maxTopologyId < topology.getTopologyId()) {
            maxTopologyId = topology.getTopologyId();
         }
      }

      // Cancel any pending rebalance in the current topology.
      // By definition, the stable topology does not have a pending CH.
      CacheTopology mergedTopology = maxTopology;
      if (maxTopology != null && maxTopology.getPendingCH() != null) {
         mergedTopology = new CacheTopology(maxTopologyId + 1, maxTopology.getRebalanceId(),
               maxTopology.getCurrentCH(), null);
      }

      context.updateTopologiesAfterMerge(mergedTopology, maxStableTopology, null);
View Full Code Here

      if (context.getAvailabilityMode() != AvailabilityMode.AVAILABLE) {
         log.debugf("Cache %s is not available, ignoring graceful leaver %s", context.getCacheName(), leaver);
         return;
      }

      CacheTopology currentTopology = context.getCurrentTopology();
      List<Address> newMembers = new ArrayList<>(currentTopology.getMembers());
      newMembers.retainAll(context.getExpectedMembers());

      if (isDataLost(context.getStableTopology().getCurrentCH(), newMembers)) {
         log.enteringUnavailableModeGracefulLeaver(context.getCacheName(), leaver);
         context.updateAvailabilityMode(AvailabilityMode.UNAVAILABLE);
View Full Code Here

      if (context.getAvailabilityMode() != AvailabilityMode.AVAILABLE) {
         log.debugf("Cache %s is not available, ignoring cluster view change", context.getCacheName());
         return;
      }

      CacheTopology currentTopology = context.getCurrentTopology();
      List<Address> newMembers = new ArrayList<>(currentTopology.getMembers());
      if (!newMembers.retainAll(clusterMembers)) {
         log.debugf("Cache %s did not lose any members, ignoring view change", context.getCacheName());
         return;
      }

      // We could keep track of the members that left gracefully and avoid entering degraded mode in some cases.
      // But the information about graceful leavers would be lost when the coordinator changes anyway, making
      // the results of the strategy harder to reason about.
      CacheTopology stableTopology = context.getStableTopology();
      List<Address> stableMembers = stableTopology.getMembers();
      List<Address> lostMembers = new ArrayList<>(stableMembers);
      lostMembers.removeAll(newMembers);
      if (isDataLost(stableTopology.getCurrentCH(), newMembers)) {
         log.enteringDegradedModeLostData(context.getCacheName(), lostMembers);
         context.updateAvailabilityMode(AvailabilityMode.DEGRADED_MODE);
         return;
      }
      if (lostMembers.size() >= stableMembers.size() - Math.ceil(stableMembers.size() / 2d)) {
View Full Code Here

      // Because of the majority check in onAbruptLeave, we assume that at most one partition was able to evolve
      // and install new cache topologies. The other(s) would have entered degraded mode, and they would keep
      // the original topology.
      // One scenario not covered is if two partitions started separately and they have completely different topologies.
      // In that case, there is no way to prevent the two partitions from having inconsistent data.
      CacheTopology maxActiveTopology = null;
      CacheTopology maxDegradedTopology = null;
      CacheTopology maxUnavailableTopology = null;
      CacheTopology maxStableTopology = null;
      for (CacheStatusResponse response : statusResponses) {
         CacheTopology partitionStableTopology = response.getStableTopology();
         if (maxStableTopology == null || !maxStableTopology.equals(partitionStableTopology)) {
            log.tracef("Found stable partition topology: %s", maxStableTopology);
         }
         if (partitionStableTopology == null) {
            // The node hasn't properly joined yet.
            continue;
         }
         if (maxStableTopology == null || maxStableTopology.getTopologyId() < partitionStableTopology.getTopologyId()) {
            maxStableTopology = partitionStableTopology;
         }

         CacheTopology partitionTopology = response.getCacheTopology();
         if (partitionTopology == null) {
            // The node hasn't properly joined yet.
            continue;
         }
         if (response.getAvailabilityMode() == AvailabilityMode.AVAILABLE) {
            if (maxActiveTopology == null || !maxActiveTopology.equals(partitionTopology)) {
               log.tracef("Found active partition topology: %s", maxActiveTopology);
            }
            if (maxActiveTopology == null || maxActiveTopology.getTopologyId() < partitionTopology.getTopologyId()) {
               maxActiveTopology = partitionTopology;
            }
         } else if (response.getAvailabilityMode() == AvailabilityMode.DEGRADED_MODE) {
            if (maxDegradedTopology == null || !maxDegradedTopology.equals(partitionTopology)) {
               log.tracef("Found degraded partition topology: %s", maxDegradedTopology);
            }
            if (maxDegradedTopology == null || maxDegradedTopology.getTopologyId() < partitionTopology.getTopologyId()) {
               maxDegradedTopology = partitionTopology;
            }
         } else if (response.getAvailabilityMode() == AvailabilityMode.UNAVAILABLE) {
            if (maxUnavailableTopology == null || !maxUnavailableTopology.equals(partitionTopology)) {
               log.tracef("Found unavailable partition topology: %s", maxUnavailableTopology);
            }
            if (maxUnavailableTopology == null || maxUnavailableTopology.getTopologyId() < partitionTopology.getTopologyId()) {
               maxUnavailableTopology = partitionTopology;
            }
         } else {
            log.unexpectedAvailabilityMode(context.getAvailabilityMode(), context.getCacheName(),
                  response.getCacheTopology());
         }
      }

      CacheTopology mergedTopology;
      AvailabilityMode mergedAvailabilityMode;
      if (maxUnavailableTopology != null) {
         log.debugf("One of the partitions is unavailable, using that partition's topology and staying in unavailable mode");
         mergedAvailabilityMode = AvailabilityMode.UNAVAILABLE;
         mergedTopology = maxUnavailableTopology;
      } else if (maxActiveTopology != null) {
         log.debugf("One of the partitions is available, using that partition's topology and staying in available mode");
         mergedAvailabilityMode = AvailabilityMode.AVAILABLE;
         mergedTopology = maxActiveTopology;
      } else if (maxDegradedTopology != null) {
         log.debugf("No active or unavailable partitions, so all the partitions must be in degraded mode.");
         mergedAvailabilityMode = AvailabilityMode.DEGRADED_MODE;
         mergedTopology = maxDegradedTopology;
      } else {
         log.debugf("No current topology, recovered only joiners for cache %s", context.getCacheName());
         mergedAvailabilityMode = AvailabilityMode.AVAILABLE;
         mergedTopology = null;
      }

      // Cancel any pending rebalance by removing the pending CH.
      // Needed because we don't recover the rebalance confirmation status (yet).
      // By definition, the stable topology doesn't have a rebalance in progress.
      if (mergedTopology != null && mergedTopology.getPendingCH() != null) {
         mergedTopology = new CacheTopology(mergedTopology.getTopologyId() + 1, mergedTopology.getRebalanceId(),
               mergedTopology.getCurrentCH(), null);
      }

      log.debugf("Updating topologies after merge for cache %s, current topology = %s, stable topology = %s, availability mode = %s",
            context.getCacheName(), mergedTopology, maxStableTopology, mergedAvailabilityMode);
      context.updateTopologiesAfterMerge(mergedTopology, maxStableTopology, mergedAvailabilityMode);

      // It shouldn't be possible to recover from unavailable mode without user action
      if (mergedAvailabilityMode == AvailabilityMode.UNAVAILABLE) {
         log.debugf("After merge, cache %s is staying in unavailable mode", context.getCacheName());
         context.updateAvailabilityMode(AvailabilityMode.UNAVAILABLE);
         return;
      }

      List<Address> newMembers = new ArrayList<>(mergedTopology.getMembers());
      newMembers.retainAll(context.getExpectedMembers());
      if (maxStableTopology != null) {
         List<Address> stableMembers = maxStableTopology.getMembers();
         List<Address> lostMembers = new ArrayList<>(stableMembers);
         lostMembers.removeAll(context.getExpectedMembers());
View Full Code Here

      RpcOptionsBuilder rpcOptionsBuilder = rpcManager.getRpcOptionsBuilder(ResponseMode.WAIT_FOR_VALID_RESPONSE, false);
      int lastTopologyId = -1;
      InternalCacheEntry value = null;
      while (value == null) {
         final CacheTopology cacheTopology = stateTransferManager.getCacheTopology();
         final int currentTopologyId = cacheTopology.getTopologyId();

         if (trace) {
            log.tracef("Perform remote get for key %s. topologyId=%s, currentTopologyId=%s",
                       key, lastTopologyId, currentTopologyId);
         }
         List<Address> targets;
         if (lastTopologyId < currentTopologyId) {
            // Cache topology has changed or it is the first time.
            lastTopologyId = currentTopologyId;
            targets = new ArrayList<Address>(cacheTopology.getReadConsistentHash().locateOwners(key));
         } else if (lastTopologyId == currentTopologyId && cacheTopology.getPendingCH() != null) {
            // Same topologyId, but the owners could have already installed the next topology
            // Lets try with pending consistent owners (the read owners in the next topology)
            lastTopologyId = currentTopologyId + 1;
            targets = new ArrayList<Address>(cacheTopology.getPendingCH().locateOwners(key));
            // Remove already contacted nodes
            targets.removeAll(cacheTopology.getReadConsistentHash().locateOwners(key));
            if (targets.isEmpty()) {
               if (trace) {
                  log.tracef("No valid values found for key '%s' (topologyId=%s).", key, currentTopologyId);
               }
               break;
View Full Code Here

      return t != null ? t.getAddress() : null;
   }

   @Override
   public int getTopologyId() {
      CacheTopology cacheTopology = stateTransferManager.getCacheTopology();
      return cacheTopology != null ? cacheTopology.getTopologyId() : -1;
   }
View Full Code Here

   public List<TransactionInfo> getTransactionsForSegments(Address destination, int requestTopologyId, Set<Integer> segments) throws InterruptedException {
      if (trace) {
         log.tracef("Received request for transactions from node %s for segments %s of cache %s with topology id %d", destination, segments, cacheName, requestTopologyId);
      }

      final CacheTopology cacheTopology = getCacheTopology(requestTopologyId, destination, true);
      final ConsistentHash readCh = cacheTopology.getReadConsistentHash();

      Set<Integer> ownedSegments = readCh.getSegmentsForOwner(rpcManager.getAddress());
      if (!ownedSegments.containsAll(segments)) {
         segments.removeAll(ownedSegments);
         throw new IllegalArgumentException("Segments " + segments + " are not owned by " + rpcManager.getAddress());
View Full Code Here

      }
      return transactions;
   }

   private CacheTopology getCacheTopology(int requestTopologyId, Address destination, boolean isReqForTransactions) throws InterruptedException {
      CacheTopology cacheTopology = stateConsumer.getCacheTopology();
      if (cacheTopology == null) {
         // no commands are processed until the join is complete, so this cannot normally happen
         throw new IllegalStateException("No cache topology received yet");
      }

      if (requestTopologyId < cacheTopology.getTopologyId()) {
         if (isReqForTransactions)
            log.transactionsRequestedByNodeWithOlderTopology(destination, requestTopologyId, cacheTopology.getTopologyId());
         else
            log.segmentsRequestedByNodeWithOlderTopology(destination, requestTopologyId, cacheTopology.getTopologyId());
      } else if (requestTopologyId > cacheTopology.getTopologyId()) {
         if (trace) {
            log.tracef("%s were requested by node %s with topology %d, greater than the local " +
                  "topology (%d). Waiting for topology %d to be installed locally.", isReqForTransactions ? "Transactions" : "Segments", destination,
                  requestTopologyId, cacheTopology.getTopologyId(), requestTopologyId);
         }
         stateTransferLock.waitForTopology(requestTopologyId);
         cacheTopology = stateConsumer.getCacheTopology();
      }
      return cacheTopology;
View Full Code Here

TOP

Related Classes of org.infinispan.topology.CacheTopology$Externalizer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.