You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2017/09/21 14:46:54 UTC
ignite git commit: IGNITE-6448: Fixed a bug causing stale SQL
statement to reside in cache after ALTER TABLE command. This closes #2702.
Repository: ignite
Updated Branches:
refs/heads/master abe4ee8ff -> c7d591ff7
IGNITE-6448: Fixed a bug causing stale SQL statement to reside in cache after ALTER TABLE command. This closes #2702.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/c7d591ff
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/c7d591ff
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/c7d591ff
Branch: refs/heads/master
Commit: c7d591ff7dbd75fb774f931816ea947dbeffc1f6
Parents: abe4ee8
Author: tledkov-gridgain <tl...@gridgain.com>
Authored: Thu Sep 21 17:46:47 2017 +0300
Committer: devozerov <pp...@gmail.com>
Committed: Thu Sep 21 17:46:47 2017 +0300
----------------------------------------------------------------------
.../jdbc/suite/IgniteJdbcDriverTestSuite.java | 3 +
.../thin/JdbcThinSelectAfterAlterTable.java | 173 +++++++++++++++++++
.../processors/query/h2/IgniteH2Indexing.java | 9 +
.../processors/query/h2/opt/GridH2Table.java | 2 +
4 files changed, 187 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/c7d591ff/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java
index 3df8e2c..1ae2427 100644
--- a/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java
+++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java
@@ -55,6 +55,7 @@ import org.apache.ignite.jdbc.thin.JdbcThinNoDefaultSchemaTest;
import org.apache.ignite.jdbc.thin.JdbcThinPreparedStatementSelfTest;
import org.apache.ignite.jdbc.thin.JdbcThinResultSetSelfTest;
import org.apache.ignite.jdbc.thin.JdbcThinSchemaCaseTest;
+import org.apache.ignite.jdbc.thin.JdbcThinSelectAfterAlterTable;
import org.apache.ignite.jdbc.thin.JdbcThinStatementSelfTest;
import org.apache.ignite.jdbc.thin.JdbcThinUpdateStatementSelfTest;
@@ -149,6 +150,8 @@ public class IgniteJdbcDriverTestSuite extends TestSuite {
// New thin JDBC driver, full SQL tests
suite.addTest(new TestSuite(JdbcThinComplexDmlDdlSelfTest.class));
+ suite.addTest(new TestSuite(JdbcThinSelectAfterAlterTable.class));
+
return suite;
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/c7d591ff/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinSelectAfterAlterTable.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinSelectAfterAlterTable.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinSelectAfterAlterTable.java
new file mode 100644
index 0000000..13b8f3e
--- /dev/null
+++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinSelectAfterAlterTable.java
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.jdbc.thin;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Statement;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConnectorConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Base class for complex SQL tests based on JDBC driver.
+ */
+public class JdbcThinSelectAfterAlterTable extends GridCommonAbstractTest {
+ /** IP finder. */
+ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+ /** Client connection port. */
+ private int cliPort = ClientConnectorConfiguration.DFLT_PORT;
+
+ /** JDBC connection. */
+ private Connection conn;
+
+ /** JDBC statement. */
+ private Statement stmt;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+ cfg.setCacheConfiguration(cacheConfiguration(DEFAULT_CACHE_NAME));
+
+ TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+ disco.setIpFinder(IP_FINDER);
+
+ cfg.setDiscoverySpi(disco);
+
+ cfg.setClientConnectorConfiguration(new ClientConnectorConfiguration().setPort(cliPort++));
+
+ return cfg;
+ }
+
+ /**
+ * @param name Cache name.
+ * @return Cache configuration.
+ * @throws Exception In case of error.
+ */
+ private CacheConfiguration cacheConfiguration(@NotNull String name) throws Exception {
+ CacheConfiguration cfg = defaultCacheConfiguration();
+
+ cfg.setName(name);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ startGridsMultiThreaded(2);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1");
+
+ stmt = conn.createStatement();
+
+ stmt.executeUpdate("CREATE TABLE person (id LONG, name VARCHAR, city_id LONG, PRIMARY KEY (id, city_id))");
+ stmt.executeUpdate("INSERT INTO person (id, name, city_id) values (1, 'name_1', 11)");
+
+ stmt.executeQuery("select * from person");
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stmt.close();
+ conn.close();
+
+ // Destroy all SQL caches after test.
+ for (String cacheName : grid(0).cacheNames()) {
+ DynamicCacheDescriptor cacheDesc = grid(0).context().cache().cacheDescriptor(cacheName);
+
+ if (cacheDesc != null && cacheDesc.sql())
+ grid(0).destroyCache0(cacheName, true);
+ }
+
+ super.afterTest();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @SuppressWarnings({"ThrowableResultOfMethodCallIgnored", "unchecked"})
+ public void testSelectAfterAlterTableSingleNode() throws Exception {
+ stmt.executeUpdate("alter table person add age int");
+
+ checkNewColumn(stmt);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @SuppressWarnings({"ThrowableResultOfMethodCallIgnored", "unchecked"})
+ public void testSelectAfterAlterTableMultiNode() throws Exception {
+ try (Connection conn2 = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:"
+ + (ClientConnectorConfiguration.DFLT_PORT + 1))) {
+
+ try (Statement stmt2 = conn2.createStatement()) {
+ stmt2.executeUpdate("alter table person add age int");
+ }
+ }
+
+ checkNewColumn(stmt);
+ }
+
+ /**
+ * @param stmt Statement to check new column.
+ * @throws SQLException If failed.
+ */
+ public void checkNewColumn(Statement stmt) throws SQLException {
+ ResultSet rs = stmt.executeQuery("select * from person");
+
+ ResultSetMetaData meta = rs.getMetaData();
+
+ assertEquals(4, meta.getColumnCount());
+
+ boolean newColExists = false;
+
+ for (int i = 1; i <= meta.getColumnCount(); ++i) {
+ if ("age".equalsIgnoreCase(meta.getColumnName(i))) {
+ newColExists = true;
+
+ break;
+ }
+ }
+
+ assertTrue(newColExists);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/c7d591ff/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
index a07d48e..03e2391 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
@@ -729,6 +729,8 @@ public class IgniteH2Indexing implements GridQueryIndexing {
}
desc.table().addColumns(cols, ifColNotExists);
+
+ clearCachedQueries();
}
/**
@@ -2244,6 +2246,13 @@ public class IgniteH2Indexing implements GridQueryIndexing {
}
}
+ /**
+ * Remove all cached queries from cached two-steps queries.
+ */
+ public void clearCachedQueries() {
+ twoStepCache.clear();
+ }
+
/** {@inheritDoc} */
@Override public IndexingQueryFilter backupFilter(@Nullable final AffinityTopologyVersion topVer,
@Nullable final int[] parts) {
http://git-wip-us.apache.org/repos/asf/ignite/blob/c7d591ff/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
index 45bb9c7..549cbfb 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
@@ -999,6 +999,8 @@ public class GridH2Table extends TableBase {
setColumns(newCols);
desc.refreshMetadataFromTypeDescriptor();
+
+ setModified();
}
finally {
unlock(true);