Package bftsmart.consensus
Class Consensus
- java.lang.Object
-
- bftsmart.consensus.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 writeSetEpoch
createEpoch(int timestamp, ServerViewController recManager)
Creates an epoch associated with this consensus, with the specified timestampEpoch
createEpoch(ServerViewController recManager)
Creates a epoch associated with this consensus, supposedly the nextvoid
decided(Epoch epoch, boolean deliver)
Called by the Acceptor object, to set the decided valueDecision
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 makeEpoch
getEpoch(int timestamp, boolean create, ServerViewController controller)
Gets a epoch associated with this consensusEpoch
getEpoch(int timestamp, ServerViewController controller)
Gets a epoch associated with this consensusint
getEts()
Returns the timestamp for the current epochint
getId()
This is the consensus IDEpoch
getLastEpoch()
The last epoch of this consensus instanceExecutionManager
getManager()
This is the execution manager for this replica's consensus instancesTimestampValuePair
getQuorumWrites()
Return the value read from a Byzantine quorum of WRITES that has previously been storedjava.util.HashSet<TimestampValuePair>
getWriteSet()
void
incEts()
Increments the ETS of this consensus, thus advancing to the next epochboolean
isDecided()
Informs whether or not the consensus instance has decided a valuevoid
removeEpochs(int limit)
Removes epochs greater than 'limit' from this consensus instancevoid
removeWritten(byte[] value)
Remove an already writte value from writeSetvoid
setETS(int ets)
Increments the ETS of this consensus, thus advancing to the next epochvoid
setQuorumWrites(byte[] value)
Store the value read from a Byzantine quorum of WRITES
-
-
-
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 instancesdecision
- 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 epochcontroller
- 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 epochcreate
- if the epoch is to be created if not existentcontroller
- 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
-
getWriteSet
public java.util.HashSet<TimestampValuePair> getWriteSet()
-
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 epochrecManager
- 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 madedeliver
- Set to true to deliver decision to TOMLayer/DeliveryThread
-
-