]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
replicator: Added replication_dsync_parameters setting to pass "doveadm sync" parameters.
authorTimo Sirainen <tss@iki.fi>
Sat, 23 Nov 2013 19:12:39 +0000 (21:12 +0200)
committerTimo Sirainen <tss@iki.fi>
Sat, 23 Nov 2013 19:12:39 +0000 (21:12 +0200)
-f and -s parameters are added automatically when needed.

src/replication/replicator/dsync-client.c
src/replication/replicator/dsync-client.h
src/replication/replicator/replicator-brain.c
src/replication/replicator/replicator-settings.c
src/replication/replicator/replicator-settings.h

index 75f2e96f9d75e7bb274d8a71642faf5c7112d286..20f411da3bfbd752635a6d8f95bb53e745943d3f 100644 (file)
 #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');
index 78962cce30032d39efa584cc79c8f56cb20ad425..e44fb2c80f2a7d69033dfebd598d99344c61b45c 100644 (file)
@@ -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,
index 2673fbd2898f575421c0581688341bf5ae2249ae..12fc6ebbd7d0d82e27547893706fc253d680c7c5 100644 (file)
@@ -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;
 }
index 127c36657c7238a5c386a0e0285e7b944f6e924d..3115350f1f81a861845e62b9c01ed059dfe8c73d 100644 (file)
@@ -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
index 961704a22a8dad2faebeec4974d449eb4754af88..947bcf8e3150176bfa405e97e7468394390aea06 100644 (file)
@@ -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;