Search in sources :

Example 1 with CacheTopologyInfo

use of org.infinispan.client.hotrod.CacheTopologyInfo in project infinispan by infinispan.

the class BaseMultiServerRemoteIteratorTest method testFilterBySegment.

@Test
public void testFilterBySegment() {
    RemoteCache<Integer, AccountHS> cache = clients.get(0).getCache();
    populateCache(CACHE_SIZE, this::newAccount, cache);
    CacheTopologyInfo cacheTopologyInfo = cache.getCacheTopologyInfo();
    // Request all segments from one node
    Set<Integer> filterBySegments = cacheTopologyInfo.getSegmentsPerServer().values().iterator().next();
    Set<Entry<Object, Object>> entries = new HashSet<>();
    try (CloseableIterator<Entry<Object, Object>> iterator = cache.retrieveEntries(null, filterBySegments, 10)) {
        while (iterator.hasNext()) {
            entries.add(iterator.next());
        }
    }
    Marshaller marshaller = clients.get(0).getMarshaller();
    KeyPartitioner keyPartitioner = TestingUtil.extractComponent(cache(0), KeyPartitioner.class);
    assertKeysInSegment(entries, filterBySegments, marshaller, keyPartitioner::getSegment);
}
Also used : Entry(java.util.Map.Entry) Marshaller(org.infinispan.commons.marshall.Marshaller) AccountHS(org.infinispan.query.dsl.embedded.testdomain.hsearch.AccountHS) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) CacheTopologyInfo(org.infinispan.client.hotrod.CacheTopologyInfo) HashSet(java.util.HashSet) Test(org.testng.annotations.Test) MultiHotRodServersTest(org.infinispan.client.hotrod.test.MultiHotRodServersTest)

Example 2 with CacheTopologyInfo

use of org.infinispan.client.hotrod.CacheTopologyInfo in project infinispan by infinispan.

the class HotRodTargetMigrator method synchronizeData.

@Override
@SuppressWarnings("rawtypes")
public long synchronizeData(Cache<Object, Object> cache, int readBatch, int threads) throws CacheException {
    ComponentRegistry cr = SecurityActions.getComponentRegistry(cache.getAdvancedCache());
    PersistenceManager loaderManager = cr.getComponent(PersistenceManager.class);
    Set<RemoteStore> stores = loaderManager.getStores(RemoteStore.class);
    String cacheName = cache.getName();
    if (stores.size() != 1) {
        throw log.couldNotMigrateData(cacheName);
    }
    RemoteStore store = stores.iterator().next();
    final RemoteCache remoteSourceCache = store.getRemoteCache();
    ClusterExecutor clusterExecutor = SecurityActions.getClusterExecutor(cache.getCacheManager());
    clusterExecutor = clusterExecutor.timeout(Long.MAX_VALUE, TimeUnit.NANOSECONDS).singleNodeSubmission();
    CacheTopologyInfo sourceCacheTopologyInfo = remoteSourceCache.getCacheTopologyInfo();
    if (sourceCacheTopologyInfo.getSegmentsPerServer().size() == 1) {
        return migrateFromSingleServer(cache.getCacheManager(), cacheName, readBatch, threads);
    }
    int sourceSegments = sourceCacheTopologyInfo.getNumSegments();
    List<Address> targetServers = cache.getAdvancedCache().getDistributionManager().getCacheTopology().getMembers();
    List<List<Integer>> partitions = split(range(sourceSegments), targetServers.size());
    Iterator<Address> iterator = targetServers.iterator();
    AtomicInteger count = new AtomicInteger();
    TriConsumer<Address, Integer, Throwable> consumer = (a, value, t) -> {
        if (t != null) {
            throw new CacheException(t);
        }
        count.addAndGet(value);
    };
    CompletableFuture[] futures = new CompletableFuture[partitions.size()];
    int offset = 0;
    for (List<Integer> partition : partitions) {
        Set<Integer> segmentSet = new HashSet<>(partition);
        futures[offset++] = clusterExecutor.filterTargets(Collections.singleton(iterator.next())).submitConsumer(new MigrationTask(cacheName, segmentSet, readBatch, threads), consumer);
    }
    CompletableFuture.allOf(futures).join();
    return count.get();
}
Also used : PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) RemoteStore(org.infinispan.persistence.remote.RemoteStore) DEFAULT_READ_BATCH_SIZE(org.infinispan.persistence.remote.upgrade.HotRodMigratorHelper.DEFAULT_READ_BATCH_SIZE) LogFactory(org.infinispan.util.logging.LogFactory) MetaInfServices(org.kohsuke.MetaInfServices) CompletableFuture(java.util.concurrent.CompletableFuture) ComponentRegistry(org.infinispan.factories.ComponentRegistry) Cache(org.infinispan.Cache) RemoteCache(org.infinispan.client.hotrod.RemoteCache) TargetMigrator(org.infinispan.upgrade.TargetMigrator) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) StoreConfiguration(org.infinispan.configuration.cache.StoreConfiguration) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClusterExecutor(org.infinispan.manager.ClusterExecutor) Address(org.infinispan.remoting.transport.Address) TriConsumer(org.infinispan.util.function.TriConsumer) CacheException(org.infinispan.commons.CacheException) Iterator(java.util.Iterator) CacheTopologyInfo(org.infinispan.client.hotrod.CacheTopologyInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Log(org.infinispan.persistence.remote.logging.Log) ProcessorInfo(org.infinispan.commons.util.ProcessorInfo) HotRodMigratorHelper.split(org.infinispan.persistence.remote.upgrade.HotRodMigratorHelper.split) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Collections(java.util.Collections) RemoteStoreConfiguration(org.infinispan.persistence.remote.configuration.RemoteStoreConfiguration) HotRodMigratorHelper.range(org.infinispan.persistence.remote.upgrade.HotRodMigratorHelper.range) Address(org.infinispan.remoting.transport.Address) CacheException(org.infinispan.commons.CacheException) CompletableFuture(java.util.concurrent.CompletableFuture) List(java.util.List) HashSet(java.util.HashSet) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) ClusterExecutor(org.infinispan.manager.ClusterExecutor) RemoteStore(org.infinispan.persistence.remote.RemoteStore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ComponentRegistry(org.infinispan.factories.ComponentRegistry) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RemoteCache(org.infinispan.client.hotrod.RemoteCache) CacheTopologyInfo(org.infinispan.client.hotrod.CacheTopologyInfo)

Aggregations

HashSet (java.util.HashSet)2 CacheTopologyInfo (org.infinispan.client.hotrod.CacheTopologyInfo)2 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Cache (org.infinispan.Cache)1 RemoteCache (org.infinispan.client.hotrod.RemoteCache)1 MultiHotRodServersTest (org.infinispan.client.hotrod.test.MultiHotRodServersTest)1 CacheException (org.infinispan.commons.CacheException)1 Marshaller (org.infinispan.commons.marshall.Marshaller)1 ProcessorInfo (org.infinispan.commons.util.ProcessorInfo)1 StoreConfiguration (org.infinispan.configuration.cache.StoreConfiguration)1 KeyPartitioner (org.infinispan.distribution.ch.KeyPartitioner)1