Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Tied hash for CGI-usage (what about file corruption?) (http://www.velocityreviews.com/forums/t883788-tied-hash-for-cgi-usage-what-about-file-corruption.html)

Dan 11-21-2003 03:44 PM

Tied hash for CGI-usage (what about file corruption?)
 
Has anyone knwoledge to share about tied hashes as database backend in
cgi-scripts?

I'm running a CGI that will acess a DBM file (DB_File) as a tied hash
like this:

sub pseudo-code{
tie %hash
read(!) something
untied %hash
}

Do I have to use a file lock algorithm wrapped around when I am just
goint to READ from the file?

Will file corruption over time be a problem? (the script will be
running on a heavy load website, multiple processes, maybe sometimes
to read all at once)

As I udnerstand it I'll have to lock the DB_File only for
write/read-write access, but for reading only??

Ben Morrow 11-21-2003 04:26 PM

Re: Tied hash for CGI-usage (what about file corruption?)
 

Dan.Schneider@web.de (Dan) wrote:
> Do I have to use a file lock algorithm wrapped around when I am just
> goint to READ from the file?
>
> Will file corruption over time be a problem? (the script will be
> running on a heavy load website, multiple processes, maybe sometimes
> to read all at once)
>
> As I udnerstand it I'll have to lock the DB_File only for
> write/read-write access, but for reading only??


[this applies much more generally than tied hashes]

If anyone is going to be writing, then *everyone* has to lock. Readers
lock with LOCK_SH, writers with LOCK_EX. See the documentation for
DB_File for some important caveats when locking. If you have control
of every program accessing this database, it is probably a better idea
to use a lockfile: lock the file before you tie, and untie before you
unlock.

Ben

--
I've seen things you people wouldn't believe: attack ships on fire off the
shoulder of Orion; I've watched C-beams glitter in the darkness near the
Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
Time to die. |-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-| ben@morrow.me.uk


All times are GMT. The time now is 04:09 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.