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

The following examples show how to use org.apache.ignite.configuration.CacheConfiguration#setBackups() . 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: GridIndexingWithNoopSwapSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);

    CacheConfiguration<?,?> cc = defaultCacheConfiguration();

    cc.setCacheMode(PARTITIONED);
    cc.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    cc.setRebalanceMode(SYNC);
    cc.setNearConfiguration(new NearCacheConfiguration());

    FifoEvictionPolicy plc = new FifoEvictionPolicy();
    plc.setMaxSize(1000);

    cc.setEvictionPolicy(plc);
    cc.setOnheapCacheEnabled(true);
    cc.setBackups(1);
    cc.setAtomicityMode(TRANSACTIONAL);
    cc.setIndexedTypes(
        Integer.class, ObjectValue.class
    );

    c.setCacheConfiguration(cc);

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

    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg.setName(CACHE_NAME);
    ccfg.setAtomicityMode(TRANSACTIONAL);
    ccfg.setWriteSynchronizationMode(PRIMARY_SYNC);
    ccfg.setBackups(2);
    ccfg.setCacheMode(PARTITIONED);

    c.setCacheConfiguration(ccfg);

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

    if (getTestIgniteInstanceIndex(igniteInstanceName) != 0) {
        CacheConfiguration cc = new CacheConfiguration(DEFAULT_CACHE_NAME);

        cc.setCacheMode(cacheMode);
        cc.setAtomicityMode(atomicityMode);
        cc.setWriteSynchronizationMode(PRIMARY_SYNC);
        cc.setRebalanceMode(SYNC);
        cc.setBackups(0);

        c.setCacheConfiguration(cc);
    }

    ((TcpDiscoverySpi)c.getDiscoverySpi()).setForceServerMode(true);

    return c;
}
 
Example 4
Source File: CrossCacheTxRandomOperationsTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param name Cache name.
 * @param cacheMode Cache mode.
 * @param writeSync Write synchronization mode.
 * @param nearCache Near cache flag.
 * @return Cache configuration.
 */
protected CacheConfiguration cacheConfiguration(String name,
    CacheMode cacheMode,
    CacheWriteSynchronizationMode writeSync,
    boolean nearCache) {
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg.setName(name);
    ccfg.setCacheMode(cacheMode);
    ccfg.setAtomicityMode(TRANSACTIONAL);
    ccfg.setWriteSynchronizationMode(writeSync);

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

    ccfg.setAffinity(new RendezvousAffinityFunction());

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

    return ccfg;
}
 
Example 5
Source File: CacheMvccAbstractTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param cacheMode Cache mode.
 * @param syncMode Write synchronization mode.
 * @param backups Number of backups.
 * @param parts Number of partitions.
 * @return Cache configuration.
 */
final CacheConfiguration<Object, Object> cacheConfiguration(
    CacheMode cacheMode,
    CacheWriteSynchronizationMode syncMode,
    int backups,
    int parts) {
    CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);

    ccfg.setCacheMode(cacheMode);
    ccfg.setAtomicityMode(TRANSACTIONAL_SNAPSHOT);
    ccfg.setWriteSynchronizationMode(syncMode);
    ccfg.setAffinity(new RendezvousAffinityFunction(false, parts));

    if (cacheMode == PARTITIONED)
        ccfg.setBackups(backups);

    return ccfg;
}
 
Example 6
Source File: IgnitePdsCorruptedStoreTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Create cache configuration.
 *
 * @param name Cache name.
 */
private CacheConfiguration cacheConfiguration(String name) {
    CacheConfiguration ccfg = new CacheConfiguration();
    ccfg.setName(name);
    ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
    ccfg.setRebalanceMode(CacheRebalanceMode.SYNC);
    ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    ccfg.setAffinity(new RendezvousAffinityFunction(false, 32));
    ccfg.setBackups(2);

    return ccfg;
}
 
Example 7
Source File: CacheGetsDistributionAbstractTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @return Cache configuration.
 */
protected <K, V> CacheConfiguration<K, V> cacheConfiguration() {
    CacheConfiguration<K, V> ccfg = defaultCacheConfiguration();

    ccfg.setCacheMode(cacheMode());
    ccfg.setAtomicityMode(atomicityMode());
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    ccfg.setReadFromBackup(true);
    ccfg.setStatisticsEnabled(true);

    if (cacheMode() == CacheMode.PARTITIONED)
        ccfg.setBackups(backupsCount());

    return ccfg;
}
 
Example 8
Source File: HadoopIgfs20FileSystemAbstractSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Gets cache configuration.
 *
 * @param igniteInstanceName Ignite instance name.
 * @return Cache configuration.
 */
protected CacheConfiguration dataCacheConfiguration(String igniteInstanceName) {
    CacheConfiguration cacheCfg = defaultCacheConfiguration();

    cacheCfg.setCacheMode(PARTITIONED);
    cacheCfg.setNearConfiguration(null);
    cacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    cacheCfg.setAffinityMapper(new IgfsGroupDataBlocksKeyMapper(GRP_SIZE));
    cacheCfg.setBackups(0);
    cacheCfg.setAtomicityMode(TRANSACTIONAL);

    return cacheCfg;
}
 
Example 9
Source File: IgniteClusterActivateDeactivateTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param name Cache name.
 * @param atomicityMode Atomicity mode.
 * @return Cache configuration.
 */
protected final CacheConfiguration cacheConfiguration(String name, CacheAtomicityMode atomicityMode) {
    CacheConfiguration ccfg = new CacheConfiguration(name);

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

    return ccfg;
}
 
Example 10
Source File: CacheKeepBinaryWithInterceptorTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param atomicityMode Cache atomicity mode.
 * @param testPrimitives {@code True} if test interceptor with primitive values.
 * @return Cache configuration.
 */
private CacheConfiguration cacheConfiguration(CacheAtomicityMode atomicityMode, boolean testPrimitives) {
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg.setAtomicityMode(atomicityMode);
    ccfg.setInterceptor(testPrimitives ? new TestInterceptor2() : new TestInterceptor1());
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    ccfg.setBackups(1);

    return ccfg;
}
 
Example 11
Source File: NearCacheSyncUpdateTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param atomicityMode Atomicity mode.
 * @return Cache configuration.
 */
private CacheConfiguration<Integer, Integer> cacheConfiguration(CacheAtomicityMode atomicityMode) {
    CacheConfiguration<Integer, Integer> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);

    ccfg.setCacheMode(PARTITIONED);
    ccfg.setBackups(1);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    ccfg.setAtomicityMode(atomicityMode);
    ccfg.setNearConfiguration(new NearCacheConfiguration<Integer, Integer>());

    return ccfg;
}
 
Example 12
Source File: GridCachePartitionedTxOriginatingNodeFailureSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
    CacheConfiguration ccfg = super.cacheConfiguration(igniteInstanceName);

    ccfg.setBackups(BACKUP_CNT);

    return ccfg;
}
 
Example 13
Source File: GridCachePartitionedHitsAndMissesSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Cache configuration.
 *
 * @return Cache configuration.
 * @throws Exception In case of error.
 */
protected CacheConfiguration cacheConfiguration() throws Exception {
    CacheConfiguration cfg = defaultCacheConfiguration();

    cfg.setCacheMode(PARTITIONED);
    cfg.setWriteSynchronizationMode(FULL_ASYNC);
    cfg.setEvictionPolicy(null);
    cfg.setBackups(1);
    cfg.setNearConfiguration(null);
    cfg.setStatisticsEnabled(true);

    return cfg;
}
 
Example 14
Source File: IgniteCacheSerializationSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param cacheMode Cache mode.
 * @param atomicityMode Atomicity mode.
 * @return Cache configuration.
 */
private CacheConfiguration<Integer, Integer> cacheConfiguration(CacheMode cacheMode, CacheAtomicityMode atomicityMode) {
    CacheConfiguration<Integer, Integer> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);

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

    ccfg.setBackups(1);

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

    CacheConfiguration cacheCfg = defaultCacheConfiguration();

    cacheCfg.setCacheMode(PARTITIONED);

    // Explicitly set number of backups equal to number of grids.
    cacheCfg.setBackups(1);

    // Query should be executed without ongoing transactions.
    cacheCfg.setWriteSynchronizationMode(FULL_SYNC);

    cfg.setCacheConfiguration(cacheCfg);

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

    CacheConfiguration cacheCfg = defaultCacheConfiguration();

    cacheCfg.setCacheMode(PARTITIONED);
    cacheCfg.setWriteSynchronizationMode(FULL_SYNC);
    cacheCfg.setRebalanceMode(NONE);

    cacheCfg.setAffinity(aff);
    cacheCfg.setAtomicityMode(atomicityMode());
    cacheCfg.setBackups(aff.backups());

    NearCacheConfiguration nearCfg = new NearCacheConfiguration();

    cacheCfg.setNearConfiguration(nearCfg);

    cfg.setCacheConfiguration(cacheCfg);

    cfg.setUserAttributes(F.asMap(GridCacheModuloAffinityFunction.IDX_ATTR, cntr.getAndIncrement()));

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

    CacheConfiguration cacheCfg = cacheConfiguration(CACHE_NAME);

    TestTpcCommunicationSpi commSpi = new TestTpcCommunicationSpi();

    commSpi.setLocalPort(GridTestUtils.getNextCommPort(getClass()));

    commSpi.setTcpNoDelay(true);

    cacheCfg.setRebalanceMode(SYNC);
    cacheCfg.setWriteSynchronizationMode(FULL_SYNC);
    cacheCfg.setBackups(1);

    cfg.setCommunicationSpi(commSpi);

    ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setForceServerMode(true);

    cfg.setCacheConfiguration(cacheCfg);

    return cfg;
}
 
Example 18
Source File: RemoveAllDeadlockTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testRemoveAllAtomicReplicated() throws Exception {
    startGrid(1);

    CacheConfiguration<Integer, Integer> cacheCfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);

    cacheCfg.setCacheMode(CacheMode.REPLICATED);

    cacheCfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);

    cacheCfg.setBackups(0);

    IgniteCache<Integer, Integer> cache = grid(1).getOrCreateCache(cacheCfg);

    removeAllConcurrent(cache);
}
 
Example 19
Source File: CacheDataRegionConfigurationTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Verifies that warning message is printed to the logs if user tries to start a static cache in data region which
 * overhead (e.g. metapages for partitions) occupies more space of the region than a defined threshold (15%)
 *
 * @throws Exception If failed.
 */
@Test
public void testWarningIfStaticCacheOverheadExceedsThreshold() throws Exception {
    DataRegionConfiguration smallRegionCfg = new DataRegionConfiguration();
    int numOfPartitions = 512;
    int partitionsMetaMemoryChunk = U.sizeInMegabytes(512 * DFLT_PAGE_SIZE);

    smallRegionCfg.setInitialSize(DFLT_MEM_PLC_SIZE);
    smallRegionCfg.setMaxSize(DFLT_MEM_PLC_SIZE);
    smallRegionCfg.setPersistenceEnabled(true);
    smallRegionCfg.setName("smallRegion");

    memCfg = new DataStorageConfiguration();
    memCfg.setDefaultDataRegionConfiguration(smallRegionCfg);
    //one hour to guarantee that checkpoint will be triggered by 'dirty pages amount' trigger
    memCfg.setCheckpointFrequency(60 * 60 * 1000);

    CacheConfiguration<Object, Object> manyPartitionsCache = new CacheConfiguration<>(DEFAULT_CACHE_NAME);

    //512 partitions are enough only if primary and backups count
    manyPartitionsCache.setAffinity(new RendezvousAffinityFunction(false, numOfPartitions));
    manyPartitionsCache.setBackups(1);

    ccfg = manyPartitionsCache;

    ListeningTestLogger srv0Logger = new ListeningTestLogger(false, null);
    LogListener cacheGrpLsnr0 = matches("Cache group 'default' brings high overhead").build();
    LogListener dataRegLsnr0 = matches("metainformation in data region 'smallRegion'").build();
    LogListener partsInfoLsnr0 = matches(numOfPartitions + " partitions, " +
        DFLT_PAGE_SIZE +
        " bytes per partition, " + partitionsMetaMemoryChunk + " MBs total").build();
    srv0Logger.registerAllListeners(cacheGrpLsnr0, dataRegLsnr0, partsInfoLsnr0);
    logger = srv0Logger;

    IgniteEx ignite0 = startGrid("srv0");

    ListeningTestLogger srv1Logger = new ListeningTestLogger(false, null);
    LogListener cacheGrpLsnr1 = matches("Cache group 'default' brings high overhead").build();
    LogListener dataRegLsnr1 = matches("metainformation in data region 'smallRegion'").build();
    LogListener partsInfoLsnr1 = matches(numOfPartitions + " partitions, " +
        DFLT_PAGE_SIZE +
        " bytes per partition, " + partitionsMetaMemoryChunk + " MBs total").build();
    srv1Logger.registerAllListeners(cacheGrpLsnr1, dataRegLsnr1, partsInfoLsnr1);
    logger = srv1Logger;

    startGrid("srv1");

    ignite0.cluster().active(true);

    //srv0 and srv1 print warning into the log as the threshold for cache in default cache group is broken
    assertTrue(cacheGrpLsnr0.check());
    assertTrue(dataRegLsnr0.check());
    assertTrue(partsInfoLsnr0.check());

    assertTrue(cacheGrpLsnr1.check());
    assertTrue(dataRegLsnr1.check());
    assertTrue(partsInfoLsnr1.check());
}
 
Example 20
Source File: IpcSharedMemoryNodeStartup.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * @param args Args.
 * @throws Exception If failed.
 */
public static void main(String[] args) throws Exception {
    IgniteConfiguration cfg = new IgniteConfiguration();

    FileSystemConfiguration igfsCfg = new FileSystemConfiguration();

    TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();

    discoSpi.setIpFinder(new TcpDiscoveryVmIpFinder(true));

    cfg.setDiscoverySpi(discoSpi);

    IgfsIpcEndpointConfiguration endpointCfg = new IgfsIpcEndpointConfiguration();

    endpointCfg.setType(IgfsIpcEndpointType.SHMEM);
    endpointCfg.setPort(10500);

    igfsCfg.setIpcEndpointConfiguration(endpointCfg);

    igfsCfg.setName("igfs");

    CacheConfiguration metaCacheCfg = new CacheConfiguration();

    metaCacheCfg.setName("partitioned");
    metaCacheCfg.setCacheMode(PARTITIONED);
    metaCacheCfg.setNearConfiguration(null);
    metaCacheCfg.setWriteSynchronizationMode(FULL_SYNC);
    metaCacheCfg.setEvictionPolicy(null);
    metaCacheCfg.setBackups(0);

    CacheConfiguration dataCacheCfg = new CacheConfiguration();

    dataCacheCfg.setName("partitioned");
    dataCacheCfg.setCacheMode(PARTITIONED);
    dataCacheCfg.setNearConfiguration(null);
    dataCacheCfg.setWriteSynchronizationMode(FULL_SYNC);
    dataCacheCfg.setEvictionPolicy(null);
    dataCacheCfg.setBackups(0);

    igfsCfg.setMetaCacheConfiguration(metaCacheCfg);
    igfsCfg.setDataCacheConfiguration(dataCacheCfg);

    cfg.setFileSystemConfiguration(igfsCfg);

    cfg.setIncludeEventTypes(EVT_TASK_FAILED, EVT_TASK_FINISHED, EVT_JOB_MAPPED);

    try (Ignite ignored = G.start(cfg)) {
        X.println("Press any key to stop grid...");

        System.in.read();
    }
}