On Thu, 22 Mar 2001, David Harris wrote:
> Two points about switching from exclusive mode to shared mode:
>
> (1) When downgrading from EX to SH, no other processes need to have cached
> data invalidated because no one else can have the database open. There is no
> cache in other processes, therefore none to be invalidated.
>
> Explanation: Lets say the method for downgrading a lock from EX to SH is
> like this: write data, sync(), flock(FLOCK_SH), read data. Until the
> flock(FLOCK_SH) nobody else can have the database open because of the
> exclusive lock. Therefore, there will not be any other processes with the
> database open and the first 4k cached in memory when the sync() happens.
David, please consider this scenario:
... At some point in time, processes A and B both read from the dbm via SH
lock.
1. A completes its reading and unlocks the DBM, while still having the
first 4k cached. (A still has the dbm tie()'d.
2. B wants to write, so it requests an EX lock and gets it granted.
3. B modifies the data in the first 4k, syncs it and releases the lock.
4. A asks for SH or EX lock, gets it, but its cache is invalid.
=> we have a data corruption (especially in the case A does writing into
the first 4k)
> (2) When downgrading from EX to SH, our processes does not need to
> invalidate cached data because its cached data is correct at the sync() and
> the data on disk will not be changed until the database is closed.
>
> Explanation: Again we downgrade form EX to SH by doing this: write data,
> sync(), flock(FLOCK_SH), read data. Our cache remains valid the entire time
> here. With the sync(), data in our cache is written to disk, so at that
> point we are good. Then after the flock(FLOCK_SH) we are still good because
> the shared lock prevents anyone else from writing to the database and
> changing the data on disk. There is no need to do a re-tie().
That's correct.
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:[EMAIL PROTECTED] http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/