#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>
"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;
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;
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);
}
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;
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);
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)
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;
}
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;
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 |
}
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) {
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);
+}
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;
return FALSE;
}
/* successfully handled all the mails locally */
+ importer->import_pos++;
return TRUE;
}
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,
hash_table_remove(importer->import_uids,
POINTER_CAST(mail->uid));
}
+ importer->import_pos++;
dsync_mailbox_save_newmails(importer, mail, all_newmails);
}
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);
+}