From 8ed58917ffd2e6909890621ab68314ae43d06657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Mon, 17 Oct 2022 10:30:19 +0200 Subject: [PATCH] fix DB-locked error in egg_update? --- www/extern/egg/EGGDatabase.php | 6 ++++-- www/extern/egg/RemoteSource.php | 18 +++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/www/extern/egg/EGGDatabase.php b/www/extern/egg/EGGDatabase.php index 34b4a53..a30ea02 100644 --- a/www/extern/egg/EGGDatabase.php +++ b/www/extern/egg/EGGDatabase.php @@ -62,7 +62,7 @@ class EGGDatabase public function abortTransactionIfExists() { - if ($this->pdo !== null) $this->pdo->rollBack(); + if ($this->pdo !== null && $this->pdo->inTransaction()) $this->pdo->rollBack(); } private function init() @@ -222,7 +222,7 @@ class EGGDatabase * @param Commit[] $commits */ public function insertNewCommits(string $source, Repository $repo, Branch $branch, array $commits) { - $this->logger->proclog("Inserted " . count($commits) . " (new) commits into [" . $source . "|" . $repo->Name . "|" . $branch->Name . "]"); + $this->logger->proclog("Inserting " . count($commits) . " (new) commits into [" . $source . "|" . $repo->Name . "|" . $branch->Name . "]"); foreach ($commits as $commit) { @@ -261,6 +261,8 @@ class EGGDatabase * @param string $head */ public function setBranchHead(Branch $branch, string $head) { + $this->logger->proclog("Set HEAD of branch [" . $branch->Repo->Source . "|" . $branch->Repo->Name . "|" . $branch->Name . "] to {".substr($head, 0, 8)."}"); + $this->sql_exec_prep("UPDATE branches SET head = :head WHERE id = :id", [ [":id", $branch->ID, PDO::PARAM_INT], diff --git a/www/extern/egg/RemoteSource.php b/www/extern/egg/RemoteSource.php index 5a646f1..86f0ef6 100644 --- a/www/extern/egg/RemoteSource.php +++ b/www/extern/egg/RemoteSource.php @@ -51,9 +51,7 @@ abstract class StandardGitConnection implements IRemoteSource { $this->preUpdate(); - $db->beginTransaction(); $repos = $this->listAndUpdateRepositories($db); - $db->commitTransaction(); $anyChanged = false; @@ -91,19 +89,21 @@ abstract class StandardGitConnection implements IRemoteSource if ($repo_changed) $db->setChangeDateOnRepository($repo); if ($repo_changed) $anyChanged = true; } + + $this->logger->proclog("Committing SQL-transaction for [" . $this->name . "|" . $repo->Name . "]"); $db->commitTransaction(); } if ($anyChanged) { - $db->beginTransaction(); + $this->logger->proclog("Deleting dangling commits..."); + $db->deleteDanglingCommitdata($this->name); - $db->commitTransaction(); } - $db->beginTransaction(); $this->postUpdate(); - $db->commitTransaction(); + + $this->logger->proclog("Finished [" . $this->name . "]"); } /** @@ -271,9 +271,11 @@ abstract class StandardGitConnection implements IRemoteSource $next_sha = [ $branch->HeadFromAPI ]; $visited = array_map(function(Commit $m):string{return $m->Hash;}, $db->getCommits($branch)); + $this->logger->proclog("Query commit for [" . $this->name . "|" . $repo->Name . "|" . $branch->Name . "] (initial @ {" . substr($next_sha[0], 0, 8) . "})"); + $json = $this->queryCommits($repo->Name, $branch->Name, $next_sha[0]); - for (;;) + for ($pg=2;;$pg++) { foreach ($json as $result_commit) { @@ -336,6 +338,8 @@ abstract class StandardGitConnection implements IRemoteSource $next_sha = array_values($next_sha); // fix numeric keys if (count($next_sha) === 0) break; + $this->logger->proclog("Query commit for [" . $this->name . "|" . $repo->Name . "|" . $branch->Name . "] (" . $pg . " @ {" . substr($next_sha[0], 0, 8) . "})"); + $json = $this->queryCommits($repo->Name, $branch->Name, $next_sha[0]); }