use of org.apache.ignite.cache.QueryEntity in project ignite by apache.
the class CacheConfiguration method setIndexedTypes.
/**
* Array of key and value type pairs to be indexed (thus array length must be always even).
* It means each even (0,2,4...) class in the array will be considered as key type for cache entry,
* each odd (1,3,5...) class will be considered as value type for cache entry.
* <p>
* The same key class can occur multiple times for different value classes, but each value class must be unique
* because SQL table will be named as value class simple name.
* <p>
* To expose fields of these types onto SQL level and to index them you have to use annotations
* from package {@link org.apache.ignite.cache.query.annotations}.
*
* @param indexedTypes Key and value type pairs.
* @return {@code this} for chaining.
*/
public CacheConfiguration<K, V> setIndexedTypes(Class<?>... indexedTypes) {
if (F.isEmpty(indexedTypes))
return this;
int len = indexedTypes.length;
if (len == 0)
return this;
A.ensure((len & 1) == 0, "Number of indexed types is expected to be even. Refer to method javadoc for details.");
if (this.indexedTypes != null)
throw new CacheException("Indexed types can be set only once.");
Class<?>[] newIndexedTypes = new Class<?>[len];
for (int i = 0; i < len; i++) {
if (indexedTypes[i] == null)
throw new NullPointerException("Indexed types array contains null at index: " + i);
newIndexedTypes[i] = U.box(indexedTypes[i]);
}
if (qryEntities == null)
qryEntities = new ArrayList<>();
for (int i = 0; i < len; i += 2) {
Class<?> keyCls = newIndexedTypes[i];
Class<?> valCls = newIndexedTypes[i + 1];
QueryEntity newEntity = new QueryEntity(keyCls, valCls);
boolean dup = false;
for (QueryEntity entity : qryEntities) {
if (F.eq(entity.findValueType(), newEntity.findValueType())) {
dup = true;
break;
}
}
if (!dup)
qryEntities.add(newEntity);
// Set key configuration if needed.
String affFieldName = BinaryContext.affinityFieldName(keyCls);
if (affFieldName != null) {
CacheKeyConfiguration newKeyCfg = new CacheKeyConfiguration(newEntity.getKeyType(), affFieldName);
if (F.isEmpty(keyCfg))
keyCfg = new CacheKeyConfiguration[] { newKeyCfg };
else {
boolean keyCfgDup = false;
for (CacheKeyConfiguration oldKeyCfg : keyCfg) {
if (F.eq(oldKeyCfg.getTypeName(), newKeyCfg.getTypeName())) {
keyCfgDup = true;
break;
}
}
if (!keyCfgDup) {
CacheKeyConfiguration[] keyCfg0 = new CacheKeyConfiguration[keyCfg.length + 1];
System.arraycopy(keyCfg, 0, keyCfg0, 0, keyCfg.length);
keyCfg0[keyCfg0.length - 1] = newKeyCfg;
keyCfg = keyCfg0;
}
}
}
}
return this;
}
use of org.apache.ignite.cache.QueryEntity in project ignite by apache.
the class ValidationOnNodeJoinUtils method validateNode.
/**
* Checks a joining node to configuration consistency.
*
* @param node Node.
* @param discoData Disco data.
* @param marsh Marsh.
* @param ctx Context.
* @param cacheDescProvider Cache descriptor provider.
*/
@Nullable
static IgniteNodeValidationResult validateNode(ClusterNode node, DiscoveryDataBag.JoiningNodeDiscoveryData discoData, Marshaller marsh, GridKernalContext ctx, Function<String, DynamicCacheDescriptor> cacheDescProvider) {
if (discoData.hasJoiningNodeData() && discoData.joiningNodeData() instanceof CacheJoinNodeDiscoveryData) {
CacheJoinNodeDiscoveryData nodeData = (CacheJoinNodeDiscoveryData) discoData.joiningNodeData();
boolean isGridActive = ctx.state().clusterState().active();
StringBuilder errorMsg = new StringBuilder();
if (!node.isClient()) {
validateRmtRegions(node, ctx).forEach(error -> {
if (errorMsg.length() > 0)
errorMsg.append("\n");
errorMsg.append(error);
});
}
SecurityContext secCtx = null;
if (ctx.security().enabled()) {
try {
secCtx = nodeSecurityContext(marsh, U.resolveClassLoader(ctx.config()), node);
} catch (SecurityException se) {
errorMsg.append(se.getMessage());
}
}
for (CacheJoinNodeDiscoveryData.CacheInfo cacheInfo : nodeData.caches().values()) {
if (secCtx != null && cacheInfo.cacheType() == CacheType.USER) {
try (OperationSecurityContext s = ctx.security().withContext(secCtx)) {
GridCacheProcessor.authorizeCacheCreate(ctx.security(), cacheInfo.cacheData().config());
} catch (SecurityException ex) {
if (errorMsg.length() > 0)
errorMsg.append("\n");
errorMsg.append(ex.getMessage());
}
}
DynamicCacheDescriptor locDesc = cacheDescProvider.apply(cacheInfo.cacheData().config().getName());
if (locDesc == null)
continue;
String joinedSchema = cacheInfo.cacheData().config().getSqlSchema();
Collection<QueryEntity> joinedQryEntities = cacheInfo.cacheData().queryEntities();
String locSchema = locDesc.cacheConfiguration().getSqlSchema();
// QuerySchema is empty and schema name is null (when indexing enabled dynamically).
if (!F.eq(joinedSchema, locSchema) && (locSchema != null || !locDesc.schema().isEmpty()) && (joinedSchema != null || !F.isEmpty(joinedQryEntities))) {
errorMsg.append(String.format(SQL_SCHEMA_CONFLICTS_MESSAGE, locDesc.cacheName(), joinedSchema, locSchema));
}
QuerySchemaPatch schemaPatch = locDesc.makeSchemaPatch(joinedQryEntities);
if (schemaPatch.hasConflicts() || (isGridActive && !schemaPatch.isEmpty())) {
if (errorMsg.length() > 0)
errorMsg.append("\n");
if (schemaPatch.hasConflicts()) {
errorMsg.append(String.format(MERGE_OF_CONFIG_CONFLICTS_MESSAGE, locDesc.cacheName(), schemaPatch.getConflictsMessage()));
} else
errorMsg.append(String.format(MERGE_OF_CONFIG_REQUIRED_MESSAGE, locDesc.cacheName()));
}
// This check must be done on join, otherwise group encryption key will be
// written to metastore regardless of validation check and could trigger WAL write failures.
boolean locEnc = locDesc.cacheConfiguration().isEncryptionEnabled();
boolean rmtEnc = cacheInfo.cacheData().config().isEncryptionEnabled();
if (locEnc != rmtEnc) {
if (errorMsg.length() > 0)
errorMsg.append("\n");
// Message will be printed on remote node, so need to swap local and remote.
errorMsg.append(String.format(ENCRYPT_MISMATCH_MESSAGE, locDesc.cacheName(), rmtEnc, locEnc));
}
}
if (errorMsg.length() > 0) {
String msg = errorMsg.toString();
return new IgniteNodeValidationResult(node.id(), msg);
}
}
return null;
}
use of org.apache.ignite.cache.QueryEntity in project ignite by apache.
the class WarningOnBigQueryResultsBaseTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName).setCacheConfiguration(new CacheConfiguration().setName(CACHE0).setSqlSchema("TEST0").setQueryEntities(Collections.singleton(new QueryEntity(Long.class, Long.class).setTableName("test0").addQueryField("id", Long.class.getName(), null).addQueryField("val", Long.class.getName(), null).setKeyFieldName("id").setValueFieldName("val"))).setAffinity(new RendezvousAffinityFunction(false, 10)).setNodeFilter((IgnitePredicate<ClusterNode>) node -> node.attribute(TEST0_ATTR) != null && (boolean) node.attribute(TEST0_ATTR)), new CacheConfiguration().setName(CACHE1).setSqlSchema("TEST1").setQueryEntities(Collections.singleton(new QueryEntity(Long.class, Long.class).setTableName("test1").addQueryField("id", Long.class.getName(), null).addQueryField("val", Long.class.getName(), null).setKeyFieldName("id").setValueFieldName("val"))).setAffinity(new RendezvousAffinityFunction(false, 10)).setNodeFilter((IgnitePredicate<ClusterNode>) node -> node.attribute(TEST1_ATTR) != null && (boolean) node.attribute(TEST1_ATTR)));
if (igniteInstanceName.startsWith("cli")) {
cfg.setClientMode(true).setClientConnectorConfiguration(new ClientConnectorConfiguration().setPort(CLI_PORT));
} else {
cfg.setUserAttributes(Collections.singletonMap(getTestIgniteInstanceIndex(igniteInstanceName) < 2 ? TEST0_ATTR : TEST1_ATTR, true));
}
ListeningTestLogger testLog = new ListeningTestLogger(false, log);
BigResultsLogListener lst = new BigResultsLogListener();
testLog.registerListener(lst);
logListeners.put(igniteInstanceName, lst);
cfg.setGridLogger(new ListeningTestLogger(false, testLog));
return cfg;
}
use of org.apache.ignite.cache.QueryEntity in project ignite by apache.
the class GridCachePartitionedTxMultiNodeSelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
// Default cache configuration.
CacheConfiguration ccfg = defaultCacheConfiguration();
ccfg.setCacheMode(PARTITIONED);
ccfg.setWriteSynchronizationMode(FULL_SYNC);
ccfg.setBackups(backups);
ccfg.setQueryEntities(Collections.singleton(new QueryEntity().setKeyType(String.class.getCanonicalName()).setValueType(Integer.class.getCanonicalName())));
cfg.setCacheConfiguration(ccfg);
return cfg;
}
use of org.apache.ignite.cache.QueryEntity in project ignite by apache.
the class IgnitePdsCacheRebalancingAbstractTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(gridName);
cfg.setConsistentId(gridName);
cfg.setRebalanceThreadPoolSize(2);
CacheConfiguration ccfg1 = cacheConfiguration(CACHE).setPartitionLossPolicy(PartitionLossPolicy.READ_WRITE_SAFE).setBackups(2).setRebalanceMode(CacheRebalanceMode.ASYNC).setIndexedTypes(Integer.class, Integer.class).setAffinity(new RendezvousAffinityFunction(false, 32)).setRebalanceBatchesPrefetchCount(2).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
CacheConfiguration ccfg2 = cacheConfiguration(INDEXED_CACHE).setBackups(2).setAffinity(new RendezvousAffinityFunction(false, 32)).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
CacheConfiguration ccfg3 = cacheConfiguration(INDEXED_CACHE_IN_MEMORY).setBackups(2).setDataRegionName(IN_MEMORY_REGION);
QueryEntity qryEntity = new QueryEntity(Integer.class.getName(), TestValue.class.getName());
LinkedHashMap<String, String> fields = new LinkedHashMap<>();
fields.put("v1", Integer.class.getName());
fields.put("v2", Integer.class.getName());
qryEntity.setFields(fields);
QueryIndex qryIdx = new QueryIndex("v1", true);
qryEntity.setIndexes(Collections.singleton(qryIdx));
ccfg2.setQueryEntities(Collections.singleton(qryEntity));
ccfg3.setQueryEntities(Collections.singleton(qryEntity));
List<CacheConfiguration> cacheCfgs = new ArrayList<>();
cacheCfgs.add(ccfg1);
cacheCfgs.add(ccfg2);
cacheCfgs.add(ccfg3);
if (filteredCacheEnabled && !gridName.endsWith("0")) {
CacheConfiguration ccfg4 = cacheConfiguration(FILTERED_CACHE).setPartitionLossPolicy(PartitionLossPolicy.READ_ONLY_SAFE).setBackups(2).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC).setNodeFilter(new CoordinatorNodeFilter());
cacheCfgs.add(ccfg4);
}
cfg.setCacheConfiguration(asArray(cacheCfgs));
DataStorageConfiguration dsCfg = new DataStorageConfiguration().setConcurrencyLevel(Runtime.getRuntime().availableProcessors() * 4).setCheckpointFrequency(checkpointFrequency()).setWalMode(WALMode.LOG_ONLY).setPageSize(1024).setWalSegmentSize(// For faster node restarts with enabled persistence.
8 * 1024 * 1024).setDefaultDataRegionConfiguration(new DataRegionConfiguration().setName("dfltDataRegion").setPersistenceEnabled(true).setMaxSize(256 * 1024 * 1024)).setDataRegionConfigurations(new DataRegionConfiguration().setName(IN_MEMORY_REGION).setMaxSize(256 * 1024 * 1024));
cfg.setDataStorageConfiguration(dsCfg);
return cfg;
}
Aggregations