Repository: ignite
Updated Branches:
  refs/heads/ignite-2.5 f143ad005 -> 2c4a7a2e3


IGNITE-8230: SQL: Fixed backup number propagation in CREATE TABLE command. This 
closes #3803.


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

Branch: refs/heads/ignite-2.5
Commit: 2c4a7a2e366d7308485ae5cc95d4b60e66b09589
Parents: f143ad0
Author: devozerov <voze...@gridgain.com>
Authored: Thu Apr 12 15:13:51 2018 +0300
Committer: devozerov <voze...@gridgain.com>
Committed: Thu Apr 12 15:14:54 2018 +0300

----------------------------------------------------------------------
 .../processors/query/GridQueryProcessor.java    |  7 ++--
 .../query/h2/sql/GridSqlCreateTable.java        |  7 ++--
 .../cache/index/H2DynamicTableSelfTest.java     | 37 ++++++++++++++++++++
 3 files changed, 45 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/2c4a7a2e/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 bde9427..03e5254 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
@@ -1483,10 +1483,10 @@ public class GridQueryProcessor extends 
GridProcessorAdapter {
     @SuppressWarnings("unchecked")
     public void dynamicTableCreate(String schemaName, QueryEntity entity, 
String templateName, String cacheName,
         String cacheGroup, @Nullable String dataRegion, String affinityKey, 
@Nullable CacheAtomicityMode atomicityMode,
-        @Nullable CacheWriteSynchronizationMode writeSyncMode, int backups, 
boolean ifNotExists)
+        @Nullable CacheWriteSynchronizationMode writeSyncMode, @Nullable 
Integer backups, boolean ifNotExists)
         throws IgniteCheckedException {
         assert !F.isEmpty(templateName);
-        assert backups >= 0;
+        assert backups == null || backups >= 0;
 
         CacheConfiguration<?, ?> ccfg = 
ctx.cache().getConfigFromTemplate(templateName);
 
@@ -1525,7 +1525,8 @@ public class GridQueryProcessor extends 
GridProcessorAdapter {
         if (writeSyncMode != null)
             ccfg.setWriteSynchronizationMode(writeSyncMode);
 
-        ccfg.setBackups(backups);
+        if (backups != null)
+            ccfg.setBackups(backups);
 
         ccfg.setSqlSchema(schemaName);
         ccfg.setSqlEscapeAll(true);

http://git-wip-us.apache.org/repos/asf/ignite/blob/2c4a7a2e/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlCreateTable.java
----------------------------------------------------------------------
diff --git 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlCreateTable.java
 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlCreateTable.java
index 3608aed..de86d6a 100644
--- 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlCreateTable.java
+++ 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlCreateTable.java
@@ -22,6 +22,7 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import org.apache.ignite.cache.CacheAtomicityMode;
 import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * CREATE TABLE statement.
@@ -57,7 +58,7 @@ public class GridSqlCreateTable extends GridSqlStatement {
     private CacheWriteSynchronizationMode writeSyncMode;
 
     /** Backups number for new cache. */
-    private int backups;
+    private Integer backups;
 
     /** Quietly ignore this command if table already exists. */
     private boolean ifNotExists;
@@ -184,14 +185,14 @@ public class GridSqlCreateTable extends GridSqlStatement {
     /**
      * @return Backups number for new cache.
      */
-    public int backups() {
+    @Nullable public Integer backups() {
         return backups;
     }
 
     /**
      * @param backups Backups number for new cache.
      */
-    public void backups(int backups) {
+    public void backups(Integer backups) {
         this.backups = backups;
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2c4a7a2e/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 b20bb59..8224711 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
@@ -88,7 +88,14 @@ public class H2DynamicTableSelfTest extends 
AbstractSchemaSelfTest {
     /** Bad data region name. */
     public static final String DATA_REGION_NAME_BAD = "my_data_region_bad";
 
+    /** Cache with backups. */
+    private static final String CACHE_NAME_BACKUPS = CACHE_NAME + "_backups";
+
+    /** Number of backups for backup test. */
+    private static final int DFLT_BACKUPS = 2;
+
     /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
     @Override protected void beforeTestsStarted() throws Exception {
         super.beforeTestsStarted();
 
@@ -98,6 +105,8 @@ public class H2DynamicTableSelfTest extends 
AbstractSchemaSelfTest {
         client().addCacheConfiguration(cacheConfiguration());
         client().addCacheConfiguration(cacheConfiguration().setName(CACHE_NAME 
+ "_async")
             
.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_ASYNC));
+
+        
client().addCacheConfiguration(cacheConfiguration().setName(CACHE_NAME_BACKUPS).setBackups(DFLT_BACKUPS));
     }
 
     /** {@inheritDoc} */
@@ -108,6 +117,7 @@ public class H2DynamicTableSelfTest extends 
AbstractSchemaSelfTest {
     }
 
     /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
     @Override protected void beforeTest() throws Exception {
         super.beforeTest();
 
@@ -120,6 +130,7 @@ public class H2DynamicTableSelfTest extends 
AbstractSchemaSelfTest {
         execute("DROP TABLE IF EXISTS PUBLIC.\"Person\"");
         execute("DROP TABLE IF EXISTS PUBLIC.\"City\"");
         execute("DROP TABLE IF EXISTS PUBLIC.\"NameTest\"");
+        execute("DROP TABLE IF EXISTS PUBLIC.\"BackupTest\"");
 
         super.afterTest();
     }
@@ -496,6 +507,32 @@ public class H2DynamicTableSelfTest extends 
AbstractSchemaSelfTest {
     }
 
     /**
+     * Test backups propagation.
+     *
+     * @throws Exception If failed.
+     */
+    @SuppressWarnings("unchecked")
+    public void testBackups() throws Exception {
+        String cacheName = "BackupTestCache";
+
+        execute("CREATE TABLE \"BackupTest\" (id BIGINT PRIMARY KEY, name 
VARCHAR) WITH \"template=" +
+            CACHE_NAME_BACKUPS + ", cache_name=" + cacheName + "\"");
+
+        CacheConfiguration ccfg = 
grid(0).cache(cacheName).getConfiguration(CacheConfiguration.class);
+
+        assertEquals(DFLT_BACKUPS, ccfg.getBackups());
+
+        execute("DROP TABLE PUBLIC.\"BackupTest\"");
+
+        execute("CREATE TABLE \"BackupTest\" (id BIGINT PRIMARY KEY, name 
VARCHAR) WITH \"template=" +
+            CACHE_NAME_BACKUPS + ", cache_name=" + cacheName + ", 
backups=1\"");
+
+        ccfg = 
grid(0).cache(cacheName).getConfiguration(CacheConfiguration.class);
+
+        assertEquals(1, ccfg.getBackups());
+    }
+
+    /**
      * Test that {@code CREATE TABLE} with given template cache name actually 
creates new cache,
      * H2 table and type descriptor on all nodes, optionally with cache type 
check.
      * @param tplCacheName Template cache name.

Reply via email to