Class REDIRECT

java.lang.Object
org.jgroups.stack.Protocol
org.jgroups.protocols.raft.REDIRECT
All Implemented Interfaces:
org.jgroups.Lifecycle, DynamicMembership, Settable

public class REDIRECT extends org.jgroups.stack.Protocol implements Settable, DynamicMembership
Protocol that redirects RAFT commands from clients to the actual RAFT leader. E.g. if a client issues a set(), but the current mode is not the leader, the set() is redirected to the leader and the client blocked until the set() has been committed by a majority of nodes.
Since:
0.1
Author:
Bela Ban
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
     
    static enum 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected RAFT
     
    static final short
     
    static final short
     
    protected final AtomicInteger
     
    protected org.jgroups.View
     

    Fields inherited from class org.jgroups.stack.Protocol

    after_creation_hook, down_prot, ergonomics, id, local_addr, log, policies, preview_warning, stack, stats, up_prot
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
    getAsync(byte[] buf, int offset, int length, Options options)
    Asynchronous get operation that returns immediately without blocking.
    protected void
    handleEvent(org.jgroups.Message msg, REDIRECT.RedirectHeader hdr)
     
    void
     
    protected final org.jgroups.Address
    leader(String req_type)
     
    double
     
     
     
    void
     
    setAsync(byte[] buf, int offset, int length, Options options)
    Asynchronous set, returns immediately with a CompletableFuture.
    void
     
    up(org.jgroups.Event evt)
     
    up(org.jgroups.Message msg)
     
    void
    up(org.jgroups.util.MessageBatch batch)
     

    Methods inherited from class org.jgroups.stack.Protocol

    accept, addPolicy, addr, addr, afterCreationHook, destroy, down, down, down, enableStats, getAddress, getComponents, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getPolicies, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, policies, previewWarning, previewWarning, providedDownServices, providedUpServices, removePolicy, requiredDownServices, requiredUpServices, resetStatistics, setAddress, setDownProtocol, setErgonomics, setId, setLevel, setPolicies, setProtocolStack, setSocketFactory, setUpProtocol, setValue, statsEnabled, stop, toString

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface Settable

    get, get, getAsync, set, set, setAsync
  • Field Details

    • REDIRECT_ID

      public static final short REDIRECT_ID
      See Also:
    • REDIRECT_HDR

      public static final short REDIRECT_HDR
      See Also:
    • request_ids

      protected final AtomicInteger request_ids
    • raft

      protected RAFT raft
    • view

      protected volatile org.jgroups.View view
  • Constructor Details

    • REDIRECT

      public REDIRECT()
  • Method Details

    • redirectionOperationMeanLatency

      public double redirectionOperationMeanLatency()
    • setAsync

      public CompletableFuture<byte[]> setAsync(byte[] buf, int offset, int length, Options options) throws Exception
      Description copied from interface: Settable
      Asynchronous set, returns immediately with a CompletableFuture. To wait for the result, CompletableFuture.get() or CompletableFuture.get(long, TimeUnit) can be called.
      Specified by:
      setAsync in interface Settable
      Parameters:
      buf - The buffer (usually a serialized command) which represent the change to be applied to all state machines
      offset - The offset into the buffer
      length - he number of bytes to be used in the buffer, starting at offset
      options - Options to pass to the call, may be null
      Returns:
      A CompletableFuture which can be used to fetch the result.
      Throws:
      Exception
    • getAsync

      public CompletableFuture<byte[]> getAsync(byte[] buf, int offset, int length, Options options) throws Exception
      Description copied from interface: Settable
      Asynchronous get operation that returns immediately without blocking.

      This method submits a read-only operation to the state machine. Read-only operations are treated differently by the replication algorithm. Since read-only operations do not change the state-machine state, these operations are not appended to the replicated log.

      Warning: Do not change the state-machine state by operations submitted through this method. Otherwise, the state-machine will diverge and lead to an undefined state.

      Specified by:
      getAsync in interface Settable
      Parameters:
      buf - The buffer representing the read-only operation to submit to the state machine.
      offset - The offset to skip the bytes in the buffer.
      length - The number of bytes to use from the buffer starting at offset.
      options - Options to pass along in the call chain, may be null.
      Returns:
      A buffer representing the result after submitting the read-only operation.
      Throws:
      Exception - Thrown if the operation could not be submitted.
    • addServer

      public CompletableFuture<byte[]> addServer(String name) throws Exception
      Specified by:
      addServer in interface DynamicMembership
      Throws:
      Exception
    • removeServer

      public CompletableFuture<byte[]> removeServer(String name) throws Exception
      Specified by:
      removeServer in interface DynamicMembership
      Throws:
      Exception
    • init

      public void init() throws Exception
      Specified by:
      init in interface org.jgroups.Lifecycle
      Overrides:
      init in class org.jgroups.stack.Protocol
      Throws:
      Exception
    • start

      public void start() throws Exception
      Specified by:
      start in interface org.jgroups.Lifecycle
      Overrides:
      start in class org.jgroups.stack.Protocol
      Throws:
      Exception
    • resetStats

      public void resetStats()
      Overrides:
      resetStats in class org.jgroups.stack.Protocol
    • up

      public Object up(org.jgroups.Event evt)
      Overrides:
      up in class org.jgroups.stack.Protocol
    • up

      public Object up(org.jgroups.Message msg)
      Overrides:
      up in class org.jgroups.stack.Protocol
    • up

      public void up(org.jgroups.util.MessageBatch batch)
      Overrides:
      up in class org.jgroups.stack.Protocol
    • redirectLatency

      public LatencyMetrics redirectLatency()
      Returns:
      redirect round-trip latency metrics, or disabled metrics if stats are off.
    • handleEvent

      protected void handleEvent(org.jgroups.Message msg, REDIRECT.RedirectHeader hdr)
    • leader

      protected final org.jgroups.Address leader(String req_type) throws RaftLeaderException
      Throws:
      RaftLeaderException