Jimmy Wales <jwales(a)bomis.com> writes:
[BTW, your article was hard to read due to lines longer than 80 chars]
Here's my understanding of the edit lock
problem...
I've written [[Wikipedia/Edit lock]] now. If the monastery metaphors
are two cheesy, feel free to delete ... as always.
There are several possible solutions. My own personal
solution is
wild. I just wouldn't use a lock at all. You run the risk of
collisions, but these are so rare *in my experience* as to be worth
ignoring.
Hmm, I don't think I'd risk that. My understanding is that this could
damage not only the current version/html cache, but also the revision
history. I'm not even sure the software could reliably detect this
condition (humans could of course).
Another solution is to have 'per-file' edit
locks.
Sounds good.
CGI scripts do in fact die for no apparent reason
sometimes, and
it's very hard to trap/debug/etc.
It's perl, right? So you could hang a handler onto various hooks that
removed the evil lock.
if (create_lock()) {
$SIG{__DIE__} = $SIG{TERM} = ... = \&release_lock;
...
release_lock();
}
Perl itself could die, but that's probably less often.
Also, instead of creating a directory, why not create a file that
holds the PID? This way stale locks can be removed with some
certainity.
until (sysopen(F, $lockName, O_WRONLY|O_CREAT|O_EXCL)) {
if ($! != EEXIST) {
die("can't make $LockDir: $!\n") if $errorDie;
return 0;
}
if ($n++ >= $tries){
print STDERR "failing lock for $name, $tries, $wait, $errorDie\n";
return 0;
}
if (open(F, "<$lockName")) {
my $pid = <F>;
close(F);
chomp($pid);
unless (kill(0, $pid)) {
# the lock holder no longer exists, remove it and respin immediately
unlink($lockName) or die("couldn't remove $lockName: $!");
next;
}
}
sleep($wait);
}
print F "$$\n";
close(F) or die("couldn't write to $lockName: $!");
return 1;
--
Robbe