ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject ignite git commit: IGNITE-6569: Fixed hang when trying to execute "DROP TABLE" on the cache this table belongs to. This closes #2823.
Date Mon, 09 Oct 2017 19:18:27 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-2.3 1a6bb2bbf -> 72b409cc2


IGNITE-6569: Fixed hang when trying to execute "DROP TABLE" on the cache this table belongs
to. This closes #2823.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/72b409cc
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/72b409cc
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/72b409cc

Branch: refs/heads/ignite-2.3
Commit: 72b409cc233919462b3df1547afdec082d8273e1
Parents: 1a6bb2b
Author: Alexander Paschenko <alexander.a.paschenko@gmail.com>
Authored: Mon Oct 9 22:17:28 2017 +0300
Committer: devozerov <ppozerov@gmail.com>
Committed: Mon Oct 9 22:18:13 2017 +0300

----------------------------------------------------------------------
 .../processors/query/GridQueryProcessor.java    | 17 +++++++++++++++
 .../cache/index/H2DynamicTableSelfTest.java     | 23 ++++++++++++++++++++
 2 files changed, 40 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/72b409cc/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
index f044c1d..0d8ee47 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
@@ -70,6 +70,7 @@ import org.apache.ignite.internal.processors.cache.StoredCacheData;
 import org.apache.ignite.internal.processors.cache.query.CacheQueryFuture;
 import org.apache.ignite.internal.processors.cache.query.CacheQueryType;
 import org.apache.ignite.internal.processors.cache.query.GridCacheQueryType;
+import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
 import org.apache.ignite.internal.processors.query.property.QueryBinaryProperty;
 import org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheVisitor;
@@ -186,6 +187,9 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     /** Pending status messages. */
     private final LinkedList<SchemaOperationStatusMessage> pendingMsgs = new LinkedList<>();
 
+    /** Current cache that has a query running on it. */
+    private final ThreadLocal<GridCacheContext> curCache = new ThreadLocal<>();
+
     /** Disconnected flag. */
     private boolean disconnected;
 
@@ -1440,6 +1444,13 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      */
     @SuppressWarnings("unchecked")
     public void dynamicTableDrop(String cacheName, String tblName, boolean ifExists) throws
SchemaOperationException {
+        GridCacheContext currCache = this.curCache.get();
+
+        if (currCache != null && F.eq(currCache.name(), cacheName))
+            throw new IgniteSQLException("DROP TABLE cannot be called from the same cache
that holds " +
+                "the table being dropped [cacheName-" + cacheName + ", tblName=" + tblName
+ ']',
+                IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
+
         boolean res = ctx.grid().destroyCache0(cacheName, true);
 
         if (!res && !ifExists)
@@ -1853,6 +1864,10 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         if (!busyLock.enterBusy())
             throw new IllegalStateException("Failed to execute query (grid is stopping).");
 
+        GridCacheContext oldCctx = curCache.get();
+
+        curCache.set(cctx);
+
         try {
             final String schemaName = qry.getSchema() != null ? qry.getSchema() : idx.schema(cctx.name());
             final int mainCacheId = CU.cacheId(cctx.name());
@@ -1898,6 +1913,8 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             throw new CacheException(e);
         }
         finally {
+            curCache.set(oldCctx);
+
             busyLock.leaveBusy();
         }
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/72b409cc/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicTableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicTableSelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicTableSelfTest.java
index e0ab6c5..b108bb3 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicTableSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicTableSelfTest.java
@@ -652,6 +652,29 @@ public class H2DynamicTableSelfTest extends AbstractSchemaSelfTest {
     }
 
     /**
+     * Test that attempting to execute {@code DROP TABLE} via API of cache being dropped
yields an error.
+     * @throws Exception if failed.
+     */
+    @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
+    public void testCacheSelfDrop() throws Exception {
+        execute("CREATE TABLE IF NOT EXISTS \"Person\" (\"id\" int, \"city\" varchar," +
+            " \"name\" varchar, \"surname\" varchar, \"age\" int, PRIMARY KEY (\"id\", \"city\"))
WITH " +
+            "\"template=cache\"");
+
+        GridTestUtils.assertThrows(null, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                client().cache(QueryUtils.createTableCacheName(QueryUtils.DFLT_SCHEMA, "Person"))
+                    .query(new SqlFieldsQuery("DROP TABLE \"Person\"")).getAll();
+
+                return null;
+            }
+        }, IgniteSQLException.class, "DROP TABLE cannot be called from the same cache that
holds the table " +
+            "being dropped");
+
+        execute("DROP TABLE \"Person\"");
+    }
+
+    /**
      * Test that attempting to {@code DROP TABLE} that does not exist does not yield an error
if the statement contains
      *     {@code IF EXISTS} clause.
      *


Mime
View raw message