Class Consensus


  • public class Consensus
    extends java.lang.Object
    This class stands for a consensus instance that implements the algorithm for the Byzantine fault model described in Cachin's 'Yet Another Visit to Paxos' (April 2011)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      java.util.concurrent.locks.ReentrantLock lock  
    • Constructor Summary

      Constructors 
      Constructor Description
      Consensus​(ExecutionManager manager, Decision decision)
      Creates a new instance of Consensus Important: At this point, the 'decision' parameter is only a placeholder for the future decision, and should not be delivered to the delivery thread.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addWritten​(byte[] value)
      Add a value that shall be written to the writeSet
      Epoch createEpoch​(int timestamp, ServerViewController recManager)
      Creates an epoch associated with this consensus, with the specified timestamp
      Epoch createEpoch​(ServerViewController recManager)
      Creates a epoch associated with this consensus, supposedly the next
      void decided​(Epoch epoch, boolean deliver)
      Called by the Acceptor object, to set the decided value
      Decision getDecision()
      This is the decision instance to which this consensus works for Important: The returned object should only be sent to the delivery thread after this consensus instance decides a value.
      Epoch getDecisionEpoch()
      The epoch at which a decision was possible to make
      Epoch getEpoch​(int timestamp, boolean create, ServerViewController controller)
      Gets a epoch associated with this consensus
      Epoch getEpoch​(int timestamp, ServerViewController controller)
      Gets a epoch associated with this consensus
      int getEts()
      Returns the timestamp for the current epoch
      int getId()
      This is the consensus ID
      Epoch getLastEpoch()
      The last epoch of this consensus instance
      ExecutionManager getManager()
      This is the execution manager for this replica's consensus instances
      TimestampValuePair getQuorumWrites()
      Return the value read from a Byzantine quorum of WRITES that has previously been stored
      java.util.HashSet<TimestampValuePair> getWriteSet()  
      void incEts()
      Increments the ETS of this consensus, thus advancing to the next epoch
      boolean isDecided()
      Informs whether or not the consensus instance has decided a value
      void removeEpochs​(int limit)
      Removes epochs greater than 'limit' from this consensus instance
      void removeWritten​(byte[] value)
      Remove an already writte value from writeSet
      void setETS​(int ets)
      Increments the ETS of this consensus, thus advancing to the next epoch
      void setQuorumWrites​(byte[] value)
      Store the value read from a Byzantine quorum of WRITES
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • lock

        public java.util.concurrent.locks.ReentrantLock lock
    • Constructor Detail

      • Consensus

        public Consensus​(ExecutionManager manager,
                         Decision decision)
        Creates a new instance of Consensus Important: At this point, the 'decision' parameter is only a placeholder for the future decision, and should not be delivered to the delivery thread. Use 'isDecided()' to check if the consensus already decided a value.
        Parameters:
        manager - Execution manager for this replica's consensus instances
        decision - Decision instance to which this consensus works for.
    • Method Detail

      • getId

        public int getId()
        This is the consensus ID
        Returns:
        Consensus ID
      • getManager

        public ExecutionManager getManager()
        This is the execution manager for this replica's consensus instances
        Returns:
        Execution manager for this replica
      • getDecision

        public Decision getDecision()
        This is the decision instance to which this consensus works for Important: The returned object should only be sent to the delivery thread after this consensus instance decides a value. Use 'isDecided()' to check if the consensus already decided a value.
        Returns:
        Decision instance to which this consensus works for
      • getEpoch

        public Epoch getEpoch​(int timestamp,
                              ServerViewController controller)
        Gets a epoch associated with this consensus
        Parameters:
        timestamp - The timestamp of the epoch
        controller - The view controller for the replicas
        Returns:
        The epoch
      • getEpoch

        public Epoch getEpoch​(int timestamp,
                              boolean create,
                              ServerViewController controller)
        Gets a epoch associated with this consensus
        Parameters:
        timestamp - The number of the epoch
        create - if the epoch is to be created if not existent
        controller - The view controller for the replicas
        Returns:
        The epoch
      • incEts

        public void incEts()
        Increments the ETS of this consensus, thus advancing to the next epoch
      • setETS

        public void setETS​(int ets)
        Increments the ETS of this consensus, thus advancing to the next epoch
        Parameters:
        ets - New ETS for this consensus, to advance to the next epoch. It must be greater than the current ETS
      • getEts

        public int getEts()
        Returns the timestamp for the current epoch
        Returns:
        the timestamp for the current epoch
      • setQuorumWrites

        public void setQuorumWrites​(byte[] value)
        Store the value read from a Byzantine quorum of WRITES
        Parameters:
        value -
      • getQuorumWrites

        public TimestampValuePair getQuorumWrites()
        Return the value read from a Byzantine quorum of WRITES that has previously been stored
        Returns:
        the value read from a Byzantine quorum of WRITES, if such value has been obtained already
      • addWritten

        public void addWritten​(byte[] value)
        Add a value that shall be written to the writeSet
        Parameters:
        value - Value to write to the writeSet
      • removeWritten

        public void removeWritten​(byte[] value)
        Remove an already writte value from writeSet
        Parameters:
        value - valor a remover do writeSet
      • createEpoch

        public Epoch createEpoch​(int timestamp,
                                 ServerViewController recManager)
        Creates an epoch associated with this consensus, with the specified timestamp
        Parameters:
        timestamp - The timestamp to associated to this epoch
        recManager - The replica's ServerViewController
        Returns:
        The epoch
      • createEpoch

        public Epoch createEpoch​(ServerViewController recManager)
        Creates a epoch associated with this consensus, supposedly the next
        Parameters:
        recManager - The replica's ServerViewController
        Returns:
        The epoch
      • removeEpochs

        public void removeEpochs​(int limit)
        Removes epochs greater than 'limit' from this consensus instance
        Parameters:
        limit - Epochs that should be kept (from 0 to 'limit')
      • getDecisionEpoch

        public Epoch getDecisionEpoch()
        The epoch at which a decision was possible to make
        Returns:
        Epoch at which a decision was possible to make
      • getLastEpoch

        public Epoch getLastEpoch()
        The last epoch of this consensus instance
        Returns:
        Last epoch of this consensus instance
      • isDecided

        public boolean isDecided()
        Informs whether or not the consensus instance has decided a value
        Returns:
        True if it is decided, false otherwise
      • decided

        public void decided​(Epoch epoch,
                            boolean deliver)
        Called by the Acceptor object, to set the decided value
        Parameters:
        epoch - The epoch at which a decision was made
        deliver - Set to true to deliver decision to TOMLayer/DeliveryThread