1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-09-02 11:22:41 +01:00

fw: Replace usage of file locking with atomic writes

To prevent long timeouts occurring during to file locking on
both reads and writes replace locking with
atomic writes.

While this may results in cache entries being overwritten,
the amount of time used in duplicated retrievals will likely
be saved with the prevention of stalls due to waiting to
acquire the file lock.
This commit is contained in:
Marc Bonnici
2020-06-26 11:18:03 +01:00
committed by setrofim
parent 0c1229df8c
commit 684121e2e7
4 changed files with 52 additions and 55 deletions

View File

@@ -32,7 +32,7 @@ from wa.framework.exception import WorkloadError, ConfigError
from wa.utils.types import ParameterDict, list_or_string, version_tuple
from wa.utils.revent import ReventRecorder
from wa.utils.exec_control import once_per_instance
from wa.utils.misc import lock_file
from wa.utils.misc import atomic_write_path
class Workload(TargetedPlugin):
@@ -732,32 +732,31 @@ class PackageHandler(object):
raise WorkloadError(msg)
self.error_msg = None
with lock_file(os.path.join(self.owner.dependencies_directory, self.owner.name)):
if self.prefer_host_package:
self.resolve_package_from_host(context)
if not self.apk_file:
self.resolve_package_from_target()
else:
if self.prefer_host_package:
self.resolve_package_from_host(context)
if not self.apk_file:
self.resolve_package_from_target()
if not self.apk_file:
self.resolve_package_from_host(context)
else:
self.resolve_package_from_target()
if not self.apk_file:
self.resolve_package_from_host(context)
if self.apk_file:
self.apk_info = get_cacheable_apk_info(self.apk_file)
if self.apk_file:
self.apk_info = get_cacheable_apk_info(self.apk_file)
else:
if self.error_msg:
raise WorkloadError(self.error_msg)
else:
if self.error_msg:
raise WorkloadError(self.error_msg)
if self.package_name:
message = 'Package "{package}" not found for workload {name} '\
'on host or target.'
elif self.version:
message = 'No matching package found for workload {name} '\
'(version {version}) on host or target.'
else:
if self.package_name:
message = 'Package "{package}" not found for workload {name} '\
'on host or target.'
elif self.version:
message = 'No matching package found for workload {name} '\
'(version {version}) on host or target.'
else:
message = 'No matching package found for workload {name} on host or target'
raise WorkloadError(message.format(name=self.owner.name, version=self.version,
package=self.package_name))
message = 'No matching package found for workload {name} on host or target'
raise WorkloadError(message.format(name=self.owner.name, version=self.version,
package=self.package_name))
def resolve_package_from_host(self, context):
self.logger.debug('Resolving package on host system')
@@ -900,8 +899,8 @@ class PackageHandler(object):
package_info = self.target.get_package_info(package)
apk_name = self._get_package_name(package_info.apk_path)
host_path = os.path.join(self.owner.dependencies_directory, apk_name)
with lock_file(host_path, timeout=self.install_timeout):
self.target.pull(package_info.apk_path, host_path,
with atomic_write_path(host_path) as at_path:
self.target.pull(package_info.apk_path, at_path,
timeout=self.install_timeout)
return host_path