changeset 20458:16f9c0a46cbb

dsync: When full resync is wanted in a stateful sync, output empty state. This continues 3d49dc64d, which didn't actually work because brain->require_full_resync was either cleared earlier or it was never even set in this brain.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Wed, 29 Jun 2016 22:29:20 +0300
parents d53a5a158a0b
children bf4d8143536b
files src/doveadm/dsync/dsync-brain-mailbox.c src/doveadm/dsync/dsync-brain.c src/doveadm/dsync/dsync-ibc-pipe.c src/doveadm/dsync/dsync-ibc-private.h src/doveadm/dsync/dsync-ibc-stream.c src/doveadm/dsync/dsync-ibc.c src/doveadm/dsync/dsync-ibc.h
diffstat 7 files changed, 39 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/doveadm/dsync/dsync-brain-mailbox.c	Wed Jun 29 21:09:48 2016 +0300
+++ b/src/doveadm/dsync/dsync-brain-mailbox.c	Wed Jun 29 22:29:20 2016 +0300
@@ -343,10 +343,6 @@
 
 	i_assert(brain->box != NULL);
 
-	if (brain->require_full_resync) {
-		brain->mailbox_state.last_uidvalidity = 0;
-		brain->require_full_resync = FALSE;
-	}
 	array_append(&brain->remote_mailbox_states, &brain->mailbox_state, 1);
 	if (brain->box_exporter != NULL) {
 		const char *errstr;
--- a/src/doveadm/dsync/dsync-brain.c	Wed Jun 29 21:09:48 2016 +0300
+++ b/src/doveadm/dsync/dsync-brain.c	Wed Jun 29 22:29:20 2016 +0300
@@ -568,16 +568,19 @@
 {
 	const char *error;
 	enum mail_error mail_error;
+	bool require_full_resync;
 	enum dsync_ibc_recv_ret ret;
 
 	if (!brain->master_brain) {
 		dsync_ibc_send_finish(brain->ibc,
 				      brain->failed ? "dsync failed" : NULL,
-				      brain->mail_error);
+				      brain->mail_error,
+				      brain->require_full_resync);
 		brain->state = DSYNC_STATE_DONE;
 		return TRUE;
 	} 
-	ret = dsync_ibc_recv_finish(brain->ibc, &error, &mail_error);
+	ret = dsync_ibc_recv_finish(brain->ibc, &error, &mail_error,
+				    &require_full_resync);
 	if (ret == DSYNC_IBC_RECV_RET_TRYAGAIN)
 		return FALSE;
 	if (error != NULL) {
@@ -587,6 +590,8 @@
 		    (brain->mail_error == 0 || brain->mail_error == MAIL_ERROR_TEMP))
 			brain->mail_error = mail_error;
 	}
+	if (require_full_resync)
+		brain->require_full_resync = TRUE;
 	brain->state = DSYNC_STATE_DONE;
 	return TRUE;
 }
--- a/src/doveadm/dsync/dsync-ibc-pipe.c	Wed Jun 29 21:09:48 2016 +0300
+++ b/src/doveadm/dsync/dsync-ibc-pipe.c	Wed Jun 29 22:29:20 2016 +0300
@@ -45,6 +45,7 @@
 		struct {
 			const char *error;
 			enum mail_error mail_error;
+			bool require_full_resync;
 		} finish;
 	} u;
 };
@@ -491,7 +492,8 @@
 
 static void
 dsync_ibc_pipe_send_finish(struct dsync_ibc *ibc, const char *error,
-			   enum mail_error mail_error)
+			   enum mail_error mail_error,
+			   bool require_full_resync)
 {
 	struct dsync_ibc_pipe *pipe = (struct dsync_ibc_pipe *)ibc;
 	struct item *item;
@@ -499,11 +501,13 @@
 	item = dsync_ibc_pipe_push_item(pipe->remote, ITEM_FINISH);
 	item->u.finish.error = p_strdup(item->pool, error);
 	item->u.finish.mail_error = mail_error;
+	item->u.finish.require_full_resync = require_full_resync;
 }
 
 static enum dsync_ibc_recv_ret
 dsync_ibc_pipe_recv_finish(struct dsync_ibc *ibc, const char **error_r,
-			   enum mail_error *mail_error_r)
+			   enum mail_error *mail_error_r,
+			   bool *require_full_resync_r)
 {
 	struct dsync_ibc_pipe *pipe = (struct dsync_ibc_pipe *)ibc;
 	struct item *item;
@@ -514,6 +518,7 @@
 
 	*error_r = item->u.finish.error;
 	*mail_error_r = item->u.finish.mail_error;
+	*require_full_resync_r = item->u.finish.require_full_resync;
 	return DSYNC_IBC_RECV_RET_OK;
 }
 
--- a/src/doveadm/dsync/dsync-ibc-private.h	Wed Jun 29 21:09:48 2016 +0300
+++ b/src/doveadm/dsync/dsync-ibc-private.h	Wed Jun 29 22:29:20 2016 +0300
@@ -69,10 +69,12 @@
 			     struct dsync_mail **mail_r);
 
 	void (*send_finish)(struct dsync_ibc *ibc, const char *error,
-			    enum mail_error mail_error);
+			    enum mail_error mail_error,
+			    bool require_full_resync);
 	enum dsync_ibc_recv_ret
 		(*recv_finish)(struct dsync_ibc *ibc, const char **error_r,
-			       enum mail_error *mail_error_r);
+			       enum mail_error *mail_error_r,
+			       bool *require_full_resync_r);
 
 	void (*close_mail_streams)(struct dsync_ibc *ibc);
 	bool (*is_send_queue_full)(struct dsync_ibc *ibc);
--- a/src/doveadm/dsync/dsync-ibc-stream.c	Wed Jun 29 21:09:48 2016 +0300
+++ b/src/doveadm/dsync/dsync-ibc-stream.c	Wed Jun 29 22:29:20 2016 +0300
@@ -125,7 +125,7 @@
 	},
 	{ .name = "finish",
 	  .chr = 'F',
-	  .optional_keys = "error mail_error",
+	  .optional_keys = "error mail_error require_full_resync",
 	  .min_minor_version = DSYNC_PROTOCOL_MINOR_HAVE_FINISH
 	},
 	{ .name = "mailbox_cache_field",
@@ -1906,7 +1906,8 @@
 
 static void
 dsync_ibc_stream_send_finish(struct dsync_ibc *_ibc, const char *error,
-			     enum mail_error mail_error)
+			     enum mail_error mail_error,
+			     bool require_full_resync)
 {
 	struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc;
 	struct dsync_serializer_encoder *encoder;
@@ -1920,13 +1921,16 @@
 		dsync_serializer_encode_add(encoder, "mail_error",
 					    dec2str(mail_error));
 	}
+	if (require_full_resync)
+		dsync_serializer_encode_add(encoder, "require_full_resync", "");
 	dsync_serializer_encode_finish(&encoder, str);
 	dsync_ibc_stream_send_string(ibc, str);
 }
 
 static enum dsync_ibc_recv_ret
 dsync_ibc_stream_recv_finish(struct dsync_ibc *_ibc, const char **error_r,
-			     enum mail_error *mail_error_r)
+			     enum mail_error *mail_error_r,
+			     bool *require_full_resync_r)
 {
 	struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc;
 	struct dsync_deserializer_decoder *decoder;
@@ -1936,6 +1940,7 @@
 
 	*error_r = NULL;
 	*mail_error_r = 0;
+	*require_full_resync_r = FALSE;
 
 	p_clear(ibc->ret_pool);
 
@@ -1953,6 +1958,8 @@
 		dsync_ibc_input_error(ibc, decoder, "Invalid mail_error");
 		return DSYNC_IBC_RECV_RET_TRYAGAIN;
 	}
+	if (dsync_deserializer_decode_try(decoder, "require_full_resync", &value))
+		*require_full_resync_r = TRUE;
 	*mail_error_r = i;
 
 	ibc->finish_received = TRUE;
--- a/src/doveadm/dsync/dsync-ibc.c	Wed Jun 29 21:09:48 2016 +0300
+++ b/src/doveadm/dsync/dsync-ibc.c	Wed Jun 29 22:29:20 2016 +0300
@@ -196,16 +196,19 @@
 }
 
 void dsync_ibc_send_finish(struct dsync_ibc *ibc, const char *error,
-			   enum mail_error mail_error)
+			   enum mail_error mail_error,
+			   bool require_full_resync)
 {
-	ibc->v.send_finish(ibc, error, mail_error);
+	ibc->v.send_finish(ibc, error, mail_error, require_full_resync);
 }
 
 enum dsync_ibc_recv_ret
 dsync_ibc_recv_finish(struct dsync_ibc *ibc, const char **error_r,
-		      enum mail_error *mail_error_r)
+		      enum mail_error *mail_error_r,
+		      bool *require_full_resync_r)
 {
-	return ibc->v.recv_finish(ibc, error_r, mail_error_r);
+	return ibc->v.recv_finish(ibc, error_r, mail_error_r,
+				  require_full_resync_r);
 }
 
 void dsync_ibc_close_mail_streams(struct dsync_ibc *ibc)
--- a/src/doveadm/dsync/dsync-ibc.h	Wed Jun 29 21:09:48 2016 +0300
+++ b/src/doveadm/dsync/dsync-ibc.h	Wed Jun 29 22:29:20 2016 +0300
@@ -148,10 +148,12 @@
 dsync_ibc_recv_mail(struct dsync_ibc *ibc, struct dsync_mail **mail_r);
 
 void dsync_ibc_send_finish(struct dsync_ibc *ibc, const char *error,
-			   enum mail_error mail_error);
+			   enum mail_error mail_error,
+			   bool require_full_resync);
 enum dsync_ibc_recv_ret
 dsync_ibc_recv_finish(struct dsync_ibc *ibc, const char **error_r,
-		      enum mail_error *mail_error_r);
+		      enum mail_error *mail_error_r,
+		      bool *require_full_resync_r);
 
 /* Close any mail input streams that are kept open. This needs to be called
    before the mail is attempted to be freed (usually on error conditions). */