forked from dagster-io/dagster
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[backfills] Add batch inserts for ranged materialization/observation …
…backfills (dagster-io#19862) ## Summary & Motivation Internal companion PR: dagster-io/internal#8634 See this comment for up-to-date summary: dagster-io#19862 (comment) Add batch insert support for asset materializations and observations emitted in a single step. Previously, a ranged backfill that generated N `AssetMaterialization` events would perform N DB inserts. After this PR, it generates only a few inserts (more than 1 because a few tables are hit). ## How it works - Logged dagster events take the following pathway: - `DagsterEvent.<event_type>` (e.g. `DagsterEvent.asset_materialization`) - `DagsterEvent.from_step` - `log_dagster_event` - `DagsterLogManager.log` - `DagsterLogManager._log` - `DagsterLogHandler.filter` - `DagsterLogHandler.emit` - `_EventListenerLogHandler` (in `_core/instance/__init__.py`) - `DagsterInstance.handle_new_event` - This pathway has been modified to pass batch metadata, represented in a new `DagsterEventBatchMetadata` class, along the entire path. `DagsterEventBatchMetadata` has two fields: `id` and `is_end`. - `DagsterEventBatchMetadata` must be passed in to the static method that creates the event (`DagsterEvent.<event_type>`). It is then packaged side by side with the event and passed up the call chain. `DagsterEvent` itself is not modified. - Batching management is done in `DagsterInstance.handle_new_event`, which receives optional `DagsterEventBatchMetadata`. If a call receives batch metadata, the event is buffered under the batch id. The buffer is cleared and a write is performed if (a) the buffer has hit the `EVENT_BATCH_SIZE` threshold (set at 1000, overridable via env var); or (b) `DagsterEventBatchMetadata.is_end` is set. - The write is implemented via a new method `EventLogStorage.store_event_batch`. The default implementation of this is just to loop over the events in the batch and call `store_event`, i.e. equivalent to the old behavior. In the `EventLogStorage` implementations in cloud and `dagster-postgres`, this method is overridden to perform a batch insert instead. ## How I Tested These Changes - Add new storage test that performs a single-run partition range materialization. The organization of the storage tests is unfamiliar to me so I'm not sure I put it in the appropriate place. - Add simple single run backfill test that actually executes the full backfill.
- Loading branch information
Showing
11 changed files
with
408 additions
and
104 deletions.
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
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
Oops, something went wrong.