dovecot-2.0-sslstream: dsync: Sync mailboxes' cache fields.
dovecot at dovecot.org
dovecot at dovecot.org
Sat Feb 13 02:56:27 EET 2010
details: http://hg.dovecot.org/dovecot-2.0-sslstream/rev/278d4da53141
changeset: 10340:278d4da53141
user: Timo Sirainen <tss at iki.fi>
date: Mon Nov 16 20:00:33 2009 -0500
description:
dsync: Sync mailboxes' cache fields.
diffstat:
16 files changed, 164 insertions(+), 57 deletions(-)
src/dsync/dsync-brain-msgs-new.c | 9 +----
src/dsync/dsync-brain-msgs.c | 12 +++++--
src/dsync/dsync-data.h | 1
src/dsync/dsync-proxy-client.c | 5 ++-
src/dsync/dsync-proxy-server-cmd.c | 17 +++++++----
src/dsync/dsync-proxy.c | 29 +++++++++++++++++-
src/dsync/dsync-proxy.h | 3 +
src/dsync/dsync-worker-local.c | 55 ++++++++++++++++++++++++++++--------
src/dsync/dsync-worker-private.h | 3 +
src/dsync/dsync-worker.c | 7 ++--
src/dsync/dsync-worker.h | 2 -
src/dsync/test-dsync-brain.c | 44 ++++++++++++++--------------
src/dsync/test-dsync-common.c | 15 +++++++++
src/dsync/test-dsync-proxy.c | 14 +++++++++
src/dsync/test-dsync-worker.c | 4 +-
src/dsync/test-dsync-worker.h | 1
diffs (truncated from 527 to 300 lines):
diff -r d7e946e3c0c4 -r 278d4da53141 src/dsync/dsync-brain-msgs-new.c
--- a/src/dsync/dsync-brain-msgs-new.c Mon Nov 16 19:59:41 2009 -0500
+++ b/src/dsync/dsync-brain-msgs-new.c Mon Nov 16 20:00:33 2009 -0500
@@ -27,7 +27,6 @@ static void msg_get_callback(enum dsync_
{
struct dsync_brain_msg_save_context *ctx = context;
const struct dsync_brain_mailbox *mailbox;
- const mailbox_guid_t *mailbox_guid;
struct istream *input;
mailbox = array_idx(&ctx->iter->sync->mailboxes, ctx->mailbox_idx);
@@ -35,8 +34,7 @@ static void msg_get_callback(enum dsync_
case DSYNC_MSG_GET_RESULT_SUCCESS:
/* the mailbox may have changed, make sure we've the
right one */
- mailbox_guid = &mailbox->box.mailbox_guid;
- dsync_worker_select_mailbox(ctx->iter->worker, mailbox_guid);
+ dsync_worker_select_mailbox(ctx->iter->worker, &mailbox->box);
input = data->input;
dsync_worker_msg_save(ctx->iter->worker, ctx->msg, data);
@@ -229,7 +227,7 @@ dsync_brain_msg_sync_add_new_msgs(struct
while (iter->mailbox_idx < array_count(&iter->sync->mailboxes)) {
mailbox = array_idx(&iter->sync->mailboxes, iter->mailbox_idx);
mailbox_guid = &mailbox->box.mailbox_guid;
- dsync_worker_select_mailbox(iter->worker, mailbox_guid);
+ dsync_worker_select_mailbox(iter->worker, &mailbox->box);
if (dsync_brain_mailbox_add_new_msgs(iter, mailbox_guid)) {
/* continue later */
@@ -337,8 +335,7 @@ sync_iter_resolve_uid_conflicts(struct d
conflicts = array_get(&iter->uid_conflicts, &count);
for (i = 0; i < count; i++) {
mailbox = &mailboxes[conflicts[i].mailbox_idx];
- dsync_worker_select_mailbox(iter->worker,
- &mailbox->box.mailbox_guid);
+ dsync_worker_select_mailbox(iter->worker, &mailbox->box);
dsync_worker_msg_update_uid(iter->worker, conflicts[i].old_uid,
conflicts[i].new_uid);
}
diff -r d7e946e3c0c4 -r 278d4da53141 src/dsync/dsync-brain-msgs.c
--- a/src/dsync/dsync-brain-msgs.c Mon Nov 16 19:59:41 2009 -0500
+++ b/src/dsync/dsync-brain-msgs.c Mon Nov 16 20:00:33 2009 -0500
@@ -284,9 +284,9 @@ void dsync_brain_msg_sync_more(struct ds
return;
}
dsync_worker_select_mailbox(sync->src_worker,
- &mailboxes[mailbox_idx].box.mailbox_guid);
+ &mailboxes[mailbox_idx].box);
dsync_worker_select_mailbox(sync->dest_worker,
- &mailboxes[mailbox_idx].box.mailbox_guid);
+ &mailboxes[mailbox_idx].box);
}
}
@@ -321,8 +321,12 @@ dsync_brain_msg_iter_init(struct dsync_b
dsync_worker_msg_callback, sync);
dsync_worker_set_output_callback(worker,
dsync_worker_msg_callback, sync);
- if (mailbox_count > 0)
- dsync_worker_select_mailbox(worker, &mailboxes[0]);
+ if (mailbox_count > 0) {
+ const struct dsync_brain_mailbox *first;
+
+ first = array_idx(&sync->mailboxes, 0);
+ dsync_worker_select_mailbox(worker, &first->box);
+ }
return iter;
}
diff -r d7e946e3c0c4 -r 278d4da53141 src/dsync/dsync-data.h
--- a/src/dsync/dsync-data.h Mon Nov 16 19:59:41 2009 -0500
+++ b/src/dsync/dsync-data.h Mon Nov 16 20:00:33 2009 -0500
@@ -25,6 +25,7 @@ struct dsync_mailbox {
uint64_t highest_modseq;
time_t last_renamed;
enum dsync_mailbox_flags flags;
+ ARRAY_TYPE(const_string) cache_fields;
};
ARRAY_DEFINE_TYPE(dsync_mailbox, struct dsync_mailbox *);
diff -r d7e946e3c0c4 -r 278d4da53141 src/dsync/dsync-proxy-client.c
--- a/src/dsync/dsync-proxy-client.c Mon Nov 16 19:59:41 2009 -0500
+++ b/src/dsync/dsync-proxy-client.c Mon Nov 16 20:00:33 2009 -0500
@@ -716,7 +716,8 @@ proxy_client_worker_update_mailbox(struc
static void
proxy_client_worker_select_mailbox(struct dsync_worker *_worker,
- const mailbox_guid_t *mailbox)
+ const mailbox_guid_t *mailbox,
+ const ARRAY_TYPE(const_string) *cache_fields)
{
struct proxy_client_dsync_worker *worker =
(struct proxy_client_dsync_worker *)_worker;
@@ -732,6 +733,8 @@ proxy_client_worker_select_mailbox(struc
str_append(str, "BOX-SELECT\t");
dsync_proxy_mailbox_guid_export(str, mailbox);
+ if (cache_fields != NULL)
+ dsync_proxy_strings_export(str, cache_fields);
str_append_c(str, '\n');
o_stream_send(worker->output, str_data(str), str_len(str));
} T_END;
diff -r d7e946e3c0c4 -r 278d4da53141 src/dsync/dsync-proxy-server-cmd.c
--- a/src/dsync/dsync-proxy-server-cmd.c Mon Nov 16 19:59:41 2009 -0500
+++ b/src/dsync/dsync-proxy-server-cmd.c Mon Nov 16 20:00:33 2009 -0500
@@ -290,15 +290,22 @@ static int
static int
cmd_box_select(struct dsync_proxy_server *server, const char *const *args)
{
- mailbox_guid_t guid;
-
+ struct dsync_mailbox box;
+ unsigned int i, count;
+
+ memset(&box, 0, sizeof(box));
if (args[0] == NULL ||
- dsync_proxy_mailbox_guid_import(args[0], &guid) < 0) {
+ dsync_proxy_mailbox_guid_import(args[0], &box.mailbox_guid) < 0) {
i_error("box-select: Invalid mailbox GUID '%s'", args[0]);
return -1;
}
-
- dsync_worker_select_mailbox(server->worker, &guid);
+ args++;
+
+ count = str_array_length(args);
+ t_array_init(&box.cache_fields, count + 1);
+ for (i = 0; i < count; i++)
+ array_append(&box.cache_fields, &args[i], 1);
+ dsync_worker_select_mailbox(server->worker, &box);
return 1;
}
diff -r d7e946e3c0c4 -r 278d4da53141 src/dsync/dsync-proxy.c
--- a/src/dsync/dsync-proxy.c Mon Nov 16 19:59:41 2009 -0500
+++ b/src/dsync/dsync-proxy.c Mon Nov 16 20:00:33 2009 -0500
@@ -12,6 +12,22 @@
#include "dsync-proxy.h"
#include <stdlib.h>
+
+void dsync_proxy_strings_export(string_t *str,
+ const ARRAY_TYPE(const_string) *strings)
+{
+ const char *const *fields;
+ unsigned int i, count;
+
+ if (!array_is_created(strings))
+ return;
+
+ fields = array_get(strings, &count);
+ for (i = 0; i < count; i++) {
+ str_append_c(str, '\t');
+ str_tabescape_write(str, fields[i]);
+ }
+}
void dsync_proxy_msg_export(string_t *str,
const struct dsync_message *msg)
@@ -155,19 +171,20 @@ void dsync_proxy_mailbox_export(string_t
str_printfa(str, "\t%u\t%u\t%llu",
box->uid_validity, box->uid_next,
(unsigned long long)box->highest_modseq);
+ dsync_proxy_strings_export(str, &box->cache_fields);
}
int dsync_proxy_mailbox_import_unescaped(pool_t pool, const char *const *args,
struct dsync_mailbox *box_r,
const char **error_r)
{
- unsigned int count;
+ unsigned int i, count;
char *p;
memset(box_r, 0, sizeof(*box_r));
count = str_array_length(args);
- if (count != 4 && count != 8) {
+ if (count != 4 && count < 8) {
*error_r = "Mailbox missing parameters";
return -1;
}
@@ -216,6 +233,14 @@ int dsync_proxy_mailbox_import_unescaped
if (*p != '\0') {
*error_r = "Invalid mailbox highest_modseq";
return -1;
+ }
+
+ args += 8;
+ count -= 8;
+ p_array_init(&box_r->cache_fields, pool, count + 1);
+ for (i = 0; i < count; i++) {
+ const char *field_name = p_strdup(pool, args[i]);
+ array_append(&box_r->cache_fields, &field_name, 1);
}
return 0;
}
diff -r d7e946e3c0c4 -r 278d4da53141 src/dsync/dsync-proxy.h
--- a/src/dsync/dsync-proxy.h Mon Nov 16 19:59:41 2009 -0500
+++ b/src/dsync/dsync-proxy.h Mon Nov 16 20:00:33 2009 -0500
@@ -7,6 +7,9 @@
struct dsync_message;
struct dsync_mailbox;
+
+void dsync_proxy_strings_export(string_t *str,
+ const ARRAY_TYPE(const_string) *strings);
void dsync_proxy_msg_export(string_t *str, const struct dsync_message *msg);
int dsync_proxy_msg_parse_flags(pool_t pool, const char *str,
diff -r d7e946e3c0c4 -r 278d4da53141 src/dsync/dsync-worker-local.c
--- a/src/dsync/dsync-worker-local.c Mon Nov 16 19:59:41 2009 -0500
+++ b/src/dsync/dsync-worker-local.c Mon Nov 16 20:00:33 2009 -0500
@@ -405,6 +405,8 @@ local_worker_mailbox_iter_next(struct ds
struct mailbox *box;
struct mailbox_status status;
struct local_dsync_mailbox_change *change;
+ const char *const *fields;
+ unsigned int i, field_count;
memset(dsync_box_r, 0, sizeof(*dsync_box_r));
@@ -450,7 +452,8 @@ local_worker_mailbox_iter_next(struct ds
}
mailbox_get_status(box, STATUS_UIDNEXT | STATUS_UIDVALIDITY |
- STATUS_HIGHESTMODSEQ | STATUS_GUID, &status);
+ STATUS_HIGHESTMODSEQ | STATUS_GUID |
+ STATUS_CACHE_FIELDS, &status);
change = hash_table_lookup(worker->mailbox_changes_hash,
status.mailbox_guid);
@@ -464,6 +467,13 @@ local_worker_mailbox_iter_next(struct ds
dsync_box_r->uid_validity = status.uidvalidity;
dsync_box_r->uid_next = status.uidnext;
dsync_box_r->highest_modseq = status.highest_modseq;
+
+ fields = array_get(status.cache_fields, &field_count);
+ t_array_init(&dsync_box_r->cache_fields, field_count);
+ for (i = 0; i < field_count; i++) {
+ const char *field_name = t_strdup(fields[i]);
+ array_append(&dsync_box_r->cache_fields, &field_name, 1);
+ }
local_dsync_worker_add_mailbox(worker, info->ns, storage_name,
&dsync_box_r->mailbox_guid);
@@ -1043,34 +1053,57 @@ local_worker_update_mailbox(struct dsync
mailbox_close(&box);
if (selected)
- dsync_worker_select_mailbox(_worker, &dsync_box->mailbox_guid);
+ dsync_worker_select_mailbox(_worker, dsync_box);
+}
+
+static void
+local_worker_set_cache_fields(struct local_dsync_worker *worker,
+ const ARRAY_TYPE(const_string) *cache_fields)
+{
+ struct mailbox_update update;
+ const char *const *fields, **new_fields;
+ unsigned int count;
+
+ fields = array_get(cache_fields, &count);
+ new_fields = t_new(const char *, count + 1);
+ memcpy(new_fields, fields, sizeof(const char *) * count);
+
+ memset(&update, 0, sizeof(update));
+ update.cache_fields = new_fields;
+ mailbox_update(worker->selected_box, &update);
}
static void
local_worker_select_mailbox(struct dsync_worker *_worker,
- const mailbox_guid_t *mailbox)
+ const mailbox_guid_t *mailbox,
+ const ARRAY_TYPE(const_string) *cache_fields)
{
struct local_dsync_worker *worker =
(struct local_dsync_worker *)_worker;
struct mailbox_transaction_context *trans, *ext_trans;
if (worker->selected_box != NULL) {
- if (dsync_guid_equals(&worker->selected_box_guid, mailbox))
+ if (dsync_guid_equals(&worker->selected_box_guid, mailbox)) {
+ /* already selected */
return;
+ }
local_worker_mailbox_close(worker);
}
worker->selected_box_guid = *mailbox;
- if (local_mailbox_open(worker, mailbox, &worker->selected_box) < 0)
+ if (local_mailbox_open(worker, mailbox, &worker->selected_box) < 0) {
dsync_worker_set_failure(_worker);
- else {
- ext_trans = mailbox_transaction_begin(worker->selected_box,
+ return;
+ }
+ if (cache_fields != NULL && array_is_created(cache_fields))
More information about the dovecot-cvs
mailing list