-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
box: add "leader_name" field to the box.info.election
Prior to this patch, the table had no information about the leader other than his id in the "leader" field. It may not be convenient for the user to search for a name corresponding to a given id. Much more convenient to see the leader's name in box.info.election. Closes #8931 @TarantoolBot document Title: Document `box.info.election` box.info.election now contains one more field: `leader_name`: string. There are several possible values for this field: - `nil`, if there is no leader in a cluster. - `box.NULL`, if there is a leader, but he does not have a name. - `some string`, if there is a leader and he has a name. Example: ```console tarantool> box.info.election --- - leader_idle: 0 leader_name: node1 state: leader vote: 1 term: 3 leader: 1 ... ``` [box-info-election] https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_info/election/
- Loading branch information
1 parent
a4de12b
commit 307f3c5
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
changelogs/unreleased/gh-8931-box-info-election-leader-name.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## feature/box | ||
|
||
* Added the `leader_name` field to `box.info.election` (gh-8931). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
test/replication-luatest/gh_8931_box_info_election_leader_name_test.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
local t = require('luatest') | ||
local cluster = require('luatest.replica_set') | ||
local server = require('luatest.server') | ||
|
||
local g = t.group('gh-8931') | ||
-- | ||
-- gh-8931: | ||
-- There is the leader field in the given informational API, but it is easier | ||
-- to a human to understand human-readable names. We have instance names | ||
-- since #5029. Let's show them in this API. | ||
-- | ||
g.before_all(function(cg) | ||
cg.cluster = cluster:new({}) | ||
local cfg = { | ||
replication = { | ||
server.build_listen_uri('node1', cg.cluster.id), | ||
server.build_listen_uri('node2', cg.cluster.id) | ||
}, | ||
election_mode = 'candidate' | ||
} | ||
cg.node1 = cg.cluster:build_and_add_server({alias = 'node1', box_cfg = cfg}) | ||
cg.node2 = cg.cluster:build_and_add_server({alias = 'node2', box_cfg = cfg}) | ||
cg.cluster:start() | ||
end) | ||
|
||
g.before_test('test_leader_has_no_name', function(cg) | ||
cg.node1:wait_until_election_leader_found() | ||
cg.node2:wait_until_election_leader_found() | ||
end) | ||
|
||
g.test_leader_has_no_name = function(cg) | ||
cg.node1:exec(function() | ||
local function is_null(val) | ||
if val == nil and val then | ||
return true | ||
end | ||
return false | ||
end | ||
t.assert(is_null(box.info.election.leader_name)) | ||
end) | ||
end | ||
|
||
g.before_test('test_leader_has_a_name', function(cg) | ||
cg.node1:exec(function() | ||
box.cfg{instance_name = 'node1'} | ||
end) | ||
cg.node2:exec(function() | ||
box.cfg{instance_name = 'node2'} | ||
end) | ||
end) | ||
|
||
g.test_leader_has_a_name = function(cg) | ||
cg.cluster:get_leader():exec(function() | ||
t.assert_equals(box.info.election.leader_name, box.info.name) | ||
end) | ||
end | ||
|
||
g.before_test('test_no_leader', function(cg) | ||
cg.node1:exec(function() | ||
box.cfg{election_mode = 'off'} | ||
end) | ||
cg.node2:exec(function() | ||
box.cfg{election_mode = 'off'} | ||
end) | ||
cg.node1:wait_for_election_state('follower') | ||
cg.node2:wait_for_election_state('follower') | ||
end) | ||
|
||
g.test_no_leader = function(cg) | ||
cg.node1:exec(function() | ||
local function is_nil(val) | ||
if val == nil and not val then | ||
return true | ||
end | ||
return false | ||
end | ||
t.assert(is_nil(box.info.election.leader_name)) | ||
end) | ||
end | ||
|
||
g.after_all(function(cg) | ||
cg.cluster:drop() | ||
end) |