org.apache.ratis.server.raftlog.RaftLogSequentialOps Maven / Gradle / Ivy
The newest version!
/*
* 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.ratis.server.raftlog;
import org.apache.ratis.proto.RaftProtos.LogEntryProto;
import org.apache.ratis.protocol.exceptions.StateMachineException;
import org.apache.ratis.server.RaftConfiguration;
import org.apache.ratis.statemachine.TransactionContext;
import org.apache.ratis.util.Preconditions;
import org.apache.ratis.util.StringUtils;
import org.apache.ratis.util.function.CheckedSupplier;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
/**
* Sequential operations in {@link RaftLog}.
*
* All methods in this class MUST be invoked by a single thread at any time.
* The threads can be different in different time.
* The same thread may invoke any of the methods again and again.
* In other words, two or more threads invoking these methods (the same method or different methods)
* at the same time is not allowed since the sequence of invocations cannot be guaranteed.
*
* All methods in this class are asynchronous in the sense that the underlying I/O operations are asynchronous.
*/
interface RaftLogSequentialOps {
class Runner {
private final Object name;
private final AtomicReference runner = new AtomicReference<>();
Runner(Supplier name) {
this.name = StringUtils.stringSupplierAsObject(name);
}
/**
* Run the given operation sequentially.
* This method can be invoked by different threads but only one thread at any given time is allowed.
* The same thread can call this method multiple times.
*
* @throws IllegalStateException if this runner is already running another operation.
*/
© 2015 - 2024 Weber Informatics LLC | Privacy Policy