# Raft algorithm: What's the data format of term?

Time is divided into terms, and each term begins with an election. After a successful election, a single leader manages the cluster until the end of the term. Some elections fail, in which case the term ends without choosing a leader. The transitions between terms may be observed at different times on different servers.

In Raft algorithm, term is a limited period of time, and widely used in leader election, log replication.

1. What's the data format of term?

2. Is it composed of Unix timestamp and length ?

3. How does every node guarantee their timestamp are synchronous? (Google Spanner use Atomic clock to guarantee true time).

Note that we are focused on Raft algorithm.

1. What's the data format of term?
A term is just a positive integer.

2. Is it composed of Unix timestamp and length?
No, it is not. A term is just a positive integer. It is that pure and simple. In practice for reasons such as reporting or auditing, it might be helpful to record the time period when each term is valid. However, that is not an essential part of the algorithm at all.

3. How does every node guarantee their timestamp are synchronous? (Google Spanner use Atomic clock to guarantee true time).
Presumably, the question is seeking to confirm that terms can be maintained properly if term is based on time. However, as said above, this term can be considered as having nothing to do with time. So the best answer to this question should be that there is no need to be concerned with that kind of guarantee.

Here is a figure that shows how term is used in the logs in Raft algorithm. The figure is taken from the award-winning paper In Search of an Understandable Consensus Algorithm by the creators of Raft algorithm. Those numbers 1,1,1,2,3,3,3,3, etc in each log entry are the terms. Note that actual time is not mentioned anywhere in that figure, although a term does correspond to a limited continuous period of time.

• Hi @Apass, thanks for answering this question. What does x and y mean in your diagram? – Ryan Lv Oct 12 '18 at 6:42
• I assume that you are asking "what are meant by those 'x←3' and 'y←1'?". Recall that paper introduces Raft algorithm as a consensus algorithm that is used to replicated state machines across a collection of servers even if some of the servers are down. Each server stores a log containing a series of commands, which its state machine executes in order. Those 'x←3' and 'y←1' represent that series of commands. In a more general setting, you may treat them simply as a part of the consensus, the actual content of each log entry. The term in each log entry is sort of meta data. – Apass.Jack Oct 12 '18 at 12:43
• Are you able to access "the raft paper", which is also available at github? If yes, you can check its chapter 2 for more introduction about the log. – Apass.Jack Oct 12 '18 at 12:52