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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations