Skip to content

Commit

Permalink
Adapt to rare 'deadlock' errors in log deduplication.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Sep 18, 2023
1 parent 89d891f commit 52d3831
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
24 changes: 14 additions & 10 deletions src/conference.php
Original file line number Diff line number Diff line change
Expand Up @@ -4834,24 +4834,28 @@ function log_for($user, $dest_user, $text, $pids = null, $dedup = false) {
$user = self::log_clean_user($user, $text);
$dest_user = self::log_clean_user($dest_user, $text);

if ($this->_save_logs === null) {
$values = self::format_log_values($text, $user, $dest_user, $true_user, $pids);
if ($dedup && count($values) === 1) {
$this->qe_apply(self::action_log_query . " select ?, ?, ?, ?, ?, ?, ? from dual"
. " where not exists (select * from ActionLog where logId>=coalesce((select max(logId) from ActionLog),0)-199 and ipaddr<=>? and contactId<=>? and destContactId<=>? and trueContactId<=>? and paperId<=>? and timestamp>=?-3600 and action<=>?)",
array_merge($values[0], $values[0]));
} else {
$this->qe(self::action_log_query . " values ?v", $values);
}
} else {
if ($this->_save_logs !== null) {
$key = "{$user},{$dest_user},{$true_user}|{$text}";
if (!isset($this->_save_logs[$key])) {
$this->_save_logs[$key] = [];
}
foreach ($pids as $p) {
$this->_save_logs[$key][$p] = true;
}
return;
}

$values = self::format_log_values($text, $user, $dest_user, $true_user, $pids);
if ($dedup && count($values) === 1) {
$result = Dbl::qx_apply($this->dblink,
self::action_log_query
. " select ?, ?, ?, ?, ?, ?, ? from dual where not exists (select * from ActionLog where logId>=coalesce((select max(logId) from ActionLog),0)-199 and ipaddr<=>? and contactId<=>? and destContactId<=>? and trueContactId<=>? and paperId<=>? and timestamp>=?-3600 and action<=>?)",
array_merge($values[0], $values[0]));
if (!$result->is_error()) {
return;
}
}
$this->qe(self::action_log_query . " values ?v", $values);
}

/** @return list<list<string>> */
Expand Down
2 changes: 1 addition & 1 deletion src/fieldrender.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
// fieldrender.php -- HotCRP helper class for multi-format messages
// Copyright (c) 2006-2022 Eddie Kohler; see LICENSE.
// Copyright (c) 2006-2023 Eddie Kohler; see LICENSE.

class FieldRender {
/** @var ?Contact
Expand Down

0 comments on commit 52d3831

Please sign in to comment.