Search in sources :

Example 1 with H2RowCache

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);
}
Also used : SqlQuery(org.apache.ignite.cache.query.SqlQuery) H2RowCache(org.apache.ignite.internal.processors.query.h2.H2RowCache)

Example 2 with H2RowCache

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;
}
Also used : SqlQuery(org.apache.ignite.cache.query.SqlQuery) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) GridH2KeyValueRowOnheap(org.apache.ignite.internal.processors.query.h2.opt.GridH2KeyValueRowOnheap)

Example 3 with H2RowCache

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);
    }
}
Also used : H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException)

Example 4 with H2RowCache

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());
}
Also used : H2RowCache(org.apache.ignite.internal.processors.query.h2.H2RowCache)

Example 5 with H2RowCache

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));
}
Also used : H2RowCache(org.apache.ignite.internal.processors.query.h2.H2RowCache) HashSet(java.util.HashSet)

Aggregations

H2RowCache (org.apache.ignite.internal.processors.query.h2.H2RowCache)4 SqlQuery (org.apache.ignite.cache.query.SqlQuery)3 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)1 H2TreeIndex (org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex)1 GridH2KeyValueRowOnheap (org.apache.ignite.internal.processors.query.h2.opt.GridH2KeyValueRowOnheap)1