Java Code Examples for org.apache.ignite.configuration.CacheConfiguration#setWriteBehindEnabled()

The following examples show how to use org.apache.ignite.configuration.CacheConfiguration#setWriteBehindEnabled() . 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: IgniteCacheStoreSessionWriteBehindAbstractTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param igniteInstanceName Ignite instance name.
 * @return Cache configuration.
 * @throws Exception In case of error.
 */
@Override @SuppressWarnings("unchecked")
protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
    CacheConfiguration ccfg0 = super.cacheConfiguration(igniteInstanceName);

    ccfg0.setReadThrough(true);
    ccfg0.setWriteThrough(true);
    ccfg0.setWriteBehindBatchSize(10);
    ccfg0.setWriteBehindFlushSize(10);
    ccfg0.setWriteBehindFlushFrequency(600);
    ccfg0.setWriteBehindEnabled(true);

    ccfg0.setCacheStoreFactory(singletonFactory(new TestStore()));

    return ccfg0;
}
 
Example 2
Source File: TxRecoveryStoreEnabledTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);

    cfg.setCommunicationSpi(new TestCommunicationSpi());

    CacheConfiguration ccfg = defaultCacheConfiguration();

    ccfg.setName(CACHE_NAME);
    ccfg.setNearConfiguration(null);
    ccfg.setCacheMode(CacheMode.PARTITIONED);
    ccfg.setBackups(1);
    ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
    ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    ccfg.setCacheStoreFactory(new TestCacheStoreFactory());
    ccfg.setReadThrough(true);
    ccfg.setWriteThrough(true);
    ccfg.setWriteBehindEnabled(false);

    cfg.setCacheConfiguration(ccfg);

    cfg.setFailureHandler(new StopNodeFailureHandler());

    return cfg;
}
 
Example 3
Source File: CacheStoreUsageMultinodeAbstractTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @return Cache configuration.
 */
@SuppressWarnings("unchecked")
protected CacheConfiguration cacheConfiguration() {
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg.setCacheMode(PARTITIONED);
    ccfg.setAtomicityMode(atomicityMode());
    ccfg.setBackups(1);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);

    if (cacheStore) {
        if (writeBehind) {
            ccfg.setWriteBehindEnabled(true);
            ccfg.setWriteBehindFlushFrequency(100);
        }

        ccfg.setWriteThrough(true);

        ccfg.setCacheStoreFactory(locStore ? new TestLocalStoreFactory() : new TestStoreFactory());
    }

    if (nearCache)
        ccfg.setNearConfiguration(new NearCacheConfiguration());

    return ccfg;
}
 
Example 4
Source File: GridCacheWriteBehindStorePartitionedMultiNodeSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);

    CacheConfiguration cc = defaultCacheConfiguration();

    cc.setCacheMode(CacheMode.PARTITIONED);
    cc.setWriteBehindEnabled(true);
    cc.setWriteBehindFlushFrequency(WRITE_BEHIND_FLUSH_FREQ);
    cc.setAtomicityMode(TRANSACTIONAL);
    cc.setNearConfiguration(new NearCacheConfiguration());

    CacheStore store = stores[idx.getAndIncrement()] = new GridCacheTestStore();

    cc.setCacheStoreFactory(singletonFactory(store));
    cc.setReadThrough(true);
    cc.setWriteThrough(true);
    cc.setLoadPreviousValue(true);

    c.setCacheConfiguration(cc);

    return c;
}
 
Example 5
Source File: IgnteCacheClientWriteBehindStoreAbstractTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
    MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.CACHE_STORE);

    CacheConfiguration ccfg = super.cacheConfiguration(igniteInstanceName);

    ccfg.setWriteBehindEnabled(true);
    ccfg.setWriteBehindBatchSize(10);

    if (getTestIgniteInstanceName(2).equals(igniteInstanceName)) {
        ccfg.setCacheStoreFactory(null);
        ccfg.setWriteThrough(false);
        ccfg.setReadThrough(false);
        ccfg.setWriteBehindEnabled(false);
    }

    return ccfg;
}
 
Example 6
Source File: CacheJdbcStoreAbstractMultithreadedSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @return Cache configuration.
 * @throws Exception If failed.
 */
protected CacheConfiguration cacheConfiguration() throws Exception {
    CacheConfiguration cc = defaultCacheConfiguration();

    cc.setCacheMode(PARTITIONED);
    cc.setAtomicityMode(ATOMIC);
    cc.setWriteBehindEnabled(false);

    cc.setCacheStoreFactory(singletonFactory(store));

    cc.setReadThrough(true);
    cc.setWriteThrough(true);
    cc.setLoadPreviousValue(true);

    return cc;
}
 
Example 7
Source File: IgniteCacheAbstractTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param igniteInstanceName Ignite instance name.
 * @return Cache configuration.
 * @throws Exception In case of error.
 */
@SuppressWarnings("unchecked")
protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
    CacheConfiguration cfg = defaultCacheConfiguration();

    cfg.setCacheMode(cacheMode());
    cfg.setAtomicityMode(atomicityMode());

    cfg.setWriteSynchronizationMode(writeSynchronization());
    cfg.setNearConfiguration(nearConfiguration());

    cfg.setCacheLoaderFactory(loaderFactory());

    if (cfg.getCacheLoaderFactory() != null)
        cfg.setReadThrough(true);

    cfg.setCacheWriterFactory(writerFactory());

    if (cfg.getCacheWriterFactory() != null)
        cfg.setWriteThrough(true);

    Factory<CacheStore> storeFactory = cacheStoreFactory();

    if (storeFactory != null) {
        cfg.setCacheStoreFactory(storeFactory);
        cfg.setReadThrough(true);
        cfg.setWriteThrough(true);
        cfg.setLoadPreviousValue(true);

        cfg.setWriteBehindEnabled(writeBehindEnabled());
        cfg.setWriteBehindCoalescing(writeBehindCoalescing());
    }

    if (cacheMode() == PARTITIONED)
        cfg.setBackups(1);

    cfg.setOnheapCacheEnabled(onheapCacheEnabled());

    return cfg;
}
 
Example 8
Source File: CacheJdbcPojoStoreAbstractSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @return Cache configuration for test.
 * @throws Exception In case when failed to create cache configuration.
 */
protected CacheConfiguration cacheConfiguration() throws Exception {
    CacheConfiguration cc = defaultCacheConfiguration();

    cc.setName(CACHE_NAME);
    cc.setCacheMode(PARTITIONED);
    cc.setAtomicityMode(transactional ? TRANSACTIONAL : ATOMIC);
    cc.setWriteBehindEnabled(false);
    cc.setStoreKeepBinary(storeKeepBinary());

    CacheJdbcPojoStoreFactory<Object, Object> storeFactory = new CacheJdbcPojoStoreFactory<>();

    H2Dialect dialect = new H2Dialect();

    dialect.setFetchSize(FETCH_SZ);

    storeFactory.setDialect(dialect);
    storeFactory.setTypes(storeTypes());
    storeFactory.setDataSourceFactory(new H2DataSourceFactory()); // H2 DataSource factory.
    storeFactory.setSqlEscapeAll(sqlEscapeAll());
    storeFactory.setParallelLoadCacheMinimumThreshold(parallelLoadThreshold);

    cc.setCacheStoreFactory(storeFactory);
    cc.setReadThrough(true);
    cc.setWriteThrough(true);
    cc.setLoadPreviousValue(true);

    return cc;
}
 
Example 9
Source File: CacheStoreSample.java    From ignite-book-code-samples with GNU General Public License v3.0 4 votes vote down vote up
private static void jdbcStoreExample() throws Exception{
    //let's make a dynamic cache on the fly which is distributed across all running nodes.
    //the same configuration you would probably set in configuration xml format
    IgniteConfiguration cfg = new IgniteConfiguration();

    CacheConfiguration configuration = new CacheConfiguration();
    configuration.setName("dynamicCache");
    configuration.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);

    configuration.setCacheStoreFactory(FactoryBuilder.factoryOf(PostgresDBStore.class));
    configuration.setReadThrough(true);
    configuration.setWriteThrough(true);

    configuration.setWriteBehindEnabled(true);

    log("Start. PersistenceStore example.");
    cfg.setCacheConfiguration(configuration);

    try (Ignite ignite = Ignition.start(cfg)) {
        //create cache if it doesn't exist
        int count = 10;
        try (IgniteCache<String, Post> igniteCache = ignite.getOrCreateCache(configuration)) {
            try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
                //let us clear

                for (int i = 1; i <= count; i++)
                    igniteCache.put("_" + i, new Post("_" + i, "title-" + i, "description-" + i, LocalDate.now().plus(i, ChronoUnit.DAYS), "author-" + i));

                tx.commit();

                for (int i = 1; i < count; i += 2) {
                    igniteCache.clear("_" + i);
                    log("Clear every odd key: " + i);
                }

                for (long i = 1; i <= count; i++)
                    log("Local peek at [key=_" + i + ", val=" + igniteCache.localPeek("_" + i) + ']');

                for (long i = 1; i <= count; i++)
                    log("Got [key=_" + i + ", val=" + igniteCache.get("_" + i) + ']');

                tx.commit();
            }
        }

        log("PersistenceStore example finished.");
        //ignite.destroyCache("dynamicCache");
        Thread.sleep(Integer.MAX_VALUE);
    }
}
 
Example 10
Source File: CacheStoreSample.java    From ignite-book-code-samples with GNU General Public License v3.0 4 votes vote down vote up
private static void nosqlStore() {
    //let's make a dynamic cache on the fly which is distributed across all running nodes.
    //the same configuration you would probably set in configuration xml format
    IgniteConfiguration cfg = new IgniteConfiguration();

    CacheConfiguration configuration = new CacheConfiguration();
    configuration.setName("mongoDynamicCache");
    configuration.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);

    configuration.setCacheStoreFactory(FactoryBuilder.factoryOf(MongoDBStore.class));
    configuration.setReadThrough(true);
    configuration.setWriteThrough(true);

    configuration.setWriteBehindEnabled(true);

    log("Start. PersistenceStore example.");
    cfg.setCacheConfiguration(configuration);

    try (Ignite ignite = Ignition.start(cfg)) {
        //create cache if it doesn't exist
        int count = 10;
        try (IgniteCache<String, MongoPost> igniteCache = ignite.getOrCreateCache(configuration)) {
            try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
                //let us clear

                for (int i = 1; i <= count; i++)
                    igniteCache.put("_" + i, new MongoPost("_" + i, "title-" + i, "description-" + i, LocalDate.now().plus(i, ChronoUnit.DAYS), "author-" + i));

                for (int i = 1; i < count; i += 2) {
                    igniteCache.clear("_" + i);
                    log("Clear every odd key: " + i);
                }

                for (long i = 1; i <= count; i++)
                    log("Local peek at [key=_" + i + ", val=" + igniteCache.localPeek("_" + i) + ']');

                for (long i = 1; i <= count; i++)
                    log("Got [key=_" + i + ", val=" + igniteCache.get("_" + i) + ']');

                tx.commit();
            }
        }

        log("PersistenceStore example finished.");
        ignite.destroyCache("mongoDynamicCache");
    }
}
 
Example 11
Source File: CacheStoreSessionListenerWriteBehindEnabledTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
    MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.CACHE_STORE);

    CacheConfiguration cacheCfg = super.cacheConfiguration(igniteInstanceName);

    cacheCfg.setCacheStoreFactory(FactoryBuilder.factoryOf(EmptyCacheStore.class));

    cacheCfg.setCacheStoreSessionListenerFactories(new CacheStoreSessionFactory());

    cacheCfg.setReadThrough(true);
    cacheCfg.setWriteThrough(true);

    cacheCfg.setWriteBehindEnabled(true);
    cacheCfg.setWriteBehindBatchSize(CNT * 2);
    cacheCfg.setWriteBehindFlushFrequency(WRITE_BEHIND_FLUSH_FREQUENCY);

    cacheCfg.setBackups(0);

    return cacheCfg;
}
 
Example 12
Source File: BasicWarmupClosure.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * Prepares configuration for warmup.
 *
 * @param gridCfg Original grid configuration.
 * @return Prepared configuration or {@code null} if no caches found.
 */
private IgniteConfiguration prepareConfiguration(IgniteConfiguration gridCfg) {
    if (F.isEmpty(gridCfg.getCacheConfiguration()))
        return null;

    IgniteConfiguration cp = new IgniteConfiguration();

    cp.setConnectorConfiguration(null);

    Collection<CacheConfiguration> reduced = new ArrayList<>();

    for (CacheConfiguration ccfg : gridCfg.getCacheConfiguration()) {
        if (CU.isSystemCache(ccfg.getName()))
            continue;

        if (!matches(reduced, ccfg)) {
            CacheConfiguration ccfgCp = new CacheConfiguration(ccfg);

            ccfgCp.setCacheStoreFactory(null);
            ccfgCp.setWriteBehindEnabled(false);

            reduced.add(ccfgCp);
        }
    }

    if (F.isEmpty(reduced))
        return null;

    CacheConfiguration[] res = new CacheConfiguration[reduced.size()];

    reduced.toArray(res);

    cp.setCacheConfiguration(res);

    return cp;
}
 
Example 13
Source File: GridCacheWriteBehindStoreLoadTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings({"unchecked"})
@Override protected final IgniteConfiguration getConfiguration() throws Exception {
    IgniteConfiguration c = super.getConfiguration();

    TcpDiscoverySpi disco = new TcpDiscoverySpi();

    disco.setIpFinder(new TcpDiscoveryVmIpFinder(true));

    c.setDiscoverySpi(disco);

    CacheConfiguration cc = defaultCacheConfiguration();

    cc.setCacheMode(cacheMode());
    cc.setWriteSynchronizationMode(FULL_SYNC);

    cc.setCacheStoreFactory(singletonFactory(store));
    cc.setReadThrough(true);
    cc.setWriteThrough(true);
    cc.setLoadPreviousValue(true);

    cc.setWriteBehindEnabled(true);
    cc.setWriteBehindFlushFrequency(WRITE_FROM_BEHIND_FLUSH_FREQUENCY);

    c.setCacheConfiguration(cc);

    return c;
}
 
Example 14
Source File: GridCacheWriteBehindStoreAbstractTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override protected IgniteConfiguration getConfiguration() throws Exception {
    MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.CACHE_STORE);

    IgniteConfiguration c = super.getConfiguration();

    TcpDiscoverySpi disco = new TcpDiscoverySpi();

    disco.setIpFinder(new TcpDiscoveryVmIpFinder(true));

    c.setDiscoverySpi(disco);

    CacheConfiguration cc = defaultCacheConfiguration();

    cc.setCacheMode(cacheMode());
    cc.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    cc.setAtomicityMode(TRANSACTIONAL);

    cc.setCacheStoreFactory(singletonFactory(store));
    cc.setReadThrough(true);
    cc.setWriteThrough(true);
    cc.setLoadPreviousValue(true);

    cc.setWriteBehindEnabled(true);
    cc.setWriteBehindFlushFrequency(WRITE_FROM_BEHIND_FLUSH_FREQUENCY);

    c.setCacheConfiguration(cc);

    return c;
}
 
Example 15
Source File: GridCacheLifecycleAwareSelfTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override protected final IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    cfg.setDiscoverySpi(new TcpDiscoverySpi());

    CacheConfiguration ccfg = defaultCacheConfiguration();

    ccfg.setCacheMode(PARTITIONED);

    ccfg.setWriteBehindEnabled(writeBehind);

    ccfg.setCacheMode(CacheMode.PARTITIONED);

    ccfg.setName(CACHE_NAME);

    TestStore store = new TestStore();

    ccfg.setCacheStoreFactory(singletonFactory(store));
    ccfg.setReadThrough(true);
    ccfg.setWriteThrough(true);
    ccfg.setLoadPreviousValue(true);

    lifecycleAwares.add(store.lifecycleAware);

    TestAffinityFunction affinity = new TestAffinityFunction();

    ccfg.setAffinity(affinity);

    lifecycleAwares.add(affinity);

    TestEvictionPolicy evictionPlc = new TestEvictionPolicy();

    ccfg.setEvictionPolicy(evictionPlc);
    ccfg.setOnheapCacheEnabled(true);

    lifecycleAwares.add(evictionPlc);

    if (near) {
        TestEvictionPolicy nearEvictionPlc = new TestEvictionPolicy();

        NearCacheConfiguration nearCfg = new NearCacheConfiguration();

        nearCfg.setNearEvictionPolicy(nearEvictionPlc);

        ccfg.setNearConfiguration(nearCfg);

        lifecycleAwares.add(nearEvictionPlc);
    }

    TestEvictionFilter evictionFilter = new TestEvictionFilter();

    ccfg.setEvictionFilter(evictionFilter);

    lifecycleAwares.add(evictionFilter);

    TestAffinityKeyMapper mapper = new TestAffinityKeyMapper();

    ccfg.setAffinityMapper(mapper);

    lifecycleAwares.add(mapper);

    TestInterceptor interceptor = new TestInterceptor();

    lifecycleAwares.add(interceptor);

    ccfg.setInterceptor(interceptor);

    TestTopologyValidator topValidator = new TestTopologyValidator();

    lifecycleAwares.add(topValidator);

    ccfg.setTopologyValidator(topValidator);

    cfg.setCacheConfiguration(ccfg);

    return cfg;
}
 
Example 16
Source File: CacheJdbcPojoWriteBehindStoreWithCoalescingTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/** */
public CacheConfiguration getCacheConfiguration() {
    CacheConfiguration ccfg = new CacheConfiguration();

    ccfg.setName("TEST_CACHE");

    ccfg.setCacheMode(REPLICATED);

    ccfg.setAtomicityMode(ATOMIC);

    ccfg.setPartitionLossPolicy(READ_WRITE_SAFE);

    ccfg.setReadThrough(true);

    ccfg.setWriteThrough(true);

    ccfg.setWriteBehindEnabled(true);

    ccfg.setWriteBehindBatchSize(1000);

    QueryEntity queryEntity = new QueryEntity();

    queryEntity.setKeyType("java.lang.Integer");

    queryEntity.setValueType("org.apache.ignite.cache.store.jdbc.model.TestPojo");

    queryEntity.setTableName("TEST_CACHE");

    queryEntity.setKeyFieldName("value3");

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

    keyFiles.add("value3");

    queryEntity.setKeyFields(keyFiles);

    LinkedHashMap<String, String> fields = new LinkedHashMap<>();

    fields.put("value1", "java.lang.String");

    fields.put("value2", "java.lang.Integer");

    fields.put("value3", "java.sql.Date");

    queryEntity.setFields(fields);

    Map<String, String> aliases = new HashMap<>();

    aliases.put("value1", "VALUE1");

    aliases.put("value2", "VALUE2");

    aliases.put("value3", "VALUE3");

    queryEntity.setAliases(aliases);

    ArrayList<QueryEntity> queryEntities = new ArrayList<>();

    queryEntities.add(queryEntity);

    ccfg.setQueryEntities(queryEntities);

    return ccfg;
}