Repository navigation
Conversation
asset state store to an Async db sessionasset state store API endpoint to an async db session
fcf3abb to
a0d2de8
Compare
Dev-iL
left a comment
There was a problem hiding this comment.
I asked my agent to review the PR using the airflow-async-endpoints skill. TL;DR - the changes are good, with a couple of performance-related suggestions.
I'm attaching the review report (review.md), including helper scripts (*.py) and instructions on how to reproduce it locally: pr74540-review.zip
| @@ -138,28 +143,28 @@ def get_asset_state_store_by_name( | |||
| return AssetStateStoreResponse(value=json.loads(value)) | |||
There was a problem hiding this comment.
Converting this handler to async def moves json.loads(value) and AssetStateStoreResponse validation from FastAPI's worker thread onto the server event loop. With a stored 100,000-integer array (688,890 JSON bytes), two SQLite benchmark rounds increased median event-loop delay from 110–113 ms on the base to 152–155 ms here. Offloading parsing and response-model construction together reduced it to 112–129 ms; the remaining delay includes existing framework serialization. Larger stored values therefore delay other requests handled by the same loop.
Suggestion: move parsing and response-model construction into run_in_threadpool after the awaited backend read, and apply the same change to the URI handler at asset_state_store.py:235.
| asset_id = _resolve_asset_id_by_name(name, session) | ||
| value = get_state_backend().get(AssetScope(asset_id=asset_id), key, session=session) | ||
| asset_id = await _resolve_asset_id_by_name(name, session) | ||
| value = await get_state_backend().aget(AssetScope(asset_id=asset_id), key, session=session) |
There was a problem hiding this comment.
Both converted GET routes call MetastoreBackend._aget_asset_state_store at state/metastore.py:551, which selects the entire 13-column AssetStateStoreModel but returns only row.value.
Suggestions: select AssetStateStoreModel.value and return the scalar directly, keeping the existing filters and session. The value column is non-null, so missing keys still return None. A comparative HTTP probe on SQLite, PostgreSQL, and MySQL preserved the returned values and missing-key responses while reducing selected columns from 13 to 1 and ORM loads from one to zero per successful GET. Apply this to both selectors through the shared helper.
There was a problem hiding this comment.
@Dev-iL , Got it!
Apologies for the delay - I'll work on these updates and aim to wrap them up in a couple of days
|
Fork CI: waiting for a push. The workflow is enabled in your fork, but it has not run for the latest commit of this pull request. Push the branch again to start it. If you already pushed, verify in your fork's Actions tab that workflows are not disabled by GitHub's fork banner. Pull requests from contributors run their CI in the contributor's own fork. GitHub Actions is free and has no minute limit on public forks, while the CI capacity of the Apache Software Foundation is shared by every ASF project and is finite. How this works: CI in your fork. This comment was posted automatically by the fork CI monitor from templates drafted with an AI-assisted tool, so it may contain mistakes. An Apache Airflow maintainer, a real person, will review the pull request once its fork CI is green. Why the first pass is automated. |
aa8cfb7 to
446150d
Compare
446150d to
3966b3c
Compare
|
Do we need to create a async decorator for this async function ? (I discussed with claude but didn't understand !) Would love to hear from you ! |
dabla
left a comment
There was a problem hiding this comment.
Addressed
- Selecting only
valuein_aget_asset_state_store(thread r4280952204): done in3966b3c517; the backend tests inairflow-core/tests/unit/statepass on this head.
Open
- Comment [1]: both GET routes return the undecoded JSON string; 9 route tests fail.
- Comments [2] and [3]: nits.
- JSON decoding and response validation on the event loop (thread r4280775014): no reply and no change yet. With
aget_valuethe decoding still runs on the loop, so the point stands as raised. - Your question about
allow_asset_watcher: no async variant is needed. It does not wrap the endpoint; it sets an attribute on the function and returns the same function, so FastAPI still sees theasync defand awaits it. The six decorated routes pass their tests, the watcher and the rejected-identity cases included. - CI has not run on this head: the fork CI is waiting for a push.
Reviewed at 3966b3c517 from the diff plus the full source of both files and the shared backend base class. Each sync call was matched to its async twin (set/aset, set_asset_state_store/aset_asset_state_store, delete/adelete, clear/aclear agree in arguments and writer fields; get_value/aget do not, comment [1]). Tests run locally on SQLite: the route tests (34 passed, 9 failed) and, with the fix of comment [1] applied, the route tests plus airflow-core/tests/unit/state (110 passed, 3 skipped). Not covered: PostgreSQL and MySQL, and the event-loop delay measurement from the earlier review was not repeated.
| asset_id = _resolve_asset_id_by_name(name, session) | ||
| if (value := get_state_backend().get_value(AssetScope(asset_id=asset_id), key, session=session)) is None: | ||
| asset_id = await _resolve_asset_id_by_name(name, session) | ||
| if (value := await get_state_backend().aget(AssetScope(asset_id=asset_id), key, session=session)) is None: |
There was a problem hiding this comment.
[blocker] aget returns the stored JSON string, get_value returned the decoded value: both GET routes now answer with the wrong value.
main calls get_value(), which decodes what get() returns. aget() is the async twin of get(), not of get_value(), so the response now carries the raw string ({"value": "\"2026-04-29\""} instead of {"value": "2026-04-29"}, a dict comes back as a string), and a stored JSON null answers 200 instead of 404. The async twin already exists: aget_value. It also keeps the override point for a backend that stores values natively.
if (value := await get_state_backend().aget_value(AssetScope(asset_id=asset_id), key, session=session)) is None:The same change is needed in get_asset_state_store_by_uri (line 233). On this head, 9 of the 43 tests in test_asset_state_store.py fail (test_get_returns_value, test_get_stored_null_returns_404, test_get_asset_name_with_slashes, the four test_put_*_roundtrip / test_put_overwrites_existing, for by-name and by-uri); with aget_value in both handlers all 43 pass.
| """Return exact writer attribution for the execution identified by the token.""" | ||
| row = session.execute( | ||
| async def _fetch_ti_writer_fields(token: TIToken, session: AsyncSessionDep) -> _TIWriterFields: | ||
| """Return (dag_id, run_id, task_id, map_index) for the TI identified by the token.""" |
There was a problem hiding this comment.
[nit] The rebase brought back an older docstring.
main says "Return exact writer attribution for the execution identified by the token." The function returns eight fields (task_instance_id, region_id, region_index and try_number included), so the four-field list is no longer true. Keep the docstring of main.
| ) -> str | None: | ||
| row = await session.scalar( | ||
| select(TaskStateStoreModel).where( | ||
| select(TaskStateStoreModel.value).where( |
There was a problem hiding this comment.
[nit] Three of the four readers now select only value; the sync _get_task_state_store (line 249, not in the diff) still loads the whole row.
Either change that one too, so the sync and async task readers stay the same, or leave the task-state readers out of this PR, which is about the asset state store routes. In the three changed readers row now holds the value itself, so return await session.scalar(...) (and return session.scalar(...)) says it without the misleading name.
Convert
Asset state store — routes/asset_state_store.pyendpoint toAsyncSessionDeprelated : #67799
Was generative AI tooling used to co-author this PR?
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.