Package org.infinispan.distribution.ch

Examples of org.infinispan.distribution.ch.ConsistentHash


      return cache.getAdvancedCache().getRpcManager().getTransport().getMembers();
   }

   private Address getAddressForKey(Object key) {
      DistributionManager distributionManager = getDistributionManager();
      ConsistentHash hash = distributionManager.getConsistentHash();
      List<Address> addressList = hash.locate(key, 1);
      if (addressList.size() == 0) {
         throw new IllegalStateException("Empty address list returned by consistent hash " + hash + " for key " + key);
      }
      return addressList.get(0);
   }
View Full Code Here


   protected void performRehash() throws Exception {
      long start = trace ? System.currentTimeMillis() : 0;
      if (log.isDebugEnabled()) log.debug("Commencing rehash on node: " + getMyAddress() + ". Before start, dmi.joinComplete = " + dmi.isJoinComplete());
      TransactionLogger transactionLogger = dmi.getTransactionLogger();
      boolean unlocked = false;
      ConsistentHash chOld;
      ConsistentHash chNew;
      try {
         if (dmi.isJoinComplete()) {
            throw new IllegalStateException("Join cannot be complete without rehash to finish (node " + getMyAddress() + " )");
         }
         // 1.  Get chOld from coord.        
View Full Code Here

   private ConsistentHash retrieveOldCH(boolean trace) throws InterruptedException, IllegalAccessException,
                    InstantiationException, ClassNotFoundException {
       
        // this happens in a loop to ensure we receive the correct CH and not a "union".
        // TODO make at least *some* of these configurable!
        ConsistentHash result = null;
        long minSleepTime = 500, maxSleepTime = 2000; // sleep time between retries
        int maxWaitTime = (int) configuration.getRehashRpcTimeout() * 10; // after which we give up!
        Random rand = new Random();
        long giveupTime = System.currentTimeMillis() + maxWaitTime;
        do {
View Full Code Here

         }
         joiner = null;           
      } else {
         topologyInfo.addNodeTopologyInfo(a, nodeTopologyInfo);
         log.trace("Node topology info added({0}).  Topology info is {1}", nodeTopologyInfo, topologyInfo);        
         ConsistentHash chOld = consistentHash;
         if (chOld instanceof UnionConsistentHash) throw new RuntimeException("Not expecting a union CH!");
         oldConsistentHash = chOld;
         joiner = a;       
         ConsistentHash chNew = ConsistentHashHelper.createConsistentHash(configuration, chOld.getCaches(), topologyInfo, a);
         consistentHash = new UnionConsistentHash(chOld, chNew);
      }
      log.trace("New CH is {0}", consistentHash);
      return topologyInfo.getNodeTopologyInfo(rpcManager.getAddress());
   }
View Full Code Here

   protected void performRehash() throws Exception {
      long start = trace ? System.currentTimeMillis() : 0;

      int replCount = configuration.getNumOwners();
      ConsistentHash newCH = dmi.getConsistentHash();
      ConsistentHash oldCH = ConsistentHashHelper.createConsistentHash(configuration, newCH.getCaches(), leaversHandled, dmi.topologyInfo);

      try {
         log.debug("Starting leave rehash[enabled={0},isReceiver={1},isSender={2}] on node {3}",
                  configuration.isRehashEnabled(), isReceiver, isSender, self);
View Full Code Here

   protected void performRehash() throws Exception {
      long start = System.currentTimeMillis();
      if (log.isDebugEnabled())
         log.debugf("Commencing rehash on node: %s. Before start, data container had %d entries",
               getMyAddress(), dataContainer.size());
      ConsistentHash chOld, chNew;
      try {
         // Don't need to log anything, all transactions will be blocked
         //distributionManager.getTransactionLogger().enable();
         if (rehashInterrupted) {
            log.tracef("Rehash is still in progress, not blocking transactions as they should already be blocked");
         } else {
            // if the previous rehash was interrupted by the arrival of a new view
            // then the transactions are still blocked, we don't need to block them again
            distributionManager.getTransactionLogger().blockNewTransactions();
         }

         // Create the new CH:
         List<Address> newMembers = rpcManager.getTransport().getMembers();
         chNew = createConsistentHash(configuration, newMembers);
         chOld = distributionManager.setConsistentHash(chNew);

         if (trace) {
            log.tracef("Rebalancing\nchOld = %s\nchNew = %s", chOld, chNew);
         }

         if (configuration.isRehashEnabled()) {
            // Cache sets for notification
            Collection<Address> oldCacheSet = Immutables.immutableCollectionWrap(chOld.getCaches());
            Collection<Address> newCacheSet = Immutables.immutableCollectionWrap(chNew.getCaches());

            // notify listeners that a rehash is about to start
            notifier.notifyDataRehashed(oldCacheSet, newCacheSet, newViewId, true);
View Full Code Here

      public void onTopologyChange(TopologyChangedEvent tce) {
         // do all the work AFTER the consistent hash has changed
         if (tce.isPre())
            return;

         final ConsistentHash chNew = tce.getConsistentHashAtEnd();
         final Set<Address> oldMembers = tce.getConsistentHashAtStart().getCaches();
         final Set<Address> newMembers = tce.getConsistentHashAtEnd().getCaches();

         final Set<Address> leavers = MembershipArithmetic.getMembersLeft(oldMembers, newMembers);
         if (!leavers.isEmpty()) {
            // roll back local transactions if they had acquired locks on one of the leavers
            if (configuration.isEagerLockingSingleNodeInUse()) {
               for (LocalTransaction localTx : localTransactions.values()) {
                  if (localTx.hasRemoteLocksAcquired(leavers)) {
                     localTx.markForRollback(true);
                     if (trace) log.tracef("Marked local transaction for rollback, as it had acquired " +
                                                 "locks on a node that has left the cluster: %s", localTx);
                  }
               }
            }
         }

         final Set<Address> joiners = MembershipArithmetic.getMembersJoined(oldMembers, newMembers);
         if (!joiners.isEmpty()) {
            // roll back local transactions if their main data owner has changed
            if (configuration.isEagerLockingSingleNodeInUse()) {
               for (LocalTransaction localTx : localTransactions.values()) {
                  for (Object k : localTx.getAffectedKeys()) {
                     Address newMainOwner = chNew.locate(k, 1).get(0);
                     if (joiners.contains(newMainOwner)) {
                        localTx.markForRollback(true);
                        if (trace) log.tracef("Marked local transaction for rollback, as the main data " +
                                                   "owner has changed %s", localTx);
                        break;
View Full Code Here

                          Address sender, int viewId) throws InterruptedException {
      waitForJoinToStart();

      // use the sender's CH if his view is newer
      // an use our CH if the our view is newer
      ConsistentHash latestCH = consistentHash;
      if (viewId < lastViewId) {
         log.debugf("Rejecting state pushed by node %s for old rehash %d (last view id is %d)", sender, viewId, lastViewId);
         latestCH = getConsistentHash();
      }
View Full Code Here

      return cache.getAdvancedCache().getRpcManager().getTransport().getMembers();
   }

   private Address getAddressForKey(Object key) {
      DistributionManager distributionManager = getDistributionManager();
      ConsistentHash hash = distributionManager.getConsistentHash();
      return hash.locatePrimaryOwner(key);
   }
View Full Code Here

      return hash.locatePrimaryOwner(key);
   }

   private boolean isNodeInConsistentHash(Address address) {
      DistributionManager distributionManager = getDistributionManager();
      ConsistentHash hash = distributionManager.getConsistentHash();
      return hash.getMembers().contains(address);
   }
View Full Code Here

TOP

Related Classes of org.infinispan.distribution.ch.ConsistentHash

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.