You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2022/12/26 18:44:24 UTC

[GitHub] [ignite-3] sergeyuttsel opened a new pull request, #1477: IGNITE-18141 Added ability to bind tables with distribution zones on table creation.

sergeyuttsel opened a new pull request, #1477:
URL: https://github.com/apache/ignite-3/pull/1477

   https://issues.apache.org/jira/browse/IGNITE-18141


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] sergeyuttsel commented on a diff in pull request #1477: IGNITE-18141 Added ability to bind tables with distribution zones on table creation.

Posted by GitBox <gi...@apache.org>.
sergeyuttsel commented on code in PR #1477:
URL: https://github.com/apache/ignite-3/pull/1477#discussion_r1065414673


##########
modules/distribution-zones/src/main/java/org/apache/ignite/internal/distributionzones/exception/DistributionZoneAlreadyExistsException.java:
##########
@@ -27,6 +27,15 @@
  * because a distribution zone with same name already exists.
  */
 public class DistributionZoneAlreadyExistsException extends IgniteInternalException {
+    /**
+     * The constructor.
+     *
+     * @param zoneName Zone name.
+     */
+    public DistributionZoneAlreadyExistsException(String zoneName) {

Review Comment:
   Yes, I removed it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] sanpwc closed pull request #1477: IGNITE-18141 Added ability to bind tables with distribution zones on table creation.

Posted by GitBox <gi...@apache.org>.
sanpwc closed pull request #1477: IGNITE-18141 Added ability to bind tables with distribution zones on table creation.
URL: https://github.com/apache/ignite-3/pull/1477


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] sergeyuttsel commented on a diff in pull request #1477: IGNITE-18141 Added ability to bind tables with distribution zones on table creation.

Posted by GitBox <gi...@apache.org>.
sergeyuttsel commented on code in PR #1477:
URL: https://github.com/apache/ignite-3/pull/1477#discussion_r1065410424


##########
modules/distribution-zones/src/main/java/org/apache/ignite/internal/distributionzones/DistributionZoneManager.java:
##########
@@ -328,20 +341,34 @@ public CompletableFuture<Void> dropZone(String name) {
             CompletableFuture<Void> fut = new CompletableFuture<>();
 
             zonesConfiguration.change(zonesChange -> zonesChange.changeDistributionZones(zonesListChange -> {
-                DistributionZoneView view = zonesListChange.get(name);
+                DistributionZoneView zoneView = zonesListChange.get(name);
 
-                if (view == null) {
+                if (zoneView == null) {
                     throw new DistributionZoneNotFoundException(name);
                 }
 
+                NamedConfigurationTree<TableConfiguration, TableView, TableChange> tables = tablesConfiguration.tables();
+
+                boolean bindTable = tables.value().namedListKeys().stream()
+                        .anyMatch(tableName -> {
+                            Integer tableZoneId = tables.get(tableName).zoneId().value();
+
+                            return tableZoneId != null && tableZoneId.equals(zoneView.zoneId());

Review Comment:
   I changed it. But it will be changed again within the scope of the default zone ticket.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] sergeyuttsel commented on a diff in pull request #1477: IGNITE-18141 Added ability to bind tables with distribution zones on table creation.

Posted by GitBox <gi...@apache.org>.
sergeyuttsel commented on code in PR #1477:
URL: https://github.com/apache/ignite-3/pull/1477#discussion_r1065414476


##########
modules/distribution-zones/src/main/java/org/apache/ignite/internal/distributionzones/DistributionZoneManager.java:
##########
@@ -354,6 +381,23 @@ public CompletableFuture<Void> dropZone(String name) {
         }
     }
 
+    /**
+     * Gets zone id by zone name.
+     *
+     * @param name Distribution zone name.
+     * @return The zone id.
+     * @throws DistributionZoneNotFoundException If the zone is not exist..
+     */
+    public int getZoneId(String name) {
+        DistributionZoneConfiguration zoneCfg = zonesConfiguration.distributionZones().get(name);

Review Comment:
   The idea used here is the same as when iterating over tablesConfiguration.tables() in the dropZone. The getZoneId method is invoked in the "change". The ticket will be created to work it correctly.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] sergeyuttsel commented on a diff in pull request #1477: IGNITE-18141 Added ability to bind tables with distribution zones on table creation.

Posted by GitBox <gi...@apache.org>.
sergeyuttsel commented on code in PR #1477:
URL: https://github.com/apache/ignite-3/pull/1477#discussion_r1065422106


##########
modules/distribution-zones/build.gradle:
##########
@@ -36,6 +36,7 @@ dependencies {
     implementation project(':ignite-metastorage')
     implementation project(':ignite-vault')
     implementation project(':ignite-configuration')
+    implementation project(':ignite-schema')

Review Comment:
   Because DistributionZoneManager has a TablesConfiguration which is located in 'ignite-schema'



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] sergeyuttsel commented on a diff in pull request #1477: IGNITE-18141 Added ability to bind tables with distribution zones on table creation.

Posted by GitBox <gi...@apache.org>.
sergeyuttsel commented on code in PR #1477:
URL: https://github.com/apache/ignite-3/pull/1477#discussion_r1065701321


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/ddl/DdlSqlToCommandConverter.java:
##########
@@ -132,6 +133,7 @@ public DdlSqlToCommandConverter(
 
         this.tableOptionInfos = Map.of(
                 REPLICAS.name(), new DdlOptionInfo<>(Integer.class, this::checkPositiveNumber, CreateTableCommand::replicas),
+                PRIMARY_ZONE.name(), new DdlOptionInfo<>(String.class, null, CreateTableCommand::zone),
                 PARTITIONS.name(), new DdlOptionInfo<>(Integer.class, this::checkPositiveNumber, CreateTableCommand::partitions)
         );

Review Comment:
   Fixed. Thanks.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] sergeyuttsel commented on a diff in pull request #1477: IGNITE-18141 Added ability to bind tables with distribution zones on table creation.

Posted by GitBox <gi...@apache.org>.
sergeyuttsel commented on code in PR #1477:
URL: https://github.com/apache/ignite-3/pull/1477#discussion_r1065417203


##########
modules/distribution-zones/src/main/java/org/apache/ignite/internal/distributionzones/exception/DistributionZoneBindTableException.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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.internal.distributionzones.exception;
+
+import static org.apache.ignite.lang.ErrorGroups.DistributionZones.ZONE_BIND_TABLE_ERR;
+
+import java.util.UUID;
+import org.apache.ignite.lang.IgniteInternalException;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Exception is thrown when the distribution zone cannot be dropped because there is a table bound to the distribution zone.
+ */
+public class DistributionZoneBindTableException extends IgniteInternalException {
+    /**
+     * The constructor.
+     *
+     * @param zoneName Zone name.
+     */
+    public DistributionZoneBindTableException(String zoneName) {
+        this(zoneName, null);
+    }
+
+    /**
+     * The constructor.
+     *
+     * @param zoneName Zone name.
+     * @param cause Optional nested exception (can be {@code null}).
+     */
+    public DistributionZoneBindTableException(String zoneName, @Nullable Throwable cause) {
+        super(ZONE_BIND_TABLE_ERR, "Distribution zone is assigned to the table [zoneName=" + zoneName + ']', cause);

Review Comment:
   The exception throws after first bound table is found, not full list of bound tables. So I think it is not so useful to know only one table name.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] sergeyuttsel commented on a diff in pull request #1477: IGNITE-18141 Added ability to bind tables with distribution zones on table creation.

Posted by GitBox <gi...@apache.org>.
sergeyuttsel commented on code in PR #1477:
URL: https://github.com/apache/ignite-3/pull/1477#discussion_r1065433476


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/sql/IgniteSqlCreateTableOptionEnum.java:
##########
@@ -0,0 +1,26 @@
+/*
+ * 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.internal.sql.engine.sql;
+
+/**
+ * Enumerates the options for CREATE TABLE statement.
+ */
+public enum IgniteSqlCreateTableOptionEnum {
+    /** Distribution zone. */
+    PRIMARY_ZONE

Review Comment:
   Other options located in `zoneOptionInfos`, `dataStorageOptionInfos` and other. But I will check it in SQL team.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] sergeyuttsel commented on a diff in pull request #1477: IGNITE-18141 Added ability to bind tables with distribution zones on table creation.

Posted by GitBox <gi...@apache.org>.
sergeyuttsel commented on code in PR #1477:
URL: https://github.com/apache/ignite-3/pull/1477#discussion_r1065699411


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/sql/IgniteSqlCreateTableOptionEnum.java:
##########
@@ -0,0 +1,26 @@
+/*
+ * 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.internal.sql.engine.sql;
+
+/**
+ * Enumerates the options for CREATE TABLE statement.
+ */
+public enum IgniteSqlCreateTableOptionEnum {
+    /** Distribution zone. */
+    PRIMARY_ZONE

Review Comment:
   As was decided I removed IgniteSqlCreateTableOptionEnum and used a "PRIMARY_ZONE" string.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] sanpwc commented on a diff in pull request #1477: IGNITE-18141 Added ability to bind tables with distribution zones on table creation.

Posted by GitBox <gi...@apache.org>.
sanpwc commented on code in PR #1477:
URL: https://github.com/apache/ignite-3/pull/1477#discussion_r1064726060


##########
modules/distribution-zones/src/main/java/org/apache/ignite/internal/distributionzones/DistributionZoneManager.java:
##########
@@ -354,6 +381,23 @@ public CompletableFuture<Void> dropZone(String name) {
         }
     }
 
+    /**
+     * Gets zone id by zone name.
+     *
+     * @param name Distribution zone name.
+     * @return The zone id.
+     * @throws DistributionZoneNotFoundException If the zone is not exist..
+     */
+    public int getZoneId(String name) {
+        DistributionZoneConfiguration zoneCfg = zonesConfiguration.distributionZones().get(name);

Review Comment:
   Not sure whether local evaluation is enough here. What do you think? We can use directValue as a last resort, but should start with considering other options.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] sergeyuttsel commented on a diff in pull request #1477: IGNITE-18141 Added ability to bind tables with distribution zones on table creation.

Posted by GitBox <gi...@apache.org>.
sergeyuttsel commented on code in PR #1477:
URL: https://github.com/apache/ignite-3/pull/1477#discussion_r1065408386


##########
modules/distribution-zones/src/main/java/org/apache/ignite/internal/distributionzones/DistributionZoneManager.java:
##########
@@ -328,20 +341,34 @@ public CompletableFuture<Void> dropZone(String name) {
             CompletableFuture<Void> fut = new CompletableFuture<>();
 
             zonesConfiguration.change(zonesChange -> zonesChange.changeDistributionZones(zonesListChange -> {
-                DistributionZoneView view = zonesListChange.get(name);
+                DistributionZoneView zoneView = zonesListChange.get(name);
 
-                if (view == null) {
+                if (zoneView == null) {
                     throw new DistributionZoneNotFoundException(name);
                 }
 
+                NamedConfigurationTree<TableConfiguration, TableView, TableChange> tables = tablesConfiguration.tables();
+
+                boolean bindTable = tables.value().namedListKeys().stream()

Review Comment:
   The idea was that this is not possible, since we do this in the "change". But it turned out that it doesn't work that way. I'll create a ticket for this issue, but for now let's leave it like that.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] sergeyuttsel commented on a diff in pull request #1477: IGNITE-18141 Added ability to bind tables with distribution zones on table creation.

Posted by GitBox <gi...@apache.org>.
sergeyuttsel commented on code in PR #1477:
URL: https://github.com/apache/ignite-3/pull/1477#discussion_r1065707633


##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/ddl/DdlCommandHandlerExceptionHandlingTest.java:
##########
@@ -89,8 +97,21 @@ void before() {
 
         DistributionZonesConfiguration zonesConfiguration = registry.getConfiguration(DistributionZonesConfiguration.KEY);
 
+        TablesConfiguration tablesConfiguration = mock(TablesConfiguration.class);
+
+        NamedConfigurationTree<TableConfiguration, TableView, TableChange> tables = mock(NamedConfigurationTree.class);
+
+        when(tablesConfiguration.tables()).thenReturn(tables);
+
+        NamedListView<TableView> value = mock(NamedListView.class);
+
+        when(tables.value()).thenReturn(value);
+
+        when(value.namedListKeys()).thenReturn(new ArrayList<>());
+
         distributionZoneManager = new DistributionZoneManager(
                 zonesConfiguration,
+                tablesConfiguration,

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] sergeyuttsel commented on a diff in pull request #1477: IGNITE-18141 Added ability to bind tables with distribution zones on table creation.

Posted by GitBox <gi...@apache.org>.
sergeyuttsel commented on code in PR #1477:
URL: https://github.com/apache/ignite-3/pull/1477#discussion_r1065697362


##########
modules/distribution-zones/src/main/java/org/apache/ignite/internal/distributionzones/exception/DistributionZoneBindTableException.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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.internal.distributionzones.exception;
+
+import static org.apache.ignite.lang.ErrorGroups.DistributionZones.ZONE_BIND_TABLE_ERR;
+
+import java.util.UUID;
+import org.apache.ignite.lang.IgniteInternalException;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Exception is thrown when the distribution zone cannot be dropped because there is a table bound to the distribution zone.
+ */
+public class DistributionZoneBindTableException extends IgniteInternalException {
+    /**
+     * The constructor.
+     *
+     * @param zoneName Zone name.
+     */
+    public DistributionZoneBindTableException(String zoneName) {
+        this(zoneName, null);
+    }
+
+    /**
+     * The constructor.
+     *
+     * @param zoneName Zone name.
+     * @param cause Optional nested exception (can be {@code null}).
+     */
+    public DistributionZoneBindTableException(String zoneName, @Nullable Throwable cause) {
+        super(ZONE_BIND_TABLE_ERR, "Distribution zone is assigned to the table [zoneName=" + zoneName + ']', cause);

Review Comment:
   OK. I added table name.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] sergeyuttsel commented on a diff in pull request #1477: IGNITE-18141 Added ability to bind tables with distribution zones on table creation.

Posted by GitBox <gi...@apache.org>.
sergeyuttsel commented on code in PR #1477:
URL: https://github.com/apache/ignite-3/pull/1477#discussion_r1065701708


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/ddl/CreateTableCommand.java:
##########
@@ -164,4 +167,20 @@ public void addDataStorageOption(String name, Object value) {
 
         dataStorageOptions.put(name, value);
     }
+
+    /**
+     * Get zone name.
+     */
+    @Nullable
+    public String zone() {
+        return zone;
+    }
+
+    /**
+     * Set zone name.
+     */
+    @Nullable

Review Comment:
   Removed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] xtern commented on a diff in pull request #1477: IGNITE-18141 Added ability to bind tables with distribution zones on table creation.

Posted by GitBox <gi...@apache.org>.
xtern commented on code in PR #1477:
URL: https://github.com/apache/ignite-3/pull/1477#discussion_r1065571895


##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/ddl/DdlCommandHandlerExceptionHandlingTest.java:
##########
@@ -89,8 +97,21 @@ void before() {
 
         DistributionZonesConfiguration zonesConfiguration = registry.getConfiguration(DistributionZonesConfiguration.KEY);
 
+        TablesConfiguration tablesConfiguration = mock(TablesConfiguration.class);
+
+        NamedConfigurationTree<TableConfiguration, TableView, TableChange> tables = mock(NamedConfigurationTree.class);
+
+        when(tablesConfiguration.tables()).thenReturn(tables);
+
+        NamedListView<TableView> value = mock(NamedListView.class);
+
+        when(tables.value()).thenReturn(value);
+
+        when(value.namedListKeys()).thenReturn(new ArrayList<>());
+
         distributionZoneManager = new DistributionZoneManager(
                 zonesConfiguration,
+                tablesConfiguration,

Review Comment:
   ```suggestion
                   null,
   ```
   Can you see the difference in test behavior without the `tableConfiguration` mock?



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/ddl/DdlSqlToCommandConverter.java:
##########
@@ -132,6 +133,7 @@ public DdlSqlToCommandConverter(
 
         this.tableOptionInfos = Map.of(
                 REPLICAS.name(), new DdlOptionInfo<>(Integer.class, this::checkPositiveNumber, CreateTableCommand::replicas),
+                PRIMARY_ZONE.name(), new DdlOptionInfo<>(String.class, null, CreateTableCommand::zone),
                 PARTITIONS.name(), new DdlOptionInfo<>(Integer.class, this::checkPositiveNumber, CreateTableCommand::partitions)
         );

Review Comment:
   ```suggestion
           this.tableOptionInfos = Map.of(
                   "PRIMARY_ZONE", new DdlOptionInfo<>(String.class, null, CreateTableCommand::zone),
                   REPLICAS.name(), new DdlOptionInfo<>(Integer.class, this::checkPositiveNumber, CreateTableCommand::replicas),
                   PARTITIONS.name(), new DdlOptionInfo<>(Integer.class, this::checkPositiveNumber, CreateTableCommand::partitions)
           );
   ```



##########
modules/distribution-zones/src/main/java/org/apache/ignite/internal/distributionzones/exception/DistributionZoneBindTableException.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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.internal.distributionzones.exception;
+
+import static org.apache.ignite.lang.ErrorGroups.DistributionZones.ZONE_BIND_TABLE_ERR;
+
+import java.util.UUID;
+import org.apache.ignite.lang.IgniteInternalException;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Exception is thrown when the distribution zone cannot be dropped because there is a table bound to the distribution zone.
+ */
+public class DistributionZoneBindTableException extends IgniteInternalException {
+    /**
+     * The constructor.
+     *
+     * @param zoneName Zone name.
+     */
+    public DistributionZoneBindTableException(String zoneName) {
+        this(zoneName, null);
+    }
+
+    /**
+     * The constructor.
+     *
+     * @param zoneName Zone name.
+     * @param cause Optional nested exception (can be {@code null}).
+     */
+    public DistributionZoneBindTableException(String zoneName, @Nullable Throwable cause) {
+        super(ZONE_BIND_TABLE_ERR, "Distribution zone is assigned to the table [zoneName=" + zoneName + ']', cause);

Review Comment:
   I don't insist, but I would also suggest listing all the related tables in the exception message. It seems that this may make life easier for someone in the future.



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/sql/IgniteSqlCreateTableOptionEnum.java:
##########
@@ -0,0 +1,26 @@
+/*
+ * 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.internal.sql.engine.sql;
+
+/**
+ * Enumerates the options for CREATE TABLE statement.
+ */
+public enum IgniteSqlCreateTableOptionEnum {
+    /** Distribution zone. */
+    PRIMARY_ZONE

Review Comment:
   Personally, it seems to me that it is not worth creating this enumerator yet.
   When we remove unnecessary options for creating a table (partitions, replicas, etc.), we will probably do refactoring and, if necessary, add such an enum.



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/ddl/CreateTableCommand.java:
##########
@@ -164,4 +167,20 @@ public void addDataStorageOption(String name, Object value) {
 
         dataStorageOptions.put(name, value);
     }
+
+    /**
+     * Get zone name.
+     */
+    @Nullable
+    public String zone() {
+        return zone;
+    }
+
+    /**
+     * Set zone name.
+     */
+    @Nullable

Review Comment:
   do not forget to remove



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] sanpwc commented on a diff in pull request #1477: IGNITE-18141 Added ability to bind tables with distribution zones on table creation.

Posted by GitBox <gi...@apache.org>.
sanpwc commented on code in PR #1477:
URL: https://github.com/apache/ignite-3/pull/1477#discussion_r1064745862


##########
modules/distribution-zones/build.gradle:
##########
@@ -36,6 +36,7 @@ dependencies {
     implementation project(':ignite-metastorage')
     implementation project(':ignite-vault')
     implementation project(':ignite-configuration')
+    implementation project(':ignite-schema')

Review Comment:
   Why? Do you really mean that zone depend on schemas now?



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/ddl/CreateTableCommand.java:
##########
@@ -164,4 +167,20 @@ public void addDataStorageOption(String name, Object value) {
 
         dataStorageOptions.put(name, value);
     }
+
+    /**
+     * Get zone name.
+     */
+    @Nullable

Review Comment:
   I don't think that we need Nullable here.



##########
modules/distribution-zones/src/main/java/org/apache/ignite/internal/distributionzones/DistributionZoneManager.java:
##########
@@ -354,6 +381,23 @@ public CompletableFuture<Void> dropZone(String name) {
         }
     }
 
+    /**
+     * Gets zone id by zone name.
+     *
+     * @param name Distribution zone name.
+     * @return The zone id.
+     * @throws DistributionZoneNotFoundException If the zone is not exist..
+     */
+    public int getZoneId(String name) {
+        DistributionZoneConfiguration zoneCfg = zonesConfiguration.distributionZones().get(name);

Review Comment:
   Not sure whether local evaluation is enough here. What do you think?



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/sql/IgniteSqlCreateTableOptionEnum.java:
##########
@@ -0,0 +1,26 @@
+/*
+ * 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.internal.sql.engine.sql;
+
+/**
+ * Enumerates the options for CREATE TABLE statement.
+ */
+public enum IgniteSqlCreateTableOptionEnum {
+    /** Distribution zone. */
+    PRIMARY_ZONE

Review Comment:
   It's the only option option? What about storage options, etc?



##########
modules/distribution-zones/src/main/java/org/apache/ignite/internal/distributionzones/DistributionZoneManager.java:
##########
@@ -328,20 +341,34 @@ public CompletableFuture<Void> dropZone(String name) {
             CompletableFuture<Void> fut = new CompletableFuture<>();
 
             zonesConfiguration.change(zonesChange -> zonesChange.changeDistributionZones(zonesListChange -> {
-                DistributionZoneView view = zonesListChange.get(name);
+                DistributionZoneView zoneView = zonesListChange.get(name);
 
-                if (view == null) {
+                if (zoneView == null) {
                     throw new DistributionZoneNotFoundException(name);
                 }
 
+                NamedConfigurationTree<TableConfiguration, TableView, TableChange> tables = tablesConfiguration.tables();
+
+                boolean bindTable = tables.value().namedListKeys().stream()
+                        .anyMatch(tableName -> {
+                            Integer tableZoneId = tables.get(tableName).zoneId().value();
+
+                            return tableZoneId != null && tableZoneId.equals(zoneView.zoneId());

Review Comment:
   How it's possible to have tableZoneId == null? Or you a going to remove this within the scope of the default zone ticket?



##########
modules/distribution-zones/src/main/java/org/apache/ignite/internal/distributionzones/DistributionZoneManager.java:
##########
@@ -328,20 +341,34 @@ public CompletableFuture<Void> dropZone(String name) {
             CompletableFuture<Void> fut = new CompletableFuture<>();
 
             zonesConfiguration.change(zonesChange -> zonesChange.changeDistributionZones(zonesListChange -> {
-                DistributionZoneView view = zonesListChange.get(name);
+                DistributionZoneView zoneView = zonesListChange.get(name);
 
-                if (view == null) {
+                if (zoneView == null) {
                     throw new DistributionZoneNotFoundException(name);
                 }
 
+                NamedConfigurationTree<TableConfiguration, TableView, TableChange> tables = tablesConfiguration.tables();
+
+                boolean bindTable = tables.value().namedListKeys().stream()

Review Comment:
   As far as I understand, you are checking table existence through **local** tables configuration, how do you guarantee that it won't be possible to remove zone with bindings about which this node doesn't know yet?



##########
modules/distribution-zones/src/main/java/org/apache/ignite/internal/distributionzones/exception/DistributionZoneAlreadyExistsException.java:
##########
@@ -27,6 +27,15 @@
  * because a distribution zone with same name already exists.
  */
 public class DistributionZoneAlreadyExistsException extends IgniteInternalException {
+    /**
+     * The constructor.
+     *
+     * @param zoneName Zone name.
+     */
+    public DistributionZoneAlreadyExistsException(String zoneName) {

Review Comment:
   Seems that given constructor has no usages.



##########
modules/distribution-zones/src/main/java/org/apache/ignite/internal/distributionzones/exception/DistributionZoneBindTableException.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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.internal.distributionzones.exception;
+
+import static org.apache.ignite.lang.ErrorGroups.DistributionZones.ZONE_BIND_TABLE_ERR;
+
+import java.util.UUID;
+import org.apache.ignite.lang.IgniteInternalException;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Exception is thrown when the distribution zone cannot be dropped because there is a table bound to the distribution zone.
+ */
+public class DistributionZoneBindTableException extends IgniteInternalException {
+    /**
+     * The constructor.
+     *
+     * @param zoneName Zone name.
+     */
+    public DistributionZoneBindTableException(String zoneName) {
+        this(zoneName, null);
+    }
+
+    /**
+     * The constructor.
+     *
+     * @param zoneName Zone name.
+     * @param cause Optional nested exception (can be {@code null}).
+     */
+    public DistributionZoneBindTableException(String zoneName, @Nullable Throwable cause) {
+        super(ZONE_BIND_TABLE_ERR, "Distribution zone is assigned to the table [zoneName=" + zoneName + ']', cause);

Review Comment:
   Should we also mention a table that has a reference to our distribution zone?



##########
modules/distribution-zones/src/main/java/org/apache/ignite/internal/distributionzones/DistributionZoneManager.java:
##########
@@ -328,20 +341,34 @@ public CompletableFuture<Void> dropZone(String name) {
             CompletableFuture<Void> fut = new CompletableFuture<>();
 
             zonesConfiguration.change(zonesChange -> zonesChange.changeDistributionZones(zonesListChange -> {
-                DistributionZoneView view = zonesListChange.get(name);
+                DistributionZoneView zoneView = zonesListChange.get(name);
 
-                if (view == null) {
+                if (zoneView == null) {
                     throw new DistributionZoneNotFoundException(name);
                 }
 
+                NamedConfigurationTree<TableConfiguration, TableView, TableChange> tables = tablesConfiguration.tables();
+
+                boolean bindTable = tables.value().namedListKeys().stream()
+                        .anyMatch(tableName -> {

Review Comment:
   Do we really need that tableName -> get(tableName) mapping? What about using
   `tables.value().get(i) ` where i is from for loop on top of `tables.value().size() `?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] sergeyuttsel commented on a diff in pull request #1477: IGNITE-18141 Added ability to bind tables with distribution zones on table creation.

Posted by GitBox <gi...@apache.org>.
sergeyuttsel commented on code in PR #1477:
URL: https://github.com/apache/ignite-3/pull/1477#discussion_r1065418827


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/ddl/CreateTableCommand.java:
##########
@@ -164,4 +167,20 @@ public void addDataStorageOption(String name, Object value) {
 
         dataStorageOptions.put(name, value);
     }
+
+    /**
+     * Get zone name.
+     */
+    @Nullable

Review Comment:
   Ok, I removed it. But stay it on `public String zone()`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] sergeyuttsel commented on a diff in pull request #1477: IGNITE-18141 Added ability to bind tables with distribution zones on table creation.

Posted by GitBox <gi...@apache.org>.
sergeyuttsel commented on code in PR #1477:
URL: https://github.com/apache/ignite-3/pull/1477#discussion_r1065409596


##########
modules/distribution-zones/src/main/java/org/apache/ignite/internal/distributionzones/DistributionZoneManager.java:
##########
@@ -328,20 +341,34 @@ public CompletableFuture<Void> dropZone(String name) {
             CompletableFuture<Void> fut = new CompletableFuture<>();
 
             zonesConfiguration.change(zonesChange -> zonesChange.changeDistributionZones(zonesListChange -> {
-                DistributionZoneView view = zonesListChange.get(name);
+                DistributionZoneView zoneView = zonesListChange.get(name);
 
-                if (view == null) {
+                if (zoneView == null) {
                     throw new DistributionZoneNotFoundException(name);
                 }
 
+                NamedConfigurationTree<TableConfiguration, TableView, TableChange> tables = tablesConfiguration.tables();
+
+                boolean bindTable = tables.value().namedListKeys().stream()
+                        .anyMatch(tableName -> {

Review Comment:
   Fixed. Thanks.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org