dovecot-2.0: dsync: Initial code to sync mailbox list without di...
dovecot at dovecot.org
dovecot at dovecot.org
Fri Jan 1 00:19:17 EET 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/96db209efe22
changeset: 10545:96db209efe22
user: Timo Sirainen <tss at iki.fi>
date: Thu Dec 31 17:19:03 2009 -0500
description:
dsync: Initial code to sync mailbox list without dir GUID support.
Not complete yet.
diffstat:
15 files changed, 160 insertions(+), 212 deletions(-)
src/dsync/Makefile.am | 8 -
src/dsync/dsync-brain.c | 6
src/dsync/dsync-data.c | 13 -
src/dsync/dsync-data.h | 24 ++-
src/dsync/dsync-proxy-client.c | 2
src/dsync/dsync-proxy-server-cmd.c | 2
src/dsync/dsync-proxy.c | 23 +--
src/dsync/dsync-worker-local.c | 203 +++++++++++++------------------
src/dsync/dsync-worker.c | 2
src/dsync/test-dsync-brain-msgs.c | 14 --
src/dsync/test-dsync-brain.c | 29 +---
src/dsync/test-dsync-common.c | 2
src/dsync/test-dsync-proxy-server-cmd.c | 36 ++---
src/dsync/test-dsync-proxy.c | 6
src/dsync/test-dsync-worker.c | 2
diffs (truncated from 927 to 300 lines):
diff -r 3c12d0376cef -r 96db209efe22 src/dsync/Makefile.am
--- a/src/dsync/Makefile.am Thu Dec 31 17:18:00 2009 -0500
+++ b/src/dsync/Makefile.am Thu Dec 31 17:19:03 2009 -0500
@@ -64,12 +64,12 @@ test_dsync_brain_msgs_DEPENDENCIES = dsy
test_dsync_brain_msgs_DEPENDENCIES = dsync-data.o dsync-brain-msgs.o dsync-worker.o $(test_libs)
test_dsync_proxy_SOURCES = test-dsync-proxy.c test-dsync-common.c
-test_dsync_proxy_LDADD = dsync-proxy.o $(test_ldadd)
-test_dsync_proxy_DEPENDENCIES = dsync-proxy.o $(test_libs)
+test_dsync_proxy_LDADD = dsync-proxy.o dsync-data.o $(test_ldadd)
+test_dsync_proxy_DEPENDENCIES = dsync-proxy.o dsync-data.o $(test_libs)
test_dsync_proxy_server_cmd_SOURCES = test-dsync-proxy-server-cmd.c test-dsync-worker.c test-dsync-common.c
-test_dsync_proxy_server_cmd_LDADD = dsync-worker.o dsync-proxy.o dsync-proxy-server-cmd.o $(test_ldadd)
-test_dsync_proxy_server_cmd_DEPENDENCIES = dsync-worker.o dsync-proxy.o dsync-proxy-server-cmd.o $(test_libs)
+test_dsync_proxy_server_cmd_LDADD = dsync-worker.o dsync-proxy.o dsync-proxy-server-cmd.o dsync-data.o $(test_ldadd)
+test_dsync_proxy_server_cmd_DEPENDENCIES = dsync-worker.o dsync-proxy.o dsync-proxy-server-cmd.o dsync-data.o $(test_libs)
check: check-am check-test
check-test: all-am
diff -r 3c12d0376cef -r 96db209efe22 src/dsync/dsync-brain.c
--- a/src/dsync/dsync-brain.c Thu Dec 31 17:18:00 2009 -0500
+++ b/src/dsync/dsync-brain.c Thu Dec 31 17:19:03 2009 -0500
@@ -92,7 +92,7 @@ static void dsync_worker_mailbox_input(v
continue;
dup_box = dsync_mailbox_dup(list->pool, &dsync_box);
- if (!mail_guid_128_is_empty(dup_box->mailbox_guid.guid))
+ if (!dsync_mailbox_is_noselect(dup_box))
array_append(&list->mailboxes, &dup_box, 1);
else
array_append(&list->dirs, &dup_box, 1);
@@ -102,7 +102,7 @@ static void dsync_worker_mailbox_input(v
if (dsync_worker_mailbox_iter_deinit(&list->iter) < 0)
dsync_brain_fail(list->brain);
array_sort(&list->mailboxes, dsync_mailbox_p_guid_cmp);
- array_sort(&list->dirs, dsync_mailbox_p_dir_guid_cmp);
+ array_sort(&list->dirs, dsync_mailbox_p_name_cmp);
dsync_brain_mailbox_list_finished(list->brain);
}
}
@@ -542,7 +542,7 @@ dsync_brain_sync_rename_mailbox(struct d
dsync_brain_sync_rename_mailbox(struct dsync_brain *brain,
const struct dsync_brain_mailbox *mailbox)
{
- if (mailbox->src->last_changed > mailbox->dest->last_changed) {
+ if (mailbox->src->last_change > mailbox->dest->last_change) {
dsync_worker_rename_mailbox(brain->dest_worker,
&mailbox->box.mailbox_guid,
mailbox->src);
diff -r 3c12d0376cef -r 96db209efe22 src/dsync/dsync-data.c
--- a/src/dsync/dsync-data.c Thu Dec 31 17:18:00 2009 -0500
+++ b/src/dsync/dsync-data.c Thu Dec 31 17:19:03 2009 -0500
@@ -62,17 +62,16 @@ int dsync_mailbox_p_guid_cmp(struct dsyn
return dsync_mailbox_guid_cmp(*box1, *box2);
}
-int dsync_mailbox_dir_guid_cmp(const struct dsync_mailbox *box1,
- const struct dsync_mailbox *box2)
+int dsync_mailbox_name_cmp(const struct dsync_mailbox *box1,
+ const struct dsync_mailbox *box2)
{
- return memcmp(box1->dir_guid.guid, box2->dir_guid.guid,
- sizeof(box1->dir_guid.guid));
+ return strcmp(box1->name, box2->name);
}
-int dsync_mailbox_p_dir_guid_cmp(struct dsync_mailbox *const *box1,
- struct dsync_mailbox *const *box2)
+int dsync_mailbox_p_name_cmp(struct dsync_mailbox *const *box1,
+ struct dsync_mailbox *const *box2)
{
- return dsync_mailbox_dir_guid_cmp(*box1, *box2);
+ return dsync_mailbox_name_cmp(*box1, *box2);
}
bool dsync_keyword_list_equals(const char *const *k1, const char *const *k2)
diff -r 3c12d0376cef -r 96db209efe22 src/dsync/dsync-data.h
--- a/src/dsync/dsync-data.h Thu Dec 31 17:18:00 2009 -0500
+++ b/src/dsync/dsync-data.h Thu Dec 31 17:19:03 2009 -0500
@@ -9,26 +9,30 @@ ARRAY_DEFINE_TYPE(mailbox_guid, mailbox_
ARRAY_DEFINE_TYPE(mailbox_guid, mailbox_guid_t);
enum dsync_mailbox_flags {
- DSYNC_MAILBOX_FLAG_DELETED_MAILBOX = 0x01,
- DSYNC_MAILBOX_FLAG_DELETED_DIR = 0x02
+ DSYNC_MAILBOX_FLAG_NOSELECT = 0x01,
+ DSYNC_MAILBOX_FLAG_DELETED_MAILBOX = 0x02,
+ DSYNC_MAILBOX_FLAG_DELETED_DIR = 0x04
};
struct dsync_mailbox {
const char *name;
char name_sep;
- /* Mailbox directory's GUID. Not necessarily set if mailbox is
- deleted. */
- mailbox_guid_t dir_guid;
+ /* 128bit SHA1 sum of mailbox name */
+ mailbox_guid_t name_sha1;
/* Mailbox's GUID. Full of zero with \Noselect mailboxes. */
mailbox_guid_t mailbox_guid;
uint32_t uid_validity, uid_next;
uint64_t highest_modseq;
- time_t last_changed;
+ /* if mailbox is deleted, this is the deletion timestamp.
+ otherwise it's the last rename timestamp. */
+ time_t last_change;
enum dsync_mailbox_flags flags;
ARRAY_TYPE(const_string) cache_fields;
};
ARRAY_DEFINE_TYPE(dsync_mailbox, struct dsync_mailbox *);
+#define dsync_mailbox_is_noselect(dsync_box) \
+ (((dsync_box)->flags & DSYNC_MAILBOX_FLAG_NOSELECT) != 0)
/* dsync_worker_msg_iter_next() returns also all expunged messages from
the end of mailbox with this flag set. The GUIDs are 128 bit GUIDs saved
@@ -62,10 +66,10 @@ int dsync_mailbox_p_guid_cmp(struct dsyn
int dsync_mailbox_p_guid_cmp(struct dsync_mailbox *const *box1,
struct dsync_mailbox *const *box2);
-int dsync_mailbox_dir_guid_cmp(const struct dsync_mailbox *box1,
- const struct dsync_mailbox *box2);
-int dsync_mailbox_p_dir_guid_cmp(struct dsync_mailbox *const *box1,
- struct dsync_mailbox *const *box2);
+int dsync_mailbox_name_cmp(const struct dsync_mailbox *box1,
+ const struct dsync_mailbox *box2);
+int dsync_mailbox_p_name_cmp(struct dsync_mailbox *const *box1,
+ struct dsync_mailbox *const *box2);
bool dsync_keyword_list_equals(const char *const *k1, const char *const *k2);
diff -r 3c12d0376cef -r 96db209efe22 src/dsync/dsync-proxy-client.c
--- a/src/dsync/dsync-proxy-client.c Thu Dec 31 17:18:00 2009 -0500
+++ b/src/dsync/dsync-proxy-client.c Thu Dec 31 17:19:03 2009 -0500
@@ -692,7 +692,7 @@ proxy_client_worker_delete_mailbox(struc
str_append(str, "BOX-DELETE\t");
dsync_proxy_mailbox_guid_export(str, &dsync_box->mailbox_guid);
- str_printfa(str, "\t%s\n", dec2str(dsync_box->last_changed));
+ str_printfa(str, "\t%s\n", dec2str(dsync_box->last_change));
o_stream_send(worker->output, str_data(str), str_len(str));
} T_END;
}
diff -r 3c12d0376cef -r 96db209efe22 src/dsync/dsync-proxy-server-cmd.c
--- a/src/dsync/dsync-proxy-server-cmd.c Thu Dec 31 17:18:00 2009 -0500
+++ b/src/dsync/dsync-proxy-server-cmd.c Thu Dec 31 17:19:03 2009 -0500
@@ -256,7 +256,7 @@ cmd_box_delete(struct dsync_proxy_server
memset(&dsync_box, 0, sizeof(dsync_box));
dsync_box.mailbox_guid = guid;
- dsync_box.last_changed = strtoul(args[1], NULL, 10);
+ dsync_box.last_change = strtoul(args[1], NULL, 10);
dsync_worker_delete_mailbox(server->worker, &dsync_box);
return 1;
}
diff -r 3c12d0376cef -r 96db209efe22 src/dsync/dsync-proxy.c
--- a/src/dsync/dsync-proxy.c Thu Dec 31 17:18:00 2009 -0500
+++ b/src/dsync/dsync-proxy.c Thu Dec 31 17:19:03 2009 -0500
@@ -161,15 +161,14 @@ void dsync_proxy_mailbox_export(string_t
str_append_c(str, '\t');
s[0] = box->name_sep; s[1] = '\0';
str_tabescape_write(str, s);
- str_append_c(str, '\t');
- dsync_proxy_mailbox_guid_export(str, &box->dir_guid);
- str_printfa(str, "\t%lu\t%u", (unsigned long)box->last_changed,
+ str_printfa(str, "\t%lu\t%u", (unsigned long)box->last_change,
box->flags);
- if (mail_guid_128_is_empty(box->mailbox_guid.guid)) {
- /* \noselect mailbox */
+ if (dsync_mailbox_is_noselect(box)) {
+ i_assert(box->uid_validity == 0);
return;
}
+ i_assert(box->uid_validity != 0);
str_append_c(str, '\t');
dsync_proxy_mailbox_guid_export(str, &box->mailbox_guid);
@@ -189,13 +188,14 @@ int dsync_proxy_mailbox_import_unescaped
memset(box_r, 0, sizeof(*box_r));
count = str_array_length(args);
- if (count != 5 && count < 9) {
+ if (count != 4 && count < 8) {
*error_r = "Mailbox missing parameters";
return -1;
}
/* name dir_guid mailbox_guid uid_validity uid_next highest_modseq */
box_r->name = p_strdup(pool, args[i++]);
+ dsync_str_sha_to_guid(box_r->name, &box_r->name_sha1);
if (strlen(args[i]) != 1) {
*error_r = "Invalid mailbox name hierarchy separator";
@@ -203,17 +203,14 @@ int dsync_proxy_mailbox_import_unescaped
}
box_r->name_sep = args[i++][0];
- if (dsync_proxy_mailbox_guid_import(args[i++], &box_r->dir_guid) < 0) {
- *error_r = "Invalid dir GUID";
- return -1;
- }
- box_r->last_changed = strtoul(args[i++], &p, 10);
+ box_r->last_change = strtoul(args[i++], &p, 10);
if (*p != '\0') {
- *error_r = "Invalid mailbox last_renamed";
+ *error_r = "Invalid mailbox last_change";
return -1;
}
box_r->flags = strtoul(args[i++], &p, 10);
- if (*p != '\0') {
+ if (*p != '\0' ||
+ (dsync_mailbox_is_noselect(box_r) != (args[i] == NULL))) {
*error_r = "Invalid mailbox flags";
return -1;
}
diff -r 3c12d0376cef -r 96db209efe22 src/dsync/dsync-worker-local.c
--- a/src/dsync/dsync-worker-local.c Thu Dec 31 17:18:00 2009 -0500
+++ b/src/dsync/dsync-worker-local.c Thu Dec 31 17:19:03 2009 -0500
@@ -21,6 +21,7 @@ struct local_dsync_worker_mailbox_iter {
struct dsync_worker_mailbox_iter iter;
struct mailbox_list_iterate_context *list_iter;
struct hash_iterate_context *deleted_iter;
+ struct hash_iterate_context *deleted_dir_iter;
};
struct local_dsync_worker_subs_iter {
@@ -51,16 +52,20 @@ struct local_dsync_mailbox {
struct local_dsync_mailbox_change {
mailbox_guid_t guid;
- time_t last_renamed;
- time_t last_deleted;
+ time_t last_delete;
+
unsigned int deleted_mailbox:1;
- unsigned int deleted_dir:1;
};
-struct local_dsync_subscription_change {
+struct local_dsync_dir_change {
mailbox_guid_t name_sha1;
struct mailbox_list *list;
- time_t last_change;
+
+ time_t last_rename;
+ time_t last_delete;
+ time_t last_subs_change;
+
unsigned int unsubscribed:1;
+ unsigned int deleted_dir:1;
};
struct local_dsync_worker {
@@ -72,8 +77,8 @@ struct local_dsync_worker {
struct hash_table *mailbox_hash;
/* mailbox_guid_t -> struct local_dsync_mailbox_change* */
struct hash_table *mailbox_changes_hash;
- /* mailbox_guid_t -> struct local_dsync_subscription_change */
- struct hash_table *subscription_changes_hash;
+ /* <-> struct local_dsync_dir_change */
+ struct hash_table *dir_changes_hash;
char alt_char;
@@ -190,8 +195,8 @@ static void local_worker_deinit(struct d
hash_table_destroy(&worker->mailbox_hash);
if (worker->mailbox_changes_hash != NULL)
hash_table_destroy(&worker->mailbox_changes_hash);
- if (worker->subscription_changes_hash != NULL)
- hash_table_destroy(&worker->subscription_changes_hash);
+ if (worker->dir_changes_hash != NULL)
+ hash_table_destroy(&worker->dir_changes_hash);
array_free(&worker->saved_uids);
pool_unref(&worker->pool);
}
@@ -227,34 +232,23 @@ dsync_worker_save_mailbox_change(struct
switch (rec->type) {
case MAILBOX_LOG_RECORD_DELETE_MAILBOX:
change->deleted_mailbox = TRUE;
- if (change->last_deleted < stamp)
- change->last_deleted = stamp;
+ if (change->last_delete < stamp)
+ change->last_delete = stamp;
break;
case MAILBOX_LOG_RECORD_DELETE_DIR:
- change->deleted_dir = TRUE;
- break;
case MAILBOX_LOG_RECORD_RENAME:
- if (change->last_renamed < stamp)
- change->last_renamed = stamp;
- break;
case MAILBOX_LOG_RECORD_SUBSCRIBE:
case MAILBOX_LOG_RECORD_UNSUBSCRIBE:
i_unreached();
}
- if (change->deleted_dir && change->deleted_mailbox) {
- /* same GUID shouldn't be both. something's already
- broken, but change this so we don't get into more
- problems later. */
More information about the dovecot-cvs
mailing list