use of org.apache.ignite.cache.CachePeekMode in project ignite by apache.
the class IgfsAbstractSelfTest method testFormat.
/**
* Ensure that formatting is not propagated to the secondary file system.
*
* @throws Exception If failed.
*/
@SuppressWarnings("ConstantConditions")
public void testFormat() throws Exception {
if (mode == PROXY)
return;
final GridCacheAdapter<IgfsBlockKey, byte[]> dataCache = getDataCache(igfs);
assert dataCache != null;
int size0 = dataCache.size(new CachePeekMode[] { CachePeekMode.ALL });
assert size0 == 0 : "Initial data cache size = " + size0;
if (dual)
create(igfsSecondary, paths(DIR, SUBDIR, DIR_NEW, SUBDIR_NEW), paths(FILE, FILE_NEW));
create(igfs, paths(DIR, SUBDIR), paths(FILE));
try (IgfsOutputStream os = igfs.create(FILE, true)) {
os.write(new byte[10 * 1024 * 1024]);
}
awaitFileClose(igfs, FILE);
if (dual)
checkExist(igfsSecondary, DIR, SUBDIR, FILE, DIR_NEW, SUBDIR_NEW, FILE_NEW);
checkExist(igfs, DIR, SUBDIR, FILE);
assertEquals(10 * 1024 * 1024, igfs.info(FILE).length());
assert dataCache.size(new CachePeekMode[] { CachePeekMode.ALL }) > 0;
igfs.clear();
// Ensure format is not propagated to the secondary file system.
if (dual) {
checkExist(igfsSecondary, DIR, SUBDIR, FILE, DIR_NEW, SUBDIR_NEW, FILE_NEW);
igfsSecondary.format();
}
// Ensure entries deletion in the primary file system.
checkNotExist(igfs, DIR, SUBDIR, FILE);
if (!GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
try {
return dataCache.size(new CachePeekMode[] { CachePeekMode.ALL }) == 0;
} catch (IgniteCheckedException ice) {
throw new IgniteException(ice);
}
}
}, 10_000)) {
Iterable<? extends GridCacheEntryEx> entries = dataCache.allEntries();
for (GridCacheEntryEx e : entries) {
X.println("deleted = " + e.deleted());
X.println("detached = " + e.detached());
X.println("info = " + e.info());
X.println("k = " + e.key() + ", v = " + e.valueBytes());
}
assert false;
}
}
use of org.apache.ignite.cache.CachePeekMode in project ignite by apache.
the class IgniteCachePeekModesAbstractTest method checkEmpty.
/**
* Checks size is zero.
*/
private void checkEmpty() {
for (int i = 0; i < gridCount(); i++) {
IgniteCache<Integer, String> cache = jcache(i);
assertEquals(0, cache.localSize());
assertEquals(0, cache.size());
for (CachePeekMode peekMode : CachePeekMode.values()) {
assertEquals(0, cache.localSize(peekMode));
assertEquals(0, cache.size(peekMode));
}
}
checkPrimarySize(0);
}
use of org.apache.ignite.cache.CachePeekMode in project ignite by apache.
the class CacheKeepBinaryIterationTest method doTestLocalEntries.
/**
* @param ccfg Cache configuration.
*/
private void doTestLocalEntries(final CacheConfiguration<Object, Object> ccfg, boolean keepBinary, boolean primitives) throws Exception {
IgniteCache<Object, Object> cache = grid(0).createCache(ccfg);
assertEquals(0, cache.size());
try {
for (int i = 0; i < KEYS; i++) if (primitives)
cache.put(i, i);
else
cache.put(new QueryTestKey(i), new QueryTestValue(i));
for (int i = 0; i < getServerNodeCount(); i++) {
IgniteCache<Object, Object> cache0 = grid(i).cache(ccfg.getName());
if (keepBinary)
cache0 = cache0.withKeepBinary();
for (CachePeekMode mode : CachePeekMode.values()) {
int size = 0;
for (Cache.Entry<Object, Object> e : cache0.localEntries(mode)) {
Object key = e.getKey();
Object val = e.getValue();
if (!primitives) {
assertTrue("Got unexpected object: " + key.getClass() + ", keepBinary: " + keepBinary, keepBinary == key instanceof BinaryObject);
assertTrue("Got unexpected object: " + key.getClass() + ", keepBinary: " + keepBinary, keepBinary == val instanceof BinaryObject);
} else {
assertTrue("Got unexpected object: " + key.getClass() + ", keepBinary: " + keepBinary, key instanceof Integer);
assertTrue("Got unexpected object: " + key.getClass() + ", keepBinary: " + keepBinary, val instanceof Integer);
}
++size;
}
if (mode == CachePeekMode.ALL || mode == CachePeekMode.PRIMARY || mode == CachePeekMode.BACKUP || (mode == CachePeekMode.NEAR && i == 0 && ccfg.getNearConfiguration() != null))
assertTrue("Zero result at mode: " + mode, size > 0);
}
}
} finally {
if (ccfg.getEvictionPolicy() != null) {
// TODO: IGNITE-3462. Fixes evictionPolicy issues at cache destroy.
stopAllGrids();
startGridsMultiThreaded(getServerNodeCount());
} else
grid(0).destroyCache(ccfg.getName());
}
}
use of org.apache.ignite.cache.CachePeekMode in project ignite by apache.
the class EvictionPolicyFailureHandlerTest method testCacheMapDoesNotContainsWrongEntityAfterTransaction.
/**
* We expect that localPeek produces an exception, but the entry evict returns false because the transaction locks
* this entry. After transaction commit, the entry will be evicted.
*/
@Test
public void testCacheMapDoesNotContainsWrongEntityAfterTransaction() throws Exception {
LogListener lsnr = LogListener.matches(s -> s.contains("The cache entry cannot be touched")).times(1).build();
log.registerListener(lsnr);
IgniteEx node = startGrid(0);
IgniteEx client = startClientGrid(1);
GridCacheAdapter<Object, Object> cache = ((IgniteKernal) node).internalCache(DEFAULT_CACHE_NAME);
cache.put(1, 1);
CountDownLatch locPeekFinished = new CountDownLatch(1);
CountDownLatch txStarted = new CountDownLatch(1);
CountDownLatch txFinished = new CountDownLatch(1);
GridTestUtils.runAsync(() -> {
IgniteCache<Object, Object> cache1 = client.cache(DEFAULT_CACHE_NAME);
IgniteTransactions transactions = client.transactions();
try (Transaction tx = transactions.txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache1.put(2.1, 2.4);
txStarted.countDown();
locPeekFinished.await();
tx.commit();
} catch (Exception ignore) {
}
txFinished.countDown();
}, "tx-thread");
txStarted.await();
try {
cache.localPeek(2.1, new CachePeekMode[] { CachePeekMode.ONHEAP });
} catch (Exception ignore) {
}
locPeekFinished.countDown();
assertTrue(lsnr.check(10_000));
txFinished.await();
assertFalse(cache.map().entrySet(cache.context().cacheId()).stream().anyMatch(e -> new Double(2.1).equals(e.key().value(null, false))));
assertEquals(ACTIVE, node.cluster().state());
}
use of org.apache.ignite.cache.CachePeekMode in project ignite by apache.
the class GridCacheAdapter method parsePeekModes.
/**
* @param peekModes Cache peek modes array.
* @param primary Defines the default behavior if affinity flags are not specified.
* @return Peek modes flags.
*/
protected static PeekModes parsePeekModes(CachePeekMode[] peekModes, boolean primary) {
PeekModes modes = new PeekModes();
if (F.isEmpty(peekModes)) {
modes.primary = true;
if (!primary) {
modes.backup = true;
modes.near = true;
}
modes.heap = true;
modes.offheap = true;
} else {
for (CachePeekMode peekMode : peekModes) {
A.notNull(peekMode, "peekMode");
switch(peekMode) {
case ALL:
modes.near = true;
modes.primary = true;
modes.backup = true;
modes.heap = true;
modes.offheap = true;
break;
case BACKUP:
modes.backup = true;
break;
case PRIMARY:
modes.primary = true;
break;
case NEAR:
modes.near = true;
break;
case ONHEAP:
modes.heap = true;
break;
case OFFHEAP:
modes.offheap = true;
break;
default:
assert false : peekMode;
}
}
}
if (!(modes.heap || modes.offheap)) {
modes.heap = true;
modes.offheap = true;
}
if (!(modes.primary || modes.backup || modes.near)) {
modes.primary = true;
if (!primary) {
modes.backup = true;
modes.near = true;
}
}
assert modes.heap || modes.offheap;
assert modes.primary || modes.backup || modes.near;
return modes;
}
Aggregations