Package org.infinispan.distribution.ch

Examples of org.infinispan.distribution.ch.ConsistentHash


      waitForClusterToForm();

      // search for a key that was migrated to third node and the suspended TX that locked it
      Object migratedKey = null;
      Transaction migratedTransaction = null;
      ConsistentHash consistentHash = advancedCache(2).getDistributionManager().getConsistentHash();
      for (Object key : key2Tx.keySet()) {
         if (consistentHash.locatePrimaryOwner(key).equals(address(2))) {
            migratedKey = key;
            migratedTransaction = key2Tx.get(key);
            log.trace("Migrated key = " + migratedKey);
            log.trace("Migrated transaction = " + ((DummyTransaction) migratedTransaction).getEnlistedResources());
            break;
View Full Code Here


      }
   }

   private void checkVersion(Cache<Object, Object> c, MagicKey hello) {
      Address address = c.getCacheManager().getAddress();
      ConsistentHash readConsistentHash = c.getAdvancedCache().getDistributionManager().getReadConsistentHash();
      if (readConsistentHash.isKeyLocalToNode(address, hello)) {
         InternalCacheEntry ice = c.getAdvancedCache().getDataContainer().get(hello);
         assert ice != null;
         assert ice.getVersion() != null;
      }
   }
View Full Code Here

         return TestingUtil.extractComponent(c, ClusteringDependentLogic.class).localNodeIsPrimaryOwner(key);
      }
   }

   public static boolean hasOwners(Object key, Cache<?, ?> primaryOwner, Cache<?, ?>... backupOwners) {
      ConsistentHash consistentHash = primaryOwner.getAdvancedCache().getComponentRegistry().getStateTransferManager()
            .getCacheTopology().getWriteConsistentHash();
      List<Address> ownerAddresses = consistentHash.locateOwners(key);
      if (!addressOf(primaryOwner).equals(ownerAddresses.get(0)))
         return false;
      for (Cache<?, ?> backupOwner : backupOwners) {
         if (!ownerAddresses.contains(addressOf(backupOwner)))
            return false;
View Full Code Here

      // Make sure we don't send a REBALANCE_CONFIRM command before we've added all the transfer tasks
      // even if some of the tasks are removed and re-added
      waitingForState.set(false);

      final ConsistentHash previousReadCh = this.cacheTopology != null ? this.cacheTopology.getReadConsistentHash() : null;
      final ConsistentHash previousWriteCh = this.cacheTopology != null ? this.cacheTopology.getWriteConsistentHash() : null;
      // Ensures writes to the data container use the right consistent hash
      // No need for a try/finally block, since it's just an assignment
      stateTransferLock.acquireExclusiveTopologyLock();
      this.cacheTopology = cacheTopology;
      if (isRebalance) {
View Full Code Here

      return consistentHash.getMembers().contains(address) ? consistentHash.getSegmentsForOwner(address)
            : InfinispanCollections.<Integer>emptySet();
   }

   public void applyState(Address sender, int topologyId, Collection<StateChunk> stateChunks) {
      ConsistentHash wCh = cacheTopology.getWriteConsistentHash();
      // ignore responses received after we are no longer a member
      if (!wCh.getMembers().contains(rpcManager.getAddress())) {
         if (trace) {
            log.tracef("Ignoring received state because we are no longer a member");
         }

         return;
      }

      if (trace) {
         log.tracef("Before applying the received state the data container of cache %s has %d keys", cacheName, dataContainer.size());
      }

      for (StateChunk stateChunk : stateChunks) {
         // it's possible to receive a late message so we must be prepared to ignore segments we no longer own
         //todo [anistor] this check should be based on topologyId
         if (!wCh.getSegmentsForOwner(rpcManager.getAddress()).contains(stateChunk.getSegmentId())) {
            log.warnf("Discarding received cache entries for segment %d of cache %s because they do not belong to this node.", stateChunk.getSegmentId(), cacheName);
            continue;
         }

         // notify the inbound task that a chunk of cache entries was received
View Full Code Here

      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

   private void collectTransactionsToTransfer(List<TransactionInfo> transactionsToTransfer,
                                              Collection<? extends CacheTransaction> transactions,
                                              Set<Integer> segments, CacheTopology cacheTopology) {
      int topologyId = cacheTopology.getTopologyId();
      List<Address> members = cacheTopology.getMembers();
      ConsistentHash readCh = cacheTopology.getReadConsistentHash();

      // no need to filter out state transfer generated transactions because there should not be any such transactions running for any of the requested segments
      for (CacheTransaction tx : transactions) {
         // Skip transactions whose originators left. The topology id check is needed for joiners.
         if (tx.getTopologyId() < topologyId && !members.contains(tx.getGlobalTransaction().getAddress()))
            continue;

         // transfer only locked keys that belong to requested segments
         Set<Object> filteredLockedKeys = new HashSet<Object>();
         Set<Object> lockedKeys = tx.getLockedKeys();
         synchronized (lockedKeys) {
            for (Object key : lockedKeys) {
               if (segments.contains(readCh.getSegment(key))) {
                  filteredLockedKeys.add(key);
               }
            }
         }
         Set<Object> backupLockedKeys = tx.getBackupLockedKeys();
         synchronized (backupLockedKeys) {
            for (Object key : backupLockedKeys) {
               if (segments.contains(readCh.getSegment(key))) {
                  filteredLockedKeys.add(key);
               }
            }
         }
         if (!filteredLockedKeys.isEmpty()) {
View Full Code Here

      runTest(2);
      runTest(3);
   }

   private void runTest(int cacheIndex) {
      ConsistentHash serverCH = advancedCache(cacheIndex).getDistributionManager().getConsistentHash();

      // compatibility with 1.0/1.1 clients is not perfect, so we must allow for some misses
      int misses = 0;
      for (int i = 0; i < 200; i++) {
         byte[] keyBytes = (byte[]) kas.getKeyForAddress(address(cacheIndex));
         String key = DistributionRetryTest.ByteKeyGenerator.getStringObject(keyBytes);
         List<Address> serverBackups = serverCH.locateOwners(keyBytes);
         assert serverBackups.contains(address(cacheIndex));
         remoteCache.put(key, "v");

         Address hitServer = getHitServer();
         if (!serverBackups.contains(hitServer)) {
View Full Code Here

      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

            distributionManager.getTransactionLogger().blockNewTransactions();
         }

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

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

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

            // notify listeners that a rehash is about to start
            notifier.notifyDataRehashed(oldCacheSet, newCacheSet, newViewId, true);
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.