Search in sources :

Example 1 with SegmentConsistentHash

use of org.infinispan.client.hotrod.impl.consistenthash.SegmentConsistentHash in project infinispan by infinispan.

the class ChannelFactory method receiveTopology.

public void receiveTopology(byte[] cacheName, int responseTopologyAge, int responseTopologyId, InetSocketAddress[] addresses, SocketAddress[][] segmentOwners, short hashFunctionVersion) {
    WrappedByteArray wrappedCacheName = wrapBytes(cacheName);
    lock.writeLock().lock();
    try {
        CacheInfo cacheInfo = topologyInfo.getCacheInfo(wrappedCacheName);
        assert cacheInfo != null : "The cache info must exist before receiving a topology update";
        // Relies on TopologyInfo.switchCluster() to update the topologyAge for caches first
        if (responseTopologyAge == cacheInfo.getTopologyAge() && responseTopologyId > cacheInfo.getTopologyId()) {
            List<InetSocketAddress> addressList = Arrays.asList(addresses);
            HOTROD.newTopology(responseTopologyId, responseTopologyAge, addresses.length, addressList);
            CacheInfo newCacheInfo;
            if (hashFunctionVersion >= 0) {
                SegmentConsistentHash consistentHash = createConsistentHash(segmentOwners, hashFunctionVersion, cacheInfo.getCacheName());
                newCacheInfo = cacheInfo.withNewHash(responseTopologyAge, responseTopologyId, addressList, consistentHash, segmentOwners.length);
            } else {
                newCacheInfo = cacheInfo.withNewServers(responseTopologyAge, responseTopologyId, addressList);
            }
            updateCacheInfo(wrappedCacheName, newCacheInfo, false);
        } else {
            if (log.isTraceEnabled())
                log.tracef("[%s] Ignoring outdated topology: topology id = %s, topology age = %s, servers = %s", cacheInfo.getCacheName(), responseTopologyId, responseTopologyAge, Arrays.toString(addresses));
        }
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : WrappedByteArray(org.infinispan.commons.marshall.WrappedByteArray) InetSocketAddress(java.net.InetSocketAddress) SegmentConsistentHash(org.infinispan.client.hotrod.impl.consistenthash.SegmentConsistentHash) CacheInfo(org.infinispan.client.hotrod.impl.topology.CacheInfo)

Example 2 with SegmentConsistentHash

use of org.infinispan.client.hotrod.impl.consistenthash.SegmentConsistentHash in project infinispan by infinispan.

the class IterationStartOperation method acceptResponse.

@Override
public void acceptResponse(ByteBuf buf, short status, HeaderDecoder decoder) {
    SegmentConsistentHash consistentHash = (SegmentConsistentHash) channelFactory.getConsistentHash(cacheName);
    IterationStartResponse response = new IterationStartResponse(ByteBufUtil.readArray(buf), consistentHash, header.topologyId().get(), channel);
    complete(response);
}
Also used : SegmentConsistentHash(org.infinispan.client.hotrod.impl.consistenthash.SegmentConsistentHash)

Aggregations

SegmentConsistentHash (org.infinispan.client.hotrod.impl.consistenthash.SegmentConsistentHash)2 InetSocketAddress (java.net.InetSocketAddress)1 CacheInfo (org.infinispan.client.hotrod.impl.topology.CacheInfo)1 WrappedByteArray (org.infinispan.commons.marshall.WrappedByteArray)1