Skip to content

Commit

Permalink
Merge pull request #29 from guvra/global-transaction
Browse files Browse the repository at this point in the history
Move transactions to a global level
  • Loading branch information
back-2-95 authored May 20, 2023
2 parents 05d576f + 45cd7ef commit b73fdea
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/Mysqldump.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ public function start(?string $filename = '')
$this->write($this->getDumpFileHeader());
}

// Initiate a transaction at global level to create a consistent snapshot.
if ($this->settings->isEnabled('single-transaction')) {
$this->conn->exec($this->db->setupTransaction());
$this->conn->exec($this->db->startTransaction());
}

// Store server settings and use saner defaults to dump
$this->write($this->db->backupParameters());

Expand Down Expand Up @@ -234,6 +240,11 @@ public function start(?string $filename = '')
// Restore saved parameters.
$this->write($this->db->restoreParameters());

// End transaction.
if ($this->settings->isEnabled('single-transaction')) {
$this->conn->exec($this->db->commitTransaction());
}

// Write some stats to output file.
if (!$this->settings->skipComments()) {
$this->write($this->getDumpFileFooter());
Expand Down Expand Up @@ -887,11 +898,6 @@ private function prepareListValues(string $tableName)
);
}

if ($this->settings->isEnabled('single-transaction')) {
$this->conn->exec($this->db->setupTransaction());
$this->conn->exec($this->db->startTransaction());
}

if ($this->settings->isEnabled('lock-tables') && !$this->settings->isEnabled('single-transaction')) {
$this->db->lockTable($tableName);
}
Expand Down Expand Up @@ -926,10 +932,6 @@ private function endListValues(string $tableName, int $count = 0)
$this->write($this->db->endAddLockTable($tableName));
}

if ($this->settings->isEnabled('single-transaction')) {
$this->conn->exec($this->db->commitTransaction());
}

if ($this->settings->isEnabled('lock-tables')
&& !$this->settings->isEnabled('single-transaction')) {
$this->db->unlockTable($tableName);
Expand Down

0 comments on commit b73fdea

Please sign in to comment.