Mercurial > dovecot > core-2.2
changeset 3556:6170e2e5992a HEAD
Index creation was racy.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 27 Aug 2005 15:41:21 +0300 |
parents | afe8ab9072f0 |
children | ca22e27202b2 |
files | src/lib-index/mail-index.c src/lib-index/mail-transaction-log.c |
diffstat | 2 files changed, 17 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-index.c Sat Aug 27 15:40:53 2005 +0300 +++ b/src/lib-index/mail-index.c Sat Aug 27 15:41:21 2005 +0300 @@ -1390,6 +1390,13 @@ return -1; if (index->fd == -1) { + if (index->indexid != hdr.indexid) { + /* looks like someone else created the transaction log + before we had the chance. use its indexid so we + don't try to create conflicting ones. */ + hdr.indexid = index->indexid; + } + if (lock_id != 0) { mail_index_unlock(index, lock_id); lock_id = 0;
--- a/src/lib-index/mail-transaction-log.c Sat Aug 27 15:40:53 2005 +0300 +++ b/src/lib-index/mail-transaction-log.c Sat Aug 27 15:41:21 2005 +0300 @@ -347,18 +347,19 @@ return 0; } if (file->hdr.indexid != file->log->index->indexid) { - if (file->log->index->fd == -1) { - /* creating index file, silently rebuild - transaction log as well */ + if (file->log->index->fd != -1) { + /* index file was probably just rebuilt and we don't + know about it yet */ + mail_transaction_log_file_set_corrupted(file, + "invalid indexid (%u != %u)", + file->hdr.indexid, file->log->index->indexid); return 0; } - /* index file was probably just rebuilt and we don't know - about it yet */ - mail_transaction_log_file_set_corrupted(file, - "invalid indexid (%u != %u)", - file->hdr.indexid, file->log->index->indexid); - return 0; + /* creating index file. since transaction log is created + first, use the indexid in it to create the main index + to avoid races. */ + file->log->index->indexid = file->hdr.indexid; } /* make sure we already don't have a file with the same sequence