Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@dev.tarantool.org, kostja.osipov@gmail.com
Subject: [Tarantool-patches] [PATCH 3/3] replication: show errno in replication info
Date: Tue,  5 Nov 2019 17:59:52 +0300	[thread overview]
Message-ID: <a7e733bfa9aed398b9a7c10f88c9b1ccf8fb5df4.1572965692.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1572965692.git.v.shpilevoy@tarantool.org>

Box.info.replication shows applier/relay's latest error message.
But it didn't include errno description for system errors, even
though it was included in the logs. Now box.info shows the errno
description as well, when possible.

Closes #4402
---
 src/box/lua/info.c                           | 29 +++++----
 test/replication/gh-4402-info-errno.result   | 63 ++++++++++++++++++++
 test/replication/gh-4402-info-errno.test.lua | 25 ++++++++
 test/replication/suite.cfg                   |  1 +
 4 files changed, 108 insertions(+), 10 deletions(-)
 create mode 100644 test/replication/gh-4402-info-errno.result
 create mode 100644 test/replication/gh-4402-info-errno.test.lua

diff --git a/src/box/lua/info.c b/src/box/lua/info.c
index 55382fd77..b4475959b 100644
--- a/src/box/lua/info.c
+++ b/src/box/lua/info.c
@@ -50,6 +50,7 @@
 #include "box/box.h"
 #include "lua/utils.h"
 #include "fiber.h"
+#include "tt_static.h"
 
 static void
 lbox_pushvclock(struct lua_State *L, const struct vclock *vclock)
@@ -65,6 +66,20 @@ lbox_pushvclock(struct lua_State *L, const struct vclock *vclock)
 	luaL_setmaphint(L, -1); /* compact flow */
 }
 
+static inline void
+lbox_push_replication_error_message(struct lua_State *L, struct error *e,
+				    int idx)
+{
+	lua_pushstring(L, "message");
+	lua_pushstring(L, e->errmsg);
+	lua_settable(L, idx - 2);
+	if (e->syserror == 0)
+		return;
+	lua_pushstring(L, "system_message");
+	lua_pushstring(L, strerror(e->syserror));
+	lua_settable(L, idx - 2);
+}
+
 static void
 lbox_pushapplier(lua_State *L, struct applier *applier)
 {
@@ -103,11 +118,8 @@ lbox_pushapplier(lua_State *L, struct applier *applier)
 		lua_settable(L, -3);
 
 		struct error *e = diag_last_error(&applier->reader->diag);
-		if (e != NULL) {
-			lua_pushstring(L, "message");
-			lua_pushstring(L, e->errmsg);
-			lua_settable(L, -3);
-		}
+		if (e != NULL)
+			lbox_push_replication_error_message(L, e, -1);
 	}
 }
 
@@ -135,11 +147,8 @@ lbox_pushrelay(lua_State *L, struct relay *relay)
 		lua_settable(L, -3);
 
 		struct error *e = diag_last_error(relay_get_diag(relay));
-		if (e != NULL) {
-			lua_pushstring(L, "message");
-			lua_pushstring(L, e->errmsg);
-			lua_settable(L, -3);
-		}
+		if (e != NULL)
+			lbox_push_replication_error_message(L, e, -1);
 		break;
 	}
 	default: unreachable();
diff --git a/test/replication/gh-4402-info-errno.result b/test/replication/gh-4402-info-errno.result
new file mode 100644
index 000000000..661eea38b
--- /dev/null
+++ b/test/replication/gh-4402-info-errno.result
@@ -0,0 +1,63 @@
+-- test-run result file version 2
+test_run = require('test_run').new()
+ | ---
+ | ...
+
+--
+-- gh-4402: replication info table should contain not only
+-- Tarantool's error, but also a system error (errno's message)
+-- when possible.
+--
+
+box.schema.user.grant('guest', 'replication')
+ | ---
+ | ...
+
+test_run:cmd('create server replica with rpl_master=default, script="replication/replica.lua"')
+ | ---
+ | - true
+ | ...
+test_run:cmd('start server replica')
+ | ---
+ | - true
+ | ...
+i = box.info
+ | ---
+ | ...
+replica_id = i.id % 2 + 1
+ | ---
+ | ...
+d = i.replication[replica_id].downstream
+ | ---
+ | ...
+d ~= nil and d.status == 'follow' or i
+ | ---
+ | - true
+ | ...
+
+test_run:cmd('stop server replica')
+ | ---
+ | - true
+ | ...
+test_run:cmd("cleanup server replica")
+ | ---
+ | - true
+ | ...
+test_run:cmd("delete server replica")
+ | ---
+ | - true
+ | ...
+i = box.info
+ | ---
+ | ...
+d = i.replication[replica_id].downstream
+ | ---
+ | ...
+d ~= nil and d.system_message ~= nil and d.message ~= nil or i
+ | ---
+ | - true
+ | ...
+
+box.schema.user.revoke('guest', 'replication')
+ | ---
+ | ...
diff --git a/test/replication/gh-4402-info-errno.test.lua b/test/replication/gh-4402-info-errno.test.lua
new file mode 100644
index 000000000..1b2d9d814
--- /dev/null
+++ b/test/replication/gh-4402-info-errno.test.lua
@@ -0,0 +1,25 @@
+test_run = require('test_run').new()
+
+--
+-- gh-4402: replication info table should contain not only
+-- Tarantool's error, but also a system error (errno's message)
+-- when possible.
+--
+
+box.schema.user.grant('guest', 'replication')
+
+test_run:cmd('create server replica with rpl_master=default, script="replication/replica.lua"')
+test_run:cmd('start server replica')
+i = box.info
+replica_id = i.id % 2 + 1
+d = i.replication[replica_id].downstream
+d ~= nil and d.status == 'follow' or i
+
+test_run:cmd('stop server replica')
+test_run:cmd("cleanup server replica")
+test_run:cmd("delete server replica")
+i = box.info
+d = i.replication[replica_id].downstream
+d ~= nil and d.system_message ~= nil and d.message ~= nil or i
+
+box.schema.user.revoke('guest', 'replication')
diff --git a/test/replication/suite.cfg b/test/replication/suite.cfg
index eb25077d8..4abc93e20 100644
--- a/test/replication/suite.cfg
+++ b/test/replication/suite.cfg
@@ -11,6 +11,7 @@
     "on_schema_init.test.lua": {},
     "long_row_timeout.test.lua": {},
     "join_without_snap.test.lua": {},
+    "gh-4402-info-errno.test.lua": {},
     "*": {
         "memtx": {"engine": "memtx"},
         "vinyl": {"engine": "vinyl"}
-- 
2.21.0 (Apple Git-122.2)

  parent reply	other threads:[~2019-11-05 14:54 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-05 14:59 [Tarantool-patches] [PATCH 0/3] Replication status errno Vladislav Shpilevoy
2019-11-05 14:59 ` [Tarantool-patches] [PATCH 1/3] access: fix invalid error type for not found user Vladislav Shpilevoy
2019-11-05 18:15   ` Konstantin Osipov
2019-11-06 14:48     ` Vladislav Shpilevoy
2019-11-05 14:59 ` [Tarantool-patches] [PATCH 2/3] error: move errno into an error object Vladislav Shpilevoy
2019-11-05 18:18   ` Konstantin Osipov
2019-11-06 14:49     ` Vladislav Shpilevoy
2019-11-05 14:59 ` Vladislav Shpilevoy [this message]
2019-11-05 18:18   ` [Tarantool-patches] [PATCH 3/3] replication: show errno in replication info Konstantin Osipov
2019-11-05 18:13 ` [Tarantool-patches] [PATCH 0/3] Replication status errno Konstantin Osipov
2019-11-21 17:38 ` Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a7e733bfa9aed398b9a7c10f88c9b1ccf8fb5df4.1572965692.git.v.shpilevoy@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=kostja.osipov@gmail.com \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 3/3] replication: show errno in replication info' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox