rpuch commented on code in PR #5352: URL: https://github.com/apache/ignite-3/pull/5352#discussion_r1983100271
########## modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/ReplicaPrimacy.java: ########## @@ -0,0 +1,79 @@ +/* + * 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 java.util.Objects.requireNonNull; + +import org.apache.ignite.internal.partition.replicator.network.replication.ReadOnlyReplicaRequest; +import org.apache.ignite.internal.replicator.message.PrimaryReplicaRequest; +import org.apache.ignite.internal.replicator.message.ReplicaSafeTimeSyncRequest; +import org.jetbrains.annotations.Nullable; + +/** + * Represents replica primacy info. Contains the following information: + * + * <ul> + * <li>{@code leaseStartTime} - the moment when the replica became primary (only filled for {@link PrimaryReplicaRequest}s)</li> + * <li>{@code isPrimary} - whether this node currently hosts the primary (only filled for {@link ReadOnlyReplicaRequest}s + * and {@link ReplicaSafeTimeSyncRequest}s)</li> + * </ul> + */ +public class ReplicaPrimacy { + private final @Nullable Long leaseStartTime; + private final @Nullable Boolean isPrimary; + + private ReplicaPrimacy(@Nullable Long leaseStartTime, @Nullable Boolean isPrimary) { + this.leaseStartTime = leaseStartTime; + this.isPrimary = isPrimary; + } + + /** + * Creates an instance representing no primacy information. + */ + public static ReplicaPrimacy empty() { + return new ReplicaPrimacy(null, null); + } + + /** + * Creates an instance representing information about the primary replica held by this node. + */ + static ReplicaPrimacy forPrimaryReplicaRequest(long leaseStartTime) { Review Comment: `isPrimary == true` has fewer checks than `leaseStartTime != null`. The former requires that we know some primary and this primary is hosted on this node. The latter requires this, AND that the primary is not expired AND that the token matches. 'Token matches' condition can only be checked for PrimaryReplicaRequests, so we cannot unify these two fields, as it seems. But I wonder why the `isPrimary` check does not verify lease expiration. I filed an issue about this https://issues.apache.org/jira/browse/IGNITE-24714 -- 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-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org