Opened 3 years ago

Closed 3 years ago

Last modified 2 years ago

#2548 closed Bug (fixed)

Piwik reports 0 visits for single days ni some rare cases

Reported by: peterb Owned by:
Priority: normal Milestone: 1.6 Piwik 1.6
Component: Core Keywords:
Cc: Sensitive: no

Description (last modified by peterb)

See http://forum.piwik.org/read.php?2,78544,78566, and http://forum.piwik.org/read.php?5,78506.

In my case, archiving is triggered by the browser. No cron job is running.

MySQL: 5.0.51a-24+lenny5
PHP: 5.2.6-1+lenny10

Attachments (1)

piwik-bug.JPG (24.6 KB) - added by peterb 3 years ago.

Download all attachments as: .zip

Change History (16)

Changed 3 years ago by peterb (peterbo)

comment:1 Changed 3 years ago by peterb (peterbo)

  • Description modified (diff)

comment:2 Changed 3 years ago by peterb (peterbo)

  • Description modified (diff)

comment:3 Changed 3 years ago by matt (mattab)

  • Milestone set to 1.x - Piwik 1.x

I have seen this bug occur maybe once every 6 months on demo.piwik.org as well. I suspect this comes from edge case when archiving is running twice at the same time, or maybe in the case of failing archiving, but I'm not sure.

Fixing the data is done by deleting the piwik_archive_xx table for the month containing the "zero data" reports, and then re-processing usually works fine.

comment:5 Changed 3 years ago by vipsoft (robocoder)

(In [5052]) fixes #2602, fixes #2574, refs #2548, refs #2597

comment:6 Changed 3 years ago by vipsoft (robocoder)

So, my thought on this is to use MySQL's advisory lock in launchArchiving()

        public function launchArchiving()
        {
                $this->get_lock();
                $this->initCompute();
                $this->compute();
                $this->postCompute();
                // we execute again the isArchived that does some initialization work
                $this->idArchive = $this->isArchived();
                $this->release_lock();
        }

Note: Lock names are system-wide. We could use something like:

$lockname = "piwik.$dbname.$tables_prefix.$idsite";

comment:7 Changed 3 years ago by vipsoft (robocoder)

How long should the timeout be? And should it keep retrying indefinitely?

comment:8 Changed 3 years ago by matt (mattab)

The lock is I think a good idea!

the lock should also contain the $date as we want to protect records for a given site on a given day to run concurrently.

The potential problem is for times that the archiving will crash (memory exhausted etc.) after the lock was acquired. Then, would we have to release it manually, or how would this work?

This has been a long standing bug this one, which would be nice to fix if it doesn't adds complexity etc. :)

comment:9 Changed 3 years ago by vipsoft (robocoder)

By date, do you mean dateStart, dateEnd, and period?

If the mysql client connection is terminated, the lock is automatically released. There is a note somewhere which mentions a bug in older mysql versions: if the connection terminated, the lock wouldn't be released right away (i.e., it would still wait until the timeout expired).

I'm thinking a timeout of 30 seconds with no retry.

comment:10 Changed 3 years ago by vipsoft (robocoder)

  • Resolution set to fixed
  • Status changed from new to closed

(In [5065]) fixes #2548, refs #2597 - use advisory locks

comment:11 Changed 3 years ago by vipsoft (robocoder)

  • Milestone changed from 1.x - Piwik 1.x to 1.6 Piwik 1.6

comment:12 Changed 3 years ago by DaSch

Maybe this should be release in 1.5.2? They way till 1.6 is long and I don't want to manipulate my database to have the stats repaired

comment:13 Changed 3 years ago by matt (mattab)

  • Summary changed from Piwik reports 0 visits for single days to Piwik reports 0 visits for single days ni some rare cases

comment:14 Changed 2 years ago by DaSch

how is this fixed now? will Piwik recognise the broken days? Will I still have to delete something in the database? Only fixing that this will not happen again is only the half-solution, repairing the result of this bug should be done for a real fix

comment:15 Changed 2 years ago by vipsoft (robocoder)

It should be fixed for new data.

The Piwik update doesn't automatically repair previously archived data because it could potentially time-out (i.e., time intensive). It's also non-trivial to analyze previously archived data to see if an archived 0 really was a 0.

You're welcome to drop your piwik_archive_* tables, and run the archive script manually (or via cron).

Note: See TracTickets for help on using tickets.