Interface Settable

All Known Implementing Classes:
RAFT, RaftHandle, REDIRECT

public interface Settable
Interface to make changes to the Raft state machine. All changes are made through the leader, which appends the change to its log and then sends it to all followers. When the majority has acked the change, it will be committed to the log.
Since:
0.1
Author:
Bela Ban
  • Method Summary

    Modifier and Type
    Method
    Description
    default byte[]
    get(byte[] buf, int offset, int length)
    Synchronous get operation without time bound.
    default byte[]
    get(byte[] buf, int offset, int length, long timeout, TimeUnit unit)
    Synchronous get operation bounded by a timeout.
    default CompletableFuture<byte[]>
    getAsync(byte[] buf, int offset, int length)
     
    getAsync(byte[] buf, int offset, int length, Options options)
    Asynchronous get operation that returns immediately without blocking.
    default byte[]
    set(byte[] buf, int offset, int length)
    Synchronous set.
    default byte[]
    set(byte[] buf, int offset, int length, long timeout, TimeUnit unit)
    Synchronous set bounded by a timeout.
    default CompletableFuture<byte[]>
    setAsync(byte[] buf, int offset, int length)
     
    setAsync(byte[] buf, int offset, int length, Options options)
    Asynchronous set, returns immediately with a CompletableFuture.
  • Method Details

    • set

      default byte[] set(byte[] buf, int offset, int length) throws Exception
      Synchronous set. Blocks until the change has been committed.
      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 - The number of bytes to be used in the buffer, starting at offset
      Returns:
      Another buffer, representing the result of applying the change. E.g. for a put(k,v), this might be the serialized result of the previous key in a hashmap
      Throws:
      Exception - Thrown if the change could not be applied/committed, e.g. because there was no majority, or no elected leader
    • set

      default byte[] set(byte[] buf, int offset, int length, long timeout, TimeUnit unit) throws Exception
      Synchronous set bounded by a timeout. Blocks until the change has been committed or a timeout occurred
      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 - The number of bytes to be used in the buffer, starting at offset
      timeout - The timeout, in unit (below)
      unit - The unit of the timeout
      Returns:
      Another buffer, representing the result of applying the change. E.g. for a put(k,v), this might be the serialized result of the previous key in a hashmap
      Throws:
      Exception - Thrown if the change could not be applied/committed, e.g. because there was no majority, or no elected leader
    • get

      default byte[] get(byte[] buf, int offset, int length) throws Exception
      Synchronous get operation without time bound.

      This method blocks until the change has been committed.

      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.
      Returns:
      A buffer representing the result after submitting the read-only operation.
      Throws:
      Exception - Thrown if the operation could not be submitted.
      See Also:
    • get

      default byte[] get(byte[] buf, int offset, int length, long timeout, TimeUnit unit) throws Exception
      Synchronous get operation bounded by a timeout.

      This method blocks until the change has been committed or a timeout occurred.

      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.
      timeout - The operation timeout value.
      unit - The unit of the operation timeout value.
      Returns:
      A buffer representing the result after submitting the read-only operation.
      Throws:
      Exception - Thrown if the operation could not be submitted.
      See Also:
    • setAsync

      default CompletableFuture<byte[]> setAsync(byte[] buf, int offset, int length) throws Exception
      Throws:
      Exception
    • getAsync

      default CompletableFuture<byte[]> getAsync(byte[] buf, int offset, int length) throws Exception
      Throws:
      Exception
    • setAsync

      CompletableFuture<byte[]> setAsync(byte[] buf, int offset, int length, Options options) throws Exception
      Asynchronous set, returns immediately with a CompletableFuture. To wait for the result, CompletableFuture.get() or CompletableFuture.get(long, TimeUnit) can be called.
      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

      CompletableFuture<byte[]> getAsync(byte[] buf, int offset, int length, Options options) throws Exception
      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.

      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.