Search in sources :

Example 6 with GridKernalContext

use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.

the class QueryUtils method typeForQueryEntity.

/**
     * Create type candidate for query entity.
     *
     * @param cacheName Cache name.
     * @param cctx Cache context.
     * @param qryEntity Query entity.
     * @param mustDeserializeClss Classes which must be deserialized.
     * @param escape Escape flag.
     * @return Type candidate.
     * @throws IgniteCheckedException If failed.
     */
public static QueryTypeCandidate typeForQueryEntity(String cacheName, GridCacheContext cctx, QueryEntity qryEntity, List<Class<?>> mustDeserializeClss, boolean escape) throws IgniteCheckedException {
    GridKernalContext ctx = cctx.kernalContext();
    CacheConfiguration<?, ?> ccfg = cctx.config();
    boolean binaryEnabled = ctx.cacheObjects().isBinaryEnabled(ccfg);
    CacheObjectContext coCtx = binaryEnabled ? ctx.cacheObjects().contextForCache(ccfg) : null;
    QueryTypeDescriptorImpl desc = new QueryTypeDescriptorImpl(cacheName);
    desc.aliases(qryEntity.getAliases());
    // Key and value classes still can be available if they are primitive or JDK part.
    // We need that to set correct types for _key and _val columns.
    Class<?> keyCls = U.classForName(qryEntity.findKeyType(), null);
    Class<?> valCls = U.classForName(qryEntity.findValueType(), null);
    // If local node has the classes and they are externalizable, we must use reflection properties.
    boolean keyMustDeserialize = mustDeserializeBinary(ctx, keyCls);
    boolean valMustDeserialize = mustDeserializeBinary(ctx, valCls);
    boolean keyOrValMustDeserialize = keyMustDeserialize || valMustDeserialize;
    if (keyCls == null)
        keyCls = Object.class;
    String simpleValType = ((valCls == null) ? typeName(qryEntity.findValueType()) : typeName(valCls));
    desc.name(simpleValType);
    desc.tableName(qryEntity.getTableName());
    if (binaryEnabled && !keyOrValMustDeserialize) {
        // Safe to check null.
        if (SQL_TYPES.contains(valCls))
            desc.valueClass(valCls);
        else
            desc.valueClass(Object.class);
        if (SQL_TYPES.contains(keyCls))
            desc.keyClass(keyCls);
        else
            desc.keyClass(Object.class);
    } else {
        if (valCls == null)
            throw new IgniteCheckedException("Failed to find value class in the node classpath " + "(use default marshaller to enable binary objects) : " + qryEntity.findValueType());
        desc.valueClass(valCls);
        desc.keyClass(keyCls);
    }
    desc.keyTypeName(qryEntity.findKeyType());
    desc.valueTypeName(qryEntity.findValueType());
    desc.keyFieldName(qryEntity.getKeyFieldName());
    desc.valueFieldName(qryEntity.getValueFieldName());
    if (binaryEnabled && keyOrValMustDeserialize) {
        if (keyMustDeserialize)
            mustDeserializeClss.add(keyCls);
        if (valMustDeserialize)
            mustDeserializeClss.add(valCls);
    }
    QueryTypeIdKey typeId;
    QueryTypeIdKey altTypeId = null;
    if (valCls == null || (binaryEnabled && !keyOrValMustDeserialize)) {
        processBinaryMeta(ctx, qryEntity, desc);
        typeId = new QueryTypeIdKey(cacheName, ctx.cacheObjects().typeId(qryEntity.findValueType()));
        if (valCls != null)
            altTypeId = new QueryTypeIdKey(cacheName, valCls);
        if (!cctx.customAffinityMapper() && qryEntity.findKeyType() != null) {
            // Need to setup affinity key for distributed joins.
            String affField = ctx.cacheObjects().affinityField(qryEntity.findKeyType());
            if (affField != null) {
                if (!escape)
                    affField = normalizeObjectName(affField, false);
                desc.affinityKey(affField);
            }
        }
    } else {
        processClassMeta(qryEntity, desc, coCtx);
        AffinityKeyMapper keyMapper = cctx.config().getAffinityMapper();
        if (keyMapper instanceof GridCacheDefaultAffinityKeyMapper) {
            String affField = ((GridCacheDefaultAffinityKeyMapper) keyMapper).affinityKeyPropertyName(desc.keyClass());
            if (affField != null) {
                if (!escape)
                    affField = normalizeObjectName(affField, false);
                desc.affinityKey(affField);
            }
        }
        typeId = new QueryTypeIdKey(cacheName, valCls);
        altTypeId = new QueryTypeIdKey(cacheName, ctx.cacheObjects().typeId(qryEntity.findValueType()));
    }
    return new QueryTypeCandidate(typeId, altTypeId, desc);
}
Also used : GridKernalContext(org.apache.ignite.internal.GridKernalContext) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) GridCacheDefaultAffinityKeyMapper(org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper) GridCacheDefaultAffinityKeyMapper(org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper) AffinityKeyMapper(org.apache.ignite.cache.affinity.AffinityKeyMapper) IgniteCheckedException(org.apache.ignite.IgniteCheckedException)

Example 7 with GridKernalContext

use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.

the class GridManagerMxBeanIllegalArgumentHandleTest method testIllegalStateIsCatch.

/** Creates minimal disco manager mock, checks illegal state is not propagated */
public void testIllegalStateIsCatch() {
    final IgniteConfiguration cfg = new IgniteConfiguration();
    cfg.setDiscoverySpi(new TcpDiscoverySpi());
    final IgniteLogger log = Mockito.mock(IgniteLogger.class);
    final GridKernalContext ctx = Mockito.mock(GridKernalContext.class);
    when(ctx.config()).thenReturn(cfg);
    when(ctx.log(Mockito.anyString())).thenReturn(log);
    when(ctx.log(Mockito.any(Class.class))).thenReturn(log);
    final GridDiscoveryManager mgr = new GridDiscoveryManager(ctx);
    final long nHeapMax = mgr.metrics().getNonHeapMemoryMaximum();
    if (correctSetupOfTestPerformed)
        assertEquals(0, nHeapMax);
    final long heapMax = mgr.metrics().getHeapMemoryMaximum();
    if (correctSetupOfTestPerformed)
        assertEquals(0, heapMax);
}
Also used : GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridKernalContext(org.apache.ignite.internal.GridKernalContext) IgniteLogger(org.apache.ignite.IgniteLogger) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 8 with GridKernalContext

use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.

the class GridQueryParsingTest method connection.

/**
     *
     */
private JdbcConnection connection() throws Exception {
    GridKernalContext ctx = ((IgniteEx) ignite).context();
    GridQueryProcessor qryProcessor = ctx.query();
    IgniteH2Indexing idx = U.field(qryProcessor, "idx");
    String schemaName = idx.schema(DEFAULT_CACHE_NAME);
    return (JdbcConnection) idx.connectionForSchema(schemaName);
}
Also used : GridKernalContext(org.apache.ignite.internal.GridKernalContext) IgniteEx(org.apache.ignite.internal.IgniteEx) GridQueryProcessor(org.apache.ignite.internal.processors.query.GridQueryProcessor) JdbcConnection(org.h2.jdbc.JdbcConnection) IgniteH2Indexing(org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing)

Example 9 with GridKernalContext

use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.

the class GridH2IndexBase method toRow.

/**
     * @param msg Message.
     * @return Row.
     */
private Row toRow(GridH2RowMessage msg) {
    if (msg == null)
        return null;
    GridKernalContext ctx = kernalContext();
    List<GridH2ValueMessage> vals = msg.values();
    assert !F.isEmpty(vals) : vals;
    Value[] vals0 = new Value[vals.size()];
    for (int i = 0; i < vals0.length; i++) {
        try {
            vals0[i] = vals.get(i).value(ctx);
        } catch (IgniteCheckedException e) {
            throw new CacheException(e);
        }
    }
    return database.createRow(vals0, MEMORY_CALCULATE);
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheException(javax.cache.CacheException) GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridH2ValueMessage(org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2ValueMessage) Value(org.h2.value.Value)

Example 10 with GridKernalContext

use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.

the class GridH2IndexBase method broadcastSegments.

/**
     * @param qctx Query context.
     * @param cctx Cache context.
     * @param isLocalQry Local query flag.
     * @return Collection of nodes for broadcasting.
     */
private List<SegmentKey> broadcastSegments(GridH2QueryContext qctx, GridCacheContext<?, ?> cctx, boolean isLocalQry) {
    Map<UUID, int[]> partMap = qctx.partitionsMap();
    List<ClusterNode> nodes;
    if (isLocalQry) {
        if (partMap != null && !partMap.containsKey(cctx.localNodeId()))
            // Prevent remote index call for local queries.
            return Collections.<SegmentKey>emptyList();
        nodes = Collections.singletonList(cctx.localNode());
    } else {
        if (partMap == null)
            nodes = new ArrayList<>(CU.affinityNodes(cctx, qctx.topologyVersion()));
        else {
            nodes = new ArrayList<>(partMap.size());
            GridKernalContext ctx = kernalContext();
            for (UUID nodeId : partMap.keySet()) {
                ClusterNode node = ctx.discovery().node(nodeId);
                if (node == null)
                    throw new GridH2RetryException("Failed to find node.");
                nodes.add(node);
            }
        }
        if (F.isEmpty(nodes))
            throw new GridH2RetryException("Failed to collect affinity nodes.");
    }
    int segmentsCount = segmentsCount();
    List<SegmentKey> res = new ArrayList<>(nodes.size() * segmentsCount);
    for (ClusterNode node : nodes) {
        for (int seg = 0; seg < segmentsCount; seg++) res.add(new SegmentKey(node, seg));
    }
    return res;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridKernalContext(org.apache.ignite.internal.GridKernalContext)

Aggregations

GridKernalContext (org.apache.ignite.internal.GridKernalContext)19 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 IgniteKernal (org.apache.ignite.internal.IgniteKernal)6 Ignite (org.apache.ignite.Ignite)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)3 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)3 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 CacheException (javax.cache.CacheException)2 IgniteLogger (org.apache.ignite.IgniteLogger)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 CacheObjectContext (org.apache.ignite.internal.processors.cache.CacheObjectContext)2 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)2 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)2 GridH2ValueMessage (org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2ValueMessage)2 Value (org.h2.value.Value)2 Nullable (org.jetbrains.annotations.Nullable)2 InvalidObjectException (java.io.InvalidObjectException)1 ArrayList (java.util.ArrayList)1