use of org.apache.ignite.internal.processors.datastructures.SetItemKey in project ignite by apache.
the class GridCacheQueryManager method sharedCacheSetIterator.
/**
* @param qry Query.
* @return Cache set items iterator.
*/
private GridCloseableIterator<IgniteBiTuple<K, V>> sharedCacheSetIterator(GridCacheQueryAdapter<?> qry) throws IgniteCheckedException {
final GridSetQueryPredicate filter = (GridSetQueryPredicate) qry.scanFilter();
IgniteUuid id = filter.setId();
GridCacheQueryAdapter<CacheEntry<K, ?>> qry0 = new GridCacheQueryAdapter<>(cctx, SCAN, new IgniteBiPredicate<Object, Object>() {
@Override
public boolean apply(Object k, Object v) {
return k instanceof SetItemKey && id.equals(((SetItemKey) k).setId());
}
}, new IgniteClosure<Map.Entry, Object>() {
@Override
public Object apply(Map.Entry entry) {
return new IgniteBiTuple<K, V>((K) ((SetItemKey) entry.getKey()).item(), (V) Boolean.TRUE);
}
}, qry.partition(), false, true, qry.isDataPageScanEnabled());
return scanQueryLocal(qry0, false);
}
use of org.apache.ignite.internal.processors.datastructures.SetItemKey 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.datastructures.SetItemKey in project ignite by apache.
the class CacheDataStructuresManager method removeSetData.
/**
* @param setId Set ID.
* @param topVer Topology version.
* @throws IgniteCheckedException If failed.
*/
private void removeSetData(IgniteUuid setId, AffinityTopologyVersion topVer) throws IgniteCheckedException {
boolean loc = cctx.isLocal();
GridCacheAffinityManager aff = cctx.affinity();
if (!loc) {
aff.affinityReadyFuture(topVer).get();
cctx.preloader().syncFuture().get();
}
IgniteInternalCache<?, ?> cache = cctx.cache();
final int BATCH_SIZE = 100;
Collection<SetItemKey> keys = new ArrayList<>(BATCH_SIZE);
for (Cache.Entry entry : cache.localEntries(new CachePeekMode[] { CachePeekMode.PRIMARY })) {
Object obj = entry.getKey();
if (!(obj instanceof SetItemKey && setId.equals(((SetItemKey) obj).setId())))
continue;
keys.add((SetItemKey) obj);
if (keys.size() == BATCH_SIZE) {
retryRemoveAll(cache, keys);
keys.clear();
}
}
if (!keys.isEmpty())
retryRemoveAll(cache, keys);
}
use of org.apache.ignite.internal.processors.datastructures.SetItemKey in project ignite by apache.
the class GridCacheQueryManager method setIterator.
/**
* @param qry Query.
* @return Cache set items iterator.
*/
private GridCloseableIterator<IgniteBiTuple<K, V>> setIterator(GridCacheQueryAdapter<?> qry) {
final GridSetQueryPredicate filter = (GridSetQueryPredicate) qry.scanFilter();
filter.init(cctx);
IgniteUuid id = filter.setId();
Collection<SetItemKey> data = cctx.dataStructures().setData(id);
if (data == null)
data = Collections.emptyList();
final GridIterator<IgniteBiTuple<K, V>> it = F.iterator(data, new C1<SetItemKey, IgniteBiTuple<K, V>>() {
@Override
public IgniteBiTuple<K, V> apply(SetItemKey e) {
return new IgniteBiTuple<>((K) e.item(), (V) Boolean.TRUE);
}
}, true, new P1<SetItemKey>() {
@Override
public boolean apply(SetItemKey e) {
return filter.apply(e, null);
}
});
return new GridCloseableIteratorAdapter<IgniteBiTuple<K, V>>() {
@Override
protected boolean onHasNext() {
return it.hasNext();
}
@Override
protected IgniteBiTuple<K, V> onNext() {
return it.next();
}
@Override
protected void onRemove() {
it.remove();
}
@Override
protected void onClose() {
// No-op.
}
};
}
Aggregations