From: Timo Sirainen Date: Sat, 23 Nov 2013 19:12:39 +0000 (+0200) Subject: replicator: Added replication_dsync_parameters setting to pass "doveadm sync" parameters. X-Git-Tag: 2.2.9~15 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=36757b426f4761dbd837bdddc8998e22d09dc869;p=thirdparty%2Fdovecot%2Fcore.git replicator: Added replication_dsync_parameters setting to pass "doveadm sync" parameters. -f and -s parameters are added automatically when needed. --- diff --git a/src/replication/replicator/dsync-client.c b/src/replication/replicator/dsync-client.c index 75f2e96f9d..20f411da3b 100644 --- a/src/replication/replicator/dsync-client.c +++ b/src/replication/replicator/dsync-client.c @@ -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 dsync_client { struct ostream *output; struct timeout *to; + char *dsync_params; char *state; dsync_callback_t *callback; void *context; @@ -36,13 +32,15 @@ struct dsync_client { 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 @@ void dsync_client_sync(struct dsync_client *client, 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 @@ void dsync_client_sync(struct dsync_client *client, 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 --git a/src/replication/replicator/dsync-client.h b/src/replication/replicator/dsync-client.h index 78962cce30..e44fb2c80f 100644 --- a/src/replication/replicator/dsync-client.h +++ b/src/replication/replicator/dsync-client.h @@ -10,7 +10,8 @@ enum dsync_reply { 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 --git a/src/replication/replicator/replicator-brain.c b/src/replication/replicator/replicator-brain.c index 2673fbd289..12fc6ebbd7 100644 --- a/src/replication/replicator/replicator-brain.c +++ b/src/replication/replicator/replicator-brain.c @@ -80,7 +80,8 @@ get_dsync_client(struct replicator_brain *brain) 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 --git a/src/replication/replicator/replicator-settings.c b/src/replication/replicator/replicator-settings.c index 127c36657c..3115350f1f 100644 --- a/src/replication/replicator/replicator-settings.c +++ b/src/replication/replicator/replicator-settings.c @@ -53,6 +53,7 @@ struct service_settings replicator_service_settings = { 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 @@ static const struct setting_define replicator_setting_defines[] = { 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 --git a/src/replication/replicator/replicator-settings.h b/src/replication/replicator/replicator-settings.h index 961704a22a..947bcf8e31 100644 --- a/src/replication/replicator/replicator-settings.h +++ b/src/replication/replicator/replicator-settings.h @@ -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;