changeset 20971:3e6f922c2322

director: If SYNCs are received during handshake, send them later. This fixes delays during handshake: Error: Ring SYNC appears to have got lost, resending
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 24 Oct 2016 21:58:03 +0300
parents d653bcdff8a2
children 14f621e65819
files src/director/director-connection.c src/director/director-host.h
diffstat 2 files changed, 35 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/director/director-connection.c	Mon Oct 24 20:21:36 2016 +0300
+++ b/src/director/director-connection.c	Mon Oct 24 21:58:03 2016 +0300
@@ -316,6 +316,25 @@
 	return FALSE;
 }
 
+static void director_send_delayed_syncs(struct director *dir)
+{
+	struct director_host *const *hostp;
+
+	i_assert(dir->right != NULL);
+
+	dir_debug("director(%s): Sending delayed SYNCs", dir->right->name);
+	array_foreach(&dir->dir_hosts, hostp) {
+		if ((*hostp)->delayed_sync_seq == 0)
+			continue;
+
+		director_sync_send(dir, *hostp, (*hostp)->delayed_sync_seq,
+				   (*hostp)->delayed_sync_minor_version,
+				   (*hostp)->delayed_sync_timestamp,
+				   (*hostp)->delayed_sync_hosts_hash);
+		(*hostp)->delayed_sync_seq = 0;
+	}
+}
+
 static bool director_connection_assign_right(struct director_connection *conn)
 {
 	struct director *dir = conn->dir;
@@ -343,6 +362,7 @@
 	i_free(conn->name);
 	conn->name = i_strdup_printf("%s/right", conn->host->name);
 	director_connection_assigned(conn);
+	director_send_delayed_syncs(dir);
 	return TRUE;
 }
 
@@ -1422,6 +1442,13 @@
 			/* forward it to the connection on right */
 			director_sync_send(dir, host, seq, minor_version,
 					   timestamp, hosts_hash);
+		} else {
+			dir_debug("director(%s): We have no right connection - "
+				  "delay replying to SYNC until finished", conn->name);
+			host->delayed_sync_seq = seq;
+			host->delayed_sync_minor_version = minor_version;
+			host->delayed_sync_timestamp = timestamp;
+			host->delayed_sync_hosts_hash = hosts_hash;
 		}
 	}
 	return TRUE;
--- a/src/director/director-host.h	Mon Oct 24 20:21:36 2016 +0300
+++ b/src/director/director-host.h	Mon Oct 24 21:58:03 2016 +0300
@@ -30,6 +30,14 @@
 	/* Last time host was detected to be down */
 	time_t last_network_failure;
 	time_t last_protocol_failure;
+
+	/* When we finish getting a right connection, send a SYNC with these
+	   parameters (if delayed_sync_seq != 0) */
+	uint32_t delayed_sync_seq;
+	unsigned int delayed_sync_minor_version;
+	unsigned int delayed_sync_timestamp;
+	unsigned int delayed_sync_hosts_hash;
+
 	/* we are this director */
 	unsigned int self:1;
 	unsigned int removed:1;