From: Timo Sirainen Date: Mon, 24 Jun 2013 13:37:48 +0000 (+0300) Subject: dsync: If verbose_proctitle=yes, show the current state in it. X-Git-Tag: 2.2.4~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=47255691575e06a1c95ce78ff0a1b502199de3ab;p=thirdparty%2Fdovecot%2Fcore.git dsync: If verbose_proctitle=yes, show the current state in it. --- diff --git a/src/doveadm/dsync/doveadm-dsync.c b/src/doveadm/dsync/doveadm-dsync.c index 605438b929..b676afc7bb 100644 --- a/src/doveadm/dsync/doveadm-dsync.c +++ b/src/doveadm/dsync/doveadm-dsync.c @@ -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); diff --git a/src/doveadm/dsync/dsync-brain-private.h b/src/doveadm/dsync/dsync-brain-private.h index 63b8a753ce..e50ea54981 100644 --- a/src/doveadm/dsync/dsync-brain-private.h +++ b/src/doveadm/dsync/dsync-brain-private.h @@ -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; }; diff --git a/src/doveadm/dsync/dsync-brain.c b/src/doveadm/dsync/dsync-brain.c index 2feca4938d..6f65cfa5a2 100644 --- a/src/doveadm/dsync/dsync-brain.c +++ b/src/doveadm/dsync/dsync-brain.c @@ -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 @@ -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; } diff --git a/src/doveadm/dsync/dsync-brain.h b/src/doveadm/dsync/dsync-brain.h index c280908f3e..fe9650c143 100644 --- a/src/doveadm/dsync/dsync-brain.h +++ b/src/doveadm/dsync/dsync-brain.h @@ -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); diff --git a/src/doveadm/dsync/dsync-mailbox-export.c b/src/doveadm/dsync/dsync-mailbox-export.c index 9914d2d6a8..7176a362ed 100644 --- a/src/doveadm/dsync/dsync-mailbox-export.c +++ b/src/doveadm/dsync/dsync-mailbox-export.c @@ -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); +} diff --git a/src/doveadm/dsync/dsync-mailbox-export.h b/src/doveadm/dsync/dsync-mailbox-export.h index 4c1b66b76e..5777b32f21 100644 --- a/src/doveadm/dsync/dsync-mailbox-export.h +++ b/src/doveadm/dsync/dsync-mailbox-export.h @@ -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 diff --git a/src/doveadm/dsync/dsync-mailbox-import.c b/src/doveadm/dsync/dsync-mailbox-import.c index dab5cf8cca..cb31260b27 100644 --- a/src/doveadm/dsync/dsync-mailbox-import.c +++ b/src/doveadm/dsync/dsync-mailbox-import.c @@ -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); +} diff --git a/src/doveadm/dsync/dsync-mailbox-import.h b/src/doveadm/dsync/dsync-mailbox-import.h index e1799652a6..27930f6b45 100644 --- a/src/doveadm/dsync/dsync-mailbox-import.h +++ b/src/doveadm/dsync/dsync-mailbox-import.h @@ -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