
gregarios
stranger
May 29, 2002, 2:39 PM
Post #13 of 17
(7617 views)
|
Re: [yapp] Database Unexpected Erasure Problem
[In reply to]
|
Can't Post
|
|
Ok... I made a small program that I'm hoping tested my theory correctly. Here is my test program:
#!/usr/bin/perl5 -wT use strict; use Fcntl qw(:DEFAULT :flock); $| = 1; sysopen(ADDCTX, "ads.dta", O_RDWR|O_EXLOCK) or die "Could not open and lock file: $!"; sysopen(ADTEST, "ads.dta", O_RDWR|O_EXLOCK) or die "Could not open and lock file: $!"; truncate(ADTEST,0) or die "Could not truncate file: $!"; close(ADTEST) or die "Could not close file: $!"; my @ads = <ADDCTX>; if ($ads[0]) {print "Ad list: @ads"} else {print "Truncated File"}; close(ADDCTX); exit; Here are the results. I'll show you the changes to the two lines of code that matter and give you a description of the outcome. These two examples of code caused an endless wait period... presumably on the "O_EXLOCK" lock. Interestingly enough, in the second set, the second sysopen command shown here wouldn't apply an exclusive lock while the file was previously open, even though the first open did not apply a lock. Niether ever truncated:
sysopen(ADDCTX, "ads.dta", O_RDWR|O_EXLOCK) or die "Could not open and lock file: $!"; sysopen(ADTEST, "ads.dta", O_RDWR|O_EXLOCK) or die "Could not open and lock file: $!"; orsysopen(ADDCTX, "ads.dta", O_RDWR) or die "Could not open and lock file: $!"; sysopen(ADTEST, "ads.dta", O_RDWR|O_EXLOCK) or die "Could not open and lock file: $!"; These two examples of code caused the file to be truncated:
sysopen(ADDCTX, "ads.dta", O_RDWR) or die "Could not open and lock file: $!"; sysopen(ADTEST, "ads.dta", O_RDWR) or die "Could not open and lock file: $!"; orsysopen(ADDCTX, "ads.dta", O_RDWR|O_EXLOCK) or die "Could not open and lock file: $!"; sysopen(ADTEST, "ads.dta", O_RDWR) or die "Could not open and lock file: $!"; I would be grateful to hear what you have to say about this. Judging from my examples, I would think this is a great way to lock files safely... at least when running in FreeBSD?
sysopen(ADDCTX, "ads.dta", O_RDWR|O_EXLOCK) or die "Could not open and lock file: $!"; Anyone... please give me your opinions on this. Thank you for your support. :-)
(This post was edited by gregarios on May 29, 2002, 2:41 PM)
|