dovecot-2.0-sslstream: dsync: Fixed subscription syncing to work...

dovecot at dovecot.org dovecot at dovecot.org
Sat Feb 13 02:56:25 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0-sslstream/rev/b5b253d35612
changeset: 10332:b5b253d35612
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Nov 16 14:40:59 2009 -0500
description:
dsync: Fixed subscription syncing to work with namespace prefixes.

diffstat:

11 files changed, 142 insertions(+), 112 deletions(-)
src/dsync/dsync-brain-private.h         |   13 -----
src/dsync/dsync-brain.c                 |   69 +++++++++++++++++--------------
src/dsync/dsync-proxy-client.c          |   39 ++++++++++-------
src/dsync/dsync-proxy-server-cmd.c      |   25 ++++++-----
src/dsync/dsync-worker-local.c          |   25 ++++++-----
src/dsync/dsync-worker-private.h        |    5 --
src/dsync/dsync-worker.c                |   14 ++----
src/dsync/dsync-worker.h                |   17 ++++++-
src/dsync/test-dsync-proxy-server-cmd.c |   27 ++++++++----
src/dsync/test-dsync-worker.c           |   15 ++----
src/dsync/test-dsync-worker.h           |    5 --

diffs (truncated from 565 to 300 lines):

diff -r 2e4fc44c6160 -r b5b253d35612 src/dsync/dsync-brain-private.h
--- a/src/dsync/dsync-brain-private.h	Mon Nov 16 13:37:22 2009 -0500
+++ b/src/dsync/dsync-brain-private.h	Mon Nov 16 14:40:59 2009 -0500
@@ -27,22 +27,13 @@ struct dsync_brain_mailbox_list {
 	ARRAY_TYPE(dsync_mailbox) dirs;
 };
 
-struct dsync_brain_subscription {
-	const char *name;
-	time_t last_change;
-};
-struct dsync_brain_unsubscription {
-	mailbox_guid_t name_sha1;
-	time_t last_change;
-};
-
 struct dsync_brain_subs_list {
 	pool_t pool;
 	struct dsync_brain *brain;
 	struct dsync_worker *worker;
 	struct dsync_worker_subs_iter *iter;
-	ARRAY_DEFINE(subscriptions, struct dsync_brain_subscription);
-	ARRAY_DEFINE(unsubscriptions, struct dsync_brain_unsubscription);
+	ARRAY_DEFINE(subscriptions, struct dsync_worker_subscription);
+	ARRAY_DEFINE(unsubscriptions, struct dsync_worker_unsubscription);
 };
 
 struct dsync_brain_guid_instance {
diff -r 2e4fc44c6160 -r b5b253d35612 src/dsync/dsync-brain.c
--- a/src/dsync/dsync-brain.c	Mon Nov 16 13:37:22 2009 -0500
+++ b/src/dsync/dsync-brain.c	Mon Nov 16 14:40:59 2009 -0500
@@ -151,30 +151,35 @@ static void dsync_brain_subs_list_finish
 }
 
 static int
-dsync_brain_subscription_cmp(const struct dsync_brain_subscription *s1,
-			     const struct dsync_brain_subscription *s2)
-{
-	return strcmp(s1->name, s2->name);
+dsync_worker_subscription_cmp(const struct dsync_worker_subscription *s1,
+			      const struct dsync_worker_subscription *s2)
+{
+	return strcmp(s1->vname, s2->vname);
 }
 
 static int
-dsync_brain_unsubscription_cmp(const struct dsync_brain_unsubscription *u1,
-			       const struct dsync_brain_unsubscription *u2)
-{
-	return dsync_guid_cmp(&u1->name_sha1, &u2->name_sha1);
+dsync_worker_unsubscription_cmp(const struct dsync_worker_unsubscription *u1,
+				const struct dsync_worker_unsubscription *u2)
+{
+	int ret;
+
+	ret = strcmp(u1->ns_prefix, u2->ns_prefix);
+	return ret != 0 ? ret :
+		dsync_guid_cmp(&u1->name_sha1, &u2->name_sha1);
 }
 
 static void dsync_worker_subs_input(void *context)
 {
 	struct dsync_brain_subs_list *list = context;
-	struct dsync_brain_subscription subs;
-	struct dsync_brain_unsubscription unsubs;
+	struct dsync_worker_subscription subs;
+	struct dsync_worker_unsubscription unsubs;
 	int ret;
 
 	memset(&subs, 0, sizeof(subs));
-	while ((ret = dsync_worker_subs_iter_next(list->iter, &subs.name,
-						  &subs.last_change)) > 0) {
-		subs.name = p_strdup(list->pool, subs.name);
+	while ((ret = dsync_worker_subs_iter_next(list->iter, &subs)) > 0) {
+		subs.vname = p_strdup(list->pool, subs.vname);
+		subs.storage_name = p_strdup(list->pool, subs.storage_name);
+		subs.ns_prefix = p_strdup(list->pool, subs.ns_prefix);
 		array_append(&list->subscriptions, &subs, 1);
 	}
 	if (ret == 0)
@@ -182,18 +187,19 @@ static void dsync_worker_subs_input(void
 
 	memset(&unsubs, 0, sizeof(unsubs));
 	while ((ret = dsync_worker_subs_iter_next_un(list->iter,
-						     &unsubs.name_sha1,
-						     &unsubs.last_change)) > 0)
+						     &unsubs)) > 0) {
+		unsubs.ns_prefix = p_strdup(list->pool, unsubs.ns_prefix);
 		array_append(&list->unsubscriptions, &unsubs, 1);
+	}
 
 	if (ret < 0) {
 		/* finished listing subscriptions */
 		if (dsync_worker_subs_iter_deinit(&list->iter) < 0)
 			dsync_brain_fail(list->brain);
 		array_sort(&list->subscriptions,
-			   dsync_brain_subscription_cmp);
+			   dsync_worker_subscription_cmp);
 		array_sort(&list->unsubscriptions,
-			   dsync_brain_unsubscription_cmp);
+			   dsync_worker_unsubscription_cmp);
 		dsync_brain_subs_list_finished(list->brain);
 	}
 }
@@ -309,15 +315,15 @@ static void dsync_brain_sync_mailboxes(s
 
 static bool
 dsync_brain_is_unsubscribed(struct dsync_brain_subs_list *list,
-			    const struct dsync_brain_subscription *subs)
-{
-	const struct dsync_brain_unsubscription *unsubs;
-	struct dsync_brain_unsubscription lookup;
-
-	/* FIXME: doesn't work with namespace prefixes */
-	dsync_str_sha_to_guid(subs->name, &lookup.name_sha1);
+			    const struct dsync_worker_subscription *subs)
+{
+	const struct dsync_worker_unsubscription *unsubs;
+	struct dsync_worker_unsubscription lookup;
+
+	lookup.ns_prefix = subs->ns_prefix;
+	dsync_str_sha_to_guid(subs->storage_name, &lookup.name_sha1);
 	unsubs = array_bsearch(&list->unsubscriptions, &lookup,
-			       dsync_brain_unsubscription_cmp);
+			       dsync_worker_unsubscription_cmp);
 	if (unsubs == NULL)
 		return FALSE;
 	else
@@ -326,7 +332,7 @@ dsync_brain_is_unsubscribed(struct dsync
 
 static void dsync_brain_sync_subscriptions(struct dsync_brain *brain)
 {
-	const struct dsync_brain_subscription *src_subs, *dest_subs;
+	const struct dsync_worker_subscription *src_subs, *dest_subs;
 	unsigned int src, dest, src_count, dest_count;
 	int ret;
 
@@ -341,7 +347,8 @@ static void dsync_brain_sync_subscriptio
 		} else if (dest == dest_count) {
 			ret = -1;
 		} else {
-			ret = strcmp(src_subs[src].name, dest_subs[dest].name);
+			ret = strcmp(src_subs[src].vname,
+				     dest_subs[dest].vname);
 			if (ret == 0) {
 				src++; dest++;
 				continue;
@@ -353,11 +360,11 @@ static void dsync_brain_sync_subscriptio
 			if (dsync_brain_is_unsubscribed(brain->dest_subs_list,
 							&src_subs[src])) {
 				dsync_worker_set_subscribed(brain->src_worker,
-							    src_subs[src].name,
+							    src_subs[src].vname,
 							    FALSE);
 			} else {
 				dsync_worker_set_subscribed(brain->dest_worker,
-							    src_subs[src].name,
+							    src_subs[src].vname,
 							    TRUE);
 			}
 			src++;
@@ -366,11 +373,11 @@ static void dsync_brain_sync_subscriptio
 			if (dsync_brain_is_unsubscribed(brain->src_subs_list,
 							&dest_subs[dest])) {
 				dsync_worker_set_subscribed(brain->dest_worker,
-							    dest_subs[dest].name,
+							    dest_subs[dest].vname,
 							    FALSE);
 			} else {
 				dsync_worker_set_subscribed(brain->src_worker,
-							    dest_subs[dest].name,
+							    dest_subs[dest].vname,
 							    TRUE);
 			}
 			dest++;
diff -r 2e4fc44c6160 -r b5b253d35612 src/dsync/dsync-proxy-client.c
--- a/src/dsync/dsync-proxy-client.c	Mon Nov 16 13:37:22 2009 -0500
+++ b/src/dsync/dsync-proxy-client.c	Mon Nov 16 14:40:59 2009 -0500
@@ -431,8 +431,8 @@ proxy_client_worker_subs_iter_init(struc
 
 static int
 proxy_client_worker_subs_iter_next_line(struct proxy_client_dsync_worker_subs_iter *iter,
-					const char **name_r,
-					time_t *last_change_r)
+					unsigned int wanted_arg_count,
+					char ***args_r)
 {
 	struct proxy_client_dsync_worker *worker =
 		(struct proxy_client_dsync_worker *)iter->iter.worker;
@@ -455,48 +455,57 @@ proxy_client_worker_subs_iter_next_line(
 
 	p_clear(iter->pool);
 	args = p_strsplit(iter->pool, line, "\t");
-	if (args[0] == NULL || args[1] == NULL) {
+	if (str_array_length((const char *const *)args) < wanted_arg_count) {
 		i_error("Invalid subscription input from worker server");
 		iter->iter.failed = TRUE;
 		return -1;
 	}
-	*name_r = args[0];
-	*last_change_r = strtoul(args[1], NULL, 10);
+	*args_r = args;
 	return 1;
 }
 
 static int
 proxy_client_worker_subs_iter_next(struct dsync_worker_subs_iter *_iter,
-				   const char **name_r, time_t *last_change_r)
+				   struct dsync_worker_subscription *rec_r)
 {
 	struct proxy_client_dsync_worker_subs_iter *iter =
 		(struct proxy_client_dsync_worker_subs_iter *)_iter;
-
-	return proxy_client_worker_subs_iter_next_line(iter, name_r,
-						       last_change_r);
+	char **args;
+	int ret;
+
+	ret = proxy_client_worker_subs_iter_next_line(iter, 4, &args);
+	if (ret <= 0)
+		return ret;
+
+	rec_r->vname = str_tabunescape(args[0]);
+	rec_r->storage_name = str_tabunescape(args[1]);
+	rec_r->ns_prefix = str_tabunescape(args[2]);
+	rec_r->last_change = strtoul(args[3], NULL, 10);
+	return 1;
 }
 
 static int
 proxy_client_worker_subs_iter_next_un(struct dsync_worker_subs_iter *_iter,
-				      mailbox_guid_t *name_sha1_r,
-				      time_t *last_change_r)
+				      struct dsync_worker_unsubscription *rec_r)
 {
 	struct proxy_client_dsync_worker_subs_iter *iter =
 		(struct proxy_client_dsync_worker_subs_iter *)_iter;
-	const char *name;
+	char **args;
 	int ret;
 
-	ret = proxy_client_worker_subs_iter_next_line(iter, &name,
-						      last_change_r);
+	ret = proxy_client_worker_subs_iter_next_line(iter, 3, &args);
 	if (ret <= 0)
 		return ret;
 
-	if (dsync_proxy_mailbox_guid_import(name, name_sha1_r) < 0) {
+	memset(rec_r, 0, sizeof(*rec_r));
+	if (dsync_proxy_mailbox_guid_import(args[0], &rec_r->name_sha1) < 0) {
 		i_error("Invalid subscription input from worker server: "
 			"Invalid unsubscription mailbox GUID");
 		iter->iter.failed = TRUE;
 		return -1;
 	}
+	rec_r->ns_prefix = str_tabunescape(args[1]);
+	rec_r->last_change = strtoul(args[2], NULL, 10);
 	return 1;
 }
 
diff -r 2e4fc44c6160 -r b5b253d35612 src/dsync/dsync-proxy-server-cmd.c
--- a/src/dsync/dsync-proxy-server-cmd.c	Mon Nov 16 13:37:22 2009 -0500
+++ b/src/dsync/dsync-proxy-server-cmd.c	Mon Nov 16 14:40:59 2009 -0500
@@ -64,17 +64,20 @@ cmd_box_list(struct dsync_proxy_server *
 
 static bool cmd_subs_list_subscriptions(struct dsync_proxy_server *server)
 {
-	const char *name;
-	time_t last_change;
+	struct dsync_worker_subscription rec;
 	string_t *str;
 	int ret;
 
 	str = t_str_new(256);
 	while ((ret = dsync_worker_subs_iter_next(server->subs_iter,
-						  &name, &last_change)) > 0) {
+						  &rec)) > 0) {
 		str_truncate(str, 0);
-		str_tabescape_write(str, name);
-		str_printfa(str, "\t%ld\n", (long)last_change);
+		str_tabescape_write(str, rec.vname);
+		str_append_c(str, '\t');
+		str_tabescape_write(str, rec.storage_name);
+		str_append_c(str, '\t');
+		str_tabescape_write(str, rec.ns_prefix);
+		str_printfa(str, "\t%ld\n", (long)rec.last_change);
 		o_stream_send(server->output, str_data(str), str_len(str));
 		if (proxy_server_is_output_full(server))
 			break;
@@ -89,18 +92,18 @@ static bool cmd_subs_list_subscriptions(
 
 static bool cmd_subs_list_unsubscriptions(struct dsync_proxy_server *server)
 {
-	mailbox_guid_t name_sha1;
-	time_t last_change;
+	struct dsync_worker_unsubscription rec;
 	string_t *str;
 	int ret;
 
 	str = t_str_new(256);


More information about the dovecot-cvs mailing list