Click here to get back home

Tie::Persistent issues

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Tie::Persistent issues The Fairey 05-11-2005
Posted by The Fairey on May 11, 2005, 10:11 am
Please log in for more thread options


Hi,

I've got a very simple hash I'm storing in a persistent file, I'm using
LockFile::Simple to handle locking.

Now if I run an app to update the contents of the persistent file and
while that is running I run another script that deletes one of the keys
from the persistent hash it doesn't seem to work and when the main
script is done the key is still there.

Obviously if I just run the delete the key goes. I've tried this with
autosync and sync in a variety of places but can't seem to get it to
work.

I'm wondering if it's the order in which I'm syncing etc. Ultimately
I'd rather have autosync on but I'm not sure if autosync works one way
in terms of changes made rather than getting notification that the file
has changed underneath it or if it checks for this when data is updated
locally.

Any help appreciated.

Si



Posted by xhoster on May 12, 2005, 2:06 am
Please log in for more thread options


> Hi,
>
> I've got a very simple hash I'm storing in a persistent file, I'm using
> LockFile::Simple to handle locking.
>
> Now if I run an app to update the contents of the persistent file and
> while that is running I run another script that deletes one of the keys
> from the persistent hash it doesn't seem to work and when the main
> script is done the key is still there.
>
> Obviously if I just run the delete the key goes. I've tried this with
> autosync and sync in a variety of places but can't seem to get it to
> work.
>
> I'm wondering if it's the order in which I'm syncing etc.

Yes, you need to swap lines 6 and 12.

(If you showed us actual code, someone might be able to actually help you.)

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB


Posted by The Fairey on May 12, 2005, 2:34 am
Please log in for more thread options


Ok fair enough, just wondering really if I was doing something
fundamentally wrong in what I was trying to achieve. Anyway here's
make, read and delete mini scripts.

Run the make and in another window delete one of the keys entered
during the make, hence the sleep to give you time to run the delete.

make:
use LockFile::Simple qw(lock unlock);
use Tie::Persistent;

my %DB;
tie %DB, 'Tie::Persistent', '/tmp/file.PD', 'rw';
while(<main::DATA>){
chomp;
lock('/tmp/file.PD');
$DB = 1;
(tied %DB)->sync;
unlock('/tmp/file.PD');
print "Added <$_> sleeping for 2\n";
sleep 2;
}
untie %DB;


__DATA__
cbcc68e3061e1abe3b22876e6dcfd4aa
c334490e6186532acdea9d74797102c9
8554cb442b20adb21b210b5c61f96805
9f1e9ba1f1334718c83882bb89890a52
bb05302d0b345b1ac92d9076214f37cc
a08b883029253e9eb449d5f7709a7fd4
dd714740296cef5b3411ed7eb34ad158
90382ab35ec165a24826b37b979541e9
ba24f06e683652c41e0083766f9d6c40
ca9470f6621f99a1e4cea37ab81c7388
b797e9e84029fa324485a2c90ecb0cf0
fb94cf44722cc2bb00a8714ce5cab75d
eb2f6463bbb2fc750f8baa1e18a0f82d
f4759fe5bebec2a074b634ccb20693a0
626bb45c592f24a58c69daf53224773c
7c5952fd9a07a4518dae83cce6a47ce3
04e612282c7a8fc207b339761e9e5a18
b61dd8350470dd441a17f4f89d7e7fe7
a72ebc7c292fa7600872ce85596940e1
e8ab7c5ec463f6e14dafc2169cc6c052

delete:
use LockFile::Simple qw(lock unlock);
use Tie::Persistent;

my %DB;
my $key = shift;
lock('/tmp/file.PD');
tie %DB, 'Tie::Persistent', '/tmp/file.PD', 'rw';
delete $DB;
untie %DB;
unlock('/tmp/file.PD');

read:
use Tie::Persistent;
my %DB;
tie %DB, 'Tie::Persistent', '/tmp/file.PD', 'r';
foreach(keys %DB) {
print "$_ => $DB\n";
}
untie %ReadOnly;

Si



Posted by xhoster on May 12, 2005, 4:41 pm
Please log in for more thread options


> Ok fair enough, just wondering really if I was doing something
> fundamentally wrong in what I was trying to achieve. Anyway here's
> make, read and delete mini scripts.
>
> Run the make and in another window delete one of the keys entered
> during the make, hence the sleep to give you time to run the delete.
>
> make:
> use LockFile::Simple qw(lock unlock);
> use Tie::Persistent;
>
> my %DB;
> tie %DB, 'Tie::Persistent', '/tmp/file.PD', 'rw';
> while(<main::DATA>){
> chomp;
> lock('/tmp/file.PD');
##tie needed here
> $DB = 1;
> (tied %DB)->sync;
## untie needed here.
> unlock('/tmp/file.PD');
> print "Added <$_> sleeping for 2\n";
> sleep 2;
> }
> untie %DB;

The loop only writes the private data out to disk each time through the
loop, it never reads the disk data back into memory, so never notices that
the other method changed the data on the disk.

Since there doesn't seem to be a reverse-sync method, what you would need
to do is tie and untie the hash inside the loop instead of outside it.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB


Posted by The Fairey on May 12, 2005, 4:08 pm
Please log in for more thread options


Yeah that was the conclusion I came to which given the time it takes to
read the quantity of keys I have makes the delay from the tie and untie
too prohibitive so I've had to make some concessions in how things work
and only allow deletes within a particular window :-(

Maybe I'll look at the shared memory stuff and see if better solution
presents itself.

Thanks

Si



Similar ThreadsPosted
In SVG, persistent signs in path ? October 25, 2007, 7:20 pm
ANNOUNCE: OOPS 1.004 - Object Oriented Persistent Store July 4, 2006, 1:53 pm
RFC: DBIx::Counter - persistent counter class April 14, 2005, 3:15 am
ISpell Issues January 22, 2006, 4:54 pm
DBD::Oracle issues January 23, 2007, 7:16 pm
ASE 12.5 UTF-8 issues with Sybase::DBLib April 5, 2006, 5:05 am
CPAN install issues February 21, 2007, 6:48 pm
Net::SNMP snmpv3 inform issues May 17, 2005, 10:18 am
Apache::Request installation issues March 1, 2005, 9:00 am
Installing mod-perl on Tiger (OSX) issues May 31, 2006, 12:06 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap