dovecot-2.2: dsync: If verbose_proctitle=yes, show the current s...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Jun 24 16:37:59 EEST 2013
details: http://hg.dovecot.org/dovecot-2.2/rev/b5876fa03b0e
changeset: 16539:b5876fa03b0e
user: Timo Sirainen <tss at iki.fi>
date: Mon Jun 24 16:37:48 2013 +0300
description:
dsync: If verbose_proctitle=yes, show the current state in it.
diffstat:
src/doveadm/dsync/doveadm-dsync.c | 4 +-
src/doveadm/dsync/dsync-brain-private.h | 2 +
src/doveadm/dsync/dsync-brain.c | 66 +++++++++++++++++++++++++++++++-
src/doveadm/dsync/dsync-brain.h | 3 +-
src/doveadm/dsync/dsync-mailbox-export.c | 11 +++++
src/doveadm/dsync/dsync-mailbox-export.h | 2 +
src/doveadm/dsync/dsync-mailbox-import.c | 13 ++++++
src/doveadm/dsync/dsync-mailbox-import.h | 2 +
8 files changed, 98 insertions(+), 5 deletions(-)
diffs (291 lines):
diff -r 83bea7e1f136 -r b5876fa03b0e src/doveadm/dsync/doveadm-dsync.c
--- a/src/doveadm/dsync/doveadm-dsync.c Mon Jun 24 16:36:32 2013 +0300
+++ b/src/doveadm/dsync/doveadm-dsync.c Mon Jun 24 16:37:48 2013 +0300
@@ -362,7 +362,7 @@
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 @@
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 -r 83bea7e1f136 -r b5876fa03b0e src/doveadm/dsync/dsync-brain-private.h
--- a/src/doveadm/dsync/dsync-brain-private.h Mon Jun 24 16:36:32 2013 +0300
+++ b/src/doveadm/dsync/dsync-brain-private.h Mon Jun 24 16:37:48 2013 +0300
@@ -68,6 +68,7 @@
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 @@
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 -r 83bea7e1f136 -r b5876fa03b0e src/doveadm/dsync/dsync-brain.c
--- a/src/doveadm/dsync/dsync-brain.c Mon Jun 24 16:36:32 2013 +0300
+++ b/src/doveadm/dsync/dsync-brain.c Mon Jun 24 16:37:48 2013 +0300
@@ -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 @@
"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 @@
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 @@
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 @@
}
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 @@
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_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 @@
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 -r 83bea7e1f136 -r b5876fa03b0e src/doveadm/dsync/dsync-brain.h
--- a/src/doveadm/dsync/dsync-brain.h Mon Jun 24 16:36:32 2013 +0300
+++ b/src/doveadm/dsync/dsync-brain.h Mon Jun 24 16:37:48 2013 +0300
@@ -53,7 +53,8 @@
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 -r 83bea7e1f136 -r b5876fa03b0e src/doveadm/dsync/dsync-mailbox-export.c
--- a/src/doveadm/dsync/dsync-mailbox-export.c Mon Jun 24 16:36:32 2013 +0300
+++ b/src/doveadm/dsync/dsync-mailbox-export.c Mon Jun 24 16:37:48 2013 +0300
@@ -26,6 +26,7 @@
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 @@
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 @@
}
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 @@
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 -r 83bea7e1f136 -r b5876fa03b0e src/doveadm/dsync/dsync-mailbox-export.h
--- a/src/doveadm/dsync/dsync-mailbox-export.h Mon Jun 24 16:36:32 2013 +0300
+++ b/src/doveadm/dsync/dsync-mailbox-export.h Mon Jun 24 16:37:48 2013 +0300
@@ -23,4 +23,6 @@
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 -r 83bea7e1f136 -r b5876fa03b0e src/doveadm/dsync/dsync-mailbox-import.c
--- a/src/doveadm/dsync/dsync-mailbox-import.c Mon Jun 24 16:36:32 2013 +0300
+++ b/src/doveadm/dsync/dsync-mailbox-import.c Mon Jun 24 16:37:48 2013 +0300
@@ -89,6 +89,7 @@
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 @@
return FALSE;
}
/* successfully handled all the mails locally */
+ importer->import_pos++;
return TRUE;
}
@@ -1764,6 +1766,8 @@
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 @@
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 @@
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 -r 83bea7e1f136 -r b5876fa03b0e src/doveadm/dsync/dsync-mailbox-import.h
--- a/src/doveadm/dsync/dsync-mailbox-import.h Mon Jun 24 16:36:32 2013 +0300
+++ b/src/doveadm/dsync/dsync-mailbox-import.h Mon Jun 24 16:37:48 2013 +0300
@@ -42,4 +42,6 @@
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
More information about the dovecot-cvs
mailing list