From: Timo Sirainen Date: Fri, 3 Dec 2010 04:25:06 +0000 (+0000) Subject: lib-index: Added "transaction boundary" record for future compatibility. X-Git-Tag: 2.0.8~18 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e188bab0b830136d04a1dd8b55e9afefae20d930;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Added "transaction boundary" record for future compatibility. --- diff --git a/src/doveadm/doveadm-dump-log.c b/src/doveadm/doveadm-dump-log.c index ae0ae401c2..2deba3b74b 100644 --- a/src/doveadm/doveadm-dump-log.c +++ b/src/doveadm/doveadm-dump-log.c @@ -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; } diff --git a/src/lib-index/mail-index-sync-update.c b/src/lib-index/mail-index-sync-update.c index 89a2339ba8..957fb447ef 100644 --- a/src/lib-index/mail-index-sync-update.c +++ b/src/lib-index/mail-index-sync-update.c @@ -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", diff --git a/src/lib-index/mail-transaction-log-append.c b/src/lib-index/mail-transaction-log-append.c index bb07bc4d62..d850c51b6f 100644 --- a/src/lib-index/mail-transaction-log-append.c +++ b/src/lib-index/mail-transaction-log-append.c @@ -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); diff --git a/src/lib-index/mail-transaction-log-file.c b/src/lib-index/mail-transaction-log-file.c index 621bbc6b2c..72d1ea3a5e 100644 --- a/src/lib-index/mail-transaction-log-file.c +++ b/src/lib-index/mail-transaction-log-file.c @@ -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; diff --git a/src/lib-index/mail-transaction-log.h b/src/lib-index/mail-transaction-log.h index c3dfe7bac4..08a6f686da 100644 --- a/src/lib-index/mail-transaction-log.h +++ b/src/lib-index/mail-transaction-log.h @@ -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;