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

The following examples show how to use org.apache.ignite.configuration.CacheConfiguration#setName() . 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: IgniteCacheMultiTxLockSelfTest.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);

    LruEvictionPolicy plc = new LruEvictionPolicy();
    plc.setMaxSize(100000);

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

    c.setCacheConfiguration(ccfg);

    return c;
}
 
Example 2
Source File: IgniteDemo.java    From banyan with MIT License 6 votes vote down vote up
public CacheConfiguration<Long, Foobar> createCacheConf() {
        CacheConfiguration<Long, Foobar> cacheConf = new CacheConfiguration<>();
//        skuConf.setBackups(1);
        cacheConf.setName("foo");

        QueryEntity entity = new QueryEntity(Long.class, Foobar.class);
        entity.setKeyFieldName("id");
        entity.setKeyType(Long.class.getName());
        entity.setValueType(Foobar.class.getName());

        // fields
        LinkedHashMap<String, String> fields = Maps.newLinkedHashMap();
        fields.put("id", Long.class.getName());
        fields.put("name", String.class.getName());
        fields.put("val", Integer.class.getName());
        fields.put("dateTime", LocalDateTime.class.getName());

        entity.setFields(fields);
        cacheConf.setQueryEntities(Collections.singletonList(entity));
        return cacheConf;
    }
 
Example 3
Source File: IgniteCacheClientMultiNodeUpdateTopologyLockTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param backups Number of backups.
 * @param writeSync Cache write synchronization mode.
 * @return Cache configuration.
 */
private CacheConfiguration<Integer, Integer> cacheConfiguration(int backups,
    CacheWriteSynchronizationMode writeSync) {
    CacheConfiguration<Integer, Integer> ccfg = new CacheConfiguration<>();

    ccfg.setName(TEST_CACHE);
    ccfg.setAtomicityMode(TRANSACTIONAL);
    ccfg.setWriteSynchronizationMode(writeSync);
    ccfg.setBackups(backups);
    ccfg.setRebalanceMode(ASYNC);

    return ccfg;
}
 
Example 4
Source File: SandboxMLCache.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Fills cache with data and returns it.
 *
 * @param data Data to fill the cache with.
 * @return Filled Ignite Cache.
 */
public IgniteCache<Integer, double[]> fillCacheWith(double[][] data) {
    CacheConfiguration<Integer, double[]> cacheConfiguration = new CacheConfiguration<>();
    cacheConfiguration.setName("TEST_" + UUID.randomUUID());
    cacheConfiguration.setAffinity(new RendezvousAffinityFunction(false, 10));

    IgniteCache<Integer, double[]> cache = ignite.createCache(cacheConfiguration);

    for (int i = 0; i < data.length; i++)
        cache.put(i, data[i]);

    return cache;
}
 
Example 5
Source File: ComputeUtilsTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that in case two caches maintain their partitions on different nodes, affinity call won't be completed.
 */
@Test
public void testAffinityCallWithRetriesNegative() {
    ClusterNode node1 = grid(1).cluster().localNode();
    ClusterNode node2 = grid(2).cluster().localNode();

    String firstCacheName = "CACHE_1_" + UUID.randomUUID();
    String secondCacheName = "CACHE_2_" + UUID.randomUUID();

    CacheConfiguration<Integer, Integer> cacheConfiguration1 = new CacheConfiguration<>();
    cacheConfiguration1.setName(firstCacheName);
    cacheConfiguration1.setAffinity(new TestAffinityFunction(node1));
    IgniteCache<Integer, Integer> cache1 = ignite.createCache(cacheConfiguration1);

    CacheConfiguration<Integer, Integer> cacheConfiguration2 = new CacheConfiguration<>();
    cacheConfiguration2.setName(secondCacheName);
    cacheConfiguration2.setAffinity(new TestAffinityFunction(node2));
    IgniteCache<Integer, Integer> cache2 = ignite.createCache(cacheConfiguration2);

    try {
        try {
            ComputeUtils.affinityCallWithRetries(
                ignite,
                Arrays.asList(firstCacheName, secondCacheName),
                part -> part,
                0,
                DeployingContext.unitialized()
            );
        }
        catch (IllegalStateException expectedException) {
            return;
        }

        fail("Missing IllegalStateException");
    }
    finally {
        cache1.destroy();
        cache2.destroy();
    }
}
 
Example 6
Source File: JdbcThinConnectionMvccEnabledSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param name Cache name.
 * @return Cache configuration.
 */
private CacheConfiguration cacheConfiguration(@NotNull String name) {
    CacheConfiguration cfg = defaultCacheConfiguration();

    cfg.setName(name);
    cfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT);

    return cfg;
}
 
Example 7
Source File: IgniteCacheConnectionRecoveryTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param name Cache name.
 * @param atomicityMode Cache atomicity mode.
 * @return Configuration.
 */
private CacheConfiguration cacheConfiguration(String name, CacheAtomicityMode atomicityMode) {
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg.setName(name);
    ccfg.setAtomicityMode(atomicityMode);
    ccfg.setCacheMode(REPLICATED);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);

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

    if (gridName.contains("server")) {
        CacheConfiguration<Integer, String> ccfg1 = new CacheConfiguration<>();

        ccfg1.setIndexedTypes(Integer.class, String.class);
        ccfg1.setName(ATOMIC_CACHE_NAME);
        ccfg1.setAtomicityMode(CacheAtomicityMode.ATOMIC);

        CacheConfiguration<Integer, String> ccfg2 = new CacheConfiguration<>();

        ccfg2.setIndexedTypes(Integer.class, String.class);
        ccfg2.setName(TX_CACHE_NAME);
        ccfg2.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);

        CacheConfiguration<Integer, String> ccfg3 = new CacheConfiguration<>();

        ccfg3.setIndexedTypes(Integer.class, String.class);
        ccfg3.setName(MVCC_TX_CACHE_NAME);
        ccfg3.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT);

        cfg.setCacheConfiguration(ccfg1, ccfg2, ccfg3);
    }
    else
        GridQueryProcessor.idxCls = FailedIndexing.class;

    return cfg;
}
 
Example 9
Source File: HibernateL2CacheStrategySelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param cacheName Cache name.
 * @return Cache configuration.
 */
private CacheConfiguration cacheConfiguration(String cacheName) {
    CacheConfiguration cfg = new CacheConfiguration();

    cfg.setName(cacheName);
    cfg.setCacheMode(PARTITIONED);
    cfg.setAtomicityMode(TRANSACTIONAL);

    return cfg;
}
 
Example 10
Source File: IgnitePdsWithTtlDeactivateOnHighloadTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new cache configuration with the given name and {@code GROUP_NAME} group.
 *
 * @param name Cache name.
 * @return Cache configuration.
 */
private CacheConfiguration<?, ?> getCacheConfiguration(String name) {
    CacheConfiguration<?, ?> ccfg = new CacheConfiguration<>();

    ccfg.setName(name);
    ccfg.setAffinity(new RendezvousAffinityFunction(false, PART_SIZE));
    ccfg.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, EXPIRATION_TIMEOUT)));
    ccfg.setEagerTtl(true);
    ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    ccfg.setRebalanceMode(CacheRebalanceMode.SYNC);

    return ccfg;
}
 
Example 11
Source File: GridCacheAbstractDistributedByteArrayValuesSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param name Cache name.
 * @return Cache configuration.
 */
protected CacheConfiguration cacheConfiguration(String name) {
    CacheConfiguration cfg = cacheConfiguration0();

    cfg.setName(name);

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

    if (register) {
        BinaryConfiguration bCfg = new BinaryConfiguration();

        BinaryTypeConfiguration enumCfg = new BinaryTypeConfiguration(EnumType.class.getName());

        enumCfg.setEnum(true);

        if (igniteInstanceName.equals(WRONG_CONF_NODE_NAME))
            enumCfg.setEnumValues(F.asMap(EnumType.ONE.name(),
                    EnumType.ONE.ordinal(),
                    EnumType.TWO.name(),
                    EnumType.ONE.ordinal()));
        else
            enumCfg.setEnumValues(F.asMap(EnumType.ONE.name(),
                    EnumType.ONE.ordinal(),
                    EnumType.TWO.name(),
                    EnumType.TWO.ordinal()));

        bCfg.setTypeConfigurations(Arrays.asList(enumCfg, new BinaryTypeConfiguration(EnumHolder.class.getName())));

        cfg.setBinaryConfiguration(bCfg);
    }

    cfg.setMarshaller(new BinaryMarshaller());

    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setName(CACHE_NAME);
    ccfg.setCacheMode(CacheMode.PARTITIONED);

    cfg.setCacheConfiguration(ccfg);

    return cfg;
}
 
Example 13
Source File: IgnitePdsTransactionsHangTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Creates cache configuration.
 *
 * @return Cache configuration.
 * */
private CacheConfiguration getCacheConfiguration() {
    CacheConfiguration ccfg = new CacheConfiguration();

    ccfg.setName(CACHE_NAME);
    ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
    ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    ccfg.setAffinity(new RendezvousAffinityFunction(false, 64 * 4));
    ccfg.setReadFromBackup(true);

    ccfg.setCacheMode(CacheMode.PARTITIONED);

    return ccfg;
}
 
Example 14
Source File: EncryptedCacheNodeJoinTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** */
protected CacheConfiguration cacheConfiguration(String gridName) {
    CacheConfiguration ccfg = defaultCacheConfiguration();

    ccfg.setName(cacheName());
    ccfg.setEncryptionEnabled(gridName.equals(GRID_0));

    return ccfg;
}
 
Example 15
Source File: IgfsOneClientNodeTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** */
protected CacheConfiguration cacheConfiguration(@NotNull String cacheName) {
    CacheConfiguration cacheCfg = defaultCacheConfiguration();

    cacheCfg.setName(cacheName);

    cacheCfg.setCacheMode(PARTITIONED);

    cacheCfg.setBackups(0);
    cacheCfg.setAffinityMapper(new IgfsGroupDataBlocksKeyMapper(128));

    cacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    cacheCfg.setAtomicityMode(TRANSACTIONAL);

    return cacheCfg;
}
 
Example 16
Source File: DecisionTreeRegressionTrainerExample.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Executes example.
 *
 * @param args Command line arguments, none required.
 */
public static void main(String... args) {
    System.out.println(">>> Decision tree regression trainer example started.");

    // Start ignite grid.
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
        System.out.println(">>> Ignite grid started.");

        // Create cache with training data.
        CacheConfiguration<Integer, LabeledVector<Double>> trainingSetCfg = new CacheConfiguration<>();
        trainingSetCfg.setName("TRAINING_SET");
        trainingSetCfg.setAffinity(new RendezvousAffinityFunction(false, 10));

        IgniteCache<Integer, LabeledVector<Double>> trainingSet = null;
        try {
            trainingSet = ignite.createCache(trainingSetCfg);

            // Fill training data.
            generatePoints(trainingSet);

            // Create regression trainer.
            DecisionTreeRegressionTrainer trainer = new DecisionTreeRegressionTrainer(10, 0);

            // Train decision tree model.
            DecisionTreeNode mdl = trainer.fit(ignite, trainingSet, new LabeledDummyVectorizer<>());

            System.out.println(">>> Decision tree regression model: " + mdl);

            System.out.println(">>> ---------------------------------");
            System.out.println(">>> | Prediction\t| Ground Truth\t|");
            System.out.println(">>> ---------------------------------");

            // Calculate score.
            for (int x = 0; x < 10; x++) {
                double predicted = mdl.predict(VectorUtils.of(x));

                System.out.printf(">>> | %.4f\t\t| %.4f\t\t|\n", predicted, Math.sin(x));
            }

            System.out.println(">>> ---------------------------------");

            System.out.println(">>> Decision tree regression trainer example completed.");
        }
        finally {
            trainingSet.destroy();
        }
    }
    finally {
        System.out.flush();
    }
}
 
Example 17
Source File: IgniteCacheClientQueryReplicatedNodeRestartSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    X.println("Ignite instance name: " + igniteInstanceName);

    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);

    int i = 0;

    CacheConfiguration<?, ?>[] ccs = new CacheConfiguration[4];

    for (String name : F.asList("co", "pr", "pe", "pu")) {
        CacheConfiguration<?, ?> cc = defaultCacheConfiguration();

        cc.setNodeFilter(DATA_NODES_FILTER);
        cc.setName(name);
        cc.setCacheMode(REPLICATED);
        cc.setWriteSynchronizationMode(FULL_SYNC);
        cc.setAtomicityMode(TRANSACTIONAL);
        cc.setRebalanceMode(SYNC);
        cc.setAffinity(new RendezvousAffinityFunction(false, 50));

        switch (name) {
            case "co":
                cc.setIndexedTypes(
                    Integer.class, Company.class
                );

                break;

            case "pr":
                cc.setIndexedTypes(
                    Integer.class, Product.class
                );

                break;

            case "pe":
                cc.setIndexedTypes(
                    Integer.class, Person.class
                );

                break;

            case "pu":
                cc.setIndexedTypes(
                    AffinityKey.class, Purchase.class
                );

                break;
        }

        ccs[i++] = cc;
    }

    c.setCacheConfiguration(ccs);

    return c;
}
 
Example 18
Source File: IgniteInternalCacheTypesTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testCacheTypes() throws Exception {
    Ignite ignite0 = startGrid(0);

    checkCacheTypes(ignite0, CACHE1);

    Ignite ignite1 = startGrid(1);

    checkCacheTypes(ignite1, CACHE1);

    CacheConfiguration ccfg = defaultCacheConfiguration();

    ccfg.setName(CACHE2);

    assertNotNull(ignite0.createCache(ccfg));

    checkCacheTypes(ignite0, CACHE1, CACHE2);
    checkCacheTypes(ignite1, CACHE1, CACHE2);

    Ignite ignite2 = startGrid(2);

    checkCacheTypes(ignite0, CACHE1, CACHE2);
    checkCacheTypes(ignite1, CACHE1, CACHE2);
    checkCacheTypes(ignite2, CACHE1, CACHE2);
}
 
Example 19
Source File: IgfsUtils.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Prepare cache configuration if this is IGFS meta or data cache.
 *
 * @param cfg Configuration.
 * @throws IgniteCheckedException If failed.
 */
public static void prepareCacheConfigurations(IgniteConfiguration cfg) throws IgniteCheckedException {
    FileSystemConfiguration[] igfsCfgs = cfg.getFileSystemConfiguration();
    List<CacheConfiguration> ccfgs = new ArrayList<>(Arrays.asList(cfg.getCacheConfiguration()));

    if (igfsCfgs != null) {
        for (FileSystemConfiguration igfsCfg : igfsCfgs) {
            if (igfsCfg == null)
                continue;

            CacheConfiguration ccfgMeta = igfsCfg.getMetaCacheConfiguration();

            if (ccfgMeta == null) {
                ccfgMeta = defaultMetaCacheConfig();

                igfsCfg.setMetaCacheConfiguration(ccfgMeta);
            }

            ccfgMeta.setName(IGFS_CACHE_PREFIX + igfsCfg.getName() + META_CACHE_SUFFIX);

            ccfgs.add(ccfgMeta);

            CacheConfiguration ccfgData = igfsCfg.getDataCacheConfiguration();

            if (ccfgData == null) {
                ccfgData = defaultDataCacheConfig();

                igfsCfg.setDataCacheConfiguration(ccfgData);
            }

            ccfgData.setName(IGFS_CACHE_PREFIX + igfsCfg.getName() + DATA_CACHE_SUFFIX);

            ccfgs.add(ccfgData);

            // No copy-on-read.
            ccfgMeta.setCopyOnRead(false);
            ccfgData.setCopyOnRead(false);

            // Always full-sync to maintain consistency.
            ccfgMeta.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
            ccfgData.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);

            // Set co-located affinity mapper if needed.
            if (igfsCfg.isColocateMetadata() && ccfgMeta.getAffinityMapper() == null)
                ccfgMeta.setAffinityMapper(new IgfsColocatedMetadataAffinityKeyMapper());

            // Set affinity mapper if needed.
            if (ccfgData.getAffinityMapper() == null)
                ccfgData.setAffinityMapper(new IgfsGroupDataBlocksKeyMapper());
        }

        cfg.setCacheConfiguration(ccfgs.toArray(new CacheConfiguration[ccfgs.size()]));
    }

    validateLocalIgfsConfigurations(cfg);
}
 
Example 20
Source File: NodeWithFilterRestartTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception if failed.
 */
@Test
public void testSpecificRestart() throws Exception {
    try {
        startGrids(6);

        {
            CacheConfiguration cfg1 = new CacheConfiguration();
            cfg1.setName("TRANSIENT_JOURNEY_ID");
            cfg1.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
            cfg1.setBackups(1);
            cfg1.setRebalanceMode(CacheRebalanceMode.ASYNC);
            cfg1.setAffinity(new RendezvousAffinityFunction(false, 64));
            cfg1.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
            cfg1.setNodeFilter(new NodeFilter());

            CacheConfiguration cfg2 = new CacheConfiguration();
            cfg2.setName("ENTITY_CONFIG");
            cfg2.setAtomicityMode(CacheAtomicityMode.ATOMIC);
            cfg2.setCacheMode(CacheMode.REPLICATED);
            cfg2.setRebalanceMode(CacheRebalanceMode.ASYNC);
            cfg2.setBackups(0);
            cfg2.setAffinity(new RendezvousAffinityFunction(false, 256));

            grid(0).getOrCreateCaches(Arrays.asList(cfg1, cfg2));
        }

        stopGrid(5, true);

        // Start grid 5 to trigger a local join exchange (node 0 is coordinator).
        // Since the message is blocked, node 5 will not complete the exchange.
        // Fail coordinator, check if the next exchange can be completed.
        // 5 should send single message to the new coordinator 1.
        IgniteInternalFuture<IgniteEx> fut = GridTestUtils.runAsync(() -> startGrid(5));

        // Increase if does not reproduce.
        U.sleep(2000);

        stopGrid(0, true);

        fut.get();

        awaitPartitionMapExchange();
    }
    finally {
        stopAllGrids();
    }
}