-
Notifications
You must be signed in to change notification settings - Fork 92
Sink from-proto through a disk spool, and load without constraints #869
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
Changes from all commits
28978d1
8ec16c6
17362ae
daa7737
8d5c16b
2e999da
2d6fa36
d25be1f
6309fe6
1ad8981
5f0f029
a7f9d08
0ef8061
a3b0aaa
7636edb
c15e379
d39ca7b
2813a16
6b0a6dd
8d45b63
fe6aa2a
1fb4eaa
ded38bd
b81894f
d339a97
e347d58
9adefd3
1ded630
5c22716
0b75225
529d13f
6d11882
6474c8e
fa3c73b
277e9c0
5fade48
0bb497f
ae9036b
1d801df
e6f4060
002aa52
a6bf758
c7b45d2
371fde7
7dbf1f5
6b78c07
d984d28
4f50d3e
fb92889
5478b13
39ce2df
4f0a1c3
7ac5bb0
d1de5aa
f9278ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,39 +17,110 @@ var sinkPostgresCmd = &cobra.Command{ | |
| } | ||
|
|
||
| var sinkPostgresSetupCmd = &cobra.Command{ | ||
| Use: "setup <manifest>", | ||
| Use: "setup <manifest> [<module>]", | ||
| Short: "Setup the required infrastructure to deploy a Substreams SQL deployable unit", | ||
| Long: cli.Dedent(` | ||
| Setup the database for the Substreams SQL sink, auto-detecting the mode from the | ||
| output module type, exactly like the run action: | ||
|
|
||
| - DatabaseChanges output: creates the system tables (cursors, history) and applies | ||
| the 'schema.sql' bundled in the manifest sink config. | ||
| - Any other output type (from-proto): resolves the schema from the module's output | ||
| proto and creates the database schema and tables, then exits. This step is | ||
| idempotent and can be run again safely. | ||
| - Database Changes Mode ('DatabaseChanges' output): creates the system tables | ||
| (cursors, history) and applies the 'schema.sql' bundled in the manifest sink | ||
| config. | ||
| - Relational Mappings Mode (any other output type): resolves the schema from the | ||
| module's output proto and creates the database schema and tables, then exits. | ||
| This step is idempotent and can be run again safely. | ||
| `), | ||
| Args: cobra.ExactArgs(1), | ||
| Args: cobra.RangeArgs(1, 2), | ||
| RunE: newSinkSetupE(sinkPostgresDriver), | ||
| } | ||
|
|
||
| var sinkPostgresConstraintsCmd = &cobra.Command{ | ||
| Use: "constraints", | ||
| Short: "Create or drop the schema's constraints on an already loaded database", | ||
| } | ||
|
|
||
| var sinkPostgresConstraintsApplyCmd = &cobra.Command{ | ||
| Use: "apply <manifest> [<module>]", | ||
| Short: "Create the schema's constraints on an already loaded database", | ||
| Long: cli.Dedent(` | ||
| Create the primary keys, unique and foreign key constraints of a Relational | ||
| Mappings schema on a database the sink has already loaded, skipping the ones | ||
| already in place. | ||
|
|
||
| The sink loads without them on purpose: measured through binary COPY, loading with | ||
| foreign keys in place runs 27x slower than loading without, where building the very | ||
| same constraints afterwards costs 3.3x. Creating them is a stop-the-world | ||
| operation, though — every index is built and every foreign key validated, with the | ||
| tables locked while it runs — so on a large database this belongs in a maintenance | ||
| window, which is what --apply-constraints=manual leaves it to this command for. | ||
|
|
||
| The index on _block_number_ is not created here. The sink creates that one when it | ||
| starts, concurrently: this command is yours to schedule, and the reorg path cannot | ||
| wait for a maintenance window. | ||
|
|
||
| Running it again is safe: constraints already in place are left alone. | ||
|
|
||
| The module is inferred from the package when it is left out. A package with more | ||
| than one candidate has to be told which, or the schema this derives will not be the | ||
| one the run created. | ||
| `), | ||
| Args: cobra.RangeArgs(1, 2), | ||
| RunE: newSinkConstraintsE(sinkPostgresDriver, constraintsApply), | ||
| } | ||
|
|
||
| var sinkPostgresConstraintsDropCmd = &cobra.Command{ | ||
| Use: "drop <manifest> [<module>]", | ||
| Short: "Drop the schema's constraints", | ||
| Long: cli.Dedent(` | ||
| Drop the primary keys, unique and foreign key constraints of a Relational Mappings | ||
| schema, leaving anything the sink did not create alone — the index on _block_number_ | ||
| included, that one being the sink's own and recreated when it next starts. | ||
|
|
||
| This is the escape hatch after --apply-constraints=always, and what makes a | ||
| backfill that has to be resumed fast again without setting the schema up afresh: | ||
| loading with foreign keys in place measured 27x slower than loading without them. | ||
|
|
||
| Running it again is safe: anything already absent is skipped. | ||
| `), | ||
| Args: cobra.RangeArgs(1, 2), | ||
| RunE: newSinkConstraintsE(sinkPostgresDriver, constraintsDrop), | ||
| } | ||
|
|
||
| func init() { | ||
| persistent := sinkPostgresCmd.PersistentFlags() | ||
| addDSNFlag(persistent) | ||
| addOperatorFlags(persistent) | ||
|
|
||
| addSinkRunFlags(sinkPostgresCmd.Flags(), sinkPostgresDriver) | ||
| setModeGroupedUsage(sinkPostgresCmd) | ||
|
|
||
| setupFlags := sinkPostgresSetupCmd.Flags() | ||
| addCursorTableFlags(setupFlags) | ||
| addOnModuleHashMismatchFlag(setupFlags) | ||
| setupFlags.Bool("postgraphile", false, "[DatabaseChanges mode] Will append the necessary 'comments' on cursors table to fully support postgraphile") | ||
| setupFlags.Bool("system-tables-only", false, "[DatabaseChanges mode] will only create/update the systems tables (cursors, substreams_history) and ignore the schema from the manifest") | ||
| setupFlags.Bool("ignore-duplicate-table-errors", false, "[DatabaseChanges mode][Dev] Use this if you want to ignore duplicate table errors, take caution that this means the 'schema.sql' file will not have run fully!") | ||
| setupFlags.Bool("postgraphile", false, "Will append the necessary 'comments' on cursors table to fully support postgraphile") | ||
| setupFlags.Bool("system-tables-only", false, "will only create/update the systems tables (cursors, substreams_history) and ignore the schema from the manifest") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why we lost |
||
| setupFlags.Bool("ignore-duplicate-table-errors", false, "[Dev] Use this if you want to ignore duplicate table errors, take caution that this means the 'schema.sql' file will not have run fully!") | ||
| addBytesEncodingFlag(setupFlags) | ||
| addFromProtoModeRunFlags(setupFlags, sinkPostgresDriver) | ||
| addFromProtoSchemaFlags(setupFlags) | ||
| addConstraintTimingFlag(setupFlags) | ||
|
|
||
| applyFlags := sinkPostgresConstraintsApplyCmd.Flags() | ||
| addBytesEncodingFlag(applyFlags) | ||
| addFromProtoSchemaFlags(applyFlags) | ||
| addConstraintPassFlags(applyFlags) | ||
|
|
||
| // Drop always removes every constraint managed by the sink. The disable-* and | ||
| // --no-constraints flags describe what should be created, so exposing them here would | ||
| // suggest that drop honors a policy it cannot apply. | ||
| dropFlags := sinkPostgresConstraintsDropCmd.Flags() | ||
| addBytesEncodingFlag(dropFlags) | ||
| dropFlags.String("proto-file-override", "", "Override protobuf file to use instead of extracting from substreams package") | ||
| addConstraintPassFlags(dropFlags) | ||
| sinkPostgresConstraintsCmd.AddCommand(sinkPostgresConstraintsApplyCmd) | ||
| sinkPostgresConstraintsCmd.AddCommand(sinkPostgresConstraintsDropCmd) | ||
|
|
||
| sinkPostgresCmd.AddCommand(sinkPostgresSetupCmd) | ||
| sinkPostgresCmd.AddCommand(sinkPostgresConstraintsCmd) | ||
| sinkPostgresCmd.AddCommand(newSinkToolsCmd(sinkPostgresDriver)) | ||
|
|
||
| SinkCmd.AddCommand(sinkPostgresCmd) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,7 +104,7 @@ func sinkPostgresGenerateCSVE(cmd *cobra.Command, args []string) error { | |
| supportedOutputTypes, | ||
| manifestPath, | ||
| outputModule, | ||
| "sink_database_changes", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah! |
||
| sinkUserAgent("sink_database_changes", sinkPostgresDriver), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We should do the same + show full name
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also embedded CLI version in the user agent too |
||
| zlog, | ||
| tracer, | ||
| ) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless, still not running ...