-
Notifications
You must be signed in to change notification settings - Fork 37
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
StorageFrontend remoteness attribute and test #617
Merged
JoranAngevaare
merged 6 commits into
AxFoundation:master
from
JoranAngevaare:frontend_remoteness
Jan 10, 2022
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c399091
add database remoteness and test
JoranAngevaare c5d0e12
fix typo
JoranAngevaare 80b6fe3
review comments
JoranAngevaare 2ba2f39
why commenting code is bad practice
JoranAngevaare 2fb16ea
Merge branch 'master' into frontend_remoteness
JoranAngevaare 8fc2b8e
Merge branch 'master' into frontend_remoteness
JoranAngevaare File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -679,17 +679,29 @@ def _find_options(self): | |||||
fuzzy_for_options=self.context_config['fuzzy_for_options'], | ||||||
allow_incomplete=self.context_config['allow_incomplete']) | ||||||
|
||||||
@property | ||||||
def _sorted_storage(self) -> ty.List[strax.StorageFrontend]: | ||||||
""" | ||||||
Simple ordering of the storage frontends on the fly when e.g. | ||||||
looking for data. This allows us to use the simple self.storage | ||||||
as a simple list without asking users to keep any particular | ||||||
order in mind. Return the fastest first and try loading from it | ||||||
""" | ||||||
storage_sfs = self.storage | ||||||
storage_sfs.sort(key=lambda x: x.storage_type) | ||||||
return storage_sfs | ||||||
|
||||||
def _get_partial_loader_for(self, key, time_range=None, chunk_number=None): | ||||||
""" | ||||||
Get partial loaders to allow loading data later | ||||||
:param key: strax.DataKey | ||||||
:param time_range: 2-length arraylike of (start, exclusive end) of row | ||||||
numbers to get. Default is None, which means get the entire run. | ||||||
numbers to get. Default is None, which means get the entire run. | ||||||
:param chunk_number: number of the chunk for data specified by | ||||||
strax.DataKey. This chunck is loaded exclusively. | ||||||
strax.DataKey. This chunck is loaded exclusively. | ||||||
:return: partial object | ||||||
""" | ||||||
for sb_i, sf in enumerate(self.storage): | ||||||
for _, sf in enumerate(self._sorted_storage): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
double jeopardy! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you are absolutely right! |
||||||
try: | ||||||
# Partial is clunky... but allows specifying executor later | ||||||
# Since it doesn't run until later, we must do a find now | ||||||
|
@@ -879,7 +891,7 @@ def concat_loader(*args, **kwargs): | |||||
|
||||||
key = strax.DataKey(run_id, d_to_save, target_plugin.lineage) | ||||||
|
||||||
for sf in self.storage: | ||||||
for sf in self._sorted_storage: | ||||||
if sf.readonly: | ||||||
continue | ||||||
if loading_this_data: | ||||||
|
@@ -1469,10 +1481,10 @@ def get_meta(self, run_id, target) -> dict: | |||||
:param target: data type to get | ||||||
""" | ||||||
key = self.key_for(run_id, target) | ||||||
for sf in self.storage: | ||||||
for sf in self._sorted_storage: | ||||||
try: | ||||||
return sf.get_metadata(key, **self._find_options) | ||||||
except strax.DataNotAvailable as e: | ||||||
except strax.DataNotAvailable: | ||||||
self.log.debug(f"Frontend {sf} does not have {key}") | ||||||
raise strax.DataNotAvailable(f"Can't load metadata, " | ||||||
f"data for {key} not available") | ||||||
|
@@ -1487,7 +1499,7 @@ def run_metadata(self, run_id, projection=None) -> dict: | |||||
:param projection: Selection of fields to get, following MongoDB | ||||||
syntax. May not be supported by frontend. | ||||||
""" | ||||||
for sf in self.storage: | ||||||
for sf in self._sorted_storage: | ||||||
if not sf.provide_run_metadata: | ||||||
continue | ||||||
try: | ||||||
|
@@ -1523,7 +1535,8 @@ def run_defaults(self, run_id): | |||||
return defs | ||||||
|
||||||
def is_stored(self, run_id, target, **kwargs): | ||||||
"""Return whether data type target has been saved for run_id | ||||||
""" | ||||||
Return whether data type target has been saved for run_id | ||||||
through any of the registered storage frontends. | ||||||
|
||||||
Note that even if False is returned, the data type may still be made | ||||||
|
@@ -1540,7 +1553,7 @@ def is_stored(self, run_id, target, **kwargs): | |||||
# noinspection PyMethodFirstArgAssignment | ||||||
self = self.new_context(**kwargs) | ||||||
|
||||||
for sf in self.storage: | ||||||
for sf in self._sorted_storage: | ||||||
if self._is_stored_in_sf(run_id, target, sf): | ||||||
return True | ||||||
# None of the frontends has the data | ||||||
|
@@ -1592,13 +1605,16 @@ def copy_to_frontend(self, | |||||
rechunk: bool = False): | ||||||
""" | ||||||
Copy data from one frontend to another | ||||||
|
||||||
:param run_id: run_id | ||||||
:param target: target datakind | ||||||
:param target_frontend_id: index of the frontend that the data should go to | ||||||
in context.storage. If no index is specified, try all. | ||||||
:param target_compressor: if specified, recompress with this compressor. | ||||||
:param rechunk: allow re-chunking for saving | ||||||
""" | ||||||
|
||||||
# NB! We don't want to use self.sorted_storage here since the order matters! | ||||||
if not self.is_stored(run_id, target): | ||||||
raise strax.DataNotAvailable(f'Cannot copy {run_id} {target} since it ' | ||||||
f'does not exist') | ||||||
|
@@ -1781,7 +1797,7 @@ def _get_source_sf(self, run_id, target, should_exist=False): | |||||
:return: strax.StorageFrontend or None (when raise_error is | ||||||
False) | ||||||
""" | ||||||
for sf in self.storage: | ||||||
for sf in self._sorted_storage: | ||||||
if self._is_stored_in_sf(run_id, target, sf): | ||||||
return sf | ||||||
if should_exist: | ||||||
|
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want to keep original list since order is used in
copy_to_frontend
right? I think the way it is would sort in place the original list no?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!