Re: Multiple processes and tie'd files



Tuc <tuctboh@xxxxxxxxx> wrote:
On Aug 30, 10:20 pm, xhos...@xxxxxxxxx wrote:
Tuc <tuct...@xxxxxxxxx> wrote:
When I tie to a DB_File, if one of the processes or even an
external process updates the file, the persistent processes aren't
seeing the update. I have to stop them and restart them for that to
happen.

Have you read the documentation for DB_File?

I did, way back. Then 10 minutes after I posted I read it again
and found the section that said "Hey, Tuc, you can't do that with
DB_File".

You might be able to use DB_File, you would just need to untie and retie
each time you want to sync. But, if you have multiple concurrent accesses,
which you do otherwise the problem wouldn't exist, then you need to do
locking as well or your database file will be corrupted.

From the DB_File docs, it sound like Tie::DB_LockFile might be just
what you need, except that no module by that name actually seems to exist
on CPAN or anywhere else I can find.



Sorta defeats the whole reason for using a tie'd file, I could
just put it into a hash.

If that is the "whole" reason you are using DB_File, then you shouldn't
be using DB_File in the first place.

What should I be using then? I need something that I can ask it
by a key, and get data back. It needs to be accessible from multiple
programs, and easily updated without modifying the program. I need it
to be fast/lightweight/not require any additional processes running.

You will probably have to compromise somewhere along that list. But
without knowing your usage patterns, it is hard to say where.


....

Short of going to mysql (Which is like trying to swat a fly with
the supercollider) is there another option?

Mysql is not a super-collider, it is a very light-weight fly swatter.
What you are trying to doing with DB_File is like trying to swat a fly
with a pencil sharpener.

Doesn't make sense to start an instance of Mysql for a table
that will probably be 75-100 entries.

Database servers aren't just about size. Allowing multiple connections to
access data quickly and concurrently without causing corruption or needless
slowness is the very reason that database servers exist. Saying "I don't
need a database because it is only 100 rows" is like saying "I don't need
to put engine oil in my engine because I'm only going to drive 30 mph".

So what do you suggest to be able to do this? Just "open, while,
close" a text file?

I don't see how this would get the job done. There would have to be a
"print" in there someplace, or else the whole premise of your question
would be void. And then there would have to be locking, or corruption
would happen.



I was also trying to keep with DB_File since another program
actually was generating it, DB_File the only available format. I might
be able to (and it looks like might have to, unless I want to keep 2
copies) remove the usage of the file from the other program.

If this other program doesn't do locking and can't be made to do it
in a way compatible with your program, then you are already playing with
fire by having them touch the same DB_File file.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
.