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

XENON RunDB Frontend #100

Merged
merged 6 commits into from Oct 3, 2018
Merged

XENON RunDB Frontend #100

merged 6 commits into from Oct 3, 2018

Conversation

tunnell
Copy link
Member

@tunnell tunnell commented Sep 12, 2018

(This is XENON-specific, still need to do #48)

This addresses Issue #73. There is a frontend that looks for data in a run database. Currently, no default is given, so the MongoURL has to be fed in. For example:

import strax

st = strax.Context(
    storage=strax.xenon.RunDB(mongo_url='mongodb://rundb-rw:XXXXX@rundbcluster-shard-00-00-cfaei.gcp.mongodb.net:27017,rundbcluster-shard-00-01-cfaei.gcp.mongodb.net:27017,rundbcluster-shard-00-02-cfaei.gcp.mongodb.net:27017/test?ssl=true&replicaSet=RunDBCluster-shard-0&authSource=admin&retryWrites=true'),
    register_all=strax.xenon.plugins,
    register=strax.xenon.pax_interface.RecordsFromPax
)

d = st.get_array('170321_0620', 'raw_records')

The way it works is by searching the RunDB for data of interest (this is the only RunDB call!). If a run document exists, then it tries to determine if it knows how to read it. S3 can be read anywhere. A fuzzy hacky match is used (like in hax) to determine if you're running on dali, where other XENON data is. At the moment, this interface cannot write RunDB aware. This is reserved for snax.

This relies on a RunDB mirror hosted through MongoDB Atlas on Google Cloud Platform. Which data is available can also be seen here.

@tunnell tunnell added the enhancement New feature or request label Sep 12, 2018
@tunnell
Copy link
Member Author

tunnell commented Sep 12, 2018

I just realized: this PR also includes a cleanup and fix of the S3 interface.

super().__init__(*args, **kwargs)

self.client = pymongo.MongoClient(mongo_url)
self.collection = self.client['xenon1t']['runs']
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one use.

if fuzzy_for or fuzzy_for_options:
raise NotImplementedError("Can't do fuzzy with S3")

query = {'name': key.run_id,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another.

@briedel
Copy link

briedel commented Sep 12, 2018

To understand this correctly, strax only queries for the location of the data of a certain type?

@tunnell
Copy link
Member Author

tunnell commented Sep 13, 2018

At present, yes. Writing to the RunDB will be more centralized I'm guessing (cax/snax) since not everybody needs to write. This will be more complicated and I can link there (just factored runDB calls into one place to make easier to replace).

The real reason it doesn't write is because writing to the RunDB happens in multiple threads and we couldn't figure out how to do it just once (yet). @briedel

@JelleAalbers
Copy link
Member

@briedel We will probably add some more rundb calls later for fetching of run-level metadata and possibly some configuration.

RunDB write support should come soon, but not in this first concept:

  • We need to add a hook when data is done writing that calls back to the storage frontend (mongodb in this case). First of all we'll have to change the storage base classes a bit for this.
  • Next, we'll hit a problem where we can't put this callback it in the most obvious place (Saver) in the most obvious way (attribute) because Savers can get forked over multiple processes (in low-level multiprocessing, the ParallelSourcePlugin), and you can't put unpickleable attributes (like callbacks, mongo clients, etc.) on things that will be forked. This isn't really a problem, as the forked versions don't need the callback, so we just have to erase it just before forking.

Even if we only use snax for writing, it's still useful to have write support in the strax frontend, to simplify snax's life.

@tunnell
Copy link
Member Author

tunnell commented Sep 26, 2018

PR good?


# Create bucket (does nothing if exists)
self.s3.create_bucket(Bucket=BUCKET_NAME)
# self.s3.create_bucket(Bucket=BUCKET_NAME)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this accidentally commented out or do we no longer need it?

try:
self.backends[0].get_metadata(key)
except ClientError as ex:
if ex.response['Error']['Code'] == 'NoSuchKey':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you catch this in get_metadata and raise DataNotAvailable there? This would fix #90. (Then here, you'd catch DataNotAvailable again if you're writing.)

The S3 frontend is unusual in that _find relies on get_metadata rather than the other way around. But the context relies on DataNotAvailable being raised if get_metadata fails, so it can try other storage frontends (https://github.com/AxFoundation/strax/blob/master/strax/context.py#L632).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it turns out #90 has already been fixed, so never mind.

class RunDB(strax.StorageFrontend):
"""Frontend that searches RunDB MongoDB for data.

Loads appropriate backends ranging from Files to S3.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add the caveats about writing you wrote in the PR here. If I remember correctly, writing is supported, but it doesn't get registered back in the rundb.

Also perhaps worth noting the chosen write backend is files if you're on dali and S3 otherwise (right?).

Copy link
Member

@JelleAalbers JelleAalbers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I left a few comments that might be useful to look at (one would fix #90 I think), but feel free to merge.

@JelleAalbers JelleAalbers merged commit 2da113c into master Oct 3, 2018
@JelleAalbers JelleAalbers deleted the rundb branch October 3, 2018 13:00
@JelleAalbers JelleAalbers mentioned this pull request Oct 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants