X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/b7f4b12d8722609fbd607a75d317dd60b93497b7..0ecea550fde014578e71004360b700cdfeae4909:/sdk/python/arvados/commands/put.py diff --git a/sdk/python/arvados/commands/put.py b/sdk/python/arvados/commands/put.py index 32d5fef6a8..42510754ab 100644 --- a/sdk/python/arvados/commands/put.py +++ b/sdk/python/arvados/commands/put.py @@ -543,7 +543,10 @@ class ArvPutUploadJob(object): with self._state_lock: self._state['manifest'] = manifest if self.use_cache: - self._save_state() + try: + self._save_state() + except Exception as e: + self.logger.error("Unexpected error trying to save cache file: {}".format(e)) else: self.bytes_written = self.bytes_skipped # Call the reporter, if any @@ -673,10 +676,12 @@ class ArvPutUploadJob(object): cache_filepath = os.path.join( arv_cmd.make_home_conf_dir(self.CACHE_DIR, 0o700, 'raise'), cache_filename) - if self.resume: + if self.resume and os.path.exists(cache_filepath): + self.logger.info("Resuming upload from cache file {}".format(cache_filepath)) self._cache_file = open(cache_filepath, 'a+') else: # --no-resume means start with a empty cache file. + self.logger.info("Creating new cache file at {}".format(cache_filepath)) self._cache_file = open(cache_filepath, 'w+') self._cache_filename = self._cache_file.name self._lock_file(self._cache_file) @@ -693,6 +698,7 @@ class ArvPutUploadJob(object): # Cache file empty, set up new cache self._state = copy.deepcopy(self.EMPTY_STATE) else: + self.logger.info("No cache usage requested for this run.") # No cache file, set empty state self._state = copy.deepcopy(self.EMPTY_STATE) # Load the previous manifest so we can check if files were modified remotely. @@ -719,20 +725,19 @@ class ArvPutUploadJob(object): """ Atomically save current state into cache. """ + with self._state_lock: + # We're not using copy.deepcopy() here because it's a lot slower + # than json.dumps(), and we're already needing JSON format to be + # saved on disk. + state = json.dumps(self._state) try: - with self._state_lock: - # We're not using copy.deepcopy() here because it's a lot slower - # than json.dumps(), and we're already needing JSON format to be - # saved on disk. - state = json.dumps(self._state) - new_cache_fd, new_cache_name = tempfile.mkstemp( - dir=os.path.dirname(self._cache_filename)) - self._lock_file(new_cache_fd) - new_cache = os.fdopen(new_cache_fd, 'r+') + new_cache = tempfile.NamedTemporaryFile( + dir=os.path.dirname(self._cache_filename), delete=False) + self._lock_file(new_cache) new_cache.write(state) new_cache.flush() os.fsync(new_cache) - os.rename(new_cache_name, self._cache_filename) + os.rename(new_cache.name, self._cache_filename) except (IOError, OSError, ResumeCacheConflict) as error: self.logger.error("There was a problem while saving the cache file: {}".format(error)) try: