use of org.apache.ignite.internal.processors.cache.GridCacheAdapter in project ignite by apache.
the class IgniteCollectionAbstractTest method getQueueCache.
/**
* @param queue Ignite queue.
* @return Cache configuration.
*/
protected CacheConfiguration getQueueCache(IgniteQueue queue) {
GridCacheQueueAdapter delegate = GridTestUtils.getFieldValue(queue, "delegate");
GridCacheAdapter cache = GridTestUtils.getFieldValue(delegate, GridCacheQueueAdapter.class, "cache");
return cache.configuration();
}
use of org.apache.ignite.internal.processors.cache.GridCacheAdapter in project ignite by apache.
the class GridCacheSetAbstractSelfTest method testCleanup.
/**
* @param collocated Collocation flag.
* @throws Exception If failed.
*/
private void testCleanup(boolean collocated) throws Exception {
CollectionConfiguration colCfg = config(collocated);
final IgniteSet<Integer> set0 = grid(0).set(SET_NAME, colCfg);
assertNotNull(set0);
final Collection<Set<Integer>> sets = new ArrayList<>();
for (int i = 0; i < gridCount(); i++) {
IgniteSet<Integer> set = grid(i).set(SET_NAME, null);
assertNotNull(set);
sets.add(set);
}
Collection<Integer> items = new ArrayList<>(10_000);
for (int i = 0; i < 10_000; i++) items.add(i);
set0.addAll(items);
assertEquals(10_000, set0.size());
final AtomicBoolean stop = new AtomicBoolean();
final AtomicInteger val = new AtomicInteger(10_000);
IgniteInternalFuture<?> fut;
try {
fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
try {
while (!stop.get()) {
for (Set<Integer> set : sets) set.add(val.incrementAndGet());
}
} catch (IllegalStateException e) {
log.info("Set removed: " + e);
}
return null;
}
}, 5, "set-add-thread");
set0.close();
} finally {
stop.set(true);
}
fut.get();
int cnt = 0;
GridCacheContext cctx = GridTestUtils.getFieldValue(set0, "cctx");
boolean separated = separated(set0);
if (separated)
awaitPartitionMapExchange();
for (int i = 0; i < gridCount(); i++) {
GridCacheAdapter cache = grid(i).context().cache().internalCache(cctx.name());
if (separated) {
assertNull("Cache " + cctx.name() + " was not destroyed.", cache);
continue;
}
for (Object e : cache.localEntries(new CachePeekMode[] { CachePeekMode.ALL })) {
cnt++;
log.info("Unexpected entry: " + e);
}
}
assertEquals("Found unexpected cache entries", 0, cnt);
for (final Set<Integer> set : sets) {
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
set.add(10);
return null;
}
}, IllegalStateException.class, null);
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheAdapter in project ignite by apache.
the class VisorNodeDataCollectorJob method caches.
/**
* Collect caches.
*
* @param res Job result.
* @param arg Task argument.
*/
protected void caches(VisorNodeDataCollectorJobResult res, VisorNodeDataCollectorTaskArg arg) {
try {
IgniteConfiguration cfg = ignite.configuration();
GridCacheProcessor cacheProc = ignite.context().cache();
Set<String> cacheGrps = arg.getCacheGroups();
boolean all = F.isEmpty(cacheGrps);
int partitions = 0;
double total = 0;
double ready = 0;
List<VisorCache> resCaches = res.getCaches();
boolean rebalanceInProgress = false;
for (CacheGroupContext grp : cacheProc.cacheGroups()) {
boolean first = true;
for (GridCacheContext cache : grp.caches()) {
long start0 = U.currentTimeMillis();
String cacheName = cache.name();
try {
if (isProxyCache(ignite, cacheName) || isRestartingCache(ignite, cacheName))
continue;
GridCacheAdapter ca = cacheProc.internalCache(cacheName);
if (ca == null || !ca.context().started())
continue;
if (first) {
CacheMetrics cm = ca.localMetrics();
partitions += cm.getTotalPartitionsCount();
long keysTotal = cm.getEstimatedRebalancingKeys();
long keysReady = cm.getRebalancedKeys();
if (keysReady >= keysTotal)
keysReady = Math.max(keysTotal - 1, 0);
total += keysTotal;
ready += keysReady;
if (!rebalanceInProgress && cm.getRebalancingPartitionsCount() > 0)
rebalanceInProgress = true;
first = false;
}
boolean addToRes = arg.getSystemCaches() || !(isSystemCache(cacheName));
if (addToRes && (all || cacheGrps.contains(ca.configuration().getGroupName())))
resCaches.add(new VisorCache(ignite, ca, arg.isCollectCacheMetrics()));
} catch (IllegalStateException | IllegalArgumentException e) {
if (debug && ignite.log() != null)
ignite.log().error("Ignored cache: " + cacheName, e);
} finally {
if (debug)
log(ignite.log(), "Collected cache: " + cacheName, getClass(), start0);
}
}
}
if (partitions == 0)
res.setRebalance(NOTHING_TO_REBALANCE);
else if (total == 0 && rebalanceInProgress)
res.setRebalance(MINIMAL_REBALANCE);
else
res.setRebalance(total > 0 && rebalanceInProgress ? Math.max(ready / total, MINIMAL_REBALANCE) : REBALANCE_COMPLETE);
} catch (Exception e) {
res.setRebalance(REBALANCE_NOT_AVAILABLE);
res.setCachesEx(new VisorExceptionWrapper(e));
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheAdapter in project ignite by apache.
the class GridCacheSetFailoverAbstractSelfTest method testNodeRestart.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("WhileLoopReplaceableByForEach")
@Test
public void testNodeRestart() throws Exception {
IgniteSet<Integer> set = grid(0).set(SET_NAME, config(false));
final int ITEMS = 10_000;
Collection<Integer> items = new ArrayList<>(ITEMS);
for (int i = 0; i < ITEMS; i++) items.add(i);
set.addAll(items);
assertEquals(ITEMS, set.size());
AtomicBoolean stop = new AtomicBoolean();
IgniteInternalFuture<?> killFut = startNodeKiller(stop);
long stopTime = System.currentTimeMillis() + TEST_DURATION;
try {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
while (System.currentTimeMillis() < stopTime) {
for (int i = 0; i < 10; i++) {
try {
int size = set.size();
assertEquals(ITEMS, size);
} catch (IgniteException ignore) {
// No-op.
}
try {
Iterator<Integer> iter = set.iterator();
int cnt = 0;
while (iter.hasNext()) {
assertNotNull(iter.next());
cnt++;
}
assertEquals(ITEMS, cnt);
} catch (IgniteException ignore) {
// No-op.
}
int val = rnd.nextInt(ITEMS);
assertTrue("Not contains: " + val, set.contains(val));
val = ITEMS + rnd.nextInt(ITEMS);
assertFalse("Contains: " + val, set.contains(val));
}
log.info("Remove set.");
set.close();
log.info("Create new set.");
set = grid(0).set(SET_NAME, config(false));
set.addAll(items);
}
} finally {
stop.set(true);
}
killFut.get();
set.close();
if (false) {
// TODO IGNITE-600: enable check when fixed.
int cnt = 0;
Set<IgniteUuid> setIds = new HashSet<>();
for (int i = 0; i < gridCount(); i++) {
GridCacheAdapter cache = grid(i).context().cache().internalCache(DEFAULT_CACHE_NAME);
Iterator<GridCacheMapEntry> entries = cache.map().entries(cache.context().cacheId()).iterator();
while (entries.hasNext()) {
GridCacheEntryEx entry = entries.next();
if (entry.hasValue()) {
cnt++;
if (entry.key() instanceof SetItemKey) {
SetItemKey setItem = (SetItemKey) entry.key();
if (setIds.add(setItem.setId()))
log.info("Unexpected set item [setId=" + setItem.setId() + ", grid: " + grid(i).name() + ", entry=" + entry + ']');
}
}
}
}
assertEquals("Found unexpected cache entries", 0, cnt);
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheAdapter in project ignite by apache.
the class GridCacheSequenceApiSelfAbstractTest method testCacheSets.
/**
* @throws Exception If failed.
*/
@Test
public void testCacheSets() throws Exception {
// Make new atomic sequence in cache.
IgniteAtomicSequence seq = grid().atomicSequence(UUID.randomUUID().toString(), 0, true);
seq.incrementAndGet();
final String cacheName = DataStructuresProcessor.ATOMICS_CACHE_NAME + "@default-ds-group";
GridCacheAdapter cache = ((IgniteKernal) grid()).internalCache(cacheName);
assertNotNull(cache);
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
grid().cache(cacheName);
return null;
}
}, IllegalStateException.class, null);
for (String seqName : seqNames) assert null != cache.get(new GridCacheInternalKeyImpl(seqName, "default-ds-group"));
}
Aggregations