Mercurial > dovecot > core-2.2
changeset 7573:de08cc81da73 HEAD
Fixes to handling races in initial index creation.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 30 May 2008 02:09:20 +0300 |
parents | b7fcace54fad |
children | 346f172c8c71 |
files | src/lib-index/mail-index-private.h src/lib-index/mail-index.c src/lib-index/mail-transaction-log-file.c src/lib-index/mail-transaction-log.c src/lib-index/mail-transaction-log.h |
diffstat | 5 files changed, 14 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-index-private.h Thu May 29 19:11:32 2008 +0300 +++ b/src/lib-index/mail-index-private.h Fri May 30 02:09:20 2008 +0300 @@ -218,6 +218,7 @@ unsigned int mapping:1; unsigned int syncing:1; unsigned int need_recreate:1; + unsigned int initial_create:1; }; extern struct mail_index_module_register mail_index_module_register;
--- a/src/lib-index/mail-index.c Thu May 29 19:11:32 2008 +0300 +++ b/src/lib-index/mail-index.c Fri May 30 02:09:20 2008 +0300 @@ -341,19 +341,21 @@ /* Create a new indexid for us. If we're opening index into memory, index->map doesn't exist yet. */ index->indexid = ioloop_time; + index->initial_create = TRUE; if (index->map != NULL) index->map->hdr.indexid = index->indexid; } - ret = mail_transaction_log_create(index->log); + ret = mail_transaction_log_create(index->log, FALSE); + index->initial_create = FALSE; created = TRUE; } if (ret >= 0) { - ret = index->map != NULL ? 0 : mail_index_try_open(index); + ret = index->map != NULL ? 1 : mail_index_try_open(index); if (ret == 0) { - /* doesn't exist / corrupted */ + /* corrupted */ mail_transaction_log_close(index->log); - ret = mail_transaction_log_create(index->log); + ret = mail_transaction_log_create(index->log, TRUE); if (ret == 0) { if (index->map != NULL) mail_index_unmap(&index->map);
--- a/src/lib-index/mail-transaction-log-file.c Thu May 29 19:11:32 2008 +0300 +++ b/src/lib-index/mail-transaction-log-file.c Fri May 30 02:09:20 2008 +0300 @@ -357,7 +357,8 @@ return 0; } if (file->hdr.indexid != file->log->index->indexid) { - if (file->log->index->indexid != 0) { + if (file->log->index->indexid != 0 && + !file->log->index->initial_create) { /* index file was probably just rebuilt and we don't know about it yet */ mail_transaction_log_file_set_corrupted(file, @@ -477,8 +478,6 @@ file->fd = fd; if (mail_transaction_log_file_read_hdr(file, FALSE) > 0 && - file->hdr.file_seq == 1 && - file->hdr.prev_file_seq == 0 && mail_transaction_log_file_stat(file, FALSE) == 0) { /* yes, it was ok */ (void)file_dotlock_delete(dotlock);
--- a/src/lib-index/mail-transaction-log.c Thu May 29 19:11:32 2008 +0300 +++ b/src/lib-index/mail-transaction-log.c Fri May 30 02:09:20 2008 +0300 @@ -99,7 +99,7 @@ return 1; } -int mail_transaction_log_create(struct mail_transaction_log *log) +int mail_transaction_log_create(struct mail_transaction_log *log, bool reset) { struct mail_transaction_log_file *file; const char *path; @@ -125,7 +125,7 @@ mail_transaction_log_file_free(&log->open_file); } - if (mail_transaction_log_file_create(file, FALSE) < 0) { + if (mail_transaction_log_file_create(file, reset) < 0) { mail_transaction_log_file_free(&file); return -1; } @@ -187,7 +187,7 @@ log->head->hdr.indexid != log->index->indexid) { if (--log->head->refcount == 0) mail_transaction_log_file_free(&log->head); - (void)mail_transaction_log_create(log); + (void)mail_transaction_log_create(log, FALSE); } } @@ -291,7 +291,7 @@ someone deleted it manually while the index was open. try to handle this nicely by creating a new log file. */ file = log->head; - if (mail_transaction_log_create(log) < 0) + if (mail_transaction_log_create(log, FALSE) < 0) return -1; i_assert(file->refcount > 0); file->refcount--;
--- a/src/lib-index/mail-transaction-log.h Thu May 29 19:11:32 2008 +0300 +++ b/src/lib-index/mail-transaction-log.h Fri May 30 02:09:20 2008 +0300 @@ -122,7 +122,7 @@ is corrupted, -1 if there was some I/O error. */ int mail_transaction_log_open(struct mail_transaction_log *log); /* Create, or recreate, the transaction log. Returns 0 if ok, -1 if error. */ -int mail_transaction_log_create(struct mail_transaction_log *log); +int mail_transaction_log_create(struct mail_transaction_log *log, bool reset); /* Close all the open transactions log files. */ void mail_transaction_log_close(struct mail_transaction_log *log);