changeset 22264:e95435889161

dsync: Use header hashing version 3
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Fri, 23 Jun 2017 11:15:32 +0300
parents 096f0c8b9cb1
children 66e02e3235d3
files src/doveadm/dsync/dsync-brain-mailbox.c src/doveadm/dsync/dsync-brain-private.h src/doveadm/dsync/dsync-brain.c src/doveadm/dsync/dsync-ibc-stream.c src/doveadm/dsync/dsync-ibc.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
diffstat 9 files changed, 33 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/doveadm/dsync/dsync-brain-mailbox.c	Fri Jun 23 11:02:24 2017 +0300
+++ b/src/doveadm/dsync/dsync-brain-mailbox.c	Fri Jun 23 11:15:32 2017 +0300
@@ -218,8 +218,6 @@
 		import_flags |= DSYNC_MAILBOX_IMPORT_FLAG_MAILS_USE_GUID128;
 	if (brain->no_notify)
 		import_flags |= DSYNC_MAILBOX_IMPORT_FLAG_NO_NOTIFY;
-	if (brain->hdr_hash_v2)
-		import_flags |= DSYNC_MAILBOX_IMPORT_FLAG_HDR_HASH_V2;
 	if (brain->empty_hdr_workaround)
 		import_flags |= DSYNC_MAILBOX_IMPORT_FLAG_EMPTY_HDR_WORKAROUND;
 
@@ -237,7 +235,7 @@
 					  brain->sync_max_size,
 					  brain->sync_flag,
 					  brain->import_commit_msgs_interval,
-					  import_flags);
+					  import_flags, brain->hdr_hash_version);
 }
 
 int dsync_brain_sync_mailbox_open(struct dsync_brain *brain,
@@ -329,8 +327,6 @@
 		exporter_flags |= DSYNC_MAILBOX_EXPORTER_FLAG_TIMESTAMPS;
 	if (brain->sync_max_size > 0)
 		exporter_flags |= DSYNC_MAILBOX_EXPORTER_FLAG_VSIZES;
-	if (brain->hdr_hash_v2)
-		exporter_flags |= DSYNC_MAILBOX_EXPORTER_FLAG_HDR_HASH_V2;
 	if (remote_dsync_box->messages_count == 0) {
 		/* remote mailbox is empty - we don't really need to export
 		   header hashes since they're not going to match anything
@@ -341,7 +337,8 @@
 	brain->box_exporter = brain->backup_recv ? NULL :
 		dsync_mailbox_export_init(brain->box, brain->log_scan,
 					  last_common_uid,
-					  exporter_flags);
+					  exporter_flags,
+					  brain->hdr_hash_version);
 	dsync_brain_sync_mailbox_init_remote(brain, remote_dsync_box);
 	return 1;
 }
--- a/src/doveadm/dsync/dsync-brain-private.h	Fri Jun 23 11:02:24 2017 +0300
+++ b/src/doveadm/dsync/dsync-brain-private.h	Fri Jun 23 11:15:32 2017 +0300
@@ -63,6 +63,7 @@
 	const char *sync_flag;
 	char alt_char;
 	unsigned int import_commit_msgs_interval;
+	unsigned int hdr_hash_version;
 
 	unsigned int lock_timeout;
 	int lock_fd;
@@ -116,7 +117,6 @@
 	unsigned int require_full_resync:1;
 	unsigned int verbose_proctitle:1;
 	unsigned int no_notify:1;
-	unsigned int hdr_hash_v2:1;
 	unsigned int failed:1;
 	unsigned int empty_hdr_workaround:1;
 };
--- a/src/doveadm/dsync/dsync-brain.c	Fri Jun 23 11:02:24 2017 +0300
+++ b/src/doveadm/dsync/dsync-brain.c	Fri Jun 23 11:15:32 2017 +0300
@@ -424,6 +424,18 @@
 	return brain->lock_fd == -1 ? -1 : 0;
 }
 
+static void
+dsync_brain_set_hdr_hash_version(struct dsync_brain *brain,
+				 const struct dsync_ibc_settings *ibc_set)
+{
+	if (ibc_set->hdr_hash_v3)
+		brain->hdr_hash_version = 3;
+	else if (ibc_set->hdr_hash_v2)
+		brain->hdr_hash_version = 3;
+	else
+		brain->hdr_hash_version = 1;
+}
+
 static bool dsync_brain_master_recv_handshake(struct dsync_brain *brain)
 {
 	const struct dsync_ibc_settings *ibc_set;
@@ -439,7 +451,7 @@
 			return FALSE;
 		}
 	}
-	brain->hdr_hash_v2 = ibc_set->hdr_hash_v2;
+	dsync_brain_set_hdr_hash_version(brain, ibc_set);
 
 	brain->state = brain->sync_type == DSYNC_BRAIN_SYNC_TYPE_STATE ?
 		DSYNC_STATE_MASTER_SEND_LAST_COMMON :
@@ -457,7 +469,7 @@
 
 	if (dsync_ibc_recv_handshake(brain->ibc, &ibc_set) == 0)
 		return FALSE;
-	brain->hdr_hash_v2 = ibc_set->hdr_hash_v2;
+	dsync_brain_set_hdr_hash_version(brain, ibc_set);
 
 	if (ibc_set->lock_timeout > 0) {
 		brain->lock_timeout = ibc_set->lock_timeout;
--- a/src/doveadm/dsync/dsync-ibc-stream.c	Fri Jun 23 11:02:24 2017 +0300
+++ b/src/doveadm/dsync/dsync-ibc-stream.c	Fri Jun 23 11:15:32 2017 +0300
@@ -26,13 +26,14 @@
 #define DSYNC_IBC_STREAM_OUTBUF_THROTTLE_SIZE (1024*128)
 
 #define DSYNC_PROTOCOL_VERSION_MAJOR 3
-#define DSYNC_PROTOCOL_VERSION_MINOR 4
-#define DSYNC_HANDSHAKE_VERSION "VERSION\tdsync\t3\t4\n"
+#define DSYNC_PROTOCOL_VERSION_MINOR 5
+#define DSYNC_HANDSHAKE_VERSION "VERSION\tdsync\t3\t5\n"
 
 #define DSYNC_PROTOCOL_MINOR_HAVE_ATTRIBUTES 1
 #define DSYNC_PROTOCOL_MINOR_HAVE_SAVE_GUID 2
 #define DSYNC_PROTOCOL_MINOR_HAVE_FINISH 3
 #define DSYNC_PROTOCOL_MINOR_HAVE_HDR_HASH_V2 4
+#define DSYNC_PROTOCOL_MINOR_HAVE_HDR_HASH_V3 5
 
 enum item_type {
 	ITEM_NONE,
@@ -884,6 +885,7 @@
 	if (dsync_deserializer_decode_try(decoder, "empty_hdr_workaround", &value))
 		set->brain_flags |= DSYNC_BRAIN_FLAG_EMPTY_HDR_WORKAROUND;
 	set->hdr_hash_v2 = ibc->minor_version >= DSYNC_PROTOCOL_MINOR_HAVE_HDR_HASH_V2;
+	set->hdr_hash_v3 = ibc->minor_version >= DSYNC_PROTOCOL_MINOR_HAVE_HDR_HASH_V3;
 
 	*set_r = set;
 	return DSYNC_IBC_RECV_RET_OK;
--- a/src/doveadm/dsync/dsync-ibc.h	Fri Jun 23 11:02:24 2017 +0300
+++ b/src/doveadm/dsync/dsync-ibc.h	Fri Jun 23 11:15:32 2017 +0300
@@ -68,6 +68,7 @@
 	enum dsync_brain_sync_type sync_type;
 	enum dsync_brain_flags brain_flags;
 	bool hdr_hash_v2;
+	bool hdr_hash_v3;
 	unsigned int lock_timeout;
 	unsigned int import_commit_msgs_interval;
 };
--- a/src/doveadm/dsync/dsync-mailbox-export.c	Fri Jun 23 11:02:24 2017 +0300
+++ b/src/doveadm/dsync/dsync-mailbox-export.c	Fri Jun 23 11:15:32 2017 +0300
@@ -498,7 +498,8 @@
 dsync_mailbox_export_init(struct mailbox *box,
 			  struct dsync_transaction_log_scan *log_scan,
 			  uint32_t last_common_uid,
-			  enum dsync_mailbox_exporter_flags flags)
+			  enum dsync_mailbox_exporter_flags flags,
+			  unsigned int hdr_hash_version)
 {
 	struct dsync_mailbox_exporter *exporter;
 	pool_t pool;
@@ -520,8 +521,7 @@
 		(flags & DSYNC_MAILBOX_EXPORTER_FLAG_TIMESTAMPS) != 0;
 	exporter->export_virtual_sizes =
 		(flags & DSYNC_MAILBOX_EXPORTER_FLAG_VSIZES) != 0;
-	exporter->hdr_hash_version =
-		(flags & DSYNC_MAILBOX_EXPORTER_FLAG_HDR_HASH_V2) ? 2 : 1;
+	exporter->hdr_hash_version = hdr_hash_version;
 	exporter->no_hdr_hashes =
 		(flags & DSYNC_MAILBOX_EXPORTER_FLAG_NO_HDR_HASHES) != 0;
 	p_array_init(&exporter->requested_uids, pool, 16);
--- a/src/doveadm/dsync/dsync-mailbox-export.h	Fri Jun 23 11:02:24 2017 +0300
+++ b/src/doveadm/dsync/dsync-mailbox-export.h	Fri Jun 23 11:15:32 2017 +0300
@@ -6,7 +6,6 @@
 	DSYNC_MAILBOX_EXPORTER_FLAG_MAILS_HAVE_GUIDS	= 0x02,
 	DSYNC_MAILBOX_EXPORTER_FLAG_MINIMAL_DMAIL_FILL	= 0x04,
 	DSYNC_MAILBOX_EXPORTER_FLAG_TIMESTAMPS		= 0x08,
-	DSYNC_MAILBOX_EXPORTER_FLAG_HDR_HASH_V2		= 0x10,
 	DSYNC_MAILBOX_EXPORTER_FLAG_NO_HDR_HASHES	= 0x20,
 	DSYNC_MAILBOX_EXPORTER_FLAG_VSIZES		= 0x40,
 };
@@ -15,7 +14,8 @@
 dsync_mailbox_export_init(struct mailbox *box,
 			  struct dsync_transaction_log_scan *log_scan,
 			  uint32_t last_common_uid,
-			  enum dsync_mailbox_exporter_flags flags);
+			  enum dsync_mailbox_exporter_flags flags,
+			  unsigned int hdr_hash_version);
 /* Returns 1 if attribute was returned, 0 if no more attributes, -1 on error */
 int dsync_mailbox_export_next_attr(struct dsync_mailbox_exporter *exporter,
 				   const struct dsync_mailbox_attribute **attr_r);
--- a/src/doveadm/dsync/dsync-mailbox-import.c	Fri Jun 23 11:02:24 2017 +0300
+++ b/src/doveadm/dsync/dsync-mailbox-import.c	Fri Jun 23 11:15:32 2017 +0300
@@ -226,7 +226,8 @@
 			  uoff_t sync_max_size,
 			  const char *sync_flag,
 			  unsigned int commit_msgs_interval,
-			  enum dsync_mailbox_import_flags flags)
+			  enum dsync_mailbox_import_flags flags,
+			  unsigned int hdr_hash_version)
 {
 	struct dsync_mailbox_importer *importer;
 	struct mailbox_status status;
@@ -289,8 +290,7 @@
 		(flags & DSYNC_MAILBOX_IMPORT_FLAG_MAILS_HAVE_GUIDS) != 0;
 	importer->mails_use_guid128 =
 		(flags & DSYNC_MAILBOX_IMPORT_FLAG_MAILS_USE_GUID128) != 0;
-	importer->hdr_hash_version =
-		(flags & DSYNC_MAILBOX_IMPORT_FLAG_HDR_HASH_V2) != 0 ? 2 : 1;
+	importer->hdr_hash_version = hdr_hash_version;
 	importer->empty_hdr_workaround =
 		(flags & DSYNC_MAILBOX_IMPORT_FLAG_EMPTY_HDR_WORKAROUND) != 0;
 
--- a/src/doveadm/dsync/dsync-mailbox-import.h	Fri Jun 23 11:02:24 2017 +0300
+++ b/src/doveadm/dsync/dsync-mailbox-import.h	Fri Jun 23 11:15:32 2017 +0300
@@ -11,7 +11,6 @@
 	DSYNC_MAILBOX_IMPORT_FLAG_MAILS_HAVE_GUIDS	= 0x10,
 	DSYNC_MAILBOX_IMPORT_FLAG_MAILS_USE_GUID128	= 0x20,
 	DSYNC_MAILBOX_IMPORT_FLAG_NO_NOTIFY		= 0x40,
-	DSYNC_MAILBOX_IMPORT_FLAG_HDR_HASH_V2		= 0x80,
 	DSYNC_MAILBOX_IMPORT_FLAG_EMPTY_HDR_WORKAROUND	= 0x100
 };
 
@@ -37,7 +36,8 @@
 			  uoff_t sync_max_size,
 			  const char *sync_flag,
 			  unsigned int commit_msgs_interval,
-			  enum dsync_mailbox_import_flags flags);
+			  enum dsync_mailbox_import_flags flags,
+			  unsigned int hdr_hash_version);
 int dsync_mailbox_import_attribute(struct dsync_mailbox_importer *importer,
 				   const struct dsync_mailbox_attribute *attr);
 int dsync_mailbox_import_change(struct dsync_mailbox_importer *importer,