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 2023/01/09 15:58:54 UTC

[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.

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