sanpwc commented on code in PR #5484:
URL: https://github.com/apache/ignite-3/pull/5484#discussion_r2010072903


##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/TableAwareReplicaRequestPreProcessor.java:
##########
@@ -0,0 +1,186 @@
+/*
+ * 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.partition.replicator;
+
+import static 
org.apache.ignite.internal.lang.IgniteSystemProperties.enabledColocation;
+
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.hlc.ClockService;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import 
org.apache.ignite.internal.partition.replicator.network.replication.BuildIndexReplicaRequest;
+import 
org.apache.ignite.internal.partition.replicator.network.replication.GetEstimatedSizeRequest;
+import 
org.apache.ignite.internal.partition.replicator.network.replication.ReadOnlyReplicaRequest;
+import 
org.apache.ignite.internal.partition.replicator.network.replication.ReadWriteReplicaRequest;
+import 
org.apache.ignite.internal.partition.replicator.network.replication.ScanCloseReplicaRequest;
+import 
org.apache.ignite.internal.partition.replicator.schemacompat.SchemaCompatibilityValidator;
+import 
org.apache.ignite.internal.replicator.message.ReadOnlyDirectReplicaRequest;
+import org.apache.ignite.internal.replicator.message.ReplicaRequest;
+import 
org.apache.ignite.internal.replicator.message.SchemaVersionAwareReplicaRequest;
+import org.apache.ignite.internal.replicator.message.TableAware;
+import org.apache.ignite.internal.schema.SchemaSyncService;
+import org.apache.ignite.internal.tx.TransactionIds;
+import 
org.apache.ignite.internal.tx.message.TableWriteIntentSwitchReplicaRequest;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * TableAware requests pre processor.
+ */
+public class TableAwareReplicaRequestPreProcessor {
+    private final ClockService clockService;
+
+    private final SchemaCompatibilityValidator schemaCompatValidator;
+
+    private final SchemaSyncService schemaSyncService;
+
+    /** Constructor. */
+    public TableAwareReplicaRequestPreProcessor(
+            ClockService clockService,
+            SchemaCompatibilityValidator schemaCompatValidator,
+            SchemaSyncService schemaSyncService
+    ) {
+        this.clockService = clockService;
+        this.schemaCompatValidator = schemaCompatValidator;
+        this.schemaSyncService = schemaSyncService;
+    }
+
+    /**
+     * Pre processes {@link TableAware} request.
+     *
+     * @param request Request to be processed.
+     * @param replicaPrimacy Replica primacy information.
+     * @param senderId Node sender id.
+     * @return Future with the result of the request.
+     */
+    public CompletableFuture<Void> preProcessTableAwareRequest(
+            ReplicaRequest request,
+            ReplicaPrimacy replicaPrimacy,
+            UUID senderId
+    ) {
+        // TODO https://issues.apache.org/jira/browse/IGNITE-22522 add
+        //  assert request instanceof TableAware : "Request should be 
TableAware [request=" + request.getClass().getSimpleName() + ']';
+
+        HybridTimestamp opTs = getOperationTimestamp(request);
+
+        if (enabledColocation()) {
+            assert opTs != null : "Table aware operation timestamp must not be 
null [request=" + request + ']';
+        }
+
+        @Nullable HybridTimestamp opTsIfDirectRo = (request instanceof 
ReadOnlyDirectReplicaRequest) ? opTs : null;
+        @Nullable HybridTimestamp txTs = getTxStartTimestamp(request);
+        if (txTs == null) {
+            txTs = opTsIfDirectRo;
+        }
+
+        assert txTs == null || opTs.compareTo(txTs) >= 0 : "Tx started at " + 
txTs + ", but opTs precedes it: " + opTs
+                + "; request " + request;
+
+        assert txTs == null
+                ? request instanceof GetEstimatedSizeRequest || request 
instanceof ScanCloseReplicaRequest
+                || request instanceof BuildIndexReplicaRequest || request 
instanceof TableWriteIntentSwitchReplicaRequest
+                : opTs.compareTo(txTs) >= 0 :
+                "Invalid request timestamps [request=" + request + ']';
+
+        int tableId = ((TableAware) request).tableId();
+
+        @Nullable HybridTimestamp finalTxTs = txTs;
+        Runnable validateClo = () -> {
+            schemaCompatValidator.failIfTableDoesNotExistAt(opTs, tableId);
+
+            boolean hasSchemaVersion = request instanceof 
SchemaVersionAwareReplicaRequest;
+
+            if (hasSchemaVersion) {
+                SchemaVersionAwareReplicaRequest versionAwareRequest = 
(SchemaVersionAwareReplicaRequest) request;
+
+                schemaCompatValidator.failIfRequestSchemaDiffersFromTxTs(
+                        finalTxTs,
+                        versionAwareRequest.schemaVersion(),
+                        tableId
+                );
+            }
+        };
+
+        return 
schemaSyncService.waitForMetadataCompleteness(opTs).thenRun(validateClo);
+    }
+
+    /**
+     * Returns the txn operation timestamp.

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

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

Reply via email to