tkalkirill commented on code in PR #1869: URL: https://github.com/apache/ignite-3/pull/1869#discussion_r1159979792
########## modules/raft/src/main/java/org/apache/ignite/raft/jraft/rpc/impl/ActionRequestProcessor.java: ########## @@ -19,8 +19,8 @@ import java.io.Serializable; import java.nio.ByteBuffer; import java.util.List; -import java.util.concurrent.Executor; -import org.apache.ignite.internal.logger.IgniteLogger; +import java.util.concurrent.CompletableFuture;import java.util.concurrent.Executor; +import java.util.function.BiFunction;import org.apache.ignite.internal.logger.IgniteLogger; Review Comment: ```suggestion import java.util.function.BiFunction; import org.apache.ignite.internal.logger.IgniteLogger; ``` ########## modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/server/time/ClusterTimeImpl.java: ########## @@ -0,0 +1,147 @@ +/* + * 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.metastorage.server.time; + +import java.util.concurrent.CompletableFuture; +import org.apache.ignite.internal.hlc.HybridClock; +import org.apache.ignite.internal.hlc.HybridTimestamp; +import org.apache.ignite.internal.metastorage.impl.MetaStorageServiceImpl; +import org.apache.ignite.internal.util.IgniteSpinBusyLock; +import org.apache.ignite.internal.util.PendingComparableValuesTracker; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.TestOnly; + +/** + * Cluster time implementation with additional methods to adjust time and update safe time. + */ +public class ClusterTimeImpl implements ClusterTime { + private final IgniteSpinBusyLock busyLock; + + private volatile @Nullable LeaderTimer leaderTimer; + + private final HybridClock clock; + + private final PendingComparableValuesTracker<HybridTimestamp> safeTime; + + /** + * Constructor. + * + * @param busyLock Busy lock. + * @param clock Node's hybrid clock. + */ + public ClusterTimeImpl(IgniteSpinBusyLock busyLock, HybridClock clock) { + this.busyLock = busyLock; + this.clock = clock; + this.safeTime = new PendingComparableValuesTracker<>(clock.now()); + } + + /** + * Starts sync time scheduler. + * + * @param service MetaStorage service that is used by scheduler to sync time. + */ + public void startLeaderTimer(MetaStorageServiceImpl service) { + if (!busyLock.enterBusy()) { + return; + } + + try { + assert leaderTimer == null; + + LeaderTimer newTimer = new LeaderTimer(service); + + leaderTimer = newTimer; + + newTimer.start(); + } finally { + busyLock.leaveBusy(); + } + } + + /** + * Stops sync time scheduler if it exists. + */ + public void stopLeaderTimer() { + LeaderTimer timer = leaderTimer; + + if (timer != null) { + timer.stop(); + + leaderTimer = null; + } + } + + @Override + public HybridTimestamp now() { + return clock.now(); + } + + @Override + public CompletableFuture<Void> waitFor(HybridTimestamp time) { + return safeTime.waitFor(time); + } + + public void updateSafeTime(HybridTimestamp ts) { Review Comment: Please add in the description of the method why it is, how it differs from `adjust`. ########## modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/server/time/ClusterTimeImpl.java: ########## @@ -0,0 +1,172 @@ +/* + * 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.metastorage.server.time; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executors; +import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.internal.hlc.HybridClock; +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.metastorage.impl.MetaStorageServiceImpl; +import org.apache.ignite.internal.thread.NamedThreadFactory; +import org.apache.ignite.internal.util.IgniteSpinBusyLock; +import org.apache.ignite.internal.util.IgniteUtils; +import org.apache.ignite.internal.util.PendingComparableValuesTracker; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.TestOnly; + +/** + * Cluster time implementation with additional methods to adjust time and update safe time. + */ +public class ClusterTimeImpl implements ClusterTime { + /** The logger. */ + private static final IgniteLogger LOG = Loggers.forClass(ClusterTimeImpl.class); + + private final IgniteSpinBusyLock busyLock; + + private volatile @Nullable LeaderTimer leaderTimer; + + private final HybridClock clock; + + private final PendingComparableValuesTracker<HybridTimestamp> safeTime; + + /** + * Constructor. + * + * @param busyLock Busy lock. + * @param clock Node's hybrid clock. + */ + public ClusterTimeImpl(IgniteSpinBusyLock busyLock, HybridClock clock) { + this.busyLock = busyLock; + this.clock = clock; + this.safeTime = new PendingComparableValuesTracker<>(clock.now()); + } + + /** + * Starts sync time scheduler. + * + * @param service MetaStorage service that is used by scheduler to sync time. + */ + public void startLeaderTimer(MetaStorageServiceImpl service) { + if (!busyLock.enterBusy()) { + return; + } + + try { + assert leaderTimer == null; + + LeaderTimer newTimer = new LeaderTimer(service); + + leaderTimer = newTimer; + + newTimer.start(); + } finally { + busyLock.leaveBusy(); + } + } + + /** + * Stops sync time scheduler. + */ + public void stopLeaderTimer() { + LeaderTimer timer = leaderTimer; + + assert timer != null; + + timer.stop(); + + leaderTimer = null; + } + + @Override + public HybridTimestamp now() { + return clock.now(); + } + + @Override + public CompletableFuture<Void> waitFor(HybridTimestamp time) { + return safeTime.waitFor(time); + } + + public void updateSafeTime(HybridTimestamp ts) { + this.safeTime.update(ts); + } + + public void adjust(HybridTimestamp ts) { Review Comment: Please add in the description of the method why it is. ########## modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/server/time/ClusterTimeImpl.java: ########## @@ -0,0 +1,172 @@ +/* + * 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.metastorage.server.time; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executors; +import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.internal.hlc.HybridClock; +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.metastorage.impl.MetaStorageServiceImpl; +import org.apache.ignite.internal.thread.NamedThreadFactory; +import org.apache.ignite.internal.util.IgniteSpinBusyLock; +import org.apache.ignite.internal.util.IgniteUtils; +import org.apache.ignite.internal.util.PendingComparableValuesTracker; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.TestOnly; + +/** + * Cluster time implementation with additional methods to adjust time and update safe time. + */ +public class ClusterTimeImpl implements ClusterTime { + /** The logger. */ + private static final IgniteLogger LOG = Loggers.forClass(ClusterTimeImpl.class); + + private final IgniteSpinBusyLock busyLock; + + private volatile @Nullable LeaderTimer leaderTimer; + + private final HybridClock clock; + + private final PendingComparableValuesTracker<HybridTimestamp> safeTime; + + /** + * Constructor. + * + * @param busyLock Busy lock. + * @param clock Node's hybrid clock. + */ + public ClusterTimeImpl(IgniteSpinBusyLock busyLock, HybridClock clock) { + this.busyLock = busyLock; + this.clock = clock; + this.safeTime = new PendingComparableValuesTracker<>(clock.now()); + } + + /** + * Starts sync time scheduler. + * + * @param service MetaStorage service that is used by scheduler to sync time. + */ + public void startLeaderTimer(MetaStorageServiceImpl service) { + if (!busyLock.enterBusy()) { + return; + } + + try { + assert leaderTimer == null; + + LeaderTimer newTimer = new LeaderTimer(service); + + leaderTimer = newTimer; + + newTimer.start(); + } finally { + busyLock.leaveBusy(); + } + } + + /** + * Stops sync time scheduler. + */ + public void stopLeaderTimer() { + LeaderTimer timer = leaderTimer; + + assert timer != null; + + timer.stop(); + + leaderTimer = null; + } + + @Override + public HybridTimestamp now() { + return clock.now(); + } + + @Override + public CompletableFuture<Void> waitFor(HybridTimestamp time) { + return safeTime.waitFor(time); + } + + public void updateSafeTime(HybridTimestamp ts) { + this.safeTime.update(ts); + } + + public void adjust(HybridTimestamp ts) { + this.clock.update(ts); + } + + private class LeaderTimer { Review Comment: It would be nice, I think. ########## modules/raft-api/src/main/java/org/apache/ignite/internal/raft/service/RaftGroupListener.java: ########## @@ -81,4 +82,13 @@ default void onConfigurationCommitted(CommittedConfiguration config) { * Invoked once after a raft node has been shut down. */ void onShutdown(); + + /** + * Invoked before submitting a command to a raft group. Review Comment: It seems that you reminded what is performed before writing to the raft log or not? -- 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]
