Java Code Examples for org.apache.ignite.IgniteCache#withSkipStore()

The following examples show how to use org.apache.ignite.IgniteCache#withSkipStore() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IgniteCacheConfigVariationsFullApiTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testWithSkipStoreTx() throws Exception {
    if (txShouldBeUsed() && storeEnabled()) {
        IgniteCache<String, Integer> cache = grid(0).cache(cacheName());

        IgniteCache<String, Integer> cacheSkipStore = cache.withSkipStore();

        final int KEYS = 250;

        // Put/remove data from multiple nodes.

        List<String> keys = new ArrayList<>(KEYS);

        for (int i = 0; i < KEYS; i++)
            keys.add("key_" + i);

        Map<String, Integer> data = new LinkedHashMap<>();

        for (int i = 0; i < keys.size(); i++)
            data.put(keys.get(i), i);

        checkSkipStoreWithTransaction(cache, cacheSkipStore, data, keys, OPTIMISTIC, READ_COMMITTED);

        checkSkipStoreWithTransaction(cache, cacheSkipStore, data, keys, OPTIMISTIC, REPEATABLE_READ);

        checkSkipStoreWithTransaction(cache, cacheSkipStore, data, keys, OPTIMISTIC, SERIALIZABLE);

        checkSkipStoreWithTransaction(cache, cacheSkipStore, data, keys, PESSIMISTIC, READ_COMMITTED);

        checkSkipStoreWithTransaction(cache, cacheSkipStore, data, keys, PESSIMISTIC, REPEATABLE_READ);

        checkSkipStoreWithTransaction(cache, cacheSkipStore, data, keys, PESSIMISTIC, SERIALIZABLE);
    }
}
 
Example 2
Source File: GridCacheAbstractFullApiSelfTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testWithSkipStoreTx() throws Exception {
    if (txShouldBeUsed()) {
        IgniteCache<String, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);

        IgniteCache<String, Integer> cacheSkipStore = cache.withSkipStore();

        final int KEYS = 250;

        // Put/remove data from multiple nodes.

        List<String> keys = new ArrayList<>(KEYS);

        for (int i = 0; i < KEYS; i++)
            keys.add("key_" + i);

        Map<String, Integer> data = new LinkedHashMap<>();

        for (int i = 0; i < keys.size(); i++)
            data.put(keys.get(i), i);

        checkSkipStoreWithTransaction(cache, cacheSkipStore, data, keys, OPTIMISTIC, READ_COMMITTED);

        checkSkipStoreWithTransaction(cache, cacheSkipStore, data, keys, OPTIMISTIC, REPEATABLE_READ);

        checkSkipStoreWithTransaction(cache, cacheSkipStore, data, keys, OPTIMISTIC, SERIALIZABLE);

        checkSkipStoreWithTransaction(cache, cacheSkipStore, data, keys, PESSIMISTIC, READ_COMMITTED);

        checkSkipStoreWithTransaction(cache, cacheSkipStore, data, keys, PESSIMISTIC, REPEATABLE_READ);

        checkSkipStoreWithTransaction(cache, cacheSkipStore, data, keys, PESSIMISTIC, SERIALIZABLE);
    }
}
 
Example 3
Source File: IgniteCacheWriteBehindNoUpdateSelfTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testEntryProcessorNoUpdate() throws Exception {
    IgniteCache<Object, Object> cache = ignite(0).cache(THROTTLES_CACHE_NAME);

    IgniteCache<Object, Object> skipStore = cache.withSkipStore();

    int entryCnt = 500;

    Set<String> keys = new HashSet<>();

    for (int i = 0; i < entryCnt; i++) {
        skipStore.put(String.valueOf(i), i);

        keys.add(String.valueOf(i));
    }

    TestCacheStore testStore = (TestCacheStore)grid(0).context().cache().cache(THROTTLES_CACHE_NAME).context()
        .store().configuredStore();

    assertEquals(0, testStore.writeCnt.get());

    cache.invokeAll(keys, new NoOpEntryProcessor());

    assertEquals(0, testStore.writeCnt.get());

    cache.invokeAll(keys, new OpEntryProcessor());

    assertEquals(1, testStore.writeCnt.get());
}
 
Example 4
Source File: CacheJdbcStoreExample.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * Executes transaction with read/write-through to persistent store.
 *
 * @param cache Cache to execute transaction on.
 */
private static void executeTransaction(IgniteCache<Long, Person> cache) {
    try (Transaction tx = Ignition.ignite().transactions().txStart()) {
        Person val = cache.get(id);

        System.out.println("Read value: " + val);

        val = cache.getAndPut(id, new Person(id, "Isaac", "Newton"));

        System.out.println("Overwrote old value: " + val);

        val = cache.get(id);

        System.out.println("Read value: " + val);

        tx.commit();
    }

    System.out.println("Read value after commit: " + cache.get(id));

    // Clear entry from memory, but keep it in store.
    cache.clear(id);

    // Operations on this cache will not affect store.
    IgniteCache<Long, Person> cacheSkipStore = cache.withSkipStore();

    System.out.println("Read value skipping store (expecting null): " + cacheSkipStore.get(id));

    System.out.println("Read value with store lookup (expecting NOT null): " + cache.get(id));

    // Expecting not null, since entry should be in memory since last call.
    System.out.println("Read value skipping store (expecting NOT null): " + cacheSkipStore.get(id));
}