[server 4/5] relay: send heartbeat on subscribe if replica is uptodate
Vladimir Davydov
vdavydov.dev at gmail.com
Wed Jan 24 20:44:53 MSK 2018
Currently, a realy sends a heartbeat message to the replica only if
there was no WAL events for 'replication_timeout' seconds. As a result,
a replica that happens to be uptodate on subscribe will not update the
lag until the timeout passes, which may delay configuration. Let's make
relay send a heartbeat message right after subscribe in case the replica
is uptodate.
---
src/box/relay.cc | 31 ++++++++++++++++++++++---------
1 file changed, 22 insertions(+), 9 deletions(-)
diff --git a/src/box/relay.cc b/src/box/relay.cc
index 967874e7..124942a0 100644
--- a/src/box/relay.cc
+++ b/src/box/relay.cc
@@ -385,6 +385,18 @@ relay_reader_f(va_list ap)
return 0;
}
+static void
+relay_send_heartbeat(struct relay *relay)
+{
+ struct xrow_header row;
+ xrow_encode_timestamp(&row, instance_id, ev_now(loop()));
+ try {
+ relay_send(relay, &row);
+ } catch (Exception *e) {
+ e->log();
+ }
+}
+
/**
* A libev callback invoked when a relay client socket is ready
* for read. This currently only happens when the client closes
@@ -417,6 +429,15 @@ relay_subscribe_f(va_list ap)
fiber_set_joinable(reader, true);
fiber_start(reader, relay, fiber());
+ /*
+ * If the replica happens to be uptodate on subscribe,
+ * don't wait for timeout to happen - send a heartbeat
+ * message right away to update the replication lag as
+ * soon as possible.
+ */
+ if (vclock_compare(&r->vclock, &replicaset.vclock) == 0)
+ relay_send_heartbeat(relay);
+
while (!fiber_is_cancelled()) {
double timeout = replication_timeout;
struct errinj *inj = errinj(ERRINJ_RELAY_REPORT_INTERVAL,
@@ -430,15 +451,7 @@ relay_subscribe_f(va_list ap)
* Send a heartbeat message to update
* the replication lag on the slave.
*/
- struct xrow_header row;
- xrow_encode_timestamp(&row, instance_id,
- ev_now(loop()));
- try {
- relay_send(relay, &row);
- } catch (Exception *e) {
- e->log();
- break;
- }
+ relay_send_heartbeat(relay);
}
/*
--
2.11.0
More information about the Tarantool-patches
mailing list