Link to home
Start Free TrialLog in
Avatar of bjornh
bjornhFlag for Netherlands

asked on

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.
Avatar of marcelofr
marcelofr

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
Avatar of bjornh

ASKER

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)?
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
Avatar of bjornh

ASKER

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
you forgot the check box ;-)
Avatar of bjornh

ASKER

Check box?
ASKER CERTIFIED SOLUTION
Avatar of marcelofr
marcelofr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bjornh

ASKER

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.