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

The following examples show how to use org.apache.ignite.configuration.CacheConfiguration#setNearConfiguration() . 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: CacheStoreReadFromBackupTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** */
@SuppressWarnings("unchecked")
private CacheConfiguration cacheConfig(String cacheName) {
    CacheConfiguration ccfg = new CacheConfiguration<>(cacheName);

    ccfg.setCacheMode(cacheMode);
    ccfg.setBackups(backups);
    ccfg.setAtomicityMode(atomicityMode());
    ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    ccfg.setAffinity(new RendezvousAffinityFunction(false, 1));
    ccfg.setReadThrough(true);
    ccfg.setReadFromBackup(true);
    ccfg.setCacheStoreFactory(FactoryBuilder.factoryOf(TestStore.class));

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

    return ccfg;
}
 
Example 2
Source File: GridCachePreloadRestartAbstractSelfTest.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);

    c.setDeploymentMode(CONTINUOUS);

    // Cache.
    CacheConfiguration cc = defaultCacheConfiguration();

    cc.setName(CACHE_NAME);
    cc.setCacheMode(PARTITIONED);
    cc.setWriteSynchronizationMode(FULL_SYNC);
    cc.setRebalanceMode(preloadMode);
    cc.setRebalanceBatchSize(preloadBatchSize);
    cc.setAffinity(new RendezvousAffinityFunction(false, partitions));
    cc.setBackups(backups);
    cc.setAtomicityMode(TRANSACTIONAL);

    if (!nearEnabled())
        cc.setNearConfiguration(null);

    c.setCacheConfiguration(cc);

    return c;
}
 
Example 3
Source File: IgniteAbstractTxSuspendResumeTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param cacheMode Cache mode.
 * @param backups Number of backups.
 * @param nearCache If {@code true} near cache is enabled.
 * @return Cache configuration.
 */
private CacheConfiguration<Integer, Integer> cacheConfiguration(
    String name,
    CacheMode cacheMode,
    int backups,
    boolean nearCache) {
    CacheConfiguration<Integer, Integer> ccfg = new CacheConfiguration<>(name);

    ccfg.setCacheMode(cacheMode);
    ccfg.setAtomicityMode(TRANSACTIONAL);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);

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

    if (nearCache)
        ccfg.setNearConfiguration(new NearCacheConfiguration<Integer, Integer>());

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

    CacheConfiguration partCacheCfg = defaultCacheConfiguration();

    partCacheCfg.setCacheMode(PARTITIONED);
    partCacheCfg.setAffinity(new GridCacheModuloAffinityFunction(1, 1));
    partCacheCfg.setWriteSynchronizationMode(FULL_SYNC);
    partCacheCfg.setNearConfiguration(null);
    partCacheCfg.setEvictionPolicy(null);
    partCacheCfg.setRebalanceMode(ASYNC);
    partCacheCfg.setAtomicityMode(TRANSACTIONAL);

    // This test requires artificial slowing down of the preloading.
    partCacheCfg.setRebalanceThrottle(2000);

    cfg.setCacheConfiguration(partCacheCfg);

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

    cfg.setNetworkTimeout(60000);

    return cfg;
}
 
Example 5
Source File: GridQueryParsingTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param name Cache name.
 * @param clsK Key class.
 * @param clsV Value class.
 * @return Cache configuration.
 */
@SuppressWarnings("unchecked")
private CacheConfiguration cacheConfiguration(@NotNull String name, String sqlSchema, Class<?> clsK,
    Class<?> clsV) {
    CacheConfiguration cc = defaultCacheConfiguration();

    cc.setName(name);
    cc.setCacheMode(CacheMode.PARTITIONED);
    cc.setAtomicityMode(CacheAtomicityMode.ATOMIC);
    cc.setNearConfiguration(null);
    cc.setWriteSynchronizationMode(FULL_SYNC);
    cc.setRebalanceMode(SYNC);
    cc.setSqlSchema(sqlSchema);
    cc.setSqlFunctionClasses(GridQueryParsingTest.class);
    cc.setIndexedTypes(clsK, clsV);

    if (!QueryUtils.isSqlType(clsK))
        cc.setKeyConfiguration(new CacheKeyConfiguration(clsK));

    return cc;
}
 
Example 6
Source File: GridCachePartitionedEventSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
    CacheConfiguration cfg = defaultCacheConfiguration();

    cfg.setCacheMode(PARTITIONED);
    cfg.setBackups(gridCount() - 1);
    cfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    cfg.setAtomicityMode(TRANSACTIONAL);
    cfg.setNearConfiguration(new NearCacheConfiguration());

    // Setting preload mode to SYNC is necessary due to race condition with test scenario in ASYNC mode.
    // In ASYNC mode preloader can fetch value from previous test and update it before next test run.
    // As a result test will see previous value while it expects null
    cfg.setRebalanceMode(SYNC);

    return cfg;
}
 
Example 7
Source File: GridCacheAbstractTransformWriteThroughSelfTest.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 {
    MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.CACHE_STORE);

    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    GridCacheGenericTestStore<String, Integer> store = new GridCacheGenericTestStore<>();

    stores.add(store);

    CacheConfiguration cacheCfg = defaultCacheConfiguration();

    cacheCfg.setCacheMode(PARTITIONED);
    cacheCfg.setBackups(1);
    cacheCfg.setCacheStoreFactory(singletonFactory(store));
    cacheCfg.setReadThrough(true);
    cacheCfg.setWriteThrough(true);
    cacheCfg.setLoadPreviousValue(true);
    cacheCfg.setAtomicityMode(TRANSACTIONAL);
    cacheCfg.setNearConfiguration(new NearCacheConfiguration());

    cfg.setCacheConfiguration(cacheCfg);

    return cfg;
}
 
Example 8
Source File: TxPessimisticDeadlockDetectionTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param cacheMode Cache mode.
 * @param syncMode Write sync mode.
 * @param near Near.
 * @return Created cache.
 */
@SuppressWarnings("unchecked")
private IgniteCache createCache(CacheMode cacheMode, CacheWriteSynchronizationMode syncMode, boolean near)
    throws IgniteInterruptedCheckedException, InterruptedException {
    awaitPartitionMapExchange();

    int minorTopVer = grid(0).context().discovery().topologyVersionEx().minorTopologyVersion();

    CacheConfiguration ccfg = defaultCacheConfiguration();

    ccfg.setName(CACHE_NAME);
    ccfg.setCacheMode(cacheMode);
    ccfg.setBackups(1);
    ccfg.setNearConfiguration(near ? new NearCacheConfiguration() : null);
    ccfg.setWriteSynchronizationMode(syncMode);

    if (cacheMode == LOCAL)
        ccfg.setDataRegionName("dfltPlc");

    IgniteCache cache = ignite(0).createCache(ccfg);

    if (near) {
        for (int i = 0; i < NODES_CNT; i++) {
            Ignite client = ignite(i + NODES_CNT);

            assertTrue(client.configuration().isClientMode());

            client.createNearCache(ccfg.getName(), new NearCacheConfiguration<>());
        }
    }

    waitForLateAffinityAssignment(minorTopVer);

    return cache;
}
 
Example 9
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 10
Source File: TxWithKeyContentionSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** */
protected CacheConfiguration<?, ?> getCacheConfiguration(String name) {
    CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(name)
        .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL)
        .setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC)
        .setAffinity(new RendezvousAffinityFunction(false, 16))
        .setBackups(2)
        .setStatisticsEnabled(true);

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

    return ccfg;
}
 
Example 11
Source File: GridCachePartitionedMultiNodeLockSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected CacheConfiguration cacheConfiguration() {
    CacheConfiguration cc = defaultCacheConfiguration();

    cc.setCacheMode(PARTITIONED);
    cc.setBackups(2); // 2 backups, so all nodes are involved.
    cc.setAtomicityMode(TRANSACTIONAL);
    cc.setNearConfiguration(new NearCacheConfiguration());

    return cc;
}
 
Example 12
Source File: GridCachePartitionedGetSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @return Cache configuration.
 */
private CacheConfiguration cacheConfiguration() {
    CacheConfiguration cc = defaultCacheConfiguration();

    cc.setCacheMode(PARTITIONED);
    cc.setBackups(1);
    cc.setRebalanceMode(SYNC);
    cc.setWriteSynchronizationMode(FULL_SYNC);
    cc.setNearConfiguration(null);

    return cc;
}
 
Example 13
Source File: CacheKeepBinaryIterationNearEnabledTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected CacheConfiguration<Object, Object> cacheConfiguration(
    CacheMode cacheMode,
    int backups,
    CacheAtomicityMode atomicityMode) {
    CacheConfiguration<Object, Object> ccfg =
        super.cacheConfiguration(cacheMode, backups, atomicityMode);

    ccfg.setNearConfiguration(new NearCacheConfiguration<>());

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

    cfg.setNearConfiguration(null);
    cfg.setBackups(4);

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

    c.getTransactionConfiguration().setTxSerializableEnabled(true);

    CacheConfiguration cc = defaultCacheConfiguration();

    cc.setCacheMode(PARTITIONED);
    cc.setBackups(1);
    cc.setNearConfiguration(null);
    cc.setAtomicityMode(TRANSACTIONAL);

    cc.setEvictionPolicy(null);

    cc.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_ASYNC);

    cc.setRebalanceMode(NONE);

    c.setCacheConfiguration(cc);

    if (CACHE_DEBUG)
        resetLog4j(Level.DEBUG, false, GridCacheProcessor.class.getPackage().getName());

    return c;
}
 
Example 16
Source File: SortedEvictionPolicyPerformanceTest.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 ccfg = defaultCacheConfiguration();

    ccfg.setCacheMode(CacheMode.PARTITIONED);
    ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
    ccfg.setNearConfiguration(null);

    SortedEvictionPolicy plc = new SortedEvictionPolicy();
    plc.setMaxSize(MAX_SIZE);

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

    cfg.setPeerClassLoadingEnabled(false);

    cfg.setCacheConfiguration(ccfg);

    return cfg;
}
 
Example 17
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 18
Source File: IgfsSizeSelfTest.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);

    FileSystemConfiguration igfsCfg = new FileSystemConfiguration();

    igfsCfg.setName(IGFS_NAME);
    igfsCfg.setBlockSize(BLOCK_SIZE);
    igfsCfg.setFragmentizerEnabled(false);
    igfsCfg.setManagementPort(++mgmtPort);

    CacheConfiguration dataCfg = defaultCacheConfiguration();

    dataCfg.setCacheMode(cacheMode);

    if (cacheMode == PARTITIONED) {
        if (nearEnabled)
            dataCfg.setNearConfiguration(new NearCacheConfiguration());

        dataCfg.setBackups(0);
    }

    dataCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    dataCfg.setRebalanceMode(SYNC);
    dataCfg.setAffinityMapper(new IgfsGroupDataBlocksKeyMapper(128));
    dataCfg.setAtomicityMode(TRANSACTIONAL);

    CacheConfiguration metaCfg = defaultCacheConfiguration();

    metaCfg.setCacheMode(REPLICATED);

    metaCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    metaCfg.setRebalanceMode(SYNC);
    metaCfg.setAtomicityMode(TRANSACTIONAL);

    igfsCfg.setMetaCacheConfiguration(metaCfg);
    igfsCfg.setDataCacheConfiguration(dataCfg);

    cfg.setFileSystemConfiguration(igfsCfg);

    if (memIgfsdDataPlcSetter != null)
        memIgfsdDataPlcSetter.apply(cfg);

    return cfg;
}
 
Example 19
Source File: IgniteDynamicClientCacheStartSelfTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testReplicatedCacheClient() throws Exception {
    ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg.setCacheMode(REPLICATED);

    final String cacheName = DEFAULT_CACHE_NAME;

    Ignite ignite0 = startGrid(0);

    checkCache(ignite0, cacheName, true, false);

    final Ignite ignite1 = startClientGrid(1);

    checkCache(ignite1, cacheName, false, false);

    ccfg.setNearConfiguration(new NearCacheConfiguration());

    Ignite ignite2 = startClientGrid(2);

    checkCache(ignite2, cacheName, false, true);

    ccfg = null;

    Ignite ignite3 = startClientGrid(3);

    checkNoCache(ignite3, cacheName);
}
 
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();
    }
}