Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Storable dumping core

by Random_Walk (Prior)
on May 01, 2015 at 15:35 UTC ( [id://1125369]=perlquestion: print w/replies, xml ) Need Help??

Random_Walk has asked for the wisdom of the Perl Monks concerning the following question:

Good Day Fair Monks,

I am using Storable and every so often it all goes pear shaped.

Magic number checking on storable file failed at /usr/localperl/lib/5.18.2/x86_64-linux-thread-multi/Storable.pm line 380 ...

My code runs every five minutes, and will happily store about 5 samples, then it throws the above and dumps core. The store file is zero bytes after that event. When things are good I see these details.

> file itm6_linux_server.memstore > itm6_linux_server.memstore: perl Storable (v0.7) data (major 2) (min +or 9) # from print Dumper Storable::file_magic 'hdrsize' => 19, 'ptrsize' => 8, 'byteorder' => '12345678', 'intsize' => 4, 'file' => 'itm6_linux_server.memstore', 'longsize' => 8, 'netorder' => 0, 'minor' => 9, 'version_nv' => '2.009', 'major' => 2, 'nvsize' => 8, 'version' => '2.9' > ls -l itm6_linux_server.memstore -rw-rw-rw- 1 root root 2514 May 1 16:25 itm6_linux_server.memstore >perl -v This is perl 5, version 18, subversion 2 (v5.18.2) built for x86_64-li +nux-thread-multi

The amount of data is not massive, It currently has 5 records in there, and is 2026 Bytes. The Data I am storing is a hash/array structure, 5 levels at its deepest.

I'm using lock_store and lock_retrieve to get at it, as the script runs on a schedule, as well as me running it every so often for development and debug. The script uses a file lock to guard against multiple runs anyway. I just added the lock_ versions when I hit this error. Did not help. It is only being accessed on the one machine, with the one version of Perl

Any ideas what could be wrong. The code is long and complex. So building a small test case will be a rather long winded process. If there are any known gotchas with Storable I would love a pointer.

Update

All the code is massive. But here are my retrieve and store routines

sub getMem { my $self = shift; my $confID = shift; $confID = $self->{_itm6_lib_gen}->{_CONFID} unless defined $confID +; my $mem = {}; # default to an empty one my $local_store = "local_$confID.memstore"; if (-e $local_store) { eval { $mem = lock_retrieve $local_store }; if ($@) { $self->{_logger}->trace( 1, "getMem: Reading store failed: + $@"); print "getMem: Reading store failed: $@\n"; } } else { # print "$local_store not found\n"; } push @{ $self->{_file_to_write} }, [$mem, $local_store]; # note we + need to write this return $mem; } # Saving is done in DESTROY sub DESTROY { my $self = shift; for (@{ $self->{_file_to_write} }) { my ($mem, $store) = @$_; lock_store ($mem, $store); } }

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

Replies are listed 'Best First'.
Re: Storable dumping core
by RichardK (Parson) on May 01, 2015 at 16:31 UTC

    Are you sure that your DESTROY method is getting called when you expect?

    See perlobj for details, but it has this to say -- which may be relevant to your issue.

    The order in which objects are destroyed during the global destruction + before the program exits is unpredictable. This means that any objec +ts contained by your object may already have been destroyed. You shou +ld check that a contained object is defined before calling a method o +n it.

    I've never had much luck trying to use perl destructors, they seem to be far too unpredictable but YMMV ;)

      You hit the nail on the head. I took my saving out of the DESTROY and into a separate saveMem sub, and it has been running fine all weekend.

      Many thanks for your help,
      R.

      Pereant, qui ante nos nostra dixerunt!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1125369]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-26 08:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found