vldpyatkov commented on code in PR #927:
URL: https://github.com/apache/ignite-3/pull/927#discussion_r921011973


##########
modules/replicator/src/main/java/org/apache/ignite/internal/replicator/Replica.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.replicator;
+
+import org.apache.ignite.internal.replicator.message.ReadOnlyMultyEntryRequest;
+import org.apache.ignite.internal.replicator.message.ReadOnlyRequest;
+import 
org.apache.ignite.internal.replicator.message.ReadOnlySingleEntryRequest;
+import 
org.apache.ignite.internal.replicator.message.ReadWriteMultiEntryRequest;
+import org.apache.ignite.internal.replicator.message.ReadWriteRequest;
+import 
org.apache.ignite.internal.replicator.message.ReadWriteSingleEntryRequest;
+import org.apache.ignite.internal.replicator.message.ReplicaMessagesFactory;
+import org.apache.ignite.internal.replicator.message.ReplicaRequest;
+import org.apache.ignite.internal.replicator.message.ReplicaResponse;
+import 
org.apache.ignite.internal.replicator.message.container.MultiEntryContainer;
+import 
org.apache.ignite.internal.replicator.message.container.SingleEntryContainer;
+import org.apache.ignite.lang.IgniteInternalException;
+import org.apache.ignite.lang.IgniteStringFormatter;
+import org.apache.ignite.network.ClusterNode;
+import org.apache.ignite.network.TopologyService;
+
+/**
+ * Replica server.
+ * TODO:IGNITE-17257 Implement Replica server-side logic.
+ */
+public class Replica implements AutoCloseable {
+    /** Replicator network message factory. */
+    private static final ReplicaMessagesFactory REPLICA_MESSAGES_FACTORY = new 
ReplicaMessagesFactory();
+
+    /** Replica group identity, this id is the same as the considered 
partition's id. */
+    private final String partitionId;
+
+    /** Local cluster node. */
+    private final ClusterNode localNode;
+
+    /** Replica listener. */
+    private final ReplicaListener listener;
+
+    /**
+     * The constructor of replica server.
+     *
+     * @param partitionId Identity.
+     * @param topologyService Topology service.
+     * @param listener Replica listener.
+     */
+    public Replica(
+            String partitionId,
+            TopologyService topologyService,
+            ReplicaListener listener
+    ) {
+        this.partitionId = partitionId;
+        this.localNode = topologyService.localMember();
+        this.listener = listener;
+    }
+
+    /**
+     * It is an internal method to applies a RW request to replicator.
+     *
+     * @param req Request to apply in replicator.
+     * @return Response.
+     */
+    private ReplicaResponse applyReadWriteCommandInternal(ReadWriteRequest 
req) {
+        //TODO: Check locks here.
+        if (req instanceof ReadWriteSingleEntryRequest) {
+            var request = (ReadWriteSingleEntryRequest) req;
+
+            var data = (SingleEntryContainer) 
listener.applyReadWrite(req.txId(), request.entryContainer(), req.opType());
+
+            return REPLICA_MESSAGES_FACTORY
+                    .singleEntryResponse()
+                    .partitionId(partitionId)
+                    .entryContainer(data)
+                    .build();
+        } else if (req instanceof ReadWriteMultiEntryRequest) {
+            var request = (ReadWriteMultiEntryRequest) req;
+
+            var data = (MultiEntryContainer) 
listener.applyReadWrite(req.txId(), request.entryContainer(), req.opType());
+
+            return REPLICA_MESSAGES_FACTORY
+                    .multiEntryResponse()

Review Comment:
   In most cases, multi request leads to multi response, but nothing limits 
other way for some operation (or pass the response with null container, if the 
operation does not return any data).



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