feumw has asked for the wisdom of the Perl Monks concerning the following question:
We had a service provider during a project and one of them built a feature calles "Userlist and Useraction". This has two parts. There is an overview "Userlist" where we can see the userid + timestamp (last time he was active). This "Userlist" just reads the Perl-Storage. The second part is the "Useraction" which is a Controller in our CMS which is called whenever a user does anything. This "Useraction" retrieves the Perl-Storage and stores username + timestamp.
Our issue is that sometimes (randomly) this Perl-Storage seems to be cleared. When we do stat on the file, only the "modified" changed. So the file does not get deleted. But it seems like it's loosing all it's content. Apparently it seems to be like once a month. We made sure there were no updates/backups or anything at this time of the day.
Since this is built into our CMS i can only try to provide parts of the code.
Userlist.PMUseraction.PMuse Storable; use Time::Local; sub go { my $storeFile = '/db/users.store'; my $usersFile = (); if ( -e $storeFile ) { $usersFile = retrieve( $storeFile ); } # Do stuff and return me a precious overview of all my userids and + their timestamps # # userid | timestamp # 1337 | Fri Dec 16 12:11:43 2022 # 1234 | ri Jan 20 09:21:36 2023 # ... }
use Storable; sub go : Path { my $user = $common->{user}; # CMS Stuff: Get the curre +nt logged in user my $uid = $user->getInfo()->{id}; # CMS Stuff: Get his useri +d my $storeFile = '/db/users.store'; my $ts = localtime( time ); my $users = (); if (-e $storeFile) { $users = retrieve( $storeFile ); } $users->{$uid} = $ts; store $users, $storeFile; }
Is there any chance that the Module has some kind of issue if only using store and retrieve? On https://perldoc.perl.org/Storable I read something about recursion limitations. This could be the reason why we're having the issue once every month. We might reach the limitation after 1 month. I'm clueless right now what could be the issue here.
I tried to reproduce the error by copying one of our files and use the following script:
my $storeFile = "/db/users.store.test"; my $users = (); my $ts; for (my $i = 0; $i < 2000; $i++){ $users = retrieve( $storeFile ); $ts = localtime( time ); foreach my $KEY ( keys % { $users } ){ print "#" . $KEY . "#" . $ts . "#\n"; $users->{$KEY} = $ts; store $users, $storeFile; } usleep(250); }
And while the script is running and chaning the file i do ls -l on a second shell and sometimes the file will be set to 0KB.
Example File can be downloaded from my BSCW (Basic Support for Cooperative Work) Cloud
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Storable - File empties itself?
by hippo (Archbishop) on Apr 13, 2023 at 08:57 UTC | |
by feumw (Sexton) on Apr 13, 2023 at 10:07 UTC | |
by hippo (Archbishop) on Apr 13, 2023 at 10:35 UTC | |
by feumw (Sexton) on Apr 13, 2023 at 11:47 UTC | |
by eyepopslikeamosquito (Archbishop) on Apr 14, 2023 at 09:19 UTC | |
| |
by haukex (Archbishop) on Apr 14, 2023 at 07:22 UTC | |
by afoken (Chancellor) on Apr 13, 2023 at 20:12 UTC | |
by feumw (Sexton) on Apr 14, 2023 at 07:14 UTC | |
by marto (Cardinal) on Apr 14, 2023 at 07:22 UTC | |
| |
by NERDVANA (Priest) on Apr 14, 2023 at 18:07 UTC | |
Re: Storable - File empties itself?
by bliako (Abbot) on Apr 13, 2023 at 10:07 UTC | |
by feumw (Sexton) on Apr 13, 2023 at 11:54 UTC | |
Re: Storable - File empties itself?
by feumw (Sexton) on Apr 14, 2023 at 07:01 UTC | |
by stevieb (Canon) on Apr 18, 2023 at 08:55 UTC | |
by stevieb (Canon) on Apr 18, 2023 at 09:12 UTC | |
by Anonymous Monk on Apr 18, 2023 at 10:05 UTC | |
by stevieb (Canon) on Apr 18, 2023 at 10:20 UTC |