use of org.apache.ignite.internal.processors.query.h2.H2RowCache in project ignite by apache.
the class H2RowCacheSelfTest method checkDeleteEntry.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
private void checkDeleteEntry() throws Exception {
final String cacheName = "cache";
grid().getOrCreateCache(cacheConfiguration(cacheName, true));
int grpId = grid().cachex(cacheName).context().groupId();
assertEquals(grpId, grid().cachex(cacheName).context().groupId());
fillCache(cacheName);
H2RowCache rowCache = rowCache(grid(), grpId);
fillRowCache(cacheName);
assertNotNull(rowCache);
int key = RND.nextInt(ENTRIES);
grid().cache(cacheName).query(new SqlQuery(Value.class, "_key = " + key)).getAll();
int rowCacheSize = rowCache.size();
long rowLink = getLinkForKey(cacheName, rowCache, key);
assertNotNull(rowCache.get(rowLink));
// Remove
grid().cache(cacheName).remove(key);
assertNull(rowCache.get(rowLink));
int rowCacheSizeAfterUpdate = rowCache.size();
assertEquals(rowCacheSize - 1, rowCacheSizeAfterUpdate);
}
use of org.apache.ignite.internal.processors.query.h2.H2RowCache in project ignite by apache.
the class H2RowCacheSelfTest method getLinkForKey.
/**
* @param cacheName Cache name.
* @param rowCache Row cache.
* @param key Key to find.
* @return Row's link.
*/
private long getLinkForKey(String cacheName, H2RowCache rowCache, int key) {
grid().cache(cacheName).query(new SqlQuery(Value.class, "_key = " + key)).getAll().size();
ConcurrentHashMap<Long, GridH2KeyValueRowOnheap> rowsMap = GridTestUtils.getFieldValue(rowCache, "rows");
for (Map.Entry<Long, GridH2KeyValueRowOnheap> e : rowsMap.entrySet()) {
GridH2KeyValueRowOnheap val = e.getValue();
if ((Integer) val.key().value(null, false) == key)
return e.getKey();
}
fail("Row cache doesn't contain key [key=" + key + ']');
return -1;
}
use of org.apache.ignite.internal.processors.query.h2.H2RowCache in project ignite by apache.
the class IgniteH2Indexing method createSortedIndex.
/**
* Create sorted index.
*
* @param name Index name,
* @param tbl Table.
* @param pk Primary key flag.
* @param cols Columns.
* @param inlineSize Index inline size.
* @return Index.
*/
GridH2IndexBase createSortedIndex(String name, GridH2Table tbl, boolean pk, List<IndexColumn> cols, int inlineSize) {
try {
GridCacheContext cctx = tbl.cache();
if (log.isDebugEnabled())
log.debug("Creating cache index [cacheId=" + cctx.cacheId() + ", idxName=" + name + ']');
final int segments = tbl.rowDescriptor().context().config().getQueryParallelism();
H2RowCache cache = rowCache.forGroup(cctx.groupId());
return new H2TreeIndex(cctx, cache, tbl, name, pk, cols, inlineSize, segments);
} catch (IgniteCheckedException e) {
throw new IgniteException(e);
}
}
use of org.apache.ignite.internal.processors.query.h2.H2RowCache in project ignite by apache.
the class H2RowCachePageEvictionTest method checkRowCacheOnPageEviction.
/**
*/
private void checkRowCacheOnPageEviction() {
grid().getOrCreateCache(cacheConfiguration(CACHE_NAME, true));
int grpId = grid().cachex(CACHE_NAME).context().groupId();
assertEquals(grpId, grid().cachex(CACHE_NAME).context().groupId());
try (IgniteDataStreamer<Integer, Value> stream = grid().dataStreamer(CACHE_NAME)) {
for (int i = 0; i < ENTRIES; ++i) stream.addData(i, new Value(i));
}
H2RowCache rowCache = rowCache(grid()).forGroup(grpId);
fillRowCache(CACHE_NAME);
assertNotNull(rowCache);
int rowCacheSizeBeforeEvict = rowCache.size();
try (IgniteDataStreamer<Integer, Value> stream = grid().dataStreamer(CACHE_NAME)) {
for (int i = ENTRIES; i < 2 * ENTRIES; ++i) stream.addData(i, new Value(i));
}
assertTrue("rowCache size before evictions: " + rowCacheSizeBeforeEvict + ", after evictions: " + rowCache.size(), rowCacheSizeBeforeEvict > rowCache.size());
}
use of org.apache.ignite.internal.processors.query.h2.H2RowCache in project ignite by apache.
the class H2RowCacheSelfTest method checkDestroyCache.
/**
* @throws IgniteCheckedException If failed.
*/
private void checkDestroyCache() throws IgniteCheckedException {
final String cacheName0 = "cache0";
final String cacheName1 = "cache1";
grid().getOrCreateCache(cacheConfiguration(cacheName0, true));
grid().getOrCreateCache(cacheConfiguration(cacheName1, true));
int grpId = grid().cachex(cacheName0).context().groupId();
assertEquals(grpId, grid().cachex(cacheName1).context().groupId());
try (IgniteDataStreamer<Integer, Value> streamer = grid().dataStreamer(cacheName0)) {
for (int i = 0; i < ENTRIES / 2; ++i) streamer.addData(i, new Value(i));
}
try (IgniteDataStreamer<Integer, Value> streamer = grid().dataStreamer(cacheName1)) {
for (int i = ENTRIES / 2; i < ENTRIES; ++i) streamer.addData(i, new Value(i));
}
H2RowCache rowCache = rowCache(grid(), grpId);
assertNotNull(rowCache);
Set<Long> linksOfCache0 = new HashSet<>(ENTRIES / 2);
Set<Long> linksOfCache1 = new HashSet<>(ENTRIES / 2);
for (int i = 0; i < ENTRIES / 2; ++i) linksOfCache0.add(getLinkForKey(cacheName0, rowCache(grid(), grpId), i));
for (int i = ENTRIES / 2; i < ENTRIES; ++i) linksOfCache1.add(getLinkForKey(cacheName1, rowCache(grid(), grpId), i));
grid().destroyCache(cacheName0);
assertNotNull(rowCache(grid(), grpId));
for (long link : linksOfCache0) assertNull(rowCache(grid(), grpId).get(link));
grid().destroyCache(cacheName1);
assertNull(rowCache(grid(), grpId));
}
Aggregations