Tarantool development patches archive
 help / color / mirror / Atom feed
From: Ilya Markov <imarkov@tarantool.org>
To: georgy@tarantool.org
Cc: tarantool-patches@freelists.org
Subject: [tarantool-patches] [box.ctl 3/3] box.ctl: Add replica error event
Date: Thu, 14 Jun 2018 18:04:29 +0300	[thread overview]
Message-ID: <4207357911a2302156b1c9e0f153aff08a0d1326.1528988612.git.imarkov@tarantool.org> (raw)
In-Reply-To: <cover.1528988612.git.imarkov@tarantool.org>
In-Reply-To: <cover.1528988612.git.imarkov@tarantool.org>

Add event: replica fails with some error.

In scope of #3159
---
 src/box/ctl.h                     |  1 +
 src/box/lua/ctl.c                 |  6 +++++-
 src/box/relay.cc                  |  7 +++++++
 test/replication/master_onctl.lua |  3 +++
 test/replication/onctl.result     | 12 ++++++++++++
 test/replication/onctl.test.lua   |  5 ++++-
 6 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/src/box/ctl.h b/src/box/ctl.h
index 1dbb6be..db6f08a 100644
--- a/src/box/ctl.h
+++ b/src/box/ctl.h
@@ -49,6 +49,7 @@ enum ctl_event_type {
 	CTL_EVENT_SHUTDOWN,
 	CTL_EVENT_REPLICASET_ADD,
 	CTL_EVENT_REPLICASET_REMOVE,
+	CTL_EVENT_REPLICA_CONNECTION_ERROR,
 };
 
 struct on_ctl_event_ctx {
diff --git a/src/box/lua/ctl.c b/src/box/lua/ctl.c
index 5bd9be3..8a0dfc2 100644
--- a/src/box/lua/ctl.c
+++ b/src/box/lua/ctl.c
@@ -37,6 +37,7 @@
 #include <lualib.h>
 #include <lua/trigger.h>
 #include <box/ctl.h>
+#include <tt_uuid.h>
 
 #include "lua/utils.h"
 
@@ -77,7 +78,8 @@ lbox_push_on_ctl_event(struct lua_State *L, void *event)
 	lua_settable(L, -3);
 
 	if (ctx->type == CTL_EVENT_REPLICASET_ADD ||
-		ctx->type == CTL_EVENT_REPLICASET_REMOVE) {
+		ctx->type == CTL_EVENT_REPLICASET_REMOVE ||
+		ctx->type == CTL_EVENT_REPLICA_CONNECTION_ERROR) {
 		lua_pushstring(L, "replica_id");
 		luaL_pushuint64(L, ctx->replica_id);
 		lua_settable(L, -3);
@@ -125,5 +127,7 @@ box_lua_ctl_init(struct lua_State *L)
 	lua_setfield(L, -2, "REPLICASET_ADD");
 	lua_pushnumber(L, CTL_EVENT_REPLICASET_REMOVE);
 	lua_setfield(L, -2, "REPLICASET_REMOVE");
+	lua_pushnumber(L, CTL_EVENT_REPLICA_CONNECTION_ERROR);
+	lua_setfield(L, -2, "REPLICA_CONNECTION_ERROR");
 	lua_pop(L, 2); /* box, ctl */
 }
diff --git a/src/box/relay.cc b/src/box/relay.cc
index a25cc54..d535f83 100644
--- a/src/box/relay.cc
+++ b/src/box/relay.cc
@@ -52,6 +52,7 @@
 #include "xrow_io.h"
 #include "xstream.h"
 #include "wal.h"
+#include "ctl.h"
 
 /**
  * Cbus message to send status updates from relay to tx thread.
@@ -548,6 +549,12 @@ relay_subscribe_f(va_list ap)
 	if (!diag_is_empty(&relay->diag)) {
 		/* An error has occurred while reading ACKs of xlog. */
 		diag_move(&relay->diag, diag_get());
+		struct on_ctl_event_ctx ctx;
+		ctx.type = CTL_EVENT_REPLICA_CONNECTION_ERROR;
+		ctx.replica_id = relay->replica->id;
+		if (run_on_ctl_event_triggers(&ctx) < 0)
+			say_error("ctl_trigger error in replica error: %s",
+				  diag_last_error(diag_get())->errmsg);
 		/* Reference the diag in the status. */
 		diag_add_error(&relay->diag, diag_last_error(diag_get()));
 	}
diff --git a/test/replication/master_onctl.lua b/test/replication/master_onctl.lua
index e0eb39a..355e791 100644
--- a/test/replication/master_onctl.lua
+++ b/test/replication/master_onctl.lua
@@ -7,6 +7,7 @@ READ_ONLY = 0
 READ_WRITE = 0
 REPLICASET_ADD = {}
 REPLICASET_REMOVE = {}
+REPLICA_CONNECTION_ERROR = {}
 
 local function onctl(ctx)
     if ctx.type == box.ctl.event.SYSTEM_SPACE_RECOVERY then
@@ -21,6 +22,8 @@ local function onctl(ctx)
         table.insert(REPLICASET_ADD, ctx.replica_id)
     elseif ctx.type == box.ctl.event.REPLICASET_REMOVE then
         table.insert(REPLICASET_REMOVE, ctx.replica_id)
+    elseif ctx.type == box.ctl.event.REPLICA_CONNECTION_ERROR then
+        table.insert(REPLICA_CONNECTION_ERROR, ctx.replica_id)
     end
 end
 
diff --git a/test/replication/onctl.result b/test/replication/onctl.result
index 19b3e67..24a6683 100644
--- a/test/replication/onctl.result
+++ b/test/replication/onctl.result
@@ -50,6 +50,10 @@ REPLICASET_REMOVE
 ---
 - - 1
 ...
+REPLICA_CONNECTION_ERROR
+---
+- []
+...
 REPLICASET_ADD = {}
 ---
 ...
@@ -94,6 +98,10 @@ REPLICASET_REMOVE
 ---
 - []
 ...
+REPLICA_CONNECTION_ERROR
+---
+- []
+...
 new_replica_id
 ---
 - 2
@@ -186,6 +194,10 @@ test_run:cmd("switch master")
 ---
 - true
 ...
+REPLICA_CONNECTION_ERROR
+---
+- - 2
+...
 box.schema.user.revoke('guest', 'replication')
 ---
 ...
diff --git a/test/replication/onctl.test.lua b/test/replication/onctl.test.lua
index ff6a898..352b118 100644
--- a/test/replication/onctl.test.lua
+++ b/test/replication/onctl.test.lua
@@ -16,6 +16,7 @@ READ_WRITE
 REPLICASET_ADD
 -- must be one entry. Deletion of initial tuple in _cluster space.
 REPLICASET_REMOVE
+REPLICA_CONNECTION_ERROR
 
 REPLICASET_ADD = {}
 REPLICASET_REMOVE = {}
@@ -39,6 +40,7 @@ test_run:cmd("start server replica")
 
 REPLICASET_ADD
 REPLICASET_REMOVE
+REPLICA_CONNECTION_ERROR
 
 new_replica_id
 deleted_replica_id
@@ -80,8 +82,9 @@ test_run:cmd("restart server replica")
 -- TODO: test SHUTDOWN, when it is possible to grep logs of killed replica.
 --test_run:grep_log('replica', 'test replica shutdown')
 
-
 test_run:cmd("switch master")
+REPLICA_CONNECTION_ERROR
+
 box.schema.user.revoke('guest', 'replication')
 _ = box.space._cluster:delete{2}
 
-- 
2.7.4

  parent reply	other threads:[~2018-06-14 15:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-14 15:04 [tarantool-patches] [box.ctl 0/3] Introduce box.ctl.on_ctl_event trigger Ilya Markov
2018-06-14 15:04 ` [tarantool-patches] [box.ctl 1/3] box.ctl: Introduce stab box.ctl.on_ctl_event Ilya Markov
2018-07-31 11:40   ` [tarantool-patches] " Konstantin Belyavskiy
2018-06-14 15:04 ` [tarantool-patches] [box.ctl 2/3] box.ctl: Add on_ctl_event trigger calls Ilya Markov
2018-07-31 11:40   ` [tarantool-patches] " Konstantin Belyavskiy
2018-06-14 15:04 ` Ilya Markov [this message]
2018-07-31 11:40   ` [tarantool-patches] Re: [tarantool-patches] [box.ctl 3/3] box.ctl: Add replica error event Konstantin Belyavskiy

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=4207357911a2302156b1c9e0f153aff08a0d1326.1528988612.git.imarkov@tarantool.org \
    --to=imarkov@tarantool.org \
    --cc=georgy@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [box.ctl 3/3] box.ctl: Add replica error event' \
    /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