Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add a comment on the implementation of sqlite3OsLock(). No code changes. (CVS 1688) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
084f3fffbdeb1e2b375817ae1111b867 |
User & Date: | danielk1977 2004-06-25 07:21:28.000 |
Context
2004-06-25
| ||
08:32 | A few more comment changes. No code alterations. (CVS 1689) (check-in: b68b4a4262 user: danielk1977 tags: trunk) | |
07:21 | Add a comment on the implementation of sqlite3OsLock(). No code changes. (CVS 1688) (check-in: 084f3fffbd user: danielk1977 tags: trunk) | |
06:23 | Activate test cases for new journal format. (CVS 1687) (check-in: 197d00d6a6 user: danielk1977 tags: trunk) | |
Changes
Changes to src/os_unix.c.
︙ | ︙ | |||
692 693 694 695 696 697 698 699 700 701 702 703 704 705 | ** RESERVED -> (PENDING) -> EXCLUSIVE ** PENDING -> EXCLUSIVE ** ** This routine will only increase a lock. Use the sqlite3OsUnlock() ** routine to lower a locking level. */ int sqlite3OsLock(OsFile *id, int locktype){ int rc = SQLITE_OK; struct lockInfo *pLock = id->pLock; struct flock lock; int s; assert( id->isOpen ); TRACE6("LOCK %d %d was %d(%d,%d)\n", | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 | ** RESERVED -> (PENDING) -> EXCLUSIVE ** PENDING -> EXCLUSIVE ** ** This routine will only increase a lock. Use the sqlite3OsUnlock() ** routine to lower a locking level. */ int sqlite3OsLock(OsFile *id, int locktype){ /* The following describes the implementation of the various locks and ** lock transitions in terms of the POSIX advisory shared and exclusive ** lock primitives (called read-locks and write-locks below, to avoid ** confusion with SQLite lock names). The algorithms are complicated ** slightly in order to be compatible with windows systems simultaneously ** accessing the same database file, in case that is ever required. ** ** Symbols defined in os.h indentify the 'pending byte' and the 'reserved ** byte', each single bytes at well known offsets, and the 'shared byte ** range', a range of 510 bytes at a well known offset. ** ** To obtain a SHARED lock, a read-lock is obtained on the 'pending ** byte'. If this is successful, a random byte from the 'shared byte ** range' is read-locked and the lock on the 'pending byte' released. ** ** A process may only obtain a RESERVED lock after it has a SHARED lock ** (the sqlite3OsLock() routine will try to obtain this lock ** automatically if it is not already held). A RESERVED lock is ** implemented by grabbing a write-lock on the 'reserved byte'. ** ** A process may only obtain a PENDING lock after it has obtained a ** SHARED lock (done automatically by sqlite3OsLock()). A PENDING lock is ** implemented by obtaining a write-lock on the 'pending byte'. This ** ensures that no new SHARED locks can be obtained, but existing SHARED ** locks are allowed to persist. A process does not have to obtain a ** RESERVED lock on the way to a PENDING lock. This property is used by ** the algorithm for rolling back a journal file after a crash. ** ** An EXCLUSIVE lock is implemented by obtaining a write-lock on the ** entire 'shared byte range'. Since all other locks require a read-lock ** on one of the bytes within this range, this ensures that no other ** locks are held on the database. ** ** The reason a single byte cannot be used instead of the 'shared byte ** range' is that some versions of windows do not support read-locks. By ** locking a random byte from a range, concurrent SHARED locks may exist ** even if the locking primitive used is always a write-lock. */ int rc = SQLITE_OK; struct lockInfo *pLock = id->pLock; struct flock lock; int s; assert( id->isOpen ); TRACE6("LOCK %d %d was %d(%d,%d)\n", |
︙ | ︙ |
Changes to src/pager.c.
︙ | ︙ | |||
14 15 16 17 18 19 20 | ** The pager is used to access a database disk file. It implements ** atomic commit and rollback through the use of a journal file that ** is separate from the database file. The pager also implements file ** locking to prevent two processes from writing the same database ** file simultaneously, or one process from reading the database while ** another is writing. ** | | | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ** The pager is used to access a database disk file. It implements ** atomic commit and rollback through the use of a journal file that ** is separate from the database file. The pager also implements file ** locking to prevent two processes from writing the same database ** file simultaneously, or one process from reading the database while ** another is writing. ** ** @(#) $Id: pager.c,v 1.140 2004/06/25 07:21:28 danielk1977 Exp $ */ #include "os.h" /* Must be first to enable large file support */ #include "sqliteInt.h" #include "pager.h" #include <assert.h> #include <string.h> |
︙ | ︙ | |||
471 472 473 474 475 476 477 | ** The format for the journal header is as follows: ** - 8 bytes: Magic identifying journal format. ** - 4 bytes: Number of records in journal, or -1 no-sync mode is on. ** - 4 bytes: Random number used for page hash. ** - 4 bytes: Initial database page count. ** - 4 bytes: Sector size used by the process that wrote this journal. ** | | | 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 | ** The format for the journal header is as follows: ** - 8 bytes: Magic identifying journal format. ** - 4 bytes: Number of records in journal, or -1 no-sync mode is on. ** - 4 bytes: Random number used for page hash. ** - 4 bytes: Initial database page count. ** - 4 bytes: Sector size used by the process that wrote this journal. ** ** Followed by (JOURNAL_HDR_SZ - 24) bytes of unused space. */ static int writeJournalHdr(Pager *pPager){ int rc = seekJournalHdr(pPager); if( rc ) return rc; pPager->journalHdr = pPager->journalOff; |
︙ | ︙ |