dovecot-2.2: replicator: Added replication_dsync_parameters sett...

dovecot at dovecot.org dovecot at dovecot.org
Sat Nov 23 21:12:53 EET 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/556e654cc9a0
changeset: 17016:556e654cc9a0
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Nov 23 21:12:39 2013 +0200
description:
replicator: Added replication_dsync_parameters setting to pass "doveadm sync" parameters.
-f and -s parameters are added automatically when needed.

diffstat:

 src/replication/replicator/dsync-client.c        |  26 ++++++++++++++++-------
 src/replication/replicator/dsync-client.h        |   3 +-
 src/replication/replicator/replicator-brain.c    |   3 +-
 src/replication/replicator/replicator-settings.c |   2 +
 src/replication/replicator/replicator-settings.h |   1 +
 5 files changed, 25 insertions(+), 10 deletions(-)

diffs (128 lines):

diff -r 0870cca2b4fb -r 556e654cc9a0 src/replication/replicator/dsync-client.c
--- a/src/replication/replicator/dsync-client.c	Sat Nov 23 18:24:24 2013 +0000
+++ b/src/replication/replicator/dsync-client.c	Sat Nov 23 21:12:39 2013 +0200
@@ -14,11 +14,6 @@
 #define DSYNC_FAIL_TIMEOUT_MSECS (1000*5)
 #define DOVEADM_HANDSHAKE "VERSION\tdoveadm-server\t1\t0\n"
 
-/* normally there shouldn't be any need for locking, since replicator doesn't
-   start dsync in parallel for the same user. we'll do locking just in case
-   anyway */
-#define DSYNC_LOCK_TIMEOUT_SECS 30
-
 struct dsync_client {
 	char *path;
 	int fd;
@@ -27,6 +22,7 @@
 	struct ostream *output;
 	struct timeout *to;
 
+	char *dsync_params;
 	char *state;
 	dsync_callback_t *callback;
 	void *context;
@@ -36,13 +32,15 @@
 	unsigned int cmd_sent:1;
 };
 
-struct dsync_client *dsync_client_init(const char *path)
+struct dsync_client *
+dsync_client_init(const char *path, const char *dsync_params)
 {
 	struct dsync_client *client;
 
 	client = i_new(struct dsync_client, 1);
 	client->path = i_strdup(path);
 	client->fd = -1;
+	client->dsync_params = i_strdup(dsync_params);
 	return client;
 }
 
@@ -190,6 +188,8 @@
 		       dsync_callback_t *callback, void *context)
 {
 	string_t *cmd;
+	unsigned int pos;
+	char *p;
 
 	i_assert(callback != NULL);
 	i_assert(!dsync_client_is_busy(client));
@@ -207,10 +207,20 @@
 		cmd = t_str_new(256);
 		str_append_c(cmd, '\t');
 		str_append_tabescaped(cmd, username);
-		str_printfa(cmd, "\tsync\t-d\t-N\t-l\t%u", DSYNC_LOCK_TIMEOUT_SECS);
+		str_append(cmd, "\tsync\t");
+		pos = str_len(cmd);
+		/* insert the parameters. we can do it simply by converting
+		   spaces into tabs, it's unlikely we'll ever need anything
+		   more complex here. */
+		str_append(cmd, client->dsync_params);
+		p = str_c_modifiable(cmd) + pos;
+		for (; *p != '\0'; p++) {
+			if (*p == ' ')
+				*p = '\t';
+		}
 		if (full)
 			str_append(cmd, "\t-f");
-		str_append(cmd, "\t-U\t-s\t");
+		str_append(cmd, "\t-s\t");
 		if (state != NULL)
 			str_append(cmd, state);
 		str_append_c(cmd, '\n');
diff -r 0870cca2b4fb -r 556e654cc9a0 src/replication/replicator/dsync-client.h
--- a/src/replication/replicator/dsync-client.h	Sat Nov 23 18:24:24 2013 +0000
+++ b/src/replication/replicator/dsync-client.h	Sat Nov 23 21:12:39 2013 +0200
@@ -10,7 +10,8 @@
 typedef void dsync_callback_t(enum dsync_reply reply,
 			      const char *state, void *context);
 
-struct dsync_client *dsync_client_init(const char *path);
+struct dsync_client *
+dsync_client_init(const char *path, const char *dsync_params);
 void dsync_client_deinit(struct dsync_client **conn);
 
 void dsync_client_sync(struct dsync_client *conn,
diff -r 0870cca2b4fb -r 556e654cc9a0 src/replication/replicator/replicator-brain.c
--- a/src/replication/replicator/replicator-brain.c	Sat Nov 23 18:24:24 2013 +0000
+++ b/src/replication/replicator/replicator-brain.c	Sat Nov 23 21:12:39 2013 +0200
@@ -80,7 +80,8 @@
 	    brain->set->replication_max_conns)
 		return NULL;
 
-	conn = dsync_client_init(brain->set->doveadm_socket_path);
+	conn = dsync_client_init(brain->set->doveadm_socket_path,
+				 brain->set->replication_dsync_parameters);
 	array_append(&brain->dsync_clients, &conn, 1);
 	return conn;
 }
diff -r 0870cca2b4fb -r 556e654cc9a0 src/replication/replicator/replicator-settings.c
--- a/src/replication/replicator/replicator-settings.c	Sat Nov 23 18:24:24 2013 +0000
+++ b/src/replication/replicator/replicator-settings.c	Sat Nov 23 21:12:39 2013 +0200
@@ -53,6 +53,7 @@
 static const struct setting_define replicator_setting_defines[] = {
 	DEF(SET_STR, auth_socket_path),
 	DEF(SET_STR, doveadm_socket_path),
+	DEF(SET_STR, replication_dsync_parameters),
 
 	DEF(SET_TIME, replication_full_sync_interval),
 	DEF(SET_UINT, replication_max_conns),
@@ -63,6 +64,7 @@
 const struct replicator_settings replicator_default_settings = {
 	.auth_socket_path = "auth-userdb",
 	.doveadm_socket_path = "doveadm-server",
+	.replication_dsync_parameters = "-d -N -l 30 -U",
 
 	.replication_full_sync_interval = 60*60*24,
 	.replication_max_conns = 10
diff -r 0870cca2b4fb -r 556e654cc9a0 src/replication/replicator/replicator-settings.h
--- a/src/replication/replicator/replicator-settings.h	Sat Nov 23 18:24:24 2013 +0000
+++ b/src/replication/replicator/replicator-settings.h	Sat Nov 23 21:12:39 2013 +0200
@@ -4,6 +4,7 @@
 struct replicator_settings {
 	const char *auth_socket_path;
 	const char *doveadm_socket_path;
+	const char *replication_dsync_parameters;
 
 	unsigned int replication_full_sync_interval;
 	unsigned int replication_max_conns;


More information about the dovecot-cvs mailing list