ivanzlenko commented on code in PR #7598:
URL: https://github.com/apache/ignite-3/pull/7598#discussion_r2818100759


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/PartitionSafeTimeValidator.java:
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.table.distributed.raft;
+
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.catalog.CatalogService;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import 
org.apache.ignite.internal.partition.replicator.network.command.TableAwareCommand;
+import 
org.apache.ignite.internal.partition.replicator.network.command.UpdateCommandBase;
+import 
org.apache.ignite.internal.partition.replicator.schema.ValidationSchemasSource;
+import 
org.apache.ignite.internal.partition.replicator.schemacompat.CompatValidationResult;
+import 
org.apache.ignite.internal.partition.replicator.schemacompat.SchemaCompatibilityValidator;
+import org.apache.ignite.internal.raft.WriteCommand;
+import org.apache.ignite.internal.schema.SchemaSyncService;
+import org.apache.ignite.raft.jraft.option.SafeTimeValidationResult;
+import org.apache.ignite.raft.jraft.option.SafeTimeValidator;
+
+/**
+ * Validator for partition commands.
+ *
+ * <ul>
+ * <li>requests a retry for full (1PC) update commands that require metadata 
to be available by safe time if that metadata
+ * is not yet available;</li>
+ * <li>rejects full (1PC) update commands whose commitTs fails schema 
compatibility validation (the caller is expected to retry the
+ * corresponding implicit transaction).</li>
+ * </ul>
+ */
+public class PartitionSafeTimeValidator implements SafeTimeValidator {
+    private static final IgniteLogger LOG = 
Loggers.forClass(PartitionSafeTimeValidator.class);
+
+    private final SchemaCompatibilityValidator schemaCompatibilityValidator;
+
+    public PartitionSafeTimeValidator(
+            ValidationSchemasSource validationSchemasSource,
+            CatalogService catalogService,
+            SchemaSyncService schemaSyncService
+    ) {
+        schemaCompatibilityValidator = new 
SchemaCompatibilityValidator(validationSchemasSource, catalogService, 
schemaSyncService);
+    }
+
+    @Override
+    public boolean shouldValidateFor(WriteCommand command) {
+        return command instanceof UpdateCommandBase
+                && ((UpdateCommandBase) command).full()
+                && command instanceof TableAwareCommand;
+    }
+
+    @Override
+    public SafeTimeValidationResult validate(String groupId, WriteCommand 
command, HybridTimestamp safeTime) {
+        UpdateCommandBase updateCommand = (UpdateCommandBase) command;
+
+        CompletableFuture<CompatValidationResult> future = 
schemaCompatibilityValidator.validateCommit(
+                updateCommand.txId(),
+                Set.of(((TableAwareCommand) updateCommand).tableId()),
+                safeTime
+        );
+
+        if (!future.isDone()) {
+            // TODO: IGNITE-20298 - throttle logging.
+            LOG.warn(
+                    "Metadata not yet available by safe time, rejecting 
ActionRequest with EBUSY [group={}, requiredLevel={}].",

Review Comment:
   Isn't requiredLevel should be safeTime?



##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/schemacompat/CompatValidationResult.java:
##########
@@ -17,6 +17,8 @@
 
 package org.apache.ignite.internal.partition.replicator.schemacompat;
 
+import static org.apache.ignite.internal.lang.IgniteStringFormatter.format;

Review Comment:
   I genuinely feel we need to stick either to our formatter or to build-in 
one. I can see usage of both spread throughout code base. 



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/schema/MetadataSufficiency.java:
##########
@@ -34,7 +36,19 @@ private CatalogVersionSufficiency() {
      * @param catalogService Catalog service.
      * @return {@code true} iff the local Catalog version is sufficient.
      */
-    public static boolean isMetadataAvailableFor(int requiredCatalogVersion, 
CatalogService catalogService) {
+    public static boolean isMetadataAvailableForCatalogVersion(int 
requiredCatalogVersion, CatalogService catalogService) {
         return 
catalogService.catalogReadyFuture(requiredCatalogVersion).isDone();
     }
+
+    /**
+     * Determines whether the local schema information is sufficient up to the 
given timestamp
+     * (that is that schema sync on the timestamp will complete immediately 
without any waits).
+     *
+     * @param timestamp Minimal timestamp at which the metadata is required to 
present.
+     * @param schemaSyncService Schema synchronization service.
+     * @return {@code true} iff the local schema information is sufficient.
+     */
+    public static boolean isMetadataAvailableForTimestamp(HybridTimestamp 
timestamp, SchemaSyncService schemaSyncService) {

Review Comment:
   This method is not used anywhere



##########
modules/raft/src/main/java/org/apache/ignite/raft/jraft/core/NodeImpl.java:
##########
@@ -1788,6 +1795,31 @@ private void executeApplyingTasks(final 
List<LogEntryAndClosure> tasks) {
         return safeTs;
     }
 
+    private boolean rejectCommandIfSafeTimeIsNotAcceptable(@Nullable 
HybridTimestamp safeTs, LogEntryAndClosure task) {

Review Comment:
   isSafeTimeCommandIsNotAcceptable feels better to me. Reject implies void 
action.



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/schema/CheckCatalogVersionOnActionRequest.java:
##########
@@ -83,18 +83,19 @@ public CheckCatalogVersionOnActionRequest(CatalogService 
catalogService) {
                 OptimizedMarshaller.ORDER));
 
         if (requiredCatalogVersion >= 0) {
-            if (!isMetadataAvailableFor(requiredCatalogVersion, 
catalogService)) {
+            if (!isMetadataAvailableForCatalogVersion(requiredCatalogVersion, 
catalogService)) {
                 // TODO: IGNITE-20298 - throttle logging.
                 LOG.warn(
-                        "Metadata not yet available, rejecting ActionRequest 
with EBUSY [group={}, requiredLevel={}].",
+                        "Metadata not yet available by catalog version, 
rejecting ActionRequest with EBUSY [group={}, requiredLevel={}].",

Review Comment:
   The same thing about message and formater here.



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/schema/MetadataSufficiency.java:
##########
@@ -18,12 +18,14 @@
 package org.apache.ignite.internal.table.distributed.schema;
 
 import org.apache.ignite.internal.catalog.CatalogService;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.schema.SchemaSyncService;
 
 /**
- * Logic that allows to determine whether the logcal Catalog version is 
sufficient.
+ * Logic that allows to determine whether the local schema metadata is 
sufficient.
  */
-public class CatalogVersionSufficiency {
-    private CatalogVersionSufficiency() {
+public class MetadataSufficiency {

Review Comment:
   I would've remove this class altogether.



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/schema/CheckCatalogVersionOnAppendEntries.java:
##########
@@ -67,7 +67,8 @@ public CheckCatalogVersionOnAppendEntries(CatalogService 
catalogService) {
         for (RaftOutter.EntryMeta entry : request.entriesList()) {
             int requiredCatalogVersion = 
readRequiredCatalogVersionForMeta(allData, entry, 
node.getOptions().getCommandsMarshaller());
 
-            if (requiredCatalogVersion != NO_VERSION_REQUIRED && 
!isMetadataAvailableFor(requiredCatalogVersion, catalogService)) {
+            if (requiredCatalogVersion != NO_VERSION_REQUIRED
+                    && 
!isMetadataAvailableForCatalogVersion(requiredCatalogVersion, catalogService)) {
                 // TODO: IGNITE-20298 - throttle logging.
                 LOG.warn(

Review Comment:
   The same thing about message and formater here.



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/PartitionSafeTimeValidator.java:
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.table.distributed.raft;
+
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.catalog.CatalogService;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import 
org.apache.ignite.internal.partition.replicator.network.command.TableAwareCommand;
+import 
org.apache.ignite.internal.partition.replicator.network.command.UpdateCommandBase;
+import 
org.apache.ignite.internal.partition.replicator.schema.ValidationSchemasSource;
+import 
org.apache.ignite.internal.partition.replicator.schemacompat.CompatValidationResult;
+import 
org.apache.ignite.internal.partition.replicator.schemacompat.SchemaCompatibilityValidator;
+import org.apache.ignite.internal.raft.WriteCommand;
+import org.apache.ignite.internal.schema.SchemaSyncService;
+import org.apache.ignite.raft.jraft.option.SafeTimeValidationResult;
+import org.apache.ignite.raft.jraft.option.SafeTimeValidator;
+
+/**
+ * Validator for partition commands.
+ *
+ * <ul>
+ * <li>requests a retry for full (1PC) update commands that require metadata 
to be available by safe time if that metadata
+ * is not yet available;</li>
+ * <li>rejects full (1PC) update commands whose commitTs fails schema 
compatibility validation (the caller is expected to retry the
+ * corresponding implicit transaction).</li>
+ * </ul>
+ */
+public class PartitionSafeTimeValidator implements SafeTimeValidator {
+    private static final IgniteLogger LOG = 
Loggers.forClass(PartitionSafeTimeValidator.class);
+
+    private final SchemaCompatibilityValidator schemaCompatibilityValidator;
+
+    public PartitionSafeTimeValidator(
+            ValidationSchemasSource validationSchemasSource,
+            CatalogService catalogService,
+            SchemaSyncService schemaSyncService
+    ) {
+        schemaCompatibilityValidator = new 
SchemaCompatibilityValidator(validationSchemasSource, catalogService, 
schemaSyncService);
+    }
+
+    @Override
+    public boolean shouldValidateFor(WriteCommand command) {
+        return command instanceof UpdateCommandBase
+                && ((UpdateCommandBase) command).full()
+                && command instanceof TableAwareCommand;
+    }
+
+    @Override
+    public SafeTimeValidationResult validate(String groupId, WriteCommand 
command, HybridTimestamp safeTime) {
+        UpdateCommandBase updateCommand = (UpdateCommandBase) command;
+
+        CompletableFuture<CompatValidationResult> future = 
schemaCompatibilityValidator.validateCommit(
+                updateCommand.txId(),
+                Set.of(((TableAwareCommand) updateCommand).tableId()),
+                safeTime
+        );
+
+        if (!future.isDone()) {
+            // TODO: IGNITE-20298 - throttle logging.
+            LOG.warn(
+                    "Metadata not yet available by safe time, rejecting 
ActionRequest with EBUSY [group={}, requiredLevel={}].",
+                    groupId, safeTime
+            );
+
+            return SafeTimeValidationResult.forRetry(
+                    String.format(
+                            "Metadata not yet available by safe time, 
rejecting ActionRequest with EBUSY [group=%s, safeTs=%s].",

Review Comment:
   In that case I would've use our formatter instead of java one and just share 
the message between this 2 invocations. Just to avoid any errors in the message.



##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/schemacompat/CompatValidationResult.java:
##########
@@ -17,6 +17,8 @@
 
 package org.apache.ignite.internal.partition.replicator.schemacompat;
 
+import static org.apache.ignite.internal.lang.IgniteStringFormatter.format;

Review Comment:
   the upside of using built-in one: IDE will highlight if you messed up with 
parameters



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to