Skip to content

Commit

Permalink
raft: introduce box.info.raft
Browse files Browse the repository at this point in the history
Box.info.raft returns a table of form:

    {
        state: <string>,
        term: <number>,
        vote: <instance ID>,
        leader: <instance ID>
    }

The fields correspond to the same named Raft concepts one to one.
This info dump is supposed to help with the tests, first of all.
And with investigation of problems in a real cluster.

Part of #1146
  • Loading branch information
Gerold103 committed Sep 29, 2020
1 parent 11536f2 commit 0da84ab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/box/lua/info.c
Expand Up @@ -49,6 +49,7 @@
#include "main.h"
#include "version.h"
#include "box/box.h"
#include "box/raft.h"
#include "lua/utils.h"
#include "fiber.h"
#include "tt_static.h"
Expand Down Expand Up @@ -577,6 +578,21 @@ lbox_info_listen(struct lua_State *L)
return 1;
}

static int
lbox_info_election(struct lua_State *L)
{
lua_createtable(L, 0, 4);
lua_pushstring(L, raft_state_strs[raft.state]);
lua_setfield(L, -2, "state");
luaL_pushuint64(L, raft.volatile_term);
lua_setfield(L, -2, "term");
lua_pushinteger(L, raft.volatile_vote);
lua_setfield(L, -2, "vote");
lua_pushinteger(L, raft.leader);
lua_setfield(L, -2, "leader");
return 1;
}

static const struct luaL_Reg lbox_info_dynamic_meta[] = {
{"id", lbox_info_id},
{"uuid", lbox_info_uuid},
Expand All @@ -595,6 +611,7 @@ static const struct luaL_Reg lbox_info_dynamic_meta[] = {
{"vinyl", lbox_info_vinyl},
{"sql", lbox_info_sql},
{"listen", lbox_info_listen},
{"election", lbox_info_election},
{NULL, NULL}
};

Expand Down
1 change: 1 addition & 0 deletions test/box/info.result
Expand Up @@ -75,6 +75,7 @@ table.sort(t)
t
---
- - cluster
- election
- gc
- id
- listen
Expand Down

0 comments on commit 0da84ab

Please sign in to comment.