]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
fts: Changed private fts_index_header accessing APIs
authorTimo Sirainen <tss@iki.fi>
Sun, 28 Aug 2011 03:18:54 +0000 (06:18 +0300)
committerTimo Sirainen <tss@iki.fi>
Sun, 28 Aug 2011 03:18:54 +0000 (06:18 +0300)
src/plugins/fts-lucene/fts-backend-lucene.c
src/plugins/fts-solr/fts-backend-solr-old.c
src/plugins/fts-solr/fts-backend-solr.c
src/plugins/fts/fts-api-private.h
src/plugins/fts/fts-api.c

index f9412c7ac70cb6384a5116e687328c6e0558b1a9..e001e11b89682560f6c5c78844ada902b7af652f 100644 (file)
@@ -166,9 +166,12 @@ fts_backend_lucene_get_last_uid(struct fts_backend *_backend,
 {
        struct lucene_fts_backend *backend =
                (struct lucene_fts_backend *)_backend;
+       struct fts_index_header hdr;
 
-       if (fts_index_get_last_uid(box, last_uid_r))
+       if (fts_index_get_header(box, &hdr)) {
+               *last_uid_r = hdr.last_indexed_uid;
                return 0;
+       }
 
        /* either nothing has been indexed, or the index was corrupted.
           do it the slow way. */
@@ -284,9 +287,12 @@ fts_backend_lucene_update_expunge(struct fts_backend_update_context *_ctx,
                (struct lucene_fts_backend_update_context *)_ctx;
        struct lucene_fts_backend *backend =
                (struct lucene_fts_backend *)_ctx->backend;
+       struct fts_index_header hdr;
 
        if (!ctx->last_indexed_uid_set) {
-               if (!fts_index_get_last_uid(ctx->box, &ctx->last_indexed_uid))
+               if (fts_index_get_header(ctx->box, &hdr))
+                       ctx->last_indexed_uid = hdr.last_indexed_uid;
+               else
                        ctx->last_indexed_uid = 0;
                ctx->last_indexed_uid_set = TRUE;
        }
index 8feb8245ab38eb9efaa0c4bb4914a331ff29d02e..fc173b15d98a6465080e3a244e60b301a9c5cf60 100644 (file)
@@ -336,9 +336,12 @@ fts_backend_solr_get_last_uid(struct fts_backend *_backend,
 {
        struct solr_fts_backend *backend =
                (struct solr_fts_backend *)_backend;
+       struct fts_index_header hdr;
 
-       if (fts_index_get_last_uid(box, last_uid_r))
+       if (fts_index_get_header(box, &hdr)) {
+               *last_uid_r = hdr.last_indexed_uid;
                return 0;
+       }
 
        /* either nothing has been indexed, or the index was corrupted.
           do it the slow way. */
index 9f5836b58395eebf7fe2241de71054626c34f50b..5efbab13f9c3429d9cde906b2f8a0b5468f9f9ae 100644 (file)
@@ -193,8 +193,12 @@ static int
 fts_backend_solr_get_last_uid(struct fts_backend *_backend,
                              struct mailbox *box, uint32_t *last_uid_r)
 {
-       if (fts_index_get_last_uid(box, last_uid_r))
+       struct fts_index_header hdr;
+
+       if (fts_index_get_header(box, &hdr)) {
+               *last_uid_r = hdr.last_indexed_uid;
                return 0;
+       }
 
        /* either nothing has been indexed, or the index was corrupted.
           do it the slow way. */
index c2ddda7a76fcd5c779136fd1ced5c182bb95831c..21c4f68b2039dcd9876780d8fb5a6885a34ac2cc 100644 (file)
@@ -4,6 +4,7 @@
 #include "fts-api.h"
 
 struct mail_user;
+struct mailbox_list;
 
 #define MAILBOX_GUID_HEX_LENGTH (GUID_128_SIZE*2)
 
@@ -79,10 +80,10 @@ struct fts_backend_update_context {
 struct fts_index_header {
        uint32_t last_indexed_uid;
 
-       /* highest UID and number of messages when optimization was last
-          time done */
-       uint32_t last_optimize_uid;
-       uint32_t last_optimize_msgcount;
+       /* Checksum of settings. If the settings change, the index should
+          be rebuilt. */
+       uint32_t settings_checksum;
+       uint32_t unused;
 };
 
 void fts_backend_register(const struct fts_backend *backend);
@@ -97,8 +98,12 @@ void fts_filter_uids(ARRAY_TYPE(seq_range) *definite_dest,
                     const ARRAY_TYPE(seq_range) *maybe_filter);
 
 /* Returns TRUE if ok, FALSE if no fts header */
-bool fts_index_get_last_uid(struct mailbox *box, uint32_t *last_uid_r);
+bool fts_index_get_header(struct mailbox *box, struct fts_index_header *hdr_r);
+int fts_index_set_header(struct mailbox *box,
+                        const struct fts_index_header *hdr);
 int fts_index_set_last_uid(struct mailbox *box, uint32_t last_uid);
+int fts_index_have_compatible_settings(struct mailbox_list *list,
+                                      uint32_t checksum);
 
 /* Returns TRUE if FTS backend should index the header for optimizing
    separate lookups */
index fc7e77ec2ea016bbd9dbfc5a6f3b57821d7af382..d998782179860403c1a09701d4c7b17101e562ae 100644 (file)
@@ -86,11 +86,15 @@ void fts_backend_deinit(struct fts_backend **_backend)
 int fts_backend_get_last_uid(struct fts_backend *backend, struct mailbox *box,
                             uint32_t *last_uid_r)
 {
+       struct fts_index_header hdr;
+
        if (strcmp(box->storage->name, VIRTUAL_STORAGE_NAME) == 0) {
                /* virtual mailboxes themselves don't have any indexes,
                   so catch this call here */
-               if (!fts_index_get_last_uid(box, last_uid_r))
+               if (!fts_index_get_header(box, &hdr))
                        *last_uid_r = 0;
+               else
+                       *last_uid_r = hdr.last_indexed_uid;
                return 0;
        }
 
@@ -316,9 +320,14 @@ int fts_backend_lookup_multi(struct fts_backend *backend,
        return backend->v.lookup_multi(backend, boxes, args, and_args, result);
 }
 
-static bool
-fts_index_get_header(struct mailbox *box, struct fts_index_header *hdr_r,
-                    uint32_t *ext_id_r)
+static uint32_t fts_index_get_ext_id(struct mailbox *box)
+{
+       return mail_index_ext_register(box->index, "fts",
+                                      sizeof(struct fts_index_header),
+                                      0, 0);
+}
+
+bool fts_index_get_header(struct mailbox *box, struct fts_index_header *hdr_r)
 {
        struct mail_index_view *view;
        const void *data;
@@ -327,10 +336,8 @@ fts_index_get_header(struct mailbox *box, struct fts_index_header *hdr_r,
 
        (void)mail_index_refresh(box->index);
        view = mail_index_view_open(box->index);
-       *ext_id_r = mail_index_ext_register(box->index, "fts",
-                                           sizeof(struct fts_index_header),
-                                           0, 0);
-       mail_index_get_header_ext(view, *ext_id_r, &data, &data_size);
+       mail_index_get_header_ext(view, fts_index_get_ext_id(box),
+                                 &data, &data_size);
        if (data_size < sizeof(*hdr_r)) {
                memset(hdr_r, 0, sizeof(*hdr_r));
                ret = FALSE;
@@ -342,32 +349,44 @@ fts_index_get_header(struct mailbox *box, struct fts_index_header *hdr_r,
        return ret;
 }
 
-bool fts_index_get_last_uid(struct mailbox *box, uint32_t *last_uid_r)
+int fts_index_set_header(struct mailbox *box,
+                        const struct fts_index_header *hdr)
 {
-       struct fts_index_header hdr;
-       uint32_t ext_id;
-
-       if (!fts_index_get_header(box, &hdr, &ext_id)) {
-               *last_uid_r = 0;
-               return FALSE;
-       }
+       struct mail_index_transaction *trans;
+       uint32_t ext_id = fts_index_get_ext_id(box);
 
-       *last_uid_r = hdr.last_indexed_uid;
-       return TRUE;
+       trans = mail_index_transaction_begin(box->view, 0);
+       mail_index_update_header_ext(trans, ext_id, 0, hdr, sizeof(*hdr));
+       return mail_index_transaction_commit(&trans);
 }
 
 int fts_index_set_last_uid(struct mailbox *box, uint32_t last_uid)
 {
-       struct mail_index_transaction *trans;
        struct fts_index_header hdr;
-       uint32_t ext_id;
-
-       (void)fts_index_get_header(box, &hdr, &ext_id);
 
+       (void)fts_index_get_header(box, &hdr);
        hdr.last_indexed_uid = last_uid;
-       trans = mail_index_transaction_begin(box->view, 0);
-       mail_index_update_header_ext(trans, ext_id, 0, &hdr, sizeof(hdr));
-       return mail_index_transaction_commit(&trans);
+       return fts_index_set_header(box, &hdr);
+}
+
+int fts_index_have_compatible_settings(struct mailbox_list *list,
+                                      uint32_t checksum)
+{
+       struct mailbox *box;
+       struct fts_index_header hdr;
+       int ret;
+
+       box = mailbox_alloc(list, "INBOX", MAILBOX_FLAG_KEEP_RECENT);
+       if (mailbox_sync(box, (enum mailbox_sync_flags)0) < 0) {
+               i_error("lucene: Failed to sync mailbox INBOX: %s",
+                       mailbox_get_last_error(box, NULL));
+               ret = -1;
+       } else {
+               ret = fts_index_get_header(box, &hdr) &&
+                       hdr.settings_checksum == checksum ? 1 : 0;
+       }
+       mailbox_free(&box);
+       return ret;
 }
 
 static const char *indexed_headers[] = {