Flatfile database over NFS (CGI)

We use two machines, one webserver and one for data which is nfs mounted on the webserver. Using a webinterface, I want people to add records to a flatfile database (using perl). I have to lock the file because I dont want two people adding records at the same time, this will mess up the database. I think I have to use the rpc.lockd daemon but it doesnt exist on my debian ditribution, Some people say this is impossible because of the caching of NFS.
bjornhAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
marcelofrConnect With a Mentor Commented:
To "give the 100 points" you are supposed to check a box telling so (probably in the same page you are looking at now) and also rate the answer with an A, B etc. grade ;-)
0
 
marcelofrCommented:
Some people are right... you must avoid such a thing. There NO NFS locking implementation that really works... but...

I assume people whould like to read the file, not only add records... but, why don't you do it with sockets with perl?

Good Luck,

--Marcelo
0
 
bjornhAuthor Commented:
I know how to use sockets but what do you want to accomplish with that?

In my current implementation I use a semaphore file containing the pid of the proces and so far no more problems did occur. I think this should be completely safe, no other proces will read from the file when another proces is busy. Will this work or is it still dangerous (due to caching)?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
marcelofrCommented:
Of course... I believe the process opens the file, reads its contents, determines if the pid stored on it is still alive, if not, it writes its own pid to the file... How can you be sure all this is done atomically even without NFS... Any way you can have a process that auto-locks its own binary: this is better, but still you can have a race condition while loading the binary. You can go further, and use named pipes which will manage up to 4kb atomically and make it work locally, but then, why don't have the file local, and share it to the data server (I can hear you shouting that this approach breaks your servers functionalities ;-)

To can get close to 100% safe algoritm in your web server side, but you can't be sure of what you have on the data server side unless the filesystem is unmounted...

Good Luck

-- Marcelo
0
 
bjornhAuthor Commented:
Marcelo,

Thank you for your respone, I think you're right. If you answer the question I can give you the 100 points.

Thanks again,
Bjorn
0
 
marcelofrCommented:
you forgot the check box ;-)
0
 
bjornhAuthor Commented:
Check box?
0
 
bjornhAuthor Commented:
That's right. But to do that you have to _answer_ the question, I cant give you points if you only add a comment. Anyway, my database works perfect now.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.