Search in sources :

Example 21 with SchemaOperationException

use of org.apache.ignite.internal.processors.query.schema.SchemaOperationException in project ignite by apache.

the class GridQueryProcessor method onSchemaProposeDiscovery.

/**
 * Process schema propose message from discovery thread.
 *
 * @param msg Message.
 * @return {@code True} if exchange should be triggered.
 */
private boolean onSchemaProposeDiscovery(SchemaProposeDiscoveryMessage msg) {
    SchemaAbstractOperation op = msg.operation();
    UUID opId = op.id();
    String cacheName = op.cacheName();
    if (!msg.initialized()) {
        // Ensure cache exists on coordinator node.
        DynamicCacheDescriptor cacheDesc = ctx.cache().cacheDescriptor(cacheName);
        if (cacheDesc == null) {
            if (log.isDebugEnabled())
                log.debug("Received schema propose discovery message, but cache doesn't exist " + "(will report error) [opId=" + opId + ", msg=" + msg + ']');
            msg.onError(new SchemaOperationException(SchemaOperationException.CODE_CACHE_NOT_FOUND, cacheName));
        } else {
            CacheConfiguration ccfg = cacheDesc.cacheConfiguration();
            if (ccfg.getCacheMode() == CacheMode.LOCAL) {
                // Distributed operation is not allowed on LOCAL caches.
                if (log.isDebugEnabled())
                    log.debug("Received schema propose discovery message, but cache is LOCAL " + "(will report error) [opId=" + opId + ", msg=" + msg + ']');
                msg.onError(new SchemaOperationException("Schema changes are not supported for LOCAL cache."));
            } else if (failOnStaticCacheSchemaChanges(cacheDesc)) {
                // Do not allow any schema changes when keep static cache configuration flag is set.
                if (log.isDebugEnabled())
                    log.debug("Received schema propose discovery message, but cache is statically configured " + "and " + IgniteSystemProperties.IGNITE_KEEP_STATIC_CACHE_CONFIGURATION + " flag is set (will report error) [opId=" + opId + ", msg=" + msg + ']');
                msg.onError(new SchemaOperationException("Schema changes are not supported for statically " + "configured cache when " + IgniteSystemProperties.IGNITE_KEEP_STATIC_CACHE_CONFIGURATION + " flag is set."));
            } else {
                // Preserve deployment ID so that we can distinguish between different caches with the same name.
                if (msg.deploymentId() == null)
                    msg.deploymentId(cacheDesc.deploymentId());
                assert F.eq(cacheDesc.deploymentId(), msg.deploymentId());
                if (msg.operation() instanceof SchemaAlterTableAddColumnOperation) {
                    SchemaAlterTableAddColumnOperation alterOp = (SchemaAlterTableAddColumnOperation) msg.operation();
                    try {
                        for (QueryField field : alterOp.columns()) {
                            if (!field.isNullable())
                                QueryUtils.checkNotNullAllowed(ccfg);
                        }
                    } catch (IgniteSQLException ex) {
                        msg.onError(new SchemaOperationException("Received schema propose discovery message, but " + "cache doesn't applicable for this modification", ex));
                    }
                }
            }
        }
    }
    // Complete client future and exit immediately in case of error.
    if (msg.hasError()) {
        SchemaOperationClientFuture cliFut = schemaCliFuts.remove(opId);
        if (cliFut != null)
            cliFut.onDone(msg.error());
        return false;
    }
    return onSchemaProposeDiscovery0(msg);
}
Also used : SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) SchemaAbstractOperation(org.apache.ignite.internal.processors.query.schema.operation.SchemaAbstractOperation) SchemaAlterTableAddColumnOperation(org.apache.ignite.internal.processors.query.schema.operation.SchemaAlterTableAddColumnOperation) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) SchemaOperationClientFuture(org.apache.ignite.internal.processors.query.schema.SchemaOperationClientFuture) UUID(java.util.UUID) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 22 with SchemaOperationException

use of org.apache.ignite.internal.processors.query.schema.SchemaOperationException in project ignite by apache.

the class QueryUtils method validateDropColumn.

/**
 * Checks if given column can be removed from the table using its {@link GridQueryTypeDescriptor}.
 *
 * @param type Type descriptor.
 * @param colName Name of the column.
 * @return {@code null} if it's OK to remove the column and exception otherwise.
 */
public static SchemaOperationException validateDropColumn(GridQueryTypeDescriptor type, String colName) {
    if (F.eq(colName, type.keyFieldName()) || KEY_FIELD_NAME.equalsIgnoreCase(colName))
        return new SchemaOperationException("Cannot drop column \"" + colName + "\" because it represents an entire cache key");
    if (F.eq(colName, type.valueFieldName()) || VAL_FIELD_NAME.equalsIgnoreCase(colName))
        return new SchemaOperationException("Cannot drop column \"" + colName + "\" because it represents an entire cache value");
    GridQueryProperty prop = type.property(colName);
    if (prop != null && prop.key())
        return new SchemaOperationException("Cannot drop column \"" + colName + "\" because it is a part of a cache key");
    Collection<GridQueryIndexDescriptor> indexes = type.indexes().values();
    for (GridQueryIndexDescriptor idxDesc : indexes) {
        if (idxDesc.fields().contains(colName))
            return new SchemaOperationException("Cannot drop column \"" + colName + "\" because an index exists (\"" + idxDesc.name() + "\") that uses the column.");
    }
    return null;
}
Also used : SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException)

Example 23 with SchemaOperationException

use of org.apache.ignite.internal.processors.query.schema.SchemaOperationException in project ignite by apache.

the class QueryUtils method checkQueryEntityConflicts.

/**
 * Check given {@link CacheConfiguration} for conflicts in table and index names from any query entities
 *     found in collection of {@link DynamicCacheDescriptor}s and belonging to the same schema.
 *
 * @param ccfg New cache configuration.
 * @param descs Cache descriptors.
 * @return Exception message describing found conflict or {@code null} if none found.
 */
public static SchemaOperationException checkQueryEntityConflicts(CacheConfiguration<?, ?> ccfg, Collection<DynamicCacheDescriptor> descs) {
    String schema = QueryUtils.normalizeSchemaName(ccfg.getName(), ccfg.getSqlSchema());
    Set<String> idxNames = new HashSet<>();
    Set<String> tblNames = new HashSet<>();
    for (DynamicCacheDescriptor desc : descs) {
        if (F.eq(ccfg.getName(), desc.cacheName()))
            continue;
        String descSchema = QueryUtils.normalizeSchemaName(desc.cacheName(), desc.cacheConfiguration().getSqlSchema());
        if (!F.eq(schema, descSchema))
            continue;
        for (QueryEntity e : desc.schema().entities()) {
            tblNames.add(e.getTableName());
            for (QueryIndex idx : e.getIndexes()) idxNames.add(idx.getName());
        }
    }
    for (QueryEntity e : ccfg.getQueryEntities()) {
        if (!tblNames.add(e.getTableName()))
            return new SchemaOperationException(SchemaOperationException.CODE_TABLE_EXISTS, e.getTableName());
        for (QueryIndex idx : e.getIndexes()) if (!idxNames.add(idx.getName()))
            return new SchemaOperationException(SchemaOperationException.CODE_INDEX_EXISTS, idx.getName());
    }
    return null;
}
Also used : SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity) HashSet(java.util.HashSet)

Example 24 with SchemaOperationException

use of org.apache.ignite.internal.processors.query.schema.SchemaOperationException in project ignite by apache.

the class GridQueryProcessor method startIndexOperationDistributed.

/**
 * Start distributed index change operation.
 *
 * @param op Operation.
 * @return Future.
 */
private IgniteInternalFuture<?> startIndexOperationDistributed(SchemaAbstractOperation op) {
    SchemaOperationClientFuture fut = new SchemaOperationClientFuture(op.id());
    SchemaOperationClientFuture oldFut = schemaCliFuts.put(op.id(), fut);
    assert oldFut == null;
    try {
        ctx.discovery().sendCustomEvent(new SchemaProposeDiscoveryMessage(op));
        if (log.isDebugEnabled())
            log.debug("Sent schema propose discovery message [opId=" + op.id() + ", op=" + op + ']');
        boolean disconnected0;
        synchronized (stateMux) {
            disconnected0 = disconnected;
        }
        if (disconnected0) {
            fut.onDone(new SchemaOperationException("Client node is disconnected (operation result is unknown)."));
            schemaCliFuts.remove(op.id());
        }
    } catch (Exception e) {
        if (e instanceof SchemaOperationException)
            fut.onDone(e);
        else {
            fut.onDone(new SchemaOperationException("Failed to start schema change operation due to " + "unexpected exception [opId=" + op.id() + ", op=" + op + ']', e));
        }
        schemaCliFuts.remove(op.id());
    }
    return fut;
}
Also used : SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) SchemaProposeDiscoveryMessage(org.apache.ignite.internal.processors.query.schema.message.SchemaProposeDiscoveryMessage) SchemaOperationClientFuture(org.apache.ignite.internal.processors.query.schema.SchemaOperationClientFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) IgniteException(org.apache.ignite.IgniteException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) CacheException(javax.cache.CacheException) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException)

Example 25 with SchemaOperationException

use of org.apache.ignite.internal.processors.query.schema.SchemaOperationException in project ignite by apache.

the class GridQueryProcessor method dynamicTableDrop.

/**
 * Drop table by destroying its cache if it's an 1:1 per cache table.
 *
 * @param cacheName Cache name.
 * @param tblName Table name.
 * @param ifExists Quietly ignore this command if table does not exist.
 * @throws SchemaOperationException if {@code ifExists} is {@code false} and cache was not found.
 */
public void dynamicTableDrop(String cacheName, String tblName, boolean ifExists) throws SchemaOperationException {
    GridCacheContext currCache = this.curCache.get();
    if (currCache != null && F.eq(currCache.name(), cacheName))
        throw new IgniteSQLException("DROP TABLE cannot be called from the same cache that holds " + "the table being dropped [cacheName-" + cacheName + ", tblName=" + tblName + ']', IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
    boolean res = ctx.grid().destroyCache0(cacheName, true);
    if (!res && !ifExists)
        throw new SchemaOperationException(SchemaOperationException.CODE_TABLE_NOT_FOUND, tblName);
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException)

Aggregations

SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)32 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)17 QueryIndex (org.apache.ignite.cache.QueryIndex)16 IgniteException (org.apache.ignite.IgniteException)12 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 LinkedHashMap (java.util.LinkedHashMap)8 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)8 Test (org.junit.Test)8 CacheException (javax.cache.CacheException)7 Ignite (org.apache.ignite.Ignite)7 IgniteClientReconnectAbstractTest (org.apache.ignite.internal.IgniteClientReconnectAbstractTest)7 Map (java.util.Map)6 QueryEntity (org.apache.ignite.cache.QueryEntity)6 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)6 GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)6 HashMap (java.util.HashMap)5 List (java.util.List)5 GridQueryProperty (org.apache.ignite.internal.processors.query.GridQueryProperty)5 GridQueryTypeDescriptor (org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor)5