Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How does file locking work?

Status
Not open for further replies.

SM777

Technical User
Mar 7, 2001
208
GB
Debian and Apache 1.3.22

I have a flat text database of 10Mb in size. Perl scripts are used to read this database. Every night I update the database by FTPing a .gz to the server and then running UNZIP to overwrite the existing live database.

How does file locking work in this instance? What happens if the perl script is reading the text file while I try to unzip at the same time. What happens if during unzipping someone tries to read the database?

Is it likely that I could corrupt the database? The perl scripts doing reading only, no writing to the database is done.

 
You aren't going to corrupt it, but your Perl scripts can get less information than they should.

It's easy enough to solve. Put something in the Perl scripts that doesn't read while you are updating. For example, I have Perl scripts that search my website and like yours, they actualy search dlat files that have been created separately. As I add info, I have to update those files, and the process is destructive.

So, the rebuild scripts start by creating a file called "reindexing" and end by removing it. The search scripts check to see if that file exists, if it does they warn the person using them that databases are being rebuilt so the results may be incomplete. They could as easily refuse to return any info, etc. Tony Lawrence
SCO Unix/Linux Resources tony@pcunix.com
 
Not too worried about the lack of information. The unzipping only takes a second or two anyway!

Just concerned that corruption might exist.

One way I though of getting around it was to have 2 databases

db1.txt and db2.txt

A flag file called db1.flg would exist to indicate to the perl script to read the db1.txt file. When the unzipping is complete db1.flg is renamed to db2.flg so that the script would then read db2.txt on its next run. The next unzip would write to db1.txt and rename the flag to db1.flg

Not too bothered with this now that I know the scripts are not going to corrupt!

Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top