Skip to content

Commit 962442c

Browse files
authored
Ignore overwrite subtable warning for summary rows for old data… (matomo-org#17891)
* Ignore warning for summary rows for old data to avoid re-archiving for a single row most users do not look at. * make sure subtables have ts_archived metadata * use period start date instead of ts_archived * try to prevent random failure
1 parent 18d04c1 commit 962442c

2 files changed

Lines changed: 43 additions & 9 deletions

File tree

core/Archive/DataTableFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ private function setSubtables($dataTable, $blobRow, $treeLevel = 0)
422422
$subtable->setMetadata(self::TABLE_METADATA_SITE_INDEX, $dataTable->getMetadata(self::TABLE_METADATA_SITE_INDEX));
423423
$subtable->setMetadata(self::TABLE_METADATA_SEGMENT_INDEX, $dataTable->getMetadata(self::TABLE_METADATA_SEGMENT_INDEX));
424424
$subtable->setMetadata(self::TABLE_METADATA_SEGMENT_PRETTY_INDEX, $dataTable->getMetadata(self::TABLE_METADATA_SEGMENT_PRETTY_INDEX));
425+
$subtable->setMetadata(DataTable::ARCHIVED_DATE_METADATA_NAME, $dataTable->getMetadata(DataTable::ARCHIVED_DATE_METADATA_NAME));
425426

426427
$this->setSubtables($subtable, $blobRow, $treeLevel + 1);
427428

core/DataTable/Row.php

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
use Exception;
1212
use Piwik\Container\StaticContainer;
1313
use Piwik\DataTable;
14+
use Piwik\Date;
1415
use Piwik\Log;
1516
use Piwik\Metrics;
17+
use Piwik\Period;
1618
use Psr\Log\LoggerInterface;
1719

1820
/**
@@ -292,7 +294,7 @@ public function sumSubtable(DataTable $subTable)
292294
if ($this->isSubtableLoaded) {
293295
$thisSubTable = $this->getSubtable();
294296
} else {
295-
$this->warnIfSubtableAlreadyExists();
297+
$this->warnIfSubtableAlreadyExists($subTable);
296298

297299
$thisSubTable = new DataTable();
298300
$this->setSubtable($thisSubTable);
@@ -765,16 +767,33 @@ public static function isEqual(Row $row1, Row $row2)
765767
return true;
766768
}
767769

768-
private function warnIfSubtableAlreadyExists()
770+
private function warnIfSubtableAlreadyExists(DataTable $subTable)
769771
{
770772
if (!is_null($this->subtableId)) {
771-
$ex = new \Exception(sprintf(
772-
"Row with label '%s' (columns = %s) has already a subtable id=%s but it was not loaded - overwriting the existing sub-table.",
773-
$this->getColumn('label'),
774-
implode(", ", $this->getColumns()),
775-
$this->getIdSubDataTable()
776-
));
777-
StaticContainer::get(LoggerInterface::class)->warning("{exception}", ['exception' => $ex]);
773+
// we only print this warning out if the row isn't a summary row, and if the period start date of the
774+
// data is later than the deploy date to cloud for Matomo 4.4.1.
775+
//
776+
// In 4.4.1 two bugs surrounding the serialization of summary rows with subtables were fixed. Previously,
777+
// if a summary row had a subtable when it was inserted into the archive table, this warning would eventually
778+
// get triggered. To properly fix this corrupt data, we'd want to invalidate and reporcess it, BUT, that would
779+
// require a lot of compute resources, just for the subtable of a row most people would not look at.
780+
//
781+
// So instead, we simply ignore this issue for data that is for periods older than the deploy date for 4.4.1. If a user
782+
// wants to see this subtable data, they can invalidate a specific date and reprocess it. For newer data,
783+
// since the bugs were fixed, we don't expect to see the issue. So if the warning gets triggered in this case,
784+
// we log the warning in order to be notified.
785+
$period = $subTable->getMetadata('period');
786+
if (!$this->isSummaryRow()
787+
|| $this->isStartDateLaterThanCloud441DeployDate($period)
788+
) {
789+
$ex = new \Exception(sprintf(
790+
"Row with label '%s' (columns = %s) has already a subtable id=%s but it was not loaded - overwriting the existing sub-table.",
791+
$this->getColumn('label'),
792+
implode(", ", $this->getColumns()),
793+
$this->getIdSubDataTable()
794+
));
795+
StaticContainer::get(LoggerInterface::class)->warning("{exception}", ['exception' => $ex]);
796+
}
778797
}
779798
}
780799

@@ -800,4 +819,18 @@ private function getColumnValueDescriptionForError($value)
800819
}
801820
return $result;
802821
}
822+
823+
private function isStartDateLaterThanCloud441DeployDate($period)
824+
{
825+
if (empty($period)
826+
|| !($period instanceof Period)
827+
) {
828+
return true; // sanity check
829+
}
830+
831+
$periodStartDate = $period->getDateStart();
832+
833+
$cloudDeployDate = Date::factory('2021-08-11 12:00:00'); // 2021-08-12 00:00:00 NZST
834+
return $periodStartDate->isLater($cloudDeployDate);
835+
}
803836
}

0 commit comments

Comments
 (0)