]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Added "transaction boundary" record for future compatibility.
authorTimo Sirainen <tss@iki.fi>
Fri, 3 Dec 2010 04:25:06 +0000 (04:25 +0000)
committerTimo Sirainen <tss@iki.fi>
Fri, 3 Dec 2010 04:25:06 +0000 (04:25 +0000)
src/doveadm/doveadm-dump-log.c
src/lib-index/mail-index-sync-update.c
src/lib-index/mail-transaction-log-append.c
src/lib-index/mail-transaction-log-file.c
src/lib-index/mail-transaction-log.h

index ae0ae401c297942caa3f0756703f2a11815d0740..2deba3b74b06d9a815b02462271711f0f462723f 100644 (file)
@@ -111,6 +111,9 @@ static const char *log_record_type(unsigned int type)
        case MAIL_TRANSACTION_INDEX_UNDELETED:
                name = "index-undeleted";
                break;
+       case MAIL_TRANSACTION_BOUNDARY:
+               name = "boundary";
+               break;
        default:
                name = t_strdup_printf("unknown: %x", type);
                break;
@@ -406,6 +409,12 @@ static void log_record_print(const struct mail_transaction_header *hdr,
        case MAIL_TRANSACTION_INDEX_DELETED:
        case MAIL_TRANSACTION_INDEX_UNDELETED:
                break;
+       case MAIL_TRANSACTION_BOUNDARY: {
+               const struct mail_transaction_boundary *rec = data;
+
+               printf(" - size=%u\n", rec->size);
+               break;
+       }
        default:
                break;
        }
index 89a2339ba8a47271a58f814426d71a7ed98263d3..957fb447eff6663d61552e43b84e8c9e9d676b46 100644 (file)
@@ -792,6 +792,8 @@ int mail_index_sync_record(struct mail_index_sync_map_ctx *ctx,
        case MAIL_TRANSACTION_INDEX_UNDELETED:
                ctx->view->index->index_delete_requested = FALSE;
                break;
+       case MAIL_TRANSACTION_BOUNDARY:
+               break;
        default:
                mail_index_sync_set_corrupted(ctx,
                        "Unknown transaction record type 0x%x",
index bb07bc4d6201d2634830c1acb4323048a9185245..d850c51b6fb4feabb27a2ea76b6bd487ec1f9dd1 100644 (file)
@@ -23,7 +23,7 @@ void mail_transaction_log_append_add(struct mail_transaction_log_append_ctx *ctx
        if (type == MAIL_TRANSACTION_EXPUNGE ||
            type == MAIL_TRANSACTION_EXPUNGE_GUID)
                hdr.type |= MAIL_TRANSACTION_EXPUNGE_PROT;
-       if (ctx->external)
+       if (ctx->external || type == MAIL_TRANSACTION_BOUNDARY)
                hdr.type |= MAIL_TRANSACTION_EXTERNAL;
        hdr.size = sizeof(hdr) + size;
        hdr.size = mail_index_uint32_to_offset(hdr.size);
index 621bbc6b2c85dd887c64efe5c393afb76d4565be..72d1ea3a5e6cefe0456c6315cfee249c0a6eed15 100644 (file)
@@ -1161,7 +1161,7 @@ log_file_track_sync(struct mail_transaction_log_file *file,
        mail_transaction_update_modseq(hdr, hdr + 1,
                                       &file->sync_highest_modseq);
        if ((hdr->type & MAIL_TRANSACTION_EXTERNAL) == 0)
-               return 0;
+               return 1;
 
        /* external transactions: */
        switch (hdr->type & MAIL_TRANSACTION_TYPE_MASK) {
@@ -1171,7 +1171,7 @@ log_file_track_sync(struct mail_transaction_log_file *file,
                                                             trans_size -
                                                             sizeof(*hdr));
                if (ret != 0)
-                       return ret < 0 ? -1 : 0;
+                       return ret < 0 ? -1 : 1;
                break;
        case MAIL_TRANSACTION_INDEX_DELETED:
                if (file->sync_offset < file->index_undeleted_offset)
@@ -1186,6 +1186,19 @@ log_file_track_sync(struct mail_transaction_log_file *file,
                file->log->index->index_delete_requested = FALSE;
                file->index_undeleted_offset = file->sync_offset + trans_size;
                break;
+       case MAIL_TRANSACTION_BOUNDARY: {
+               const struct mail_transaction_boundary *boundary =
+                       (const void *)(hdr + 1);
+               size_t wanted_buffer_size;
+
+               wanted_buffer_size = file->sync_offset - file->buffer_offset +
+                       boundary->size;
+               if (wanted_buffer_size > file->buffer->used) {
+                       /* the full transaction hasn't been written yet */
+                       return 0;
+               }
+               break;
+       }
        }
 
        if (file->max_tail_offset == file->sync_offset) {
@@ -1194,7 +1207,7 @@ log_file_track_sync(struct mail_transaction_log_file *file,
                   avoid re-reading it at the next sync. */
                file->max_tail_offset += trans_size;
        }
-       return 0;
+       return 1;
 }
 
 static int
@@ -1205,6 +1218,7 @@ mail_transaction_log_file_sync(struct mail_transaction_log_file *file)
        struct stat st;
        size_t size, avail;
        uint32_t trans_size = 0;
+       int ret;
 
        i_assert(file->sync_offset >= file->buffer_offset);
 
@@ -1233,8 +1247,11 @@ mail_transaction_log_file_sync(struct mail_transaction_log_file *file)
                        break;
 
                /* transaction has been fully written */
-               if (log_file_track_sync(file, hdr, trans_size) < 0)
-                       return -1;
+               if ((ret = log_file_track_sync(file, hdr, trans_size)) <= 0) {
+                       if (ret < 0)
+                               return -1;
+                       break;
+               }
 
                file->sync_offset += trans_size;
                trans_size = 0;
index c3dfe7bac492602e8ba0ec7e9bfed2cf86c7b16b..08a6f686da368fdbd2184eedf180359e6472e628 100644 (file)
@@ -43,6 +43,7 @@ enum mail_transaction_type {
        MAIL_TRANSACTION_EXT_HDR_UPDATE32       = 0x00010000,
        MAIL_TRANSACTION_INDEX_DELETED          = 0x00020000,
        MAIL_TRANSACTION_INDEX_UNDELETED        = 0x00040000,
+       MAIL_TRANSACTION_BOUNDARY               = 0x00080000,
 
        MAIL_TRANSACTION_TYPE_MASK              = 0x000fffff,
 
@@ -157,6 +158,10 @@ struct mail_transaction_ext_atomic_inc {
        int32_t diff;
 };
 
+struct mail_transaction_boundary {
+       uint32_t size;
+};
+
 struct mail_transaction_log_append_ctx {
        struct mail_transaction_log *log;
        buffer_t *output;