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

The following examples show how to use org.apache.ignite.configuration.CacheConfiguration#getAtomicityMode() . 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: CacheTtlReadOnlyModeSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** */
private static CacheConfiguration[] getCacheConfigurations() {
    CacheConfiguration[] cfgs = cacheConfigurations();

    List<CacheConfiguration> newCfgs = new ArrayList<>(cfgs.length);

    for (CacheConfiguration cfg : cfgs) {
        if (cfg.getAtomicityMode() == CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT) {
            // Expiry policy cannot be used with TRANSACTIONAL_SNAPSHOT.
            continue;
        }

        cfg.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(SECONDS, EXPIRATION_TIMEOUT)));
        cfg.setEagerTtl(true);

        newCfgs.add(cfg);
    }

    return newCfgs.toArray(new CacheConfiguration[0]);
}
 
Example 2
Source File: MvccProcessorImpl.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** */
private void checkMvccCacheStarted(DynamicCacheChangeBatch cacheMsg) {
    if (!mvccEnabled) {
        for (DynamicCacheChangeRequest req : cacheMsg.requests()) {
            CacheConfiguration ccfg = req.startCacheConfiguration();

            if (ccfg == null)
                continue;

            if (ccfg.getAtomicityMode() == TRANSACTIONAL_SNAPSHOT) {
                assert mvccSupported;

                mvccEnabled = true;
            }
        }
    }
}
 
Example 3
Source File: JdbcThinWalModeChangeSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected void createCache(Ignite node, CacheConfiguration ccfg) throws IgniteCheckedException {
    String template = ccfg.getCacheMode() == CacheMode.PARTITIONED ?
        QueryUtils.TEMPLATE_PARTITIONED : QueryUtils.TEMPLATE_REPLICATED;

    String cmd = "CREATE TABLE IF NOT EXISTS " + ccfg.getName() + " (k BIGINT PRIMARY KEY, v BIGINT) WITH \"" +
        "TEMPLATE=" + template + ", " +
        "CACHE_NAME=" + ccfg.getName() + ", " +
        "ATOMICITY=" + ccfg.getAtomicityMode() +
        (ccfg.getGroupName() != null ? ", CACHE_GROUP=" + ccfg.getGroupName() : "") +
        (ccfg.getDataRegionName() != null ? ", DATA_REGION=" + ccfg.getDataRegionName() : "") +
        "\"";

    execute(node, cmd);

    alignCacheTopologyVersion(node);
}
 
Example 4
Source File: MvccProcessorImpl.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public void preProcessCacheConfiguration(CacheConfiguration ccfg) {
    if (FORCE_MVCC && ccfg.getAtomicityMode() == TRANSACTIONAL && !CU.isSystemCache(ccfg.getName())) {
        ccfg.setAtomicityMode(TRANSACTIONAL_SNAPSHOT);
        //noinspection unchecked
        ccfg.setNearConfiguration(null);
    }

    if (ccfg.getAtomicityMode() == TRANSACTIONAL_SNAPSHOT) {
        if (!mvccSupported)
            throw new IgniteException("Cannot start MVCC transactional cache. " +
                "MVCC is unsupported by the cluster.");

        mvccEnabled = true;
    }
}
 
Example 5
Source File: CacheGetEntryAbstractTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param cfg Cache configuration.
 * @param oneEntry If {@code true} then single entry is tested.
 * @throws Exception If failed.
 */
private void test(CacheConfiguration cfg, final boolean oneEntry) throws Exception {
    final IgniteCache<Integer, TestValue> cache = grid(0).createCache(cfg);

    try {
        init(cache);

        test(cache, null, null, null, oneEntry);

        if (cfg.getAtomicityMode() == TRANSACTIONAL) {
            TransactionConcurrency txConcurrency = concurrency();
            TransactionIsolation txIsolation = isolation();

            try (Transaction tx = grid(0).transactions().txStart(txConcurrency, txIsolation)) {
                initTx(cache);

                test(cache, txConcurrency, txIsolation, tx, oneEntry);

                tx.commit();
            }

            testConcurrentTx(cache, OPTIMISTIC, REPEATABLE_READ, oneEntry);
            testConcurrentTx(cache, OPTIMISTIC, READ_COMMITTED, oneEntry);

            testConcurrentTx(cache, PESSIMISTIC, REPEATABLE_READ, oneEntry);
            testConcurrentTx(cache, PESSIMISTIC, READ_COMMITTED, oneEntry);

            testConcurrentOptimisticTxGet(cache, REPEATABLE_READ);
            testConcurrentOptimisticTxGet(cache, READ_COMMITTED);
            testConcurrentOptimisticTxGet(cache, SERIALIZABLE);
        }
    }
    finally {
        cache.destroy();
    }
}
 
Example 6
Source File: WebSessionFilter.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Init cache.
 */
@SuppressWarnings("unchecked")
void initCache() {
    cache = webSesIgnite.cache(cacheName);
    binaryCache = webSesIgnite.cache(cacheName);

    if (cache == null)
        throw new IgniteException("Cache for web sessions is not started (is it configured?): " + cacheName);

    CacheConfiguration cacheCfg = cache.getConfiguration(CacheConfiguration.class);

    if (cacheCfg.getWriteSynchronizationMode() == FULL_ASYNC)
        throw new IgniteException("Cache for web sessions cannot be in FULL_ASYNC mode: " + cacheName);

    if (!cacheCfg.isEagerTtl())
        throw new IgniteException("Cache for web sessions cannot operate with lazy TTL. " +
            "Consider setting eagerTtl to true for cache: " + cacheName);

    if (cacheCfg.getCacheMode() == LOCAL)
        U.quietAndWarn(webSesIgnite.log(), "Using LOCAL cache for web sessions caching " +
            "(this is only OK in test mode): " + cacheName);

    if (cacheCfg.getCacheMode() == PARTITIONED && cacheCfg.getAtomicityMode() != ATOMIC)
        U.quietAndWarn(webSesIgnite.log(), "Using " + cacheCfg.getAtomicityMode() + " atomicity for web sessions " +
            "caching (switch to ATOMIC mode for better performance)");

    txEnabled = cacheCfg.getAtomicityMode() == TRANSACTIONAL;
}
 
Example 7
Source File: MvccUtils.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Throws atomicity modes compatibility validation exception.
 *
 * @param ccfg1 Config 1.
 * @param ccfg2 Config 2.
 */
public static void throwAtomicityModesMismatchException(CacheConfiguration ccfg1, CacheConfiguration ccfg2) {
    throw new IgniteException("Caches with transactional_snapshot atomicity mode cannot participate in the same" +
        " transaction with caches having another atomicity mode. [cacheName=" + ccfg1.getName() +
        ", cacheMode=" + ccfg1.getAtomicityMode() + ", anotherCacheName=" + ccfg2.getName() +
        " anotherCacheMode=" + ccfg2.getAtomicityMode() + ']');
}
 
Example 8
Source File: MvccProcessorImpl.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public void validateCacheConfiguration(CacheConfiguration ccfg) {
    if (ccfg.getAtomicityMode() == TRANSACTIONAL_SNAPSHOT) {
        if (!mvccSupported)
            throw new IgniteException("Cannot start MVCC transactional cache. " +
                "MVCC is unsupported by the cluster.");

        mvccEnabled = true;
    }
}
 
Example 9
Source File: GridCacheSqlDdlClusterReadOnlyModeTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** */
@Test
public void testAlterTableAllowed() {
    createTables();

    grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);

    for (CacheConfiguration cfg : cacheConfigurations()) {
        String cacheName = cfg.getName();

        if (cfg.getAtomicityMode() == CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT) {
            // Drop column doesn't support in MVCC mode.
            continue;
        }

        for (Ignite node : G.allGrids()) {
            String selectSql = "select city from " + tableName(cacheName);

            assertThrows(log, () -> execute(node, selectSql), IgniteSQLException.class, SQL_SELECT_ERROR_MSG);

            execute(node, "alter table " + tableName(cacheName) + " add column city varchar");

            assertNotNull(execute(node, selectSql));

            execute(node, "alter table " + tableName(cacheName) + " drop column city");

            assertThrows(log, () -> execute(node, selectSql), IgniteSQLException.class, SQL_SELECT_ERROR_MSG);
        }
    }
}
 
Example 10
Source File: IgniteSqlNotNullConstraintTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** */
private void executeWithAllTxCaches(final TestClosure clo) throws Exception {
    for (CacheConfiguration ccfg : cacheConfigurations()) {
        if (ccfg.getAtomicityMode() == CacheAtomicityMode.TRANSACTIONAL) {
            for (TransactionConcurrency con : TransactionConcurrency.values()) {
                for (TransactionIsolation iso : TransactionIsolation.values())
                    executeForCache(ccfg, clo, con, iso);
            }
        }
    }
}
 
Example 11
Source File: GridCacheContext.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @return {@code True} if transactional.
 */
public boolean transactional() {
    CacheConfiguration cfg = config();

    return cfg.getAtomicityMode() == TRANSACTIONAL || cfg.getAtomicityMode() == TRANSACTIONAL_SNAPSHOT;
}
 
Example 12
Source File: IgfsUtils.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Validates local IGFS configurations. Compares attributes only for IGFSes with same name.
 *
 * @param igniteCfg Ignite config.
 * @throws IgniteCheckedException If any of IGFS configurations is invalid.
 */
private static void validateLocalIgfsConfigurations(IgniteConfiguration igniteCfg)
    throws IgniteCheckedException {

    if (igniteCfg.getFileSystemConfiguration() == null || igniteCfg.getFileSystemConfiguration().length == 0)
        return;

    Collection<String> cfgNames = new HashSet<>();

    for (FileSystemConfiguration cfg : igniteCfg.getFileSystemConfiguration()) {
        String name = cfg.getName();

        if (name == null)
            throw new IgniteCheckedException("IGFS name cannot be null");

        if (cfgNames.contains(name))
            throw new IgniteCheckedException("Duplicate IGFS name found (check configuration and " +
                "assign unique name to each): " + name);

        CacheConfiguration ccfgData = cfg.getDataCacheConfiguration();

        CacheConfiguration ccfgMeta = cfg.getMetaCacheConfiguration();

        if (QueryUtils.isEnabled(ccfgData))
            throw new IgniteCheckedException("IGFS data cache cannot start with enabled query indexing.");

        if (QueryUtils.isEnabled(ccfgMeta))
            throw new IgniteCheckedException("IGFS metadata cache cannot start with enabled query indexing.");

        if (ccfgMeta.getAtomicityMode() != TRANSACTIONAL)
            throw new IgniteCheckedException("IGFS metadata cache should be transactional: " + cfg.getName());

        if (!(ccfgData.getAffinityMapper() instanceof IgfsGroupDataBlocksKeyMapper))
            throw new IgniteCheckedException(
                "Invalid IGFS data cache configuration (key affinity mapper class should be " +
                IgfsGroupDataBlocksKeyMapper.class.getSimpleName() + "): " + cfg);

        IgfsIpcEndpointConfiguration ipcCfg = cfg.getIpcEndpointConfiguration();

        if (ipcCfg != null) {
            final int tcpPort = ipcCfg.getPort();

            if (!(tcpPort >= MIN_TCP_PORT && tcpPort <= MAX_TCP_PORT))
                throw new IgniteCheckedException("IGFS endpoint TCP port is out of range [" + MIN_TCP_PORT +
                    ".." + MAX_TCP_PORT + "]: " + tcpPort);

            if (ipcCfg.getThreadCount() <= 0)
                throw new IgniteCheckedException("IGFS endpoint thread count must be positive: " +
                    ipcCfg.getThreadCount());
        }

        boolean secondary = cfg.getDefaultMode() == IgfsMode.PROXY;

        if (cfg.getPathModes() != null) {
            for (Map.Entry<String, IgfsMode> mode : cfg.getPathModes().entrySet()) {
                if (mode.getValue() == IgfsMode.PROXY)
                    secondary = true;
            }
        }

        if (secondary && cfg.getSecondaryFileSystem() == null) {
            // When working in any mode except of primary, secondary FS config must be provided.
            throw new IgniteCheckedException("Grid configuration parameter invalid: " +
                "secondaryFileSystem cannot be null when mode is not " + IgfsMode.PRIMARY);
        }

        cfgNames.add(name);
    }
}
 
Example 13
Source File: IgniteSqlNotNullConstraintTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** */
protected boolean isLocalAtomic() {
    CacheConfiguration cfg = cache.getConfiguration(CacheConfiguration.class);

    return cfg.getCacheMode() == CacheMode.LOCAL && cfg.getAtomicityMode() == CacheAtomicityMode.ATOMIC;
}
 
Example 14
Source File: ClusterCachesInfo.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param cfg Existing configuration.
 * @param startCfg Cache configuration to start.
 * @throws IgniteCheckedException If validation failed.
 */
private void validateCacheGroupConfiguration(CacheConfiguration cfg, CacheConfiguration startCfg)
    throws IgniteCheckedException {
    GridCacheAttributes attr1 = new GridCacheAttributes(cfg);
    GridCacheAttributes attr2 = new GridCacheAttributes(startCfg);

    CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "cacheMode", "Cache mode",
        cfg.getCacheMode(), startCfg.getCacheMode(), true);

    if (cfg.getAtomicityMode() == TRANSACTIONAL_SNAPSHOT || startCfg.getAtomicityMode() == TRANSACTIONAL_SNAPSHOT)
        CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "atomicityMode", "Atomicity mode",
            attr1.atomicityMode(), attr2.atomicityMode(), true);

    CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "affinity", "Affinity function",
        attr1.cacheAffinityClassName(), attr2.cacheAffinityClassName(), true);

    CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "affinityPartitionsCount",
        "Affinity partitions count", attr1.affinityPartitionsCount(), attr2.affinityPartitionsCount(), true);

    CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "nodeFilter", "Node filter",
        attr1.nodeFilterClassName(), attr2.nodeFilterClassName(), true);

    CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "dataRegionName", "Data region",
        cfg.getDataRegionName(), startCfg.getDataRegionName(), true);

    CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "topologyValidator", "Topology validator",
        attr1.topologyValidatorClassName(), attr2.topologyValidatorClassName(), true);

    CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "partitionLossPolicy", "Partition Loss Policy",
        cfg.getPartitionLossPolicy(), startCfg.getPartitionLossPolicy(), true);

    CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "rebalanceMode", "Rebalance mode",
        cfg.getRebalanceMode(), startCfg.getRebalanceMode(), true);

    CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "rebalanceDelay", "Rebalance delay",
        cfg.getRebalanceDelay(), startCfg.getRebalanceDelay(), false);

    CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "rebalanceOrder", "Rebalance order",
        cfg.getRebalanceOrder(), startCfg.getRebalanceOrder(), false);

    if (cfg.getCacheMode() == PARTITIONED) {
        CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "backups", "Backups",
            cfg.getBackups(), startCfg.getBackups(), true);
    }

    CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg, "encryptionEnabled", "Encrypted",
        cfg.isEncryptionEnabled(), startCfg.isEncryptionEnabled(), true);

    CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg,
        "diskPageCompression", "Disk page compression",
        cfg.getDiskPageCompression(), startCfg.getDiskPageCompression(), true);

    CU.validateCacheGroupsAttributesMismatch(log, cfg, startCfg,
        "diskPageCompressionLevel", "Disk page compression level",
        cfg.getDiskPageCompressionLevel(), startCfg.getDiskPageCompressionLevel(), true);
}
 
Example 15
Source File: VisorCacheConfiguration.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Create data transfer object for cache configuration properties.
 *
 * @param ignite Grid.
 * @param ccfg Cache configuration.
 * @param dynamicDeploymentId Dynamic deployment ID.
 */
public VisorCacheConfiguration(IgniteEx ignite, CacheConfiguration ccfg, IgniteUuid dynamicDeploymentId) {
    name = ccfg.getName();
    grpName = ccfg.getGroupName();
    this.dynamicDeploymentId = dynamicDeploymentId;
    mode = ccfg.getCacheMode();
    atomicityMode = ccfg.getAtomicityMode();
    eagerTtl = ccfg.isEagerTtl();
    writeSynchronizationMode = ccfg.getWriteSynchronizationMode();
    invalidate = ccfg.isInvalidate();
    maxConcurrentAsyncOps = ccfg.getMaxConcurrentAsyncOperations();
    interceptor = compactClass(ccfg.getInterceptor());
    dfltLockTimeout = ccfg.getDefaultLockTimeout();
    qryEntities = VisorQueryEntity.list(ccfg.getQueryEntities());
    jdbcTypes = VisorCacheJdbcType.list(ccfg.getCacheStoreFactory());
    statisticsEnabled = ccfg.isStatisticsEnabled();
    mgmtEnabled = ccfg.isManagementEnabled();
    ldrFactory = compactClass(ccfg.getCacheLoaderFactory());
    writerFactory = compactClass(ccfg.getCacheWriterFactory());
    expiryPlcFactory = compactClass(ccfg.getExpiryPolicyFactory());

    sys = ignite.context().cache().systemCache(ccfg.getName());
    storeKeepBinary = ccfg.isStoreKeepBinary();
    onheapCache = ccfg.isOnheapCacheEnabled();
    partLossPlc = ccfg.getPartitionLossPolicy();
    qryParallelism = ccfg.getQueryParallelism();

    affinityCfg = new VisorCacheAffinityConfiguration(ccfg);
    rebalanceCfg = new VisorCacheRebalanceConfiguration(ccfg);
    evictCfg = new VisorCacheEvictionConfiguration(ccfg);
    nearCfg = new VisorCacheNearConfiguration(ccfg);

    storeCfg = new VisorCacheStoreConfiguration(ignite, ccfg);

    qryCfg = new VisorQueryConfiguration(ccfg);

    cpOnRead = ccfg.isCopyOnRead();
    evictFilter = compactClass(ccfg.getEvictionFilter());
    lsnrConfigurations = compactIterable(ccfg.getCacheEntryListenerConfigurations());
    loadPrevVal = ccfg.isLoadPreviousValue();
    dataRegName = ccfg.getDataRegionName();
    sqlIdxMaxInlineSize = ccfg.getSqlIndexMaxInlineSize();
    nodeFilter = compactClass(ccfg.getNodeFilter());
    qryDetailMetricsSz = ccfg.getQueryDetailMetricsSize();
    readFromBackup = ccfg.isReadFromBackup();
    tmLookupClsName = ccfg.getTransactionManagerLookupClassName();
    topValidator = compactClass(ccfg.getTopologyValidator());

    diskPageCompression = ccfg.getDiskPageCompression();
    diskPageCompressionLevel = ccfg.getDiskPageCompressionLevel();
}
 
Example 16
Source File: CacheNearReaderUpdateTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
private void runTestGetUpdateMultithreaded(CacheConfiguration<Integer, Integer> ccfg) throws Exception {
    final List<Ignite> putNodes = new ArrayList<>();

    for (int i = 0; i < SRVS + CLIENTS - 1; i++)
        putNodes.add(ignite(i));

    final List<Ignite> getNodes = new ArrayList<>();

    getNodes.add(ignite(SRVS + CLIENTS - 1));
    getNodes.add(ignite(0));

    logCacheInfo(ccfg);

    runTestGetUpdateMultithreaded(ccfg, putNodes, getNodes, null, null);

    if (ccfg.getAtomicityMode() == TRANSACTIONAL) {
        runTestGetUpdateMultithreaded(ccfg, putNodes, getNodes, PESSIMISTIC, REPEATABLE_READ);

        runTestGetUpdateMultithreaded(ccfg, putNodes, getNodes, OPTIMISTIC, REPEATABLE_READ);

        runTestGetUpdateMultithreaded(ccfg, putNodes, getNodes, OPTIMISTIC, SERIALIZABLE);
    }
}
 
Example 17
Source File: CacheConfigurationEnricher.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * Skips deserialization for some fields.
 *
 * @param ccfg Cache configuration.
 * @param field Field.
 *
 * @return {@code true} if deserialization for given field should be skipped.
 */
private static boolean skipDeserialization(CacheConfiguration<?, ?> ccfg, Field field) {
    if ("storeFactory".equals(field.getName()) && ccfg.getAtomicityMode() == CacheAtomicityMode.ATOMIC)
        return true;

    return false;
}