Repository navigation
[SpannerIO] Add batching, retry and host options to the Spanner write SchemaTransform - #41988
Open
jonathansudhakar1 wants to merge 1 commit into
Open
jonathansudhakar1 wants to merge 1 commit into
jonathansudhakar1 wants to merge 1 commit into
Conversation
… SchemaTransform The legacy Python Spanner write transforms (SpannerTransformRegistrar's WriteBuilder) let users tune batching, commit retries and the Spanner host, but the spanner_write:v1 SchemaTransform (YAML WriteToSpanner) exposes none of them. Users moving to the SchemaTransform can't, for example, turn off batching for low-latency streaming writes or write to the Spanner emulator. Add optional max_batch_size_bytes, max_number_mutations, max_number_rows, grouping_factor, commit_deadline_seconds, max_cumulative_backoff_seconds, host and emulator_host fields, passed to the matching SpannerIO.Write methods, and validate them when the transform is built. Map them in standard_io.yaml for YAML WriteToSpanner. Also fix SpannerIO.Write#withMaxNumRows's Javadoc, which gave the default as 1000 instead of 500.
Contributor
|
Assigning reviewers: R: @chamikaramj added as fallback since no labels match configuration Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #22480.
The write-side follow-up to #41769 (merged), as discussed there: @stankiewicz suggested exposing the legacy Python wrappers' knobs on the SchemaTransforms, so the legacy wrappers could later be removed or delegate to the SchemaTransforms. #41953 does the read side.
The legacy Python Spanner writes (
SpannerInsert,SpannerInsertOrUpdate, … throughSpannerTransformRegistrar.WriteBuilder) let users tune batching, commit retries and the host. The Spanner write SchemaTransform (spanner_write:v1, YAMLWriteToSpanner) has none of these, so users moving to it can't, for example, turn off batching for low-latency streaming writes or point it at the Spanner emulator.Changes
SpannerWriteSchemaTransformProvidergets eight optional fields, each passed to the matchingSpannerIO.Writemethod:SpannerIO.Writemax_batch_size_byteswithBatchSizeBytesmax_number_mutationswithMaxNumMutationsmax_number_rowswithMaxNumRowsgrouping_factorwithGroupingFactorcommit_deadline_secondswithCommitDeadlinecommit_deadline(seconds)max_cumulative_backoff_secondswithMaxCumulativeBackoffmax_cumulative_backoff(seconds)hostwithHostemulator_hostwithEmulatorHostvalidate(), which the transform already calls when it's built: the three batch limits can't be negative (0 is allowed, and turns off batching as in SpannerIO),grouping_factormust be between 1 andInteger.MAX_VALUE, and the two durations must be positive. A zeromax_cumulative_backoffwould otherwise only fail on the workers, inFluentBackoff.SpannerIO.Writeas before (the defaults test now checks this).standard_io.yamlmaps the eight fields for YAMLWriteToSpanner.SpannerIO.Write#withMaxNumRows's Javadoc said the default is 1000, butDEFAULT_MAX_NUM_ROWSis 500 (the class Javadoc already says 500). Fixed, since the new field description gives the default.The write operation (insert, update, replace, delete instead of the hardcoded insert-or-update) is left for a separate PR. It needs a decision on how
error_handlingreports failed deletes: today the failed row is rebuilt withMutation#asMap(), which throws for DELETE mutations.Testing
All with JDK 21. Checker Framework was on, as in CI.
./gradlew :sdks:java:io:google-cloud-platform:spotlessApply, then:compileJava :compileTestJava :checkstyleMain :checkstyleTest :javadocon the same module: passed (final run:spotlessCheckinstead ofspotlessApply)../gradlew :sdks:java:io:google-cloud-platform:test --rerun --tests '…SpannerSchemaTransformProviderTest' --tests '…SpannerIOWriteTest' --tests '…SpannerTransformRegistrarTest': 16/16, 49/49 and 22/22 passed.SpannerSchemaTransformProviderTest: every field reaches the builtSpannerIO.Write; every validation error (and thatfrom()validates); and a pipeline test againstFakeServiceFactorywithmax_number_rows: 1andemit_write_results, which checks that each of three rows is committed in its own call and gets its ownwrite_resultsrow.testWriteDefaultsLeaveSpannerIOWriteUnchangednow also compares the batching, retry and host settings withSpannerIO.write()'s defaults, andtestWriteFindTransformAndMakeItWorklists the new fields.max_number_rowsandemulator_hostnot applied and thegrouping_factorlower bound changed to 0, all 3 new tests failed. The pipeline test feeds the three rows to the write in one bundle (one input element expanded into three rows), because with separate bundles it passed even with batching on.Create→WriteToSpannerpipeline through a locally built:sdks:java:io:google-cloud-platform:expansion-service:shadowJar:spanner_write:v1config schema lists the eight fields (nullableINT64or string).emit_write_results) expands.grouping_factor: 0andmax_cumulative_backoff_seconds: 0fail at expansion with the new messages.pytest apache_beam/yaml/yaml_provider_unit_test.py apache_beam/yaml/yaml_io_test.py: 49 passed, 23 skipped.pre-commit run --fileson the changed files passed (no hooks apply to them).SpannerWriteITand the YAML Spanner extended tests, which need GCP or the Docker emulator.Open questions
_secondssuffix tocommit_deadlineandmax_cumulative_backoff, to matchmax_commit_delay_millisin the same config and make the unit clear in YAML. Happy to switch to the exact legacy names if you'd rather the legacy wrapper pass its arguments straight through.