Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure to recover RE.md from files on startup #300

Open
prjemian opened this issue Apr 28, 2024 · 6 comments
Open

Failure to recover RE.md from files on startup #300

prjemian opened this issue Apr 28, 2024 · 6 comments
Labels
bug Something isn't working
Milestone

Comments

@prjemian
Copy link
Contributor

Failures have been observed from this code block:

def get_md_path():
path = iconfig.get("RUNENGINE_MD_PATH")
if path is None:
path = pathlib.Path.home() / ".config" / "Bluesky_RunEngine_md"
else:
path = pathlib.Path(path)
logger.info("RunEngine metadata saved in directory: %s", str(path))
return str(path)
# Set up a RunEngine and use metadata backed PersistentDict
RE = RunEngine({})
RE.md = PersistentDict(get_md_path())

When observed, the directory exists. Is there a mismatch between what is found and what is expected? In all observed cases so far, the problem is resolved by removing the directory defined by

# RUNENGINE_MD_PATH: /home/USERNAME/.config/Bluesky_RunEngine_md

Needs more documentation, such as the exact exception traceback.

@prjemian prjemian added the bug Something isn't working label Apr 28, 2024
@prjemian prjemian added this to the v1.0.4 milestone Apr 28, 2024
@prjemian
Copy link
Contributor Author

prjemian commented May 1, 2024

image

@prjemian
Copy link
Contributor Author

prjemian commented May 1, 2024

Thanks @strempfer for showing this example!

@prjemian
Copy link
Contributor Author

prjemian commented May 1, 2024

Was able to reproduce locally by trying to open an older PersistentDict directory.

ls
beamline_id#22  conda_prefix#24  databroker_catalog#23  iconfig#21  instrument_name#27  login_id#26  pid#28  proposal_id#29  scan_id#25  versions#30

ipython
In [1]: from bluesky.utils import PersistentDict

In [2]: %xmode Verbose
Exception reporting mode: Verbose

In [3]: pd = PersistentDict(".")
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
Cell In[3], line 1
----> 1 pd = PersistentDict(".")
        PersistentDict = <class 'bluesky.utils.PersistentDict'>

File ~/.conda/envs/bluesky_2024_2/lib/python3.11/site-packages/bluesky/utils/__init__.py:775, in PersistentDict.__init__(self=<PersistentDict {}>, directory='.')
    773 self._func = zict.Func(self._dump, self._load, self._file)
    774 self._cache = {}
--> 775 self.reload()
        self = <PersistentDict {}>
    777 # Similar to flush() or _do_update(), but without reference to self
    778 # to avoid circular reference preventing collection.
    779 # NOTE: This still doesn't guarantee call on delete or gc.collect()!
    780 #       Explicitly call flush() if immediate write to disk required.
    781 def finalize(zfile, cache, dump):

File ~/.conda/envs/bluesky_2024_2/lib/python3.11/site-packages/bluesky/utils/__init__.py:841, in PersistentDict.reload(self=<PersistentDict {}>)
    839 def reload(self):
    840     """Force a reload from disk, overwriting current cache"""
--> 841     self._cache = dict(self._func.items())
        self._cache = {}
        self = <PersistentDict {}>
        self._func = <Func: _dump<->_load <File: ., mode="a", 10 elements>>

File ~/.conda/envs/bluesky_2024_2/lib/python3.11/site-packages/zict/func.py:74, in <genexpr>(.0=<generator object ItemsView.__iter__>)
     73 def items(self) -> Iterator[tuple[KT, VT]]:  # type: ignore
---> 74     return ((k, self.load(v)) for k, v in self.d.items())
        self.load = <function PersistentDict._load at 0x7f21045d8ae0>
        self = <Func: _dump<->_load <File: ., mode="a", 10 elements>>
        self.d = <File: ., mode="a", 10 elements>

File <frozen _collections_abc>:861, in __iter__(self=ItemsView(<File: ., mode="a", 10 elements>))

File ~/.conda/envs/bluesky_2024_2/lib/python3.11/site-packages/zict/file.py:82, in File.__getitem__(self=<File: ., mode="a", 10 elements>, key='versions#30')
     80     raise KeyError(key)
     81 fn = os.path.join(self.directory, _safe_key(key))
---> 82 with open(fn, "rb") as fh:
        fn = './versions%2330'
     83     if self.memmap:
     84         return memoryview(mmap.mmap(fh.fileno(), 0, access=mmap.ACCESS_READ))

FileNotFoundError: [Errno 2] No such file or directory: './versions%2330'

@prjemian
Copy link
Contributor Author

prjemian commented May 1, 2024

The exception is correct, no such file ./versions%2330 exists. The existing file is named ./versions#30.

@prjemian
Copy link
Contributor Author

prjemian commented May 1, 2024

@prjemian
Copy link
Contributor Author

prjemian commented May 1, 2024

A workaround for the situation is described.

The problem occurs for any file ending in #n (where n is an integer) in the persistent directory. The solution is to clean up the file names in the directory before opening with PersistentDict(directory). Clean-up involves stripping the problematic suffix. If a non-suffixed file exists, just delete the suffixed version. Should make log entries for any of these actions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: No status
Development

No branches or pull requests

1 participant