-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
agent: create linked materialization publications
Introduces basic support for linked materializations into the agent. As captures and materializations are published, the agent will create additional publications as needed in order to keep materializations in sync with their `sourceCapture`s. We always use additional publications when modifying the materializations so that any automated changes are directly auditable using our existing mechanisms for that. The basic explanation for how this works is: We first identify any captures that may have been modified by the current publication. We use those capture names to query for materializations having any of them as a `sourceCapture`. The agent will then create an additional publication for each materialization, which updates the bindings of the materialization to match those of the capture. The precise meaning of "match" is: - For each enabled binding in the capture, ensure that there is a corresponding enabled binding in the materialization having the same collection name - For each binding in the materialization, if there is no corresponding enabled binding found in the capture, disable it. Materialization bindings are only ever disabled, never removed, to ensure that this process is always reversible. There are no requirements that the user publishing the capture, or the capture itself, have any capabilities to any of the linked materializations. There _is_ a requirement that the materialization spec have 'read' capability to the _prefix_ of the capture. In other words, a materialization with `sourceCapture: acmeCo/foo/source-s3` must have read capability to all of `acmeCo/foo/`. This may turn out to be overly broad, but it seems easier to lift restrictions than to enforce new ones. The spec expansion logic was itself expanded to pull in any captures that are named by the `sourceCapture` of any materializations in the draft. This will be used in a subsequent commit to validate that the `sourceCapture` exists and is a capture.
- Loading branch information
Showing
18 changed files
with
1,154 additions
and
122 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use crate::{Id, TextJson}; | ||
use serde_json::value::RawValue; | ||
|
||
pub struct Row { | ||
pub materialization_name: String, | ||
pub materialization_spec: TextJson<Box<RawValue>>, | ||
pub last_pub_id: Id, | ||
} | ||
|
||
pub async fn get_linked_materializations( | ||
txn: &mut sqlx::Transaction<'_, sqlx::Postgres>, | ||
capture_names: Vec<String>, | ||
) -> sqlx::Result<Vec<Row>> { | ||
sqlx::query_as!( | ||
Row, | ||
r#" | ||
select | ||
catalog_name as materialization_name, | ||
spec as "materialization_spec!: TextJson<Box<RawValue>>", | ||
last_pub_id as "last_pub_id!: Id" | ||
from live_specs | ||
where spec_type = 'materialization' and spec->>'sourceCapture' = ANY ($1::catalog_name[]) | ||
"#, | ||
capture_names as Vec<String> | ||
) | ||
.fetch_all(txn) | ||
.await | ||
} |
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.