Search in sources :

Example 6 with CacheWriteSynchronizationMode

use of org.apache.ignite.cache.CacheWriteSynchronizationMode in project ignite by apache.

the class TxPessimisticDeadlockDetectionTest method testDeadlocksReplicated.

/**
 * @throws Exception If failed.
 */
@Test
public void testDeadlocksReplicated() throws Exception {
    for (CacheWriteSynchronizationMode syncMode : CacheWriteSynchronizationMode.values()) {
        doTestDeadlocks(createCache(REPLICATED, syncMode, false), ORDINAL_START_KEY);
        doTestDeadlocks(createCache(REPLICATED, syncMode, false), CUSTOM_START_KEY);
    }
}
Also used : CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) Test(org.junit.Test)

Example 7 with CacheWriteSynchronizationMode

use of org.apache.ignite.cache.CacheWriteSynchronizationMode in project ignite by apache.

the class TxOptimisticDeadlockDetectionTest method testDeadlocksPartitionedNearTxOnPrimary.

/**
 * @throws Exception If failed.
 */
@Test
public void testDeadlocksPartitionedNearTxOnPrimary() throws Exception {
    for (CacheWriteSynchronizationMode syncMode : CacheWriteSynchronizationMode.values()) {
        doTestDeadlocksTxOnPrimary(createCache(PARTITIONED, syncMode, true), ORDINAL_START_KEY);
        doTestDeadlocksTxOnPrimary(createCache(PARTITIONED, syncMode, true), CUSTOM_START_KEY);
    }
}
Also used : CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) Test(org.junit.Test)

Example 8 with CacheWriteSynchronizationMode

use of org.apache.ignite.cache.CacheWriteSynchronizationMode in project ignite by apache.

the class GridSqlQueryParser method processExtraParam.

/**
 * @param name Param name.
 * @param val Param value.
 * @param res Table params to update.
 */
private static void processExtraParam(String name, String val, GridSqlCreateTable res) {
    assert !F.isEmpty(name);
    switch(name) {
        case PARAM_TEMPLATE:
            ensureNotEmpty(name, val);
            res.templateName(val);
            break;
        case PARAM_BACKUPS:
            ensureNotEmpty(name, val);
            int backups = parseIntParam(PARAM_BACKUPS, val);
            if (backups < 0) {
                throw new IgniteSQLException("\"" + PARAM_BACKUPS + "\" cannot be negative: " + backups, IgniteQueryErrorCode.PARSING);
            }
            res.backups(backups);
            break;
        case PARAM_PARALLELISM:
            ensureNotEmpty(name, val);
            int qryPar = parseIntParam(PARAM_PARALLELISM, val);
            if (qryPar <= 0)
                throw new IgniteSQLException("\"" + PARAM_PARALLELISM + "\" must be positive: " + qryPar, IgniteQueryErrorCode.PARSING);
            res.parallelism(qryPar);
            break;
        case PARAM_ATOMICITY:
            ensureNotEmpty(name, val);
            try {
                res.atomicityMode(CacheAtomicityMode.valueOf(val.toUpperCase()));
            } catch (IllegalArgumentException e) {
                String validVals = Arrays.stream(CacheAtomicityMode.values()).map(Enum::name).collect(Collectors.joining(", "));
                throw new IgniteSQLException("Invalid value of \"" + PARAM_ATOMICITY + "\" parameter " + "(should be either " + validVals + "): " + val, IgniteQueryErrorCode.PARSING, e);
            }
            break;
        case PARAM_CACHE_NAME:
            ensureNotEmpty(name, val);
            res.cacheName(val);
            break;
        case PARAM_KEY_TYPE:
            ensureNotEmpty(name, val);
            res.keyTypeName(val);
            break;
        case PARAM_VAL_TYPE:
            ensureNotEmpty(name, val);
            res.valueTypeName(val);
            break;
        case PARAM_CACHE_GROUP_OLD:
        case PARAM_CACHE_GROUP:
            ensureNotEmpty(name, val);
            res.cacheGroup(val);
            break;
        case PARAM_AFFINITY_KEY_OLD:
        case PARAM_AFFINITY_KEY:
            ensureNotEmpty(name, val);
            String affColName = null;
            // Either strip column name off its quotes, or uppercase it.
            if (val.startsWith("'")) {
                if (val.length() == 1 || !val.endsWith("'")) {
                    throw new IgniteSQLException("Affinity key column name does not have trailing quote: " + val, IgniteQueryErrorCode.PARSING);
                }
                val = val.substring(1, val.length() - 1);
                ensureNotEmpty(name, val);
                affColName = val;
            } else {
                for (String colName : res.columns().keySet()) {
                    if (val.equalsIgnoreCase(colName)) {
                        if (affColName != null) {
                            throw new IgniteSQLException("Ambiguous affinity column name, use single quotes " + "for case sensitivity: " + val, IgniteQueryErrorCode.PARSING);
                        }
                        affColName = colName;
                    }
                }
            }
            if (affColName == null || !res.columns().containsKey(affColName)) {
                throw new IgniteSQLException("Affinity key column with given name not found: " + val, IgniteQueryErrorCode.PARSING);
            }
            if (!res.primaryKeyColumns().contains(affColName)) {
                throw new IgniteSQLException("Affinity key column must be one of key columns: " + affColName, IgniteQueryErrorCode.PARSING);
            }
            res.affinityKey(affColName);
            break;
        case PARAM_WRITE_SYNC:
            ensureNotEmpty(name, val);
            CacheWriteSynchronizationMode writeSyncMode;
            if (CacheWriteSynchronizationMode.FULL_ASYNC.name().equalsIgnoreCase(val))
                writeSyncMode = CacheWriteSynchronizationMode.FULL_ASYNC;
            else if (CacheWriteSynchronizationMode.FULL_SYNC.name().equalsIgnoreCase(val))
                writeSyncMode = CacheWriteSynchronizationMode.FULL_SYNC;
            else if (CacheWriteSynchronizationMode.PRIMARY_SYNC.name().equalsIgnoreCase(val))
                writeSyncMode = CacheWriteSynchronizationMode.PRIMARY_SYNC;
            else {
                throw new IgniteSQLException("Invalid value of \"" + PARAM_WRITE_SYNC + "\" parameter " + "(should be FULL_SYNC, FULL_ASYNC, or PRIMARY_SYNC): " + val, IgniteQueryErrorCode.PARSING);
            }
            res.writeSynchronizationMode(writeSyncMode);
            break;
        case PARAM_WRAP_KEY:
            {
                res.wrapKey(F.isEmpty(val) || Boolean.parseBoolean(val));
                break;
            }
        case PARAM_WRAP_VALUE:
            res.wrapValue(F.isEmpty(val) || Boolean.parseBoolean(val));
            break;
        case PARAM_DATA_REGION:
            ensureNotEmpty(name, val);
            res.dataRegionName(val);
            break;
        case PARAM_ENCRYPTED:
            res.encrypted(F.isEmpty(val) || Boolean.parseBoolean(val));
            break;
        case PARAM_PK_INLINE_SIZE:
            ensureNotEmpty(name, val);
            int pkInlineSize = parseIntParam(PARAM_PK_INLINE_SIZE, val);
            res.primaryKeyInlineSize(pkInlineSize);
            break;
        case PARAM_AFFINITY_INDEX_INLINE_SIZE:
            ensureNotEmpty(name, val);
            int affInlineSize = parseIntParam(PARAM_AFFINITY_INDEX_INLINE_SIZE, val);
            res.affinityKeyInlineSize(affInlineSize);
            break;
        default:
            throw new IgniteSQLException("Unsupported parameter: " + name, IgniteQueryErrorCode.PARSING);
    }
}
Also used : CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) AlterTableAddConstraint(org.h2.command.ddl.AlterTableAddConstraint)

Example 9 with CacheWriteSynchronizationMode

use of org.apache.ignite.cache.CacheWriteSynchronizationMode in project ignite by apache.

the class GridDhtAtomicAbstractUpdateFuture method addNearWriteEntries.

/**
     * @param readers Entry readers.
     * @param entry Entry.
     * @param val Value.
     * @param entryProcessor Entry processor..
     * @param ttl TTL for near cache update (optional).
     * @param expireTime Expire time for near cache update (optional).
     */
final void addNearWriteEntries(Collection<UUID> readers, GridDhtCacheEntry entry, @Nullable CacheObject val, EntryProcessor<Object, Object, Object> entryProcessor, long ttl, long expireTime) {
    CacheWriteSynchronizationMode syncMode = updateReq.writeSynchronizationMode();
    addNearKey(entry.key(), readers);
    AffinityTopologyVersion topVer = updateReq.topologyVersion();
    for (UUID nodeId : readers) {
        GridDhtAtomicAbstractUpdateRequest updateReq = mappings.get(nodeId);
        if (updateReq == null) {
            ClusterNode node = cctx.discovery().node(nodeId);
            // Node left the grid.
            if (node == null)
                continue;
            updateReq = createRequest(node.id(), futId, writeVer, syncMode, topVer, ttl, expireTime, null);
            mappings.put(nodeId, updateReq);
        }
        updateReq.addNearWriteValue(entry.key(), val, entryProcessor, ttl, expireTime);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) UUID(java.util.UUID)

Example 10 with CacheWriteSynchronizationMode

use of org.apache.ignite.cache.CacheWriteSynchronizationMode in project ignite by apache.

the class GridDhtAtomicAbstractUpdateFuture method addWriteEntry.

/**
 * @param affAssignment Affinity assignment.
 * @param entry Entry to map.
 * @param val Value to write.
 * @param entryProcessor Entry processor.
 * @param ttl TTL (optional).
 * @param conflictExpireTime Conflict expire time (optional).
 * @param conflictVer Conflict version (optional).
 * @param addPrevVal If {@code true} sends previous value to backups.
 * @param prevVal Previous value.
 * @param updateCntr Partition update counter.
 * @param cacheOp Corresponding cache operation.
 */
@SuppressWarnings("ForLoopReplaceableByForEach")
final void addWriteEntry(AffinityAssignment affAssignment, GridDhtCacheEntry entry, @Nullable CacheObject val, EntryProcessor<Object, Object, Object> entryProcessor, long ttl, long conflictExpireTime, @Nullable GridCacheVersion conflictVer, boolean addPrevVal, @Nullable CacheObject prevVal, long updateCntr, GridCacheOperation cacheOp) {
    AffinityTopologyVersion topVer = updateReq.topologyVersion();
    List<ClusterNode> affNodes = affAssignment.get(entry.partition());
    // Client has seen that rebalancing finished, it is safe to use affinity mapping.
    List<ClusterNode> dhtNodes = updateReq.affinityMapping() ? affNodes : cctx.dht().topology().nodes(entry.partition(), affAssignment, affNodes);
    if (dhtNodes == null)
        dhtNodes = affNodes;
    if (log.isDebugEnabled())
        log.debug("Mapping entry to DHT nodes [nodes=" + U.nodeIds(dhtNodes) + ", entry=" + entry + ']');
    CacheWriteSynchronizationMode syncMode = updateReq.writeSynchronizationMode();
    addDhtKey(entry.key(), dhtNodes);
    for (int i = 0; i < dhtNodes.size(); i++) {
        ClusterNode node = dhtNodes.get(i);
        UUID nodeId = node.id();
        if (!nodeId.equals(cctx.localNodeId())) {
            GridDhtAtomicAbstractUpdateRequest updateReq = mappings.get(nodeId);
            if (updateReq == null) {
                updateReq = createRequest(node.id(), futId, writeVer, syncMode, topVer, ttl, conflictExpireTime, conflictVer);
                mappings.put(nodeId, updateReq);
            }
            updateReq.addWriteValue(entry.key(), val, entryProcessor, ttl, conflictExpireTime, conflictVer, addPrevVal, prevVal, updateCntr, cacheOp);
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) UUID(java.util.UUID)

Aggregations

CacheWriteSynchronizationMode (org.apache.ignite.cache.CacheWriteSynchronizationMode)20 Test (org.junit.Test)9 ClusterNode (org.apache.ignite.cluster.ClusterNode)5 CacheAtomicityMode (org.apache.ignite.cache.CacheAtomicityMode)4 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)4 UUID (java.util.UUID)3 IgniteCache (org.apache.ignite.IgniteCache)3 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)3 HashSet (java.util.HashSet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 CacheException (javax.cache.CacheException)1 Factory (javax.cache.configuration.Factory)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)1 IgniteException (org.apache.ignite.IgniteException)1 CacheMode (org.apache.ignite.cache.CacheMode)1 FifoEvictionPolicyFactory (org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicyFactory)1 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)1 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)1