Java Code Examples for org.apache.ratis.proto.RaftProtos.RaftPeerRole#LEADER
The following examples show how to use
org.apache.ratis.proto.RaftProtos.RaftPeerRole#LEADER .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArithmeticStateMachine.java From incubator-ratis with Apache License 2.0 | 6 votes |
@Override public CompletableFuture<Message> applyTransaction(TransactionContext trx) { final LogEntryProto entry = trx.getLogEntry(); final AssignmentMessage assignment = new AssignmentMessage(entry.getStateMachineLogEntry().getLogData()); final long index = entry.getIndex(); final Double result; try(AutoCloseableLock writeLock = writeLock()) { result = assignment.evaluate(variables); updateLastAppliedTermIndex(entry.getTerm(), index); } final Expression r = Expression.Utils.double2Expression(result); final CompletableFuture<Message> f = CompletableFuture.completedFuture(Expression.Utils.toMessage(r)); final RaftPeerRole role = trx.getServerRole(); if (role == RaftPeerRole.LEADER) { LOG.info("{}:{}-{}: {} = {}", role, getId(), index, assignment, r); } else { LOG.debug("{}:{}-{}: {} = {}", role, getId(), index, assignment, r); } if (LOG.isTraceEnabled()) { LOG.trace("{}-{}: variables={}", getId(), index, variables); } return f; }
Example 2
Source File: ArithmeticStateMachine.java From ratis with Apache License 2.0 | 6 votes |
@Override public CompletableFuture<Message> applyTransaction(TransactionContext trx) { final LogEntryProto entry = trx.getLogEntry(); final AssignmentMessage assignment = new AssignmentMessage(entry.getStateMachineLogEntry().getLogData()); final long index = entry.getIndex(); final Double result; try(final AutoCloseableLock writeLock = writeLock()) { result = assignment.evaluate(variables); updateLastAppliedTermIndex(entry.getTerm(), index); } final Expression r = Expression.Utils.double2Expression(result); final CompletableFuture<Message> f = CompletableFuture.completedFuture(Expression.Utils.toMessage(r)); final RaftPeerRole role = trx.getServerRole(); if (role == RaftPeerRole.LEADER) { LOG.info("{}:{}-{}: {} = {}", role, getId(), index, assignment, r); } else { LOG.debug("{}:{}-{}: {} = {}", role, getId(), index, assignment, r); } if (LOG.isTraceEnabled()) { LOG.trace("{}-{}: variables={}", getId(), index, variables); } return f; }
Example 3
Source File: OzoneManagerRatisServer.java From hadoop-ozone with Apache License 2.0 | 5 votes |
/** * Check the cached leader status. * @return true if cached role is Leader, false otherwise. */ private boolean checkCachedPeerRoleIsLeader() { this.roleCheckLock.readLock().lock(); try { if (cachedPeerRole.isPresent() && cachedPeerRole.get() == RaftPeerRole.LEADER) { return true; } return false; } finally { this.roleCheckLock.readLock().unlock(); } }
Example 4
Source File: TransactionContextImpl.java From incubator-ratis with Apache License 2.0 | 5 votes |
/** * Construct a {@link TransactionContext} from a client request. * Used by the state machine to start a transaction * and send the Log entry representing the transaction data * to be applied to the raft log. */ public TransactionContextImpl( StateMachine stateMachine, RaftClientRequest clientRequest, StateMachineLogEntryProto smLogEntryProto, Object stateMachineContext) { this(RaftPeerRole.LEADER, stateMachine); this.clientRequest = clientRequest; this.smLogEntryProto = smLogEntryProto != null? smLogEntryProto : ServerProtoUtils.toStateMachineLogEntryProto(clientRequest, null, null); this.stateMachineContext = stateMachineContext; }
Example 5
Source File: TransactionContextImpl.java From ratis with Apache License 2.0 | 5 votes |
/** * Construct a {@link TransactionContext} from a client request. * Used by the state machine to start a transaction * and send the Log entry representing the transaction data * to be applied to the raft log. */ public TransactionContextImpl( StateMachine stateMachine, RaftClientRequest clientRequest, StateMachineLogEntryProto smLogEntryProto, Object stateMachineContext) { this(RaftPeerRole.LEADER, stateMachine); this.clientRequest = clientRequest; this.smLogEntryProto = smLogEntryProto != null? smLogEntryProto : ServerProtoUtils.toStateMachineLogEntryProto(clientRequest, null, null); this.stateMachineContext = stateMachineContext; }
Example 6
Source File: RoleInfo.java From incubator-ratis with Apache License 2.0 | 4 votes |
boolean isLeader() { return role == RaftPeerRole.LEADER; }
Example 7
Source File: RoleInfo.java From ratis with Apache License 2.0 | 4 votes |
boolean isLeader() { return role == RaftPeerRole.LEADER; }