dovecot-2.2: plugins/fts: expunge-log - create flattened in-RAM ...
dovecot at dovecot.org
dovecot at dovecot.org
Tue Jan 20 23:55:14 UTC 2015
details: http://hg.dovecot.org/dovecot-2.2/rev/e1b50803e5d4
changeset: 18194:e1b50803e5d4
user: Phil Carmody <phil at dovecot.fi>
date: Wed Jan 21 01:51:46 2015 +0200
description:
plugins/fts: expunge-log - create flattened in-RAM log with no backing storage
Combine each record in a source expunge log. This source log does not get
deleted afterwards.
Signed-off-by: Phil Carmody <phil at dovecot.fi>
diffstat:
src/plugins/fts/fts-expunge-log.c | 49 +++++++++++++++++++++++++++++++++++++++
src/plugins/fts/fts-expunge-log.h | 9 +++++++
2 files changed, 58 insertions(+), 0 deletions(-)
diffs (87 lines):
diff -r 8b4693c01cce -r e1b50803e5d4 src/plugins/fts/fts-expunge-log.c
--- a/src/plugins/fts/fts-expunge-log.c Wed Jan 21 01:48:00 2015 +0200
+++ b/src/plugins/fts/fts-expunge-log.c Wed Jan 21 01:51:46 2015 +0200
@@ -231,6 +231,28 @@
if (!seq_range_array_add(&mailbox->uids, uid))
mailbox->uids_count++;
}
+void fts_expunge_log_append_range(struct fts_expunge_log_append_ctx *ctx,
+ const guid_128_t mailbox_guid,
+ const struct seq_range *uids)
+{
+ struct fts_expunge_log_mailbox *mailbox;
+
+ mailbox = fts_expunge_log_append_mailbox(ctx, mailbox_guid);
+ mailbox->uids_count += seq_range_array_add_range_count(&mailbox->uids,
+ uids->seq1, uids->seq2);
+ /* To be honest, an unbacked log doesn't need to maintain the uids_count,
+ but we don't know here if we're supporting an unbacked log or not, so we
+ have to maintain the value, just in case.
+ At the moment, the only caller of this function is for unbacked logs. */
+}
+void fts_expunge_log_append_record(struct fts_expunge_log_append_ctx *ctx,
+ const struct fts_expunge_log_read_record *record)
+{
+ const struct seq_range *range;
+ /* FIXME: Optimise with a merge */
+ array_foreach(&record->uids, range)
+ fts_expunge_log_append_range(ctx, record->mailbox_guid, range);
+}
static void
fts_expunge_log_export(struct fts_expunge_log_append_ctx *ctx,
@@ -483,3 +505,30 @@
i_free(ctx);
return ret;
}
+
+int fts_expunge_log_flatten(const char *path,
+ struct fts_expunge_log_append_ctx **flattened_r)
+{
+ struct fts_expunge_log *read;
+ struct fts_expunge_log_read_ctx *read_ctx;
+ const struct fts_expunge_log_read_record *record;
+ struct fts_expunge_log_append_ctx *append;
+ int ret;
+
+ i_assert(path != NULL && flattened_r != NULL);
+ read = fts_expunge_log_init(path);
+
+ read_ctx = fts_expunge_log_read_begin(read);
+ read_ctx->unlink = FALSE;
+
+ append = fts_expunge_log_append_begin(NULL);
+ while((record = fts_expunge_log_read_next(read_ctx)) != NULL) {
+ fts_expunge_log_append_record(append, record);
+ }
+
+ if ((ret = fts_expunge_log_read_end(&read_ctx)) > 0)
+ *flattened_r = append;
+ fts_expunge_log_deinit(&read);
+
+ return ret;
+}
diff -r 8b4693c01cce -r e1b50803e5d4 src/plugins/fts/fts-expunge-log.h
--- a/src/plugins/fts/fts-expunge-log.h Wed Jan 21 01:48:00 2015 +0200
+++ b/src/plugins/fts/fts-expunge-log.h Wed Jan 21 01:51:46 2015 +0200
@@ -17,6 +17,11 @@
void fts_expunge_log_append_next(struct fts_expunge_log_append_ctx *ctx,
const guid_128_t mailbox_guid,
uint32_t uid);
+void fts_expunge_log_append_range(struct fts_expunge_log_append_ctx *ctx,
+ const guid_128_t mailbox_guid,
+ const struct seq_range *uids);
+void fts_expunge_log_append_record(struct fts_expunge_log_append_ctx *ctx,
+ const struct fts_expunge_log_read_record *record);
int fts_expunge_log_append_commit(struct fts_expunge_log_append_ctx **ctx);
/* Do not commit non-backed structures, abort them after use. */
int fts_expunge_log_append_abort(struct fts_expunge_log_append_ctx **ctx);
@@ -32,4 +37,8 @@
If end() is called before reading all records, the log isn't unlinked. */
int fts_expunge_log_read_end(struct fts_expunge_log_read_ctx **ctx);
+/* Read an entire log file, and flatten it into one hash of arrays.
+ The struct it returns cannot be written, as it has no backing store */
+int fts_expunge_log_flatten(const char *path,
+ struct fts_expunge_log_append_ctx **flattened_r);
#endif
More information about the dovecot-cvs
mailing list