Class StateLog
- java.lang.Object
-
- bftsmart.tom.server.defaultservices.StateLog
-
- Direct Known Subclasses:
DiskStateLog,DurableStateLog
public class StateLog extends java.lang.ObjectThis classes serves as a log for the state associated with the last checkpoint, and the message batches received since the same checkpoint until the present. The state associated with the last checkpoint together with all the batches of messages received so far, comprises this replica current state
-
-
Field Summary
Fields Modifier and Type Field Description protected org.slf4j.Loggerlogger
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMessageBatch(byte[][] commands, MessageContext[] msgCtx, int lastConsensusId)Adds a message batch to the log.DefaultApplicationStategetApplicationState(int cid, boolean setState)Constructs a TransferableState using this log informationintgetLastCheckpointCID()Retrieves the consensus ID for the last checkpointintgetLastCID()Retrieves the consensus ID for the last messages batch delivered to the applicationjava.util.TreeMap<java.lang.Integer,TOMMessage>getLastReplies()byte[]getLastRepliesHash()Retrieves the last replies hashCommandsInfogetMessageBatch(int cid)Returns a batch of messages, given its correspondent consensus IDCommandsInfo[]getMessageBatches()Retrieves all the stored batches kept since the last checkpointintgetNumBatches()Retrieves the total number of stored batches kept since the last checkpointbyte[]getState()Retrieves the state associated with the last checkpointbyte[]getStateHash()Retrieves the hash of the state associated with the last checkpointvoidnewCheckpoint(byte[] state, byte[] stateHash, int lastConsensusId)Sets the state associated with the last checkpoint, and updates the consensus ID associated with itvoidsetLastCheckpointCID(int lastCheckpointCID)Sets the consensus ID for the last checkpointvoidsetLastCID(int lastCID)Sets the consensus ID for the last messages batch delivered to the applicationvoidsetLastReplies(java.util.TreeMap<java.lang.Integer,TOMMessage> lastReplies)Retrieves the last replies sent to clientsvoidsetLastRepliesHash(byte[] lastRepliesHash)Sets the last replies hashvoidupdate(DefaultApplicationState transState)Updates this log, according to the information contained in the TransferableState object
-
-
-
Constructor Detail
-
StateLog
public StateLog(int id, int k, byte[] initialState, byte[] initialHash)Constructs a State log- Parameters:
id-k- The checkpoint periodinitialState-initialHash-
-
StateLog
public StateLog(int id, int k)Constructs a State log- Parameters:
id-k- The checkpoint period
-
StateLog
public StateLog(int id, byte[] initialState, byte[] initialHash)
-
-
Method Detail
-
newCheckpoint
public void newCheckpoint(byte[] state, byte[] stateHash, int lastConsensusId)Sets the state associated with the last checkpoint, and updates the consensus ID associated with it- Parameters:
state- State associated with the last checkpointstateHash-lastConsensusId-
-
setLastCheckpointCID
public void setLastCheckpointCID(int lastCheckpointCID)
Sets the consensus ID for the last checkpoint- Parameters:
lastCheckpointCID- Consensus ID for the last checkpoint
-
getLastCheckpointCID
public int getLastCheckpointCID()
Retrieves the consensus ID for the last checkpoint- Returns:
- Consensus ID for the last checkpoint, or -1 if none was obtained
-
setLastCID
public void setLastCID(int lastCID)
Sets the consensus ID for the last messages batch delivered to the application- Parameters:
lastCID- the consensus ID for the last messages batch delivered to the application
-
getLastCID
public int getLastCID()
Retrieves the consensus ID for the last messages batch delivered to the application- Returns:
- Consensus ID for the last messages batch delivered to the application
-
getState
public byte[] getState()
Retrieves the state associated with the last checkpoint- Returns:
- State associated with the last checkpoint
-
getStateHash
public byte[] getStateHash()
Retrieves the hash of the state associated with the last checkpoint- Returns:
- Hash of the state associated with the last checkpoint
-
addMessageBatch
public void addMessageBatch(byte[][] commands, MessageContext[] msgCtx, int lastConsensusId)Adds a message batch to the log. This batches should be added to the log in the same order in which they are delivered to the application. Only the 'k' batches received after the last checkpoint are supposed to be kept- Parameters:
commands- The batch of messages to be kept.msgCtx- The message contexts related to the commandslastConsensusId-
-
getLastReplies
public java.util.TreeMap<java.lang.Integer,TOMMessage> getLastReplies()
-
setLastReplies
public void setLastReplies(java.util.TreeMap<java.lang.Integer,TOMMessage> lastReplies)
Retrieves the last replies sent to clients- Parameters:
lastReplies- last replies to clients
-
getLastRepliesHash
public byte[] getLastRepliesHash()
Retrieves the last replies hash
-
setLastRepliesHash
public void setLastRepliesHash(byte[] lastRepliesHash)
Sets the last replies hash- Parameters:
lastRepliesHash- last replies hash
-
getMessageBatch
public CommandsInfo getMessageBatch(int cid)
Returns a batch of messages, given its correspondent consensus ID- Parameters:
cid- Consensus ID associated with the batch to be fetched- Returns:
- The batch of messages associated with the batch correspondent consensus ID
-
getMessageBatches
public CommandsInfo[] getMessageBatches()
Retrieves all the stored batches kept since the last checkpoint- Returns:
- All the stored batches kept since the last checkpoint
-
getNumBatches
public int getNumBatches()
Retrieves the total number of stored batches kept since the last checkpoint- Returns:
- The total number of stored batches kept since the last checkpoint
-
getApplicationState
public DefaultApplicationState getApplicationState(int cid, boolean setState)
Constructs a TransferableState using this log information- Parameters:
cid- Consensus ID correspondent to desired statesetState-- Returns:
- TransferableState Object containing this log information
-
update
public void update(DefaultApplicationState transState)
Updates this log, according to the information contained in the TransferableState object- Parameters:
transState- TransferableState object containing the information which is used to updated this log
-
-