Print Zxid in keeper stat command in hex (so as ZooKeeper)

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
This commit is contained in:
Azat Khuzhin 2023-07-14 18:31:45 +02:00
parent 4bb95305a4
commit 6abdde12ca
2 changed files with 18 additions and 4 deletions

View File

@ -18,6 +18,20 @@
#include <unistd.h>
#include <bit>
namespace
{
String formatZxid(int64_t zxid)
{
/// ZooKeeper print zxid in hex and
String hex = getHexUIntLowercase(zxid);
/// without leading zeros
trimLeft(hex, '0');
return "0x" + hex;
}
}
namespace DB
{
@ -348,7 +362,7 @@ String ServerStatCommand::run()
write("Sent", toString(stats.getPacketsSent()));
write("Connections", toString(keeper_info.alive_connections_count));
write("Outstanding", toString(keeper_info.outstanding_requests_count));
write("Zxid", toString(keeper_info.last_zxid));
write("Zxid", formatZxid(keeper_info.last_zxid));
write("Mode", keeper_info.getRole());
write("Node count", toString(keeper_info.total_nodes_count));
@ -381,7 +395,7 @@ String StatCommand::run()
write("Sent", toString(stats.getPacketsSent()));
write("Connections", toString(keeper_info.alive_connections_count));
write("Outstanding", toString(keeper_info.outstanding_requests_count));
write("Zxid", toString(keeper_info.last_zxid));
write("Zxid", formatZxid(keeper_info.last_zxid));
write("Mode", keeper_info.getRole());
write("Node count", toString(keeper_info.total_nodes_count));

View File

@ -329,7 +329,7 @@ def test_cmd_srvr(started_cluster):
assert result["Received"] == "10"
assert result["Sent"] == "10"
assert int(result["Connections"]) == 1
assert int(result["Zxid"]) > 10
assert int(result["Zxid"], 16) > 10
assert result["Mode"] == "leader"
assert result["Node count"] == "14"
@ -369,7 +369,7 @@ def test_cmd_stat(started_cluster):
assert result["Received"] == "10"
assert result["Sent"] == "10"
assert int(result["Connections"]) == 1
assert int(result["Zxid"]) >= 10
assert int(result["Zxid"], 16) >= 10
assert result["Mode"] == "leader"
assert result["Node count"] == "14"