use of org.apache.ignite.internal.processors.cache.CacheStoreBalancingWrapper in project ignite by apache.
the class GridCacheBalancingStoreSelfTest method doTestConcurrentLoad.
/**
* @throws Exception If failed.
*/
private void doTestConcurrentLoad(int threads, final int keys, int threshold) throws Exception {
final CyclicBarrier beforeBarrier = new CyclicBarrier(threads);
ConcurrentVerifyStore store = new ConcurrentVerifyStore(keys);
final CacheStoreBalancingWrapper<Integer, Integer> wrapper = new CacheStoreBalancingWrapper<>(store, threshold);
GridTestUtils.runMultiThreaded(new Runnable() {
@Override
public void run() {
for (int i = 0; i < keys; i++) {
try {
beforeBarrier.await();
} catch (InterruptedException | BrokenBarrierException e) {
throw new RuntimeException(e);
}
info("Load key: " + i);
wrapper.load(i);
}
}
}, threads, "load-thread");
}
use of org.apache.ignite.internal.processors.cache.CacheStoreBalancingWrapper in project ignite by apache.
the class GridCacheStoreManagerAdapter method initialize.
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public void initialize(@Nullable CacheStore cfgStore, Map sesHolders) throws IgniteCheckedException {
GridKernalContext ctx = igniteContext();
CacheConfiguration cfg = cacheConfiguration();
writeThrough = cfg.isWriteThrough();
this.cfgStore = cfgStore;
store = cacheStoreWrapper(ctx, cfgStore, cfg);
singleThreadGate = store == null ? null : new CacheStoreBalancingWrapper<>(store, cfg.getStoreConcurrentLoadAllThreshold());
ThreadLocal<SessionData> sesHolder0 = null;
if (cfgStore != null) {
sesHolder0 = ((Map<CacheStore, ThreadLocal>) sesHolders).get(cfgStore);
if (sesHolder0 == null) {
sesHolder0 = new ThreadLocal<>();
locSes = new ThreadLocalSession(sesHolder0);
if (ctx.resource().injectStoreSession(cfgStore, locSes))
sesHolders.put(cfgStore, sesHolder0);
} else
locSes = new ThreadLocalSession(sesHolder0);
}
sesHolder = sesHolder0;
locStore = U.hasAnnotation(cfgStore, CacheLocalStore.class);
if (cfgStore instanceof CacheJdbcPojoStore)
alwaysKeepBinary = true;
}
use of org.apache.ignite.internal.processors.cache.CacheStoreBalancingWrapper in project ignite by apache.
the class GridCacheBalancingStoreSelfTest method testLoads.
/**
* @throws Exception If failed.
*/
public void testLoads() throws Exception {
final int range = 300;
final AtomicInteger cycles = new AtomicInteger();
final AtomicReference<Exception> err = new AtomicReference<>();
final CacheStoreBalancingWrapper<Integer, Integer> w = new CacheStoreBalancingWrapper<>(new VerifyStore(range));
final AtomicBoolean finish = new AtomicBoolean();
IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(new IgniteCallable<Void>() {
@Override
public Void call() throws Exception {
try {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
while (!finish.get()) {
int cnt = rnd.nextInt(CacheStoreBalancingWrapper.DFLT_LOAD_ALL_THRESHOLD) + 1;
if (cnt == 1) {
int key = rnd.nextInt(range);
assertEquals((Integer) key, w.load(key));
} else {
Collection<Integer> keys = new HashSet<>(cnt);
for (int i = 0; i < cnt; i++) keys.add(rnd.nextInt(range));
final Map<Integer, Integer> loaded = new HashMap<>();
w.loadAll(keys, new CI2<Integer, Integer>() {
@Override
public void apply(Integer k, Integer v) {
loaded.put(k, v);
}
});
for (Integer key : keys) assertEquals(key, loaded.get(key));
}
int c = cycles.incrementAndGet();
if (c > 0 && c % 2_000_000 == 0)
info("Finished cycles: " + c);
}
} catch (Exception e) {
e.printStackTrace();
err.compareAndSet(null, e);
}
return null;
}
}, 10, "test");
try {
Thread.sleep(30_000);
} finally {
finish.set(true);
}
fut.get();
if (err.get() != null)
throw err.get();
info("Total: " + cycles.get());
}
use of org.apache.ignite.internal.processors.cache.CacheStoreBalancingWrapper in project ignite by apache.
the class GridCacheBalancingStoreSelfTest method doTestConcurrentLoadAll.
/**
* @throws Exception If failed.
*/
private void doTestConcurrentLoadAll(int threads, final int threshold, final int keysCnt) throws Exception {
final CyclicBarrier beforeBarrier = new CyclicBarrier(threads);
ConcurrentVerifyStore store = new ConcurrentVerifyStore(keysCnt);
final CacheStoreBalancingWrapper<Integer, Integer> wrapper = new CacheStoreBalancingWrapper<>(store, threshold);
GridTestUtils.runMultiThreaded(new Runnable() {
@Override
public void run() {
for (int i = 0; i < keysCnt; i += threshold) {
try {
beforeBarrier.await();
} catch (InterruptedException | BrokenBarrierException e) {
throw new RuntimeException(e);
}
List<Integer> keys = new ArrayList<>(threshold);
for (int j = i; j < i + threshold; j++) keys.add(j);
info("Load keys: " + keys);
wrapper.loadAll(keys, new IgniteBiInClosure<Integer, Integer>() {
@Override
public void apply(Integer integer, Integer integer2) {
// No-op.
}
});
}
}
}, threads, "load-thread");
}
Aggregations