]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dsync: If verbose_proctitle=yes, show the current state in it.
authorTimo Sirainen <tss@iki.fi>
Mon, 24 Jun 2013 13:37:48 +0000 (16:37 +0300)
committerTimo Sirainen <tss@iki.fi>
Mon, 24 Jun 2013 13:37:48 +0000 (16:37 +0300)
src/doveadm/dsync/doveadm-dsync.c
src/doveadm/dsync/dsync-brain-private.h
src/doveadm/dsync/dsync-brain.c
src/doveadm/dsync/dsync-brain.h
src/doveadm/dsync/dsync-mailbox-export.c
src/doveadm/dsync/dsync-mailbox-export.h
src/doveadm/dsync/dsync-mailbox-import.c
src/doveadm/dsync/dsync-mailbox-import.h

index 605438b929fd64e25f9ae565aeceb89255bc44f2..b676afc7bb4d3eab20c6d23de7a871639f7fd04e 100644 (file)
@@ -362,7 +362,7 @@ cmd_dsync_run_local(struct dsync_cmd_context *ctx, struct mail_user *user,
                return -1;
        }
 
-       brain2 = dsync_brain_slave_init(user2, ibc2);
+       brain2 = dsync_brain_slave_init(user2, ibc2, TRUE);
 
        brain1_running = brain2_running = TRUE;
        changed1 = changed2 = TRUE;
@@ -970,7 +970,7 @@ cmd_dsync_server_run(struct doveadm_mail_cmd_context *_ctx,
        mail_user_set_get_temp_prefix(temp_prefix, user->set);
 
        ibc = cmd_dsync_icb_stream_init(ctx, "local", str_c(temp_prefix));
-       brain = dsync_brain_slave_init(user, ibc);
+       brain = dsync_brain_slave_init(user, ibc, FALSE);
 
        io_loop_run(current_ioloop);
 
index 63b8a753ce9138b7aa8fc9dd40a9a5daa580f593..e50ea549814bf12e162f60b7daf94f34990f9372 100644 (file)
@@ -68,6 +68,7 @@ struct dsync_brain {
        enum dsync_state state, pre_box_state;
        enum dsync_box_state box_recv_state;
        enum dsync_box_state box_send_state;
+       unsigned int proctitle_update_counter;
 
        struct dsync_transaction_log_scan *log_scan;
        struct dsync_mailbox_importer *box_importer;
@@ -95,6 +96,7 @@ struct dsync_brain {
        unsigned int sync_visible_namespaces:1;
        unsigned int no_mail_sync:1;
        unsigned int changes_during_sync:1;
+       unsigned int verbose_proctitle:1;
        unsigned int failed:1;
 };
 
index 2feca4938df9ea6e4a375f7c8ad14a294f9c9f3a..6f65cfa5a2fdbbe33703317ae04630bb26a8b089 100644 (file)
@@ -4,10 +4,16 @@
 #include "array.h"
 #include "hash.h"
 #include "hostpid.h"
+#include "str.h"
+#include "process-title.h"
+#include "master-service.h"
+#include "master-service-settings.h"
 #include "mail-namespace.h"
 #include "dsync-mailbox-tree.h"
 #include "dsync-ibc.h"
 #include "dsync-brain-private.h"
+#include "dsync-mailbox-import.h"
+#include "dsync-mailbox-export.h"
 
 #include <sys/stat.h>
 
@@ -26,6 +32,42 @@ static const char *dsync_state_names[] = {
        "done"
 };
 
+static const char *dsync_brain_get_proctitle(struct dsync_brain *brain)
+{
+       string_t *str = t_str_new(128);
+       const char *import_title, *export_title;
+
+       str_append_c(str, '[');
+       str_append(str, brain->user->username);
+       if (brain->box == NULL) {
+               str_append_c(str, ' ');
+               str_append(str, dsync_state_names[brain->state]);
+       } else {
+               str_append_c(str, ' ');
+               str_append(str, mailbox_get_vname(brain->box));
+               import_title = brain->box_importer == NULL ? "" :
+                       dsync_mailbox_import_get_proctitle(brain->box_importer);
+               export_title = brain->box_exporter == NULL ? "" :
+                       dsync_mailbox_export_get_proctitle(brain->box_exporter);
+               if (import_title[0] == '\0' && export_title[0] == '\0') {
+                       str_printfa(str, " send:%s recv:%s",
+                                   dsync_box_state_names[brain->box_send_state],
+                                   dsync_box_state_names[brain->box_recv_state]);
+               } else {
+                       if (import_title[0] != '\0') {
+                               str_append(str, " import:");
+                               str_append(str, import_title);
+                       }
+                       if (export_title[0] != '\0') {
+                               str_append(str, " export:");
+                               str_append(str, export_title);
+                       }
+               }
+       }
+       str_append_c(str, ']');
+       return str_c(str);
+}
+
 static void dsync_brain_run_io(void *context)
 {
        struct dsync_brain *brain = context;
@@ -57,8 +99,11 @@ static struct dsync_brain *
 dsync_brain_common_init(struct mail_user *user, struct dsync_ibc *ibc)
 {
        struct dsync_brain *brain;
+       const struct master_service_settings *service_set;
        pool_t pool;
 
+       service_set = master_service_settings_get(master_service);
+
        pool = pool_alloconly_create("dsync brain", 10240);
        brain = p_new(pool, struct dsync_brain, 1);
        brain->pool = pool;
@@ -66,6 +111,7 @@ dsync_brain_common_init(struct mail_user *user, struct dsync_ibc *ibc)
        brain->ibc = ibc;
        brain->sync_type = DSYNC_BRAIN_SYNC_TYPE_UNKNOWN;
        brain->lock_fd = -1;
+       brain->verbose_proctitle = service_set->verbose_proctitle;
        hash_table_create(&brain->mailbox_states, pool, 0,
                          guid_128_hash, guid_128_cmp);
        p_array_init(&brain->remote_mailbox_states, pool, 64);
@@ -148,7 +194,8 @@ dsync_brain_master_init(struct mail_user *user, struct dsync_ibc *ibc,
 }
 
 struct dsync_brain *
-dsync_brain_slave_init(struct mail_user *user, struct dsync_ibc *ibc)
+dsync_brain_slave_init(struct mail_user *user, struct dsync_ibc *ibc,
+                      bool local)
 {
        struct dsync_ibc_settings ibc_set;
        struct dsync_brain *brain;
@@ -156,6 +203,12 @@ dsync_brain_slave_init(struct mail_user *user, struct dsync_ibc *ibc)
        brain = dsync_brain_common_init(user, ibc);
        brain->state = DSYNC_STATE_SLAVE_RECV_HANDSHAKE;
 
+       if (local) {
+               /* both master and slave are running within the same process,
+                  update the proctitle only for master. */
+               brain->verbose_proctitle = FALSE;
+       }
+
        memset(&ibc_set, 0, sizeof(ibc_set));
        ibc_set.hostname = my_hostdomain();
        dsync_ibc_send_handshake(ibc, &ibc_set);
@@ -396,6 +449,9 @@ static bool dsync_brain_slave_recv_last_common(struct dsync_brain *brain)
 
 static bool dsync_brain_run_real(struct dsync_brain *brain, bool *changed_r)
 {
+       enum dsync_state orig_state = brain->state;
+       enum dsync_box_state orig_box_recv_state = brain->box_recv_state;
+       enum dsync_box_state orig_box_send_state = brain->box_send_state;
        bool changed = FALSE, ret = TRUE;
 
        if (brain->failed)
@@ -453,7 +509,13 @@ static bool dsync_brain_run_real(struct dsync_brain *brain, bool *changed_r)
                        brain->master_brain ? 'M' : 'S',
                        dsync_state_names[brain->state], changed);
        }
-
+       if (brain->verbose_proctitle) {
+               if (orig_state != brain->state ||
+                   orig_box_recv_state != brain->box_recv_state ||
+                   orig_box_send_state != brain->box_send_state ||
+                   ++brain->proctitle_update_counter % 100 == 0)
+                       process_title_set(dsync_brain_get_proctitle(brain));
+       }
        *changed_r = changed;
        return brain->failed ? FALSE : ret;
 }
index c280908f3e7f9340dcfde802ec5af031f91ab226..fe9650c14365e6ed3fb68cda300e0f18a4571385 100644 (file)
@@ -53,7 +53,8 @@ dsync_brain_master_init(struct mail_user *user, struct dsync_ibc *ibc,
                        enum dsync_brain_flags flags,
                        const struct dsync_brain_settings *set);
 struct dsync_brain *
-dsync_brain_slave_init(struct mail_user *user, struct dsync_ibc *ibc);
+dsync_brain_slave_init(struct mail_user *user, struct dsync_ibc *ibc,
+                      bool local);
 /* Returns 0 if everything was successful, -1 if syncing failed in some way */
 int dsync_brain_deinit(struct dsync_brain **brain);
 
index 9914d2d6a812c8a74c74420544e78ea4907dfe75..7176a362ed8ad54ec7f0ee6825e490ab733264fb 100644 (file)
@@ -26,6 +26,7 @@ struct dsync_mailbox_exporter {
 
        struct mailbox_transaction_context *trans;
        struct mail_search_context *search_ctx;
+       unsigned int search_pos, search_count;
 
        /* GUID => instances */
        HASH_TABLE(char *, struct dsync_mail_guid_instances *) export_guids;
@@ -698,6 +699,7 @@ dsync_mailbox_export_body_search_init(struct dsync_mailbox_exporter *exporter)
        array_append_array(&exporter->search_uids, &exporter->requested_uids);
        array_clear(&exporter->requested_uids);
 
+       exporter->search_count = seq_range_count(&exporter->search_uids);
        exporter->search_ctx =
                mailbox_search_init(exporter->trans, search_args, NULL,
                                    MAIL_FETCH_GUID |
@@ -797,6 +799,7 @@ dsync_mailbox_export_next_mail(struct dsync_mailbox_exporter *exporter)
        }
 
        while (mailbox_search_next(exporter->search_ctx, &mail)) {
+               exporter->search_pos++;
                if ((ret = dsync_mailbox_export_mail(exporter, mail)) > 0)
                        return &exporter->dsync_mail;
                if (ret < 0) {
@@ -850,3 +853,11 @@ int dsync_mailbox_export_deinit(struct dsync_mailbox_exporter **_exporter,
        pool_unref(&exporter->pool);
        return *error_r != NULL ? -1 : 0;
 }
+
+const char *dsync_mailbox_export_get_proctitle(struct dsync_mailbox_exporter *exporter)
+{
+       if (exporter->search_ctx == NULL)
+               return "";
+       return t_strdup_printf("%u/%u", exporter->search_pos,
+                              exporter->search_count);
+}
index 4c1b66b76ef483fa72d6406b09a7b7a8907d41df..5777b32f215ce52117d0bdf04b1c6171bc8f0852 100644 (file)
@@ -23,4 +23,6 @@ dsync_mailbox_export_next_mail(struct dsync_mailbox_exporter *exporter);
 int dsync_mailbox_export_deinit(struct dsync_mailbox_exporter **exporter,
                                const char **error_r);
 
+const char *dsync_mailbox_export_get_proctitle(struct dsync_mailbox_exporter *exporter);
+
 #endif
index dab5cf8ccaffff154d99bc6cdcf181f3dc2b7574..cb31260b278ee0a75702d7d9aee9ef3fe17e9c35 100644 (file)
@@ -89,6 +89,7 @@ struct dsync_mailbox_importer {
 
        uint32_t prev_uid, next_local_seq, local_uid_next;
        uint64_t local_initial_highestmodseq, local_initial_highestpvtmodseq;
+       unsigned int import_pos, import_count;
 
        unsigned int failed:1;
        unsigned int debug:1;
@@ -1712,6 +1713,7 @@ dsync_mailbox_import_handle_mail(struct dsync_mailbox_importer *importer,
                return FALSE;
        }
        /* successfully handled all the mails locally */
+       importer->import_pos++;
        return TRUE;
 }
 
@@ -1764,6 +1766,8 @@ void dsync_mailbox_import_changes_finish(struct dsync_mailbox_importer *importer
                        importer->failed = TRUE;
                }
        }
+       importer->import_count = hash_table_count(importer->import_guids) +
+               hash_table_count(importer->import_uids);
 
        dsync_mailbox_import_assign_new_uids(importer);
        /* save mails from local sources where possible,
@@ -2002,6 +2006,7 @@ void dsync_mailbox_import_mail(struct dsync_mailbox_importer *importer,
                hash_table_remove(importer->import_uids,
                                  POINTER_CAST(mail->uid));
        }
+       importer->import_pos++;
        dsync_mailbox_save_newmails(importer, mail, all_newmails);
 }
 
@@ -2310,3 +2315,11 @@ int dsync_mailbox_import_deinit(struct dsync_mailbox_importer **_importer,
        pool_unref(&importer->pool);
        return ret;
 }
+
+const char *dsync_mailbox_import_get_proctitle(struct dsync_mailbox_importer *importer)
+{
+       if (importer->search_ctx != NULL)
+               return "";
+       return t_strdup_printf("%u/%u", importer->import_pos,
+                              importer->import_count);
+}
index e1799652a682d6955e9e743c0cb1338dacc9b829..27930f6b45613fed442f4989ac4e3522cbbb5cae 100644 (file)
@@ -42,4 +42,6 @@ int dsync_mailbox_import_deinit(struct dsync_mailbox_importer **importer,
                                uint64_t *last_common_pvt_modseq_r,
                                bool *changes_during_sync_r);
 
+const char *dsync_mailbox_import_get_proctitle(struct dsync_mailbox_importer *importer);
+
 #endif