-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure that no two workers on the same machine simultaneously try to precache files. All workers except one skip precaching.
- Loading branch information
Showing
2 changed files
with
61 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
# Copyright © 2010-2012 Matteo Boscariol <[email protected]> | ||
# Copyright © 2013-2015 Luca Wehrstedt <[email protected]> | ||
# Copyright © 2016 Luca Versari <[email protected]> | ||
# Copyright © 2021 Fabian Gundlach <[email protected]> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
|
@@ -70,24 +71,35 @@ def precache_files(self, contest_id): | |
contest_id (int): the id of the contest | ||
""" | ||
# In order to avoid a long-living connection, first fetch the | ||
# complete list of files and then download the files; since | ||
# this is just pre-caching, possible race conditions are not | ||
# dangerous | ||
logger.info("Precaching files for contest %d.", contest_id) | ||
with SessionGen() as session: | ||
contest = Contest.get_from_id(contest_id, session) | ||
files = enumerate_files(session, contest, skip_submissions=True, | ||
skip_user_tests=True, skip_print_jobs=True) | ||
for digest in files: | ||
try: | ||
self.file_cacher.cache_file(digest) | ||
except KeyError: | ||
# No problem (at this stage) if we cannot find the | ||
# file | ||
pass | ||
|
||
logger.info("Precaching finished.") | ||
lock = self.file_cacher.precache_lock() | ||
if lock is None: | ||
# Another worker is already precaching. Hence, this worker doesn't | ||
# need to do anything. | ||
logger.info("Another worker is already precaching files for " | ||
"contest %d.", contest_id) | ||
return | ||
with lock: | ||
# In order to avoid a long-living connection, first fetch the | ||
# complete list of files and then download the files; since | ||
# this is just pre-caching, possible race conditions are not | ||
# dangerous | ||
logger.info("Precaching files for contest %d.", contest_id) | ||
with SessionGen() as session: | ||
contest = Contest.get_from_id(contest_id, session) | ||
files = enumerate_files(session, | ||
contest, | ||
skip_submissions=True, | ||
skip_user_tests=True, | ||
skip_print_jobs=True) | ||
for digest in files: | ||
try: | ||
self.file_cacher.cache_file(digest) | ||
except KeyError: | ||
# No problem (at this stage) if we cannot find the | ||
# file | ||
pass | ||
|
||
logger.info("Precaching finished.") | ||
|
||
@rpc_method | ||
def execute_job_group(self, job_group_dict): | ||
|