# The term becomes 0 when a new leader is elected

**URL:** <https://forum.opennebula.io/t/the-term-becomes-0-when-a-new-leader-is-elected/11637>\
**Category:** Operations\
**Created:** [October 27, 2023, 3:30pm UTC](https://forum.opennebula.io/t/the-term-becomes-0-when-a-new-leader-is-elected/11637 "2023-10-27T15:30:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Khang\_Nguyen\_Phuc](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/khang_nguyen_phuc/32/7811_2.png) [@Khang\_Nguyen\_Phuc](https://forum.opennebula.io/u/Khang_Nguyen_Phuc)\
**Post date:** [October 27, 2023, 3:30pm UTC](https://forum.opennebula.io/t/the-term-becomes-0-when-a-new-leader-is-elected/11637/1 "2023-10-27T15:30:22Z")

</div>

Hello everyone,

I have a HA cluster running normally, but due to an incorrect operation, a leader election occurred, and a new leader was elected. Everything seems to be fine, but the term has reset to 0; previously, it was around 1550. The index and commit both appear to be normal. Is my cluster operating incorrectly?

Some log oned.log from the follower just before it became the current leader:

```auto
Fri Oct 27 10:23:17 2023 [Z0][RRM][E]: Failed to get heartbeat from leader. Starting election proccess
Fri Oct 27 10:23:17 2023 [Z0][RCM][I]: Vote not granted from follower 2: [one.zone.voterequest] Candidate's term is outdated
Fri Oct 27 10:23:17 2023 [Z0][RCM][I]: Follower 2 is in term 4294967295 current term is 1576. Turning into follower
Fri Oct 27 10:23:17 2023 [Z0][RCM][I]: oned is set to follower mode
Fri Oct 27 10:23:17 2023 [Z0][RRM][E]: Failed to get heartbeat from leader. Starting election proccess
Fri Oct 27 10:23:17 2023 [Z0][RCM][I]: Vote not granted from follower 2: [one.zone.voterequest] Candidate's term is outdated
Fri Oct 27 10:23:17 2023 [Z0][RCM][I]: Follower 2 is in term 4294967295 current term is 0. Turning into follower
Fri Oct 27 10:23:17 2023 [Z0][RCM][I]: oned is set to follower mode
Fri Oct 27 10:23:17 2023 [Z0][RRM][E]: Failed to get heartbeat from leader. Starting election proccess
Fri Oct 27 10:23:17 2023 [Z0][RCM][I]: Vote not granted from follower 2: [one.zone.voterequest] Candidate's term is outdated
Fri Oct 27 10:23:17 2023 [Z0][RCM][I]: Follower 2 is in term 4294967295 current term is 0. Turning into follower
Fri Oct 27 10:23:17 2023 [Z0][RCM][I]: oned is set to follower mode
Fri Oct 27 10:23:17 2023 [Z0][RRM][E]: Failed to get heartbeat from leader. Starting election proccess
Fri Oct 27 10:23:17 2023 [Z0][RCM][I]: Vote not granted from follower 2: [one.zone.voterequest] Candidate's term is outdated
Fri Oct 27 10:23:17 2023 [Z0][RCM][I]: Follower 2 is in term 4294967295 current term is 0. Turning into follower
Fri Oct 27 10:23:17 2023 [Z0][RCM][I]: oned is set to follower mode
Fri Oct 27 10:23:17 2023 [Z0][RRM][E]: Failed to get heartbeat from leader. Starting election proccess
Fri Oct 27 10:23:17 2023 [Z0][RCM][I]: Vote not granted from follower 2: [one.zone.voterequest] Candidate's term is outdated
Fri Oct 27 10:23:17 2023 [Z0][RCM][I]: Follower 2 is in term 4294967295 current term is 0. Turning into follower
Fri Oct 27 10:23:17 2023 [Z0][RCM][I]: oned is set to follower mode
Fri Oct 27 10:23:17 2023 [Z0][RRM][E]: Failed to get heartbeat from leader. Starting election proccess
Fri Oct 27 10:23:17 2023 [Z0][RCM][I]: Vote not granted from follower 2: [one.zone.voterequest] Candidate's term is outdated
Fri Oct 27 10:23:17 2023 [Z0][RCM][I]: Follower 2 is in term 4294967295 current term is 0. Turning into follower

```

Onezone show:

```auto
ZONE 0 INFORMATION
ID : 0
NAME : opennebula.zone
STATE : ENABLED

ZONE SERVERS
ID NAME ENDPOINT
 2 server-2 http://192.168.0.3:2633/RPC2
 3 server-0 http://192.168.0.1:2633/RPC2
 4 server-1 http://192.168.0.2:2633/RPC2

HA & FEDERATION SYNC STATUS
ID NAME STATE TERM INDEX COMMIT VOTE FED_INDEX 
 2 server-2 follower 0 708728 708728 4 -1
 3 server-0 follower 0 708728 708728 -1 -1
 4 server-1 leader 0 708728 708728 4 -1

ZONE TEMPLATE
ENDPOINT="http://localhost:2633/RPC2"

```

I use Opennebula Frontend CE 6.6.3 and server’s os is Ubuntu 22.04  
Thank you.

---

<div class="post-metadata">

**Author:** ![vpalma](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/vpalma/32/8065_2.png) [@vpalma](https://forum.opennebula.io/u/vpalma)\
**Post date:** [October 30, 2023, 3:58pm UTC](https://forum.opennebula.io/t/the-term-becomes-0-when-a-new-leader-is-elected/11637/2 "2023-10-30T15:58:02Z")

</div>

Hi @Khang_Nguyen_Phuc

I think the issue with the `TERM` attribute comes from the fact that the maximum size of the variable has been reached. To fix the problem, please try to follow the steps below:

1. Stop all the frontends.
2. Create a backup of each frontend database.
3. Update the `TERM` attribute value in your database. It should be to run a command like this:  
`UPDATE logdb SET sqlcmd = "<TEMPLATE><TERM><![CDATA[0]]></TERM><VOTEDFOR><![CDATA[-1]]></VOTEDFOR></TEMPLATE>" WHERE log_index = -1;`
4. Restart all the frontends.

---

<div class="post-metadata">

**Author:** ![Khang\_Nguyen\_Phuc](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/khang_nguyen_phuc/32/7811_2.png) [@Khang\_Nguyen\_Phuc](https://forum.opennebula.io/u/Khang_Nguyen_Phuc)\
**Post date:** [October 31, 2023, 7:40am UTC](https://forum.opennebula.io/t/the-term-becomes-0-when-a-new-leader-is-elected/11637/3 "2023-10-31T07:40:17Z")

</div>

> [@Khang\_Nguyen\_Phuc](#):
>
> `Follower 2 is in term 4294967295`

Thank you very much for your response. Currently, the cluster is running smoothly with term = 0. Is this currently a “problem,” and do I need to fix it soon? I have also read the log file I sent, “Follower 2 is in term 4294967295,” and I suspect there is an issue with Follower 2. Everything seems to be fine, with only one leader experiencing issues, which leads to an election taking place. Why does this lead to the term on Follower 2 increasing to the maximum?  
Thanks you,
