view src/doveadm/dsync/dsync-mailbox.h @ 22715:20415dd0b85a

dsync: Add per-mailbox sync lock that is always used. Both importing and exporting gets the lock before they even sync the mailbox. The lock is kept until the import/export finishes. This guarantees that no matter how dsync is run, two dsyncs can't be working on the same mailbox at the same time. This lock is in addition to the optional per-user lock enabled by the -l parameter. If the -l parameter is used, the same lock timeout is used for the per-mailbox lock. Otherwise 30s timeout is used. This should help to avoid email duplication when replication is enabled for public namespaces, and maybe in some other rare situations as well.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 28 Dec 2017 14:10:23 +0200
parents 1f8b784712e1
children
line wrap: on
line source

#ifndef DSYNC_MAILBOX_H
#define DSYNC_MAILBOX_H

#include "mail-storage.h"

struct dsync_brain;

/* Mailbox that is going to be synced. Its name was already sent in the
   mailbox tree. */
struct dsync_mailbox {
	guid_128_t mailbox_guid;
	bool mailbox_lost;
	bool mailbox_ignore;
	bool have_guids, have_save_guids, have_only_guid128;

	uint32_t uid_validity, uid_next, messages_count, first_recent_uid;
	uint64_t highest_modseq, highest_pvt_modseq;
	ARRAY_TYPE(mailbox_cache_field) cache_fields;
};

struct dsync_mailbox_attribute {
	enum mail_attribute_type type;
	const char *key;
	/* if both values are NULL = not looked up yet / deleted */
	const char *value;
	struct istream *value_stream;

	time_t last_change; /* 0 = unknown */
	uint64_t modseq; /* 0 = unknown */

	bool deleted; /* attribute is known to have been deleted */
	bool exported; /* internally used by exporting */
};
#define DSYNC_ATTR_HAS_VALUE(attr) \
	((attr)->value != NULL || (attr)->value_stream != NULL)

void dsync_mailbox_attribute_dup(pool_t pool,
				 const struct dsync_mailbox_attribute *src,
				 struct dsync_mailbox_attribute *dest_r);

int dsync_mailbox_lock(struct dsync_brain *brain, struct mailbox *box,
		       struct file_lock **lock_r);

#endif