[dovecot-cvs] dovecot/src/plugins/fts fts-api-private.h, 1.9, 1.10 fts-api.c, 1.10, 1.11 fts-api.h, 1.8, 1.9 fts-storage.c, 1.17, 1.18
tss at dovecot.org
tss at dovecot.org
Sun Mar 25 20:00:07 EEST 2007
Update of /var/lib/cvs/dovecot/src/plugins/fts
In directory talvi:/tmp/cvs-serv3754/fts
Modified Files:
fts-api-private.h fts-api.c fts-api.h fts-storage.c
Log Message:
Don't crash if another search is started while we're still building the
index for the first search.
Index: fts-api-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/fts/fts-api-private.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- fts-api-private.h 15 Mar 2007 22:20:55 -0000 1.9
+++ fts-api-private.h 25 Mar 2007 17:00:04 -0000 1.10
@@ -45,6 +45,8 @@
enum fts_backend_flags flags;
struct fts_backend_vfuncs v;
+
+ unsigned int building:1;
};
struct fts_backend_build_context {
Index: fts-api.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/fts/fts-api.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- fts-api.c 15 Mar 2007 22:20:55 -0000 1.10
+++ fts-api.c 25 Mar 2007 17:00:04 -0000 1.11
@@ -63,6 +63,10 @@
struct fts_backend_build_context *
fts_backend_build_init(struct fts_backend *backend, uint32_t *last_uid_r)
{
+ i_assert(!backend->building);
+
+ backend->building = TRUE;
+
return backend->v.build_init(backend, last_uid_r);
}
@@ -74,9 +78,15 @@
int fts_backend_build_deinit(struct fts_backend_build_context *ctx)
{
+ ctx->backend->building = FALSE;
return ctx->backend->v.build_deinit(ctx);
}
+bool fts_backend_is_building(struct fts_backend *backend)
+{
+ return backend->building;
+}
+
void fts_backend_expunge(struct fts_backend *backend, struct mail *mail)
{
backend->v.expunge(backend, mail);
Index: fts-api.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/fts/fts-api.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- fts-api.h 15 Mar 2007 22:20:55 -0000 1.8
+++ fts-api.h 25 Mar 2007 17:00:04 -0000 1.9
@@ -32,6 +32,9 @@
/* Finish adding new data to the index. */
int fts_backend_build_deinit(struct fts_backend_build_context *ctx);
+/* Returns TRUE if there exists a build context. */
+bool fts_backend_is_building(struct fts_backend *backend);
+
/* Expunge given mail from the backend. Note that the transaction may still
fail later. */
void fts_backend_expunge(struct fts_backend *backend, struct mail *mail);
Index: fts-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/fts/fts-storage.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- fts-storage.c 15 Mar 2007 22:20:55 -0000 1.17
+++ fts-storage.c 25 Mar 2007 17:00:04 -0000 1.18
@@ -37,7 +37,9 @@
struct mail_search_arg *args, *best_arg;
struct fts_backend *backend;
struct fts_storage_build_context *build_ctx;
+ struct mailbox_transaction_context *t;
+ unsigned int build_initialized:1;
unsigned int locked:1;
};
@@ -222,9 +224,9 @@
return ret;
}
-static int fts_build_init(struct fts_search_context *fctx,
- struct mailbox_transaction_context *t)
+static int fts_build_init(struct fts_search_context *fctx)
{
+ struct mailbox_transaction_context *t = fctx->t;
struct fts_backend *backend = fctx->backend;
struct fts_storage_build_context *ctx;
struct fts_backend_build_context *build;
@@ -528,6 +530,26 @@
}
}
+static bool fts_try_build_init(struct fts_search_context *fctx)
+{
+ if (fctx->backend == NULL) {
+ fctx->build_initialized = TRUE;
+ return TRUE;
+ }
+
+ if (fts_backend_is_building(fctx->backend))
+ return FALSE;
+ fctx->build_initialized = TRUE;
+
+ if (fts_build_init(fctx) < 0)
+ fctx->backend = NULL;
+ else if (fctx->build_ctx == NULL) {
+ /* the index was up to date */
+ fts_search_init(fctx->t->box, fctx);
+ }
+ return TRUE;
+}
+
static struct mail_search_context *
fts_mailbox_search_init(struct mailbox_transaction_context *t,
const char *charset, struct mail_search_arg *args,
@@ -542,6 +564,7 @@
ctx = fbox->super.search_init(t, charset, args, sort_program);
fctx = i_new(struct fts_search_context, 1);
+ fctx->t = t;
fctx->args = args;
array_idx_set(&ctx->module_contexts, fts_storage_module_id, &fctx);
@@ -562,15 +585,7 @@
best_exact_arg : best_fast_arg;
}
- if (fctx->backend != NULL) {
- if (fts_build_init(fctx, t) < 0)
- fctx->backend = NULL;
- else if (fctx->build_ctx == NULL) {
- /* the index was up to date */
- fts_search_init(t->box, fctx);
- }
- }
-
+ fts_try_build_init(fctx);
return ctx;
}
@@ -581,6 +596,13 @@
struct fts_search_context *fctx = FTS_CONTEXT(ctx);
int ret;
+ if (!fctx->build_initialized) {
+ if (!fts_try_build_init(fctx)) {
+ *tryagain_r = TRUE;
+ return 0;
+ }
+ }
+
if (fctx->build_ctx != NULL) {
/* still building the index */
ret = fts_build_more(fctx->build_ctx);
More information about the dovecot-cvs
mailing list