use of org.jsr166.ConcurrentHashMap8 in project ignite by apache.
the class GridCacheQueryManager method start0.
/** {@inheritDoc} */
@Override
public void start0() throws IgniteCheckedException {
CacheConfiguration ccfg = cctx.config();
qryProcEnabled = QueryUtils.isEnabled(ccfg);
qryProc = cctx.kernalContext().query();
cacheName = cctx.name();
enabled = qryProcEnabled || (isIndexingSpiEnabled() && !CU.isSystemCache(cacheName));
maxIterCnt = ccfg.getMaxQueryIteratorsCount();
detailMetricsSz = ccfg.getQueryDetailMetricsSize();
if (detailMetricsSz > 0)
detailMetrics = new ConcurrentHashMap8<>(detailMetricsSz);
lsnr = new GridLocalEventListener() {
@Override
public void onEvent(Event evt) {
UUID nodeId = ((DiscoveryEvent) evt).eventNode().id();
Map<Long, GridFutureAdapter<QueryResult<K, V>>> futs = qryIters.remove(nodeId);
if (futs != null) {
for (Map.Entry<Long, GridFutureAdapter<QueryResult<K, V>>> entry : futs.entrySet()) {
final Object rcpt = recipient(nodeId, entry.getKey());
entry.getValue().listen(new CIX1<IgniteInternalFuture<QueryResult<K, V>>>() {
@Override
public void applyx(IgniteInternalFuture<QueryResult<K, V>> f) throws IgniteCheckedException {
f.get().closeIfNotShared(rcpt);
}
});
}
}
Map<Long, GridFutureAdapter<FieldsResult>> fieldsFuts = fieldsQryRes.remove(nodeId);
if (fieldsFuts != null) {
for (Map.Entry<Long, GridFutureAdapter<FieldsResult>> entry : fieldsFuts.entrySet()) {
final Object rcpt = recipient(nodeId, entry.getKey());
entry.getValue().listen(new CIX1<IgniteInternalFuture<FieldsResult>>() {
@Override
public void applyx(IgniteInternalFuture<FieldsResult> f) throws IgniteCheckedException {
f.get().closeIfNotShared(rcpt);
}
});
}
}
}
};
cctx.events().addListener(lsnr, EVT_NODE_LEFT, EVT_NODE_FAILED);
qryTopVer = cctx.startTopologyVersion();
assert qryTopVer != null : cctx.name();
}
use of org.jsr166.ConcurrentHashMap8 in project ignite by apache.
the class CacheContinuousQueryCounterAbstractTest method testLoadCache.
/**
* @throws Exception If failed.
*/
public void testLoadCache() throws Exception {
IgniteCache<Integer, Integer> cache = grid(0).cache(CACHE_NAME);
ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<>();
final Map<Integer, T2<Integer, Long>> map = new ConcurrentHashMap8<>();
final CountDownLatch latch = new CountDownLatch(10);
qry.setLocalListener(new CacheEntryUpdatedListener<Integer, Integer>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>> evts) {
for (CacheEntryEvent<? extends Integer, ? extends Integer> e : evts) {
map.put(e.getKey(), new T2<>(e.getValue(), e.unwrap(CacheQueryEntryEvent.class).getPartitionUpdateCounter()));
latch.countDown();
}
}
});
try (QueryCursor<Cache.Entry<Integer, Integer>> ignored = cache.query(qry)) {
cache.loadCache(null, 0);
assert latch.await(LATCH_TIMEOUT, MILLISECONDS) : "Count: " + latch.getCount();
assertEquals(10, map.size());
for (int i = 0; i < 10; i++) {
assertEquals(i, (int) map.get(i).get1());
assertEquals((long) 1, (long) map.get(i).get2());
}
}
}
use of org.jsr166.ConcurrentHashMap8 in project ignite by apache.
the class GridCacheAbstractRemoveFailureTest method putAndRemove.
/**
* @param duration Test duration.
* @param txConcurrency Transaction concurrency if test explicit transaction.
* @param txIsolation Transaction isolation if test explicit transaction.
* @throws Exception If failed.
*/
private void putAndRemove(long duration, final TransactionConcurrency txConcurrency, final TransactionIsolation txIsolation) throws Exception {
assertEquals(testClientNode(), (boolean) grid(0).configuration().isClientMode());
grid(0).destroyCache(DEFAULT_CACHE_NAME);
CacheConfiguration<Integer, Integer> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
ccfg.setWriteSynchronizationMode(FULL_SYNC);
ccfg.setCacheMode(cacheMode());
if (cacheMode() == PARTITIONED)
ccfg.setBackups(1);
ccfg.setAtomicityMode(atomicityMode());
ccfg.setNearConfiguration(nearCache());
final IgniteCache<Integer, Integer> sndCache0 = grid(0).createCache(ccfg);
final AtomicBoolean stop = new AtomicBoolean();
final AtomicLong cntr = new AtomicLong();
final AtomicLong errCntr = new AtomicLong();
// Expected values in cache.
final Map<Integer, GridTuple<Integer>> expVals = new ConcurrentHashMap8<>();
final AtomicReference<CyclicBarrier> cmp = new AtomicReference<>();
IgniteInternalFuture<?> updateFut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
Thread.currentThread().setName("update-thread");
ThreadLocalRandom rnd = ThreadLocalRandom.current();
IgniteTransactions txs = sndCache0.unwrap(Ignite.class).transactions();
while (!stop.get()) {
for (int i = 0; i < 100; i++) {
int key = rnd.nextInt(KEYS_CNT);
boolean put = rnd.nextInt(0, 100) > 10;
while (true) {
try {
if (put) {
boolean failed = false;
if (txConcurrency != null) {
try (Transaction tx = txs.txStart(txConcurrency, txIsolation)) {
sndCache0.put(key, i);
tx.commit();
} catch (CacheException | IgniteException e) {
if (!X.hasCause(e, ClusterTopologyCheckedException.class)) {
log.error("Unexpected error: " + e);
throw e;
}
failed = true;
}
} else
sndCache0.put(key, i);
if (!failed)
expVals.put(key, F.t(i));
} else {
boolean failed = false;
if (txConcurrency != null) {
try (Transaction tx = txs.txStart(txConcurrency, txIsolation)) {
sndCache0.remove(key);
tx.commit();
} catch (CacheException | IgniteException e) {
if (!X.hasCause(e, ClusterTopologyCheckedException.class)) {
log.error("Unexpected error: " + e);
throw e;
}
failed = true;
}
} else
sndCache0.remove(key);
if (!failed)
expVals.put(key, F.<Integer>t(null));
}
break;
} catch (CacheException e) {
if (put)
log.error("Put failed [key=" + key + ", val=" + i + ']', e);
else
log.error("Remove failed [key=" + key + ']', e);
errCntr.incrementAndGet();
}
}
}
cntr.addAndGet(100);
CyclicBarrier barrier = cmp.get();
if (barrier != null) {
log.info("Wait data check.");
barrier.await(60_000, TimeUnit.MILLISECONDS);
log.info("Finished wait data check.");
}
}
return null;
}
});
IgniteInternalFuture<?> killFut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
Thread.currentThread().setName("restart-thread");
while (!stop.get()) {
U.sleep(random(KILL_DELAY.get1(), KILL_DELAY.get2()));
killAndRestart(stop);
CyclicBarrier barrier = cmp.get();
if (barrier != null) {
log.info("Wait data check.");
barrier.await(60_000, TimeUnit.MILLISECONDS);
log.info("Finished wait data check.");
}
}
return null;
}
});
try {
long stopTime = duration + U.currentTimeMillis();
long nextAssert = U.currentTimeMillis() + ASSERT_FREQ;
while (U.currentTimeMillis() < stopTime) {
long start = System.nanoTime();
long ops = cntr.longValue();
U.sleep(1000);
long diff = cntr.longValue() - ops;
double time = (System.nanoTime() - start) / 1_000_000_000d;
long opsPerSecond = (long) (diff / time);
log.info("Operations/second: " + opsPerSecond);
if (U.currentTimeMillis() >= nextAssert) {
CyclicBarrier barrier = new CyclicBarrier(3, new Runnable() {
@Override
public void run() {
try {
cmp.set(null);
log.info("Checking cache content.");
assertCacheContent(expVals);
log.info("Finished check cache content.");
} catch (Throwable e) {
log.error("Unexpected error: " + e, e);
throw e;
}
}
});
log.info("Start cache content check.");
cmp.set(barrier);
try {
barrier.await(60_000, TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
U.dumpThreads(log);
fail("Failed to check cache content: " + e);
}
log.info("Cache content check done.");
nextAssert = System.currentTimeMillis() + ASSERT_FREQ;
}
}
} finally {
stop.set(true);
}
killFut.get();
updateFut.get();
log.info("Test finished. Update errors: " + errCntr.get());
}
use of org.jsr166.ConcurrentHashMap8 in project ignite by apache.
the class GridOffHeapPartitionedMapAbstractSelfTest method testPartitionIteratorMultithreaded.
/**
* @throws Exception If failed.
*/
public void testPartitionIteratorMultithreaded() throws Exception {
initCap = 10;
map = newMap();
final AtomicInteger rehashes = new AtomicInteger();
final AtomicInteger releases = new AtomicInteger();
map.eventListener(new GridOffHeapEventListener() {
@Override
public void onEvent(GridOffHeapEvent evt) {
switch(evt) {
case REHASH:
rehashes.incrementAndGet();
break;
case RELEASE:
releases.incrementAndGet();
break;
// No-op.
default:
}
}
});
final int max = 64;
int threads = 5;
final Map<String, String> m = new ConcurrentHashMap8<>(max);
multithreaded(new Callable() {
@Override
public Object call() throws Exception {
for (int p = 0; p < parts; p++) {
for (int i = 0; i < max; i++) {
String key = string();
String val = string();
// info("Storing [i=" + i + ", key=" + key + ", val=" + val + ']');
m.put(key, val);
assertTrue(map.put(p, hash(key), key.getBytes(), val.getBytes()));
assertTrue(map.contains(p, hash(key), key.getBytes()));
assertNotNull(map.get(p, hash(key), key.getBytes()));
assertEquals(new String(map.get(p, hash(key), key.getBytes())), val);
try (GridCloseableIterator<IgniteBiTuple<byte[], byte[]>> it = map.iterator(p)) {
while (it.hasNext()) {
IgniteBiTuple<byte[], byte[]> t = it.next();
String k = new String(t.get1());
String v = new String(t.get2());
// info("Entry [k=" + k + ", v=" + v + ']');
assertEquals(m.get(k), v);
}
}
}
}
return null;
}
}, threads);
assertEquals(max * threads * parts, map.size());
info("Stats [size=" + map.size() + ", rehashes=" + rehashes + ", releases=" + releases + ']');
assertTrue(rehashes.get() > 0);
assertEquals(rehashes.get(), releases.get());
}
use of org.jsr166.ConcurrentHashMap8 in project ignite by apache.
the class IgniteCacheAbstractQuerySelfTest method testTextQueryEvents.
/**
* @throws Exception If failed.
*/
public void testTextQueryEvents() throws Exception {
final Map<UUID, Person> map = new ConcurrentHashMap8<>();
final CountDownLatch latch = new CountDownLatch(2);
final CountDownLatch execLatch = new CountDownLatch(cacheMode() == REPLICATED ? 1 : gridCount());
final IgniteCache<UUID, Person> cache = jcache(UUID.class, Person.class);
IgnitePredicate[] objReadLsnrs = new IgnitePredicate[gridCount()];
IgnitePredicate[] qryExecLsnrs = new IgnitePredicate[gridCount()];
for (int i = 0; i < gridCount(); i++) {
IgnitePredicate<Event> objReadPred = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
assert evt instanceof CacheQueryReadEvent;
CacheQueryReadEvent<UUID, Person> qe = (CacheQueryReadEvent<UUID, Person>) evt;
assertEquals(FULL_TEXT.name(), qe.queryType());
assertEquals(cache.getName(), qe.cacheName());
assertEquals("Person", qe.className());
assertEquals("White", qe.clause());
assertNull(qe.scanQueryFilter());
assertNull(qe.continuousQueryFilter());
assertNull(qe.arguments());
map.put(qe.key(), qe.value());
latch.countDown();
return true;
}
};
grid(i).events().localListen(objReadPred, EVT_CACHE_QUERY_OBJECT_READ);
objReadLsnrs[i] = objReadPred;
IgnitePredicate<Event> qryExecPred = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
assert evt instanceof CacheQueryExecutedEvent;
CacheQueryExecutedEvent qe = (CacheQueryExecutedEvent) evt;
assertEquals(FULL_TEXT.name(), qe.queryType());
assertEquals(cache.getName(), qe.cacheName());
assertEquals("Person", qe.className());
assertEquals("White", qe.clause());
assertNull(qe.scanQueryFilter());
assertNull(qe.continuousQueryFilter());
assertNull(qe.arguments());
execLatch.countDown();
return true;
}
};
grid(i).events().localListen(qryExecPred, EVT_CACHE_QUERY_EXECUTED);
qryExecLsnrs[i] = qryExecPred;
}
try {
UUID k1 = UUID.randomUUID();
UUID k2 = UUID.randomUUID();
UUID k3 = UUID.randomUUID();
cache.put(k1, new Person("Bob White", 1000));
cache.put(k2, new Person("Tom White", 1000));
cache.put(k3, new Person("Mike Green", 1000));
QueryCursor<Cache.Entry<UUID, Person>> q = cache.query(new TextQuery<UUID, Person>(Person.class, "White"));
q.getAll();
assert latch.await(1000, MILLISECONDS);
assert execLatch.await(1000, MILLISECONDS);
assertEquals(2, map.size());
assertEquals("Bob White", map.get(k1).name());
assertEquals("Tom White", map.get(k2).name());
} finally {
for (int i = 0; i < gridCount(); i++) {
grid(i).events().stopLocalListen(objReadLsnrs[i]);
grid(i).events().stopLocalListen(qryExecLsnrs[i]);
}
}
}
Aggregations