You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by al...@apache.org on 2021/03/15 12:01:36 UTC
[ignite] branch sql-calcite updated: IGNITE-14019 Fix query on lazy
caches on client node - Fixes #8855.
This is an automated email from the ASF dual-hosted git repository.
alexpl pushed a commit to branch sql-calcite
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/sql-calcite by this push:
new bd81784 IGNITE-14019 Fix query on lazy caches on client node - Fixes #8855.
bd81784 is described below
commit bd817846ba8be3219853062ff9555503115b4753
Author: Aleksey Plekhanov <pl...@gmail.com>
AuthorDate: Mon Mar 15 14:59:24 2021 +0300
IGNITE-14019 Fix query on lazy caches on client node - Fixes #8855.
Signed-off-by: Aleksey Plekhanov <pl...@gmail.com>
---
.../query/calcite/prepare/IgniteSqlValidator.java | 15 ++++++++++
.../query/calcite/schema/IgniteTableImpl.java | 29 ++++++++++++++++--
.../query/calcite/schema/SchemaHolderImpl.java | 9 ++++--
.../query/calcite/schema/TableDescriptor.java | 6 ++++
.../query/calcite/schema/TableDescriptorImpl.java | 35 ++++++++++++++++------
.../query/calcite/SqlFieldsQueryUsageTest.java | 8 ++---
6 files changed, 83 insertions(+), 19 deletions(-)
diff --git a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/IgniteSqlValidator.java b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/IgniteSqlValidator.java
index b696116..0eb189d5 100644
--- a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/IgniteSqlValidator.java
+++ b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/IgniteSqlValidator.java
@@ -52,6 +52,7 @@ import org.apache.calcite.sql.validate.SqlValidatorScope;
import org.apache.calcite.sql.validate.SqlValidatorTable;
import org.apache.calcite.sql.validate.SqlValidatorUtil;
import org.apache.ignite.internal.processors.query.QueryUtils;
+import org.apache.ignite.internal.processors.query.calcite.schema.IgniteTableImpl;
import org.apache.ignite.internal.processors.query.calcite.schema.TableDescriptor;
import org.apache.ignite.internal.processors.query.calcite.type.IgniteTypeFactory;
import org.apache.ignite.internal.processors.query.calcite.util.IgniteResource;
@@ -168,6 +169,20 @@ public class IgniteSqlValidator extends SqlValidatorImpl {
super.validateSelect(select, targetRowType);
}
+ /** {@inheritDoc} */
+ @Override protected void validateNamespace(SqlValidatorNamespace namespace, RelDataType targetRowType) {
+ SqlValidatorTable table = namespace.getTable();
+
+ if (table != null) {
+ IgniteTableImpl igniteTable = table.unwrap(IgniteTableImpl.class);
+
+ if (igniteTable != null)
+ igniteTable.ensureCacheStarted();
+ }
+
+ super.validateNamespace(namespace, targetRowType);
+ }
+
/**
* @param n Node to check limit.
* @param nodeName Node name.
diff --git a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/IgniteTableImpl.java b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/IgniteTableImpl.java
index 3c874f1..65c5db8 100644
--- a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/IgniteTableImpl.java
+++ b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/IgniteTableImpl.java
@@ -36,6 +36,8 @@ import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.schema.Statistic;
import org.apache.calcite.schema.impl.AbstractTable;
import org.apache.calcite.util.ImmutableBitSet;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.processors.query.calcite.exec.ExecutionContext;
import org.apache.ignite.internal.processors.query.calcite.exec.TableScan;
import org.apache.ignite.internal.processors.query.calcite.metadata.ColocationGroup;
@@ -47,6 +49,7 @@ import org.apache.ignite.internal.processors.query.calcite.trait.RewindabilityTr
import org.apache.ignite.internal.processors.query.calcite.type.IgniteTypeFactory;
import org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing;
import org.apache.ignite.internal.processors.query.h2.opt.GridH2Table;
+import org.apache.ignite.internal.util.typedef.internal.U;
import org.jetbrains.annotations.Nullable;
/**
@@ -60,15 +63,20 @@ public class IgniteTableImpl extends AbstractTable implements IgniteTable {
private final Statistic statistic;
/** */
+ private final GridKernalContext ctx;
+
+ /** */
private volatile GridH2Table tbl;
/** */
private final Map<String, IgniteIndex> indexes = new ConcurrentHashMap<>();
/**
- * @param desc Table descriptor.
+ * @param ctx Kernal context.
+ * @param desc Table descriptor.
*/
- public IgniteTableImpl(TableDescriptor desc) {
+ public IgniteTableImpl(GridKernalContext ctx, TableDescriptor desc) {
+ this.ctx = ctx;
this.desc = desc;
statistic = new StatisticsImpl();
}
@@ -81,7 +89,7 @@ public class IgniteTableImpl extends AbstractTable implements IgniteTable {
/** {@inheritDoc} */
@Override public Statistic getStatistic() {
if (tbl == null) {
- IgniteH2Indexing idx = (IgniteH2Indexing) desc.cacheContext().kernalContext().query().getIndexing();
+ IgniteH2Indexing idx = (IgniteH2Indexing)ctx.query().getIndexing();
final String tblName = desc.typeDescription().tableName();
final String schemaName = desc.typeDescription().schemaName();
@@ -168,6 +176,21 @@ public class IgniteTableImpl extends AbstractTable implements IgniteTable {
return super.unwrap(aCls);
}
+ /**
+ * Start cache context for lazy caches.
+ */
+ public void ensureCacheStarted() {
+ if (desc.cacheContext() == null) {
+ try {
+ ctx.cache().dynamicStartCache(null, desc.cacheInfo().config().getName(), null,
+ false, true, true).get();
+ }
+ catch (IgniteCheckedException ex) {
+ throw U.convertException(ex);
+ }
+ }
+ }
+
/** */
private class StatisticsImpl implements Statistic {
/** {@inheritDoc} */
diff --git a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/SchemaHolderImpl.java b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/SchemaHolderImpl.java
index 9cfd787..e8caf29 100644
--- a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/SchemaHolderImpl.java
+++ b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/SchemaHolderImpl.java
@@ -52,6 +52,9 @@ public class SchemaHolderImpl extends AbstractService implements SchemaHolder, S
private final Map<String, IgniteSchema> igniteSchemas = new HashMap<>();
/** */
+ private final GridKernalContext ctx;
+
+ /** */
private GridInternalSubscriptionProcessor subscriptionProcessor;
/** */
@@ -125,6 +128,8 @@ public class SchemaHolderImpl extends AbstractService implements SchemaHolder, S
public SchemaHolderImpl(GridKernalContext ctx) {
super(ctx);
+ this.ctx = ctx;
+
subscriptionProcessor(ctx.internalSubscriptionProcessor());
init();
@@ -175,9 +180,9 @@ public class SchemaHolderImpl extends AbstractService implements SchemaHolder, S
String tblName = typeDesc.tableName();
TableDescriptorImpl desc =
- new TableDescriptorImpl(cacheInfo.cacheContext(), typeDesc, affinityIdentity(cacheInfo.config()));
+ new TableDescriptorImpl(cacheInfo, typeDesc, affinityIdentity(cacheInfo.config()));
- schema.addTable(tblName, new IgniteTableImpl(desc));
+ schema.addTable(tblName, new IgniteTableImpl(ctx, desc));
rebuild();
}
diff --git a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/TableDescriptor.java b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/TableDescriptor.java
index fc5ae01..bacafd8 100644
--- a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/TableDescriptor.java
+++ b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/TableDescriptor.java
@@ -26,6 +26,7 @@ import org.apache.calcite.sql2rel.InitializerExpressionFactory;
import org.apache.calcite.util.ImmutableBitSet;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.cache.GridCacheContextInfo;
import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow;
import org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor;
import org.apache.ignite.internal.processors.query.calcite.exec.ExecutionContext;
@@ -43,6 +44,11 @@ import org.jetbrains.annotations.Nullable;
@SuppressWarnings("rawtypes")
public interface TableDescriptor extends RelProtoDataType, InitializerExpressionFactory {
/**
+ * @return Underlying cache context info.
+ */
+ GridCacheContextInfo cacheInfo();
+
+ /**
* @return Underlying cache context.
*/
GridCacheContext cacheContext();
diff --git a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/TableDescriptorImpl.java b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/TableDescriptorImpl.java
index 1949415..c14a488 100644
--- a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/TableDescriptorImpl.java
+++ b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/TableDescriptorImpl.java
@@ -44,6 +44,7 @@ import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
import org.apache.ignite.internal.processors.cache.CacheStoppedException;
import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.cache.GridCacheContextInfo;
import org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState;
import org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology;
import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow;
@@ -79,7 +80,7 @@ public class TableDescriptorImpl extends NullInitializerExpressionFactory
private static final ColumnDescriptor[] DUMMY = new ColumnDescriptor[0];
/** */
- private final GridCacheContext cctx;
+ private final GridCacheContextInfo<?, ?> cacheInfo;
/** */
private final GridQueryTypeDescriptor typeDesc;
@@ -106,8 +107,9 @@ public class TableDescriptorImpl extends NullInitializerExpressionFactory
private final ImmutableBitSet insertFields;
/** */
- public TableDescriptorImpl(GridCacheContext<?,?> cctx, GridQueryTypeDescriptor typeDesc, Object affinityIdentity) {
- this.cctx = cctx;
+ public TableDescriptorImpl(GridCacheContextInfo<?, ?> cacheInfo, GridQueryTypeDescriptor typeDesc,
+ Object affinityIdentity) {
+ this.cacheInfo = cacheInfo;
this.typeDesc = typeDesc;
this.affinityIdentity = affinityIdentity;
@@ -183,7 +185,12 @@ public class TableDescriptorImpl extends NullInitializerExpressionFactory
/** {@inheritDoc} */
@Override public GridCacheContext cacheContext() {
- return cctx;
+ return cacheInfo.cacheContext();
+ }
+
+ /** {@inheritDoc} */
+ @Override public GridCacheContextInfo cacheInfo() {
+ return cacheInfo;
}
/** {@inheritDoc} */
@@ -193,7 +200,7 @@ public class TableDescriptorImpl extends NullInitializerExpressionFactory
else if (affField == -1)
return IgniteDistributions.random();
else
- return IgniteDistributions.affinity(affField, cctx.cacheId(), affinityIdentity);
+ return IgniteDistributions.affinity(affField, cacheInfo.cacheId(), affinityIdentity);
}
/** {@inheritDoc} */
@@ -221,7 +228,7 @@ public class TableDescriptorImpl extends NullInitializerExpressionFactory
ColumnDescriptor desc = descriptors[i];
handler.set(i, res, TypeUtils.toInternal(ectx,
- desc.value(ectx, cctx, row), desc.storageType()));
+ desc.value(ectx, cacheContext(), row), desc.storageType()));
}
}
else {
@@ -229,7 +236,7 @@ public class TableDescriptorImpl extends NullInitializerExpressionFactory
ColumnDescriptor desc = descriptors[j];
handler.set(i, res, TypeUtils.toInternal(ectx,
- desc.value(ectx, cctx, row), desc.storageType()));
+ desc.value(ectx, cacheContext(), row), desc.storageType()));
}
}
@@ -286,7 +293,7 @@ public class TableDescriptorImpl extends NullInitializerExpressionFactory
Object key = insertKey(row, ectx);
Object val = insertVal(row, ectx);
- if (cctx.binaryMarshaller()) {
+ if (cacheContext().binaryMarshaller()) {
if (key instanceof BinaryObjectBuilder)
key = ((BinaryObjectBuilder) key).build();
@@ -351,6 +358,8 @@ public class TableDescriptorImpl extends NullInitializerExpressionFactory
/** */
private Object newVal(String typeName, Class<?> typeCls) throws IgniteCheckedException {
+ GridCacheContext<?, ?> cctx = cacheContext();
+
if (cctx.binaryMarshaller()) {
BinaryObjectBuilder builder = cctx.grid().binary().builder(typeName);
cctx.prepareAffinityField(builder);
@@ -409,7 +418,7 @@ public class TableDescriptorImpl extends NullInitializerExpressionFactory
val = TypeUtils.fromInternal(ectx, fieldVal, desc.storageType());
}
- if (cctx.binaryMarshaller() && val instanceof BinaryObjectBuilder)
+ if (cacheContext().binaryMarshaller() && val instanceof BinaryObjectBuilder)
val = ((BinaryObjectBuilder) val).build();
typeDesc.validateKeyAndValue(key, val);
@@ -422,6 +431,8 @@ public class TableDescriptorImpl extends NullInitializerExpressionFactory
if (val == null || QueryUtils.isSqlType(val.getClass()))
return val;
+ GridCacheContext<?, ?> cctx = cacheContext();
+
if (!cctx.binaryMarshaller())
return cctx.marshaller().unmarshal(cctx.marshaller().marshal(val), U.resolveClassLoader(cctx.gridConfig()));
@@ -463,6 +474,8 @@ public class TableDescriptorImpl extends NullInitializerExpressionFactory
/** {@inheritDoc} */
@Override public ColocationGroup colocationGroup(PlanningContext ctx) {
+ GridCacheContext<?, ?> cctx = cacheContext();
+
if (!cctx.gate().enterIfNotStopped())
throw U.convertException(new CacheStoppedException(cctx.name()));
@@ -479,6 +492,8 @@ public class TableDescriptorImpl extends NullInitializerExpressionFactory
/** */
private ColocationGroup partitionedGroup(@NotNull AffinityTopologyVersion topVer) {
+ GridCacheContext<?, ?> cctx = cacheContext();
+
List<List<ClusterNode>> assignments = cctx.affinity().assignments(topVer);
List<List<UUID>> assignments0;
@@ -496,6 +511,8 @@ public class TableDescriptorImpl extends NullInitializerExpressionFactory
/** */
private ColocationGroup replicatedGroup(@NotNull AffinityTopologyVersion topVer) {
+ GridCacheContext<?, ?> cctx = cacheContext();
+
GridDhtPartitionTopology top = cctx.topology();
List<ClusterNode> nodes = cctx.discovery().discoCache(topVer).cacheGroupAffinityNodes(cctx.groupId());
diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/SqlFieldsQueryUsageTest.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/SqlFieldsQueryUsageTest.java
index 2546fc2..5da4fdd 100644
--- a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/SqlFieldsQueryUsageTest.java
+++ b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/SqlFieldsQueryUsageTest.java
@@ -27,7 +27,6 @@ import org.apache.ignite.internal.util.typedef.G;
import org.apache.ignite.testframework.junits.WithSystemProperty;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.junit.AfterClass;
-import org.junit.Ignore;
import org.junit.Test;
import static java.util.Collections.singletonList;
@@ -39,7 +38,6 @@ public class SqlFieldsQueryUsageTest extends GridCommonAbstractTest {
/** */
private static IgniteEx client;
- /** */
/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
startGrids(1);
@@ -65,15 +63,13 @@ public class SqlFieldsQueryUsageTest extends GridCommonAbstractTest {
}
/** */
- @Ignore("https://issues.apache.org/jira/browse/IGNITE-14019")
@Test
- public void createCacheOnSrvCallOnCli() {
+ public void createCacheOnSrvCallOnCli() throws InterruptedException {
QueryEntity projEntity = new QueryEntity();
projEntity.setKeyType(Integer.class.getName());
projEntity.setKeyFieldName("id");
projEntity.setValueType(Integer.class.getName());
projEntity.addQueryField("id", Integer.class.getName(), null);
- projEntity.addQueryField("depId", Integer.class.getName(), null);
projEntity.setTableName("Developer");
@@ -84,6 +80,8 @@ public class SqlFieldsQueryUsageTest extends GridCommonAbstractTest {
IgniteCache<Integer, Integer> devCache = grid(0).createCache(projCfg);
+ awaitPartitionMapExchange();
+
assertFalse(grid(0).configuration().isClientMode());
devCache.put(1, 2);