[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
patches for PR 218, index corruption
From: |
Dirk Bergstrom |
Subject: |
patches for PR 218, index corruption |
Date: |
Mon, 29 Oct 2001 17:34:56 -0800 |
these patches fix PR 218, "PRs fail to show up in index". it turns
out there were four separate race conditions that could cause index
corruption.
*) there was a race in the database locking code that allowed two
processes to believe that they each had a full db lock. the code
checked to see if the lock file existed, and if it wasn't found, a
file was created using creat(). there was a race between the check
and the create, and the creat() call wasn't atomic. changing
lockfile creation to open(O_EXCL) fixed this.
*) gnats read in the index before locking the database, but didn't
check to see if the index had been modified before writing out it's
cached copy. the race went like this:
0) gnatsd A is finishing up an edit on PR 123...
1) gnatsd B reads index
2) A writes new index, & unlocks DB
3) B locks DB
3) B edits PR 456, modifying index in memory
4) B writes out index from memory
thus A's changes to the index entry for PR 123 would be lost,
overwritten by B's copy of the index. i modified getFirstPr() so
that it always calls checkPRChain() to check mtime of the index on
disk before using data in memory; if cached data is stale, the index
is re-read. also added a final check in the writeIndex routine to
catch problems and alert the administrator. this adds a few stat()
calls to an edit transaction, which is a small cost. it has no
effect on queries.
*) the PR locking code suffered from the same race as the database
lock code. i applied a similar fix.
*) the append & replace field-editing routines (pr-edit --append &
--replace options & gnatsd APPN & REPL commands) did not lock the
database before editing. thus, any other process could change the
index while they were working. added code to lock the db before
taking either action.
the patches themselves, along with a copy of this message and appropriate
changelog entries, are available at this URL:
http://www.otisbean.com/gnats/race-patch.txt
--
Dirk Bergstrom address@hidden
_____________________________________________
Juniper Networks Inc., Computer Geek
Tel: 707.433.0564 Fax: 707.433.0769
- patches for PR 218, index corruption,
Dirk Bergstrom <=