vldpyatkov commented on code in PR #1871: URL: https://github.com/apache/ignite-3/pull/1871#discussion_r1165603167
########## modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/leases/Lease.java: ########## @@ -0,0 +1,146 @@ +/* + * 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.placementdriver.leases; + +import static org.apache.ignite.internal.hlc.HybridTimestamp.MIN_VALUE; + +import java.io.Serializable; +import org.apache.ignite.internal.hlc.HybridTimestamp; +import org.apache.ignite.network.ClusterNode; + +/** + * A lease representation in memory. + * The real lease is stored in Meta storage. + */ +public class Lease implements Serializable { + /** The object is used when nothing holds the lease. Empty lease is always expired. */ + public static Lease EMPTY_LEASE = new Lease(null, MIN_VALUE, MIN_VALUE, false); + + /** A node that holds a lease until {@code stopLeas}. */ + private final ClusterNode leaseholder; + + /** The lease is accepted, when the holder knows about it and applies all related obligations. */ + private final boolean accepted; + + /** Lease start timestamp. The timestamp is assigned when the lease created and is not changed when the lease is prolonged. */ + private final HybridTimestamp startTime; + + /** Timestamp to expiration the lease. */ + private final HybridTimestamp expirationTime; + + /** + * Creates a new lease. + * + * @param leaseholder Lease holder. + * @param startTime Start lease timestamp. + * @param leaseExpirationTime Lease expiration timestamp. + */ + public Lease(ClusterNode leaseholder, HybridTimestamp startTime, HybridTimestamp leaseExpirationTime) { + this(leaseholder, startTime, leaseExpirationTime, false); + } + + /** + * The constructor. + * + * @param leaseholder Lease holder. + * @param startTime Start lease timestamp. + * @param leaseExpirationTime Lease expiration timestamp. + * @param accepted The flag is true when the holder accepted the lease, the false otherwise. + */ + private Lease(ClusterNode leaseholder, HybridTimestamp startTime, HybridTimestamp leaseExpirationTime, boolean accepted) { + this.leaseholder = leaseholder; + this.expirationTime = leaseExpirationTime; + this.startTime = startTime; + this.accepted = accepted; + } + + /** + * Prolongs a lease until new timestamp. Only an accepted lease can be prolonged. + * + * @param to The new lease expiration timestamp. + * @return A new lease which will have the same properties except of expiration timestamp. + */ + public Lease prolongLease(HybridTimestamp to) { + assert accepted : "The lease should be accepted by leaseholder before prolongation [" Review Comment: Not clear. This method cannot be called with not accepted lease. -- 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]
