Julien Cristau pushed to branch master at snapshot / snapshot
Commits:
28223016 by Julien Cristau at 2024-04-06T11:41:10+02:00
Move the indexing lock to the database
We're currently running imports from 2 different hosts so we can't rely
on filesystem-based locking.
- - - - -
2aa2c9f4 by Julien Cristau at 2024-04-06T09:45:40+00:00
Merge branch 'index-lock-db' into 'master'
Move the indexing lock to the database
See merge request snapshot-team/snapshot!14
- - - - -
2 changed files:
- master/import-run
- snapshot
Changes:
=====================================
master/import-run
=====================================
@@ -53,14 +53,7 @@ case "$archive" in
#"$BASE"/code/misc/dump-tools/add-new-dumps-to-git -c "$CONFIG"
-b "$BASE"/dumps-git
- indexlock="$BASE/.snapshot-index.lock"
- touch "$indexlock"
- exec 204< "$indexlock"
- if ! flock --exclusive 204; then
- echo >&2 "Warning: Not running index as we don't have
the lock."
- else
- snapshot index --config "$CONFIG" --quick $verbose
- fi
+ snapshot index --config "$CONFIG" --quick $verbose
ls -l "$BASE"/fuse/.ctrl-reload-database > /dev/null 2>&1 ||
true
=====================================
snapshot
=====================================
@@ -1243,6 +1243,7 @@ class PackageIndexer
def index
if @only_this_mirrorrun
@db.begin
+ @db.execute("LOCK indexed_mirrorrun IN SHARE
ROW EXCLUSIVE MODE")
row = @db.query_row("SELECT run, (SELECT name
FROM archive WHERE archive.archive_id = mirrorrun.archive_id) AS archive
FROM
mirrorrun WHERE mirrorrun_id = $1", @only_this_mirrorrun)
if row.nil?
@@ -1258,9 +1259,13 @@ class PackageIndexer
@db.query("SELECT mirrorrun_id, run, (SELECT name FROM
archive WHERE archive.archive_id = mirrorrun.archive_id) AS archive
FROM mirrorrun WHERE NOT
mirrorrun_id IN (SELECT mirrorrun_id FROM indexed_mirrorrun) ORDER BY run") do
|row|
@db.begin
- $logger.info("Indexing mirrorrun
##{row['mirrorrun_id']} of #{row['archive']} from #{row['run']}")
- source = index_mirrorrun(row['mirrorrun_id'])
- @db.insert('indexed_mirrorrun', {'mirrorrun_id'
=> row['mirrorrun_id'], 'source' => source })
+ @db.execute("LOCK indexed_mirrorrun IN SHARE
ROW EXCLUSIVE MODE")
+ check = @db.query_row("SELECT 1 FROM
indexed_mirrorrun WHERE mirrorrun_id = $1", row['mirrorrun_id'])
+ if check.nil?
+ $logger.info("Indexing mirrorrun
##{row['mirrorrun_id']} of #{row['archive']} from #{row['run']}")
+ source =
index_mirrorrun(row['mirrorrun_id'])
+ @db.insert('indexed_mirrorrun',
{'mirrorrun_id' => row['mirrorrun_id'], 'source' => source })
+ end
@db.commit
end
end
View it on GitLab:
https://salsa.debian.org/snapshot-team/snapshot/-/compare/deb106c66ec84b99b3b85f76321acbbdabc37f2f...2aa2c9f4380fb9c03cfc01ba3601815451b3c73a
--
View it on GitLab:
https://salsa.debian.org/snapshot-team/snapshot/-/compare/deb106c66ec84b99b3b85f76321acbbdabc37f2f...2aa2c9f4380fb9c03cfc01ba3601815451b3c73a
You're receiving this email because of your account on salsa.debian.org.