Skip to content

Commit

Permalink
Only try to locate all sources if given path does not successfully op…
Browse files Browse the repository at this point in the history
…en file first
  • Loading branch information
Ryan Simeon committed May 29, 2024
1 parent 2f6c650 commit 16f2c52
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions src/fsspec_xrootd/xrootd.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,29 +776,33 @@ def __init__(
# Ensure any read-only handle is closed
fs.invalidate_cache(path)

if "r" in mode and self.fs.locate_all_sources:
# Try opening with given pathname before trying to locate all sources (if requested)
self._myFile = client.File()
status, _n = self._myFile.open(
fs.unstrip_protocol(path),
self.mode,
timeout=self.timeout,
)
if not status.ok and "r" in mode and self.fs.locate_all_sources:
self._hosts = self._locate_sources(path)
else:
self._hosts = [fs.storage_options["hostid"]]

# Try hosts until you find an openable file
for i_host in range(len(self._hosts)):
self._myFile = client.File()
status, _n = self._myFile.open(
fs.protocol + "://" + self._hosts[i_host] + "/" + path,
self.mode,
timeout=self.timeout,
)
if status.ok:
break

# Try hosts until you find an openable file
for i_host in range(len(self._hosts)):
self._myFile = client.File()
status, _n = self._myFile.open(
fs.protocol + "://" + self._hosts[i_host] + "/" + path,
self.mode,
timeout=self.timeout,
)
if status.ok:
# Move hosts that tried and failed to self._dismissed_hosts
self._dismissed_hosts = self._hosts[:i_host]
self._hosts = self._hosts[i_host:]
break
# If above loop cannot find source OR locate_all_sources is off and we
# could not read file initially, end up here
if not status.ok:
raise OSError(f"File did not open properly: {status.message}")

# Move hosts that tried and failed to self._dismissed_hosts
self._dismissed_hosts = self._hosts[:i_host]
self._hosts = self._hosts[i_host:]

self.metaOffset = 0
if "a" in mode:
_stats, _deets = self._myFile.stat(timeout=self.timeout)
Expand Down

0 comments on commit 16f2c52

Please sign in to comment.