Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(db): Do not log transacted reads as dirty read #42929

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/private/DB/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,16 @@ public function prepare($sql, $limit = null, $offset = null): Statement {
*/
public function executeQuery(string $sql, array $params = [], $types = [], QueryCacheProfile $qcp = null): Result {
$tables = $this->getQueriedTables($sql);
if (count(array_intersect($this->tableDirtyWrites, $tables)) === 0 && !$this->isTransactionActive()) {
if ($this->isTransactionActive()) {
// Transacted queries go to the primary. The consistency of the primary guarantees that we can not run
// into a dirty read.
} elseif (count(array_intersect($this->tableDirtyWrites, $tables)) === 0) {
// No tables read that could have been written already in the same request and no transaction active
// so we can switch back to the replica for reading as long as no writes happen that switch back to the primary
// We cannot log here as this would log too early in the server boot process
$this->ensureConnectedToReplica();
} else {
// Read to a table that was previously written to
// Read to a table that has been written to previously
// While this might not necessarily mean that we did a read after write it is an indication for a code path to check
$this->logger->debug('dirty table reads: ' . $sql, ['tables' => $this->tableDirtyWrites, 'reads' => $tables, 'exception' => new \Exception()]);
}
Expand Down
Loading