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

V3 #17

Merged
merged 101 commits into from
Jun 13, 2024
Merged

V3 #17

merged 101 commits into from
Jun 13, 2024

Conversation

jvansanten
Copy link
Contributor

No description provided.

Cutouts are stored as an AVRO packet, using ZTF alert schema 3.3
with all keys other than candid and cutouts removed.  This means
that science, reference, and difference cutouts are retrieved
together for each alert.  The underlying assumption is that cutout
queries will be rare.

Adds:
- a new endpoint, PUT /alert/{candid} for inserting new alerts
- roles for tokens.  Only writer tokens can insert new alerts
- s3 backend for cutout storage

Removes:
- with_cutouts arguments to alert query endpoints.
Instead of storing individual cutouts in s3, store entire chunks
of alerts.  These are only moderately larger than just the cutouts
themselves.  The alert table tracks the URI of the blob in which
the alert was stored, along with the byte range of the target block,
which can be retrieved with a range request.
This is ~linearly faster than the previous implementation in the number
of pixels queried, as postgres does not
seem to elide multiple calls to healpix_ang2pix_nest, even though it is
marked IMMUTABLE.

Generated columns require postgres >= 12
Inserting alerts in bulk in multiple concurrent transactions causes deadlocks like:

```
2022-02-16 12:11:30.643 CET [2834] STATEMENT:  INSERT INTO upper_limit (jd, fid, pid, diffmaglim, programid, rbversion, nid, rcid, field) VALUES (2459622.7773727, 2, 1868277372915, 19.48270034790039, 1, 't17_f5_c3', 1868, 29, 515) ON CONFLICT DO NOTHING RETURNING upper_limit.upper_limit_id
2022-02-16 12:12:19.164 CET [2832] ERROR:  deadlock detected
2022-02-16 12:12:19.164 CET [2832] DETAIL:  Process 2832 waits for ShareLock on transaction 53604; blocked by process 2835.
        Process 2835 waits for ShareLock on transaction 53602; blocked by process 2832.
        Process 2832: INSERT INTO upper_limit (jd, fid, pid, diffmaglim, programid, rbversion, nid, rcid, field) VALUES (2459622.7773727, 2, 1868277370115, 19.436500549316406, 1, 't17_f5_c3', 1868, 1, 515) ON CONFLICT DO NOTHING
        Process 2835: INSERT INTO upper_limit (jd, fid, pid, diffmaglim, programid, rbversion, nid, rcid, field) VALUES (2459624.668044, 2, 1870168043615, 19.528600692749023, 1, 't17_f5_c3', 1870, 36, 258) ON CONFLICT DO NOTHING
2022-02-16 12:12:19.164 CET [2832] HINT:  See server log for query details.
2022-02-16 12:12:19.164 CET [2832] CONTEXT:  while inserting index tuple (377163,4) in relation "upper_limit"
```
Cutouts may be explicitly retrieved for a single candidate, but do not make
sense in bulk queries.
Non-ZTF users should see only programid 1.  To accomplish this, all
bulk alert query endpoints now have an optional programid parameter,
and tokens have a partnership field, set to true if the owner's
identity is in the partnership group.  Non-partnership tokens must
set programid to 1, or omit it, in which case it defaults to 1.
Values other than 1 raise 401 Unauthorized.  Partnership queries
pass the value of programid through.

As a side-effect, fixes #5.
In addition to jd/spatial constraints, requests may specify a filter
to apply to the candidate in each alert, in a format similar to a
MongoDB match expression. For example:

``` {"fid": 1, "drb": {"$gt": 0.95}} ```

selects only alerts where fid==1 and drb>=0.95. The operators $gt,
$gte, $lt, $lte, $eq, $ne, $in, and $nin are supported.
Allow for long-running queries by creating the group outside a
transaction and running the actual query in a background task.
@jvansanten jvansanten merged commit 8fe8a38 into main Jun 13, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants