Skip to content
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

[BigQueryIO] fetch updated schema for newly created Storage API stream writers #33231

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ahmedabu98
Copy link
Contributor

@ahmedabu98 ahmedabu98 commented Nov 26, 2024

Fixes #33238

This problem happens whenever a StreamWriter is created after the table's schema is updated. The new StreamWriter ignores the previously updated schema and ends up using the base schema, dropping the new columns.
Such a case can happen when a pipeline decides to increase its parallelism (e.g. autosharding of threads or autoscaling of workers) after a schema update happens. The increased parallelism creates new stream writers that continue using the base schema, ignoring the updated schema.

This PR fixes this by fetching the stream's schema whenever we create a new append client. Existing tests are modified to cover this case, and new tests are added for schema update with dynamic destinations.

@ahmedabu98 ahmedabu98 marked this pull request as ready for review December 18, 2024 00:00
@ahmedabu98 ahmedabu98 changed the title Storage API Schema Update with dynamic destinations [BigQueryIO] fetch updated schema for newly created Storage API stream writers Dec 18, 2024
@ahmedabu98
Copy link
Contributor Author

R: @Abacn
R: @reuvenlax

Copy link
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

@ahmedabu98 ahmedabu98 added this to the 2.62.0 Release milestone Dec 18, 2024
@@ -1419,7 +1421,11 @@ public WriteStream createWriteStream(String tableUrn, WriteStream.Type type)

@Override
public @Nullable WriteStream getWriteStream(String writeStream) {
return newWriteClient.getWriteStream(writeStream);
return newWriteClient.getWriteStream(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a boolean parameter to the method, so we only return schema if requested

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI in our code base we always perform this call for the sole purpose of fetching the schema

@@ -531,6 +532,30 @@ public void process(
element.getKey().getKey(), dynamicDestinations, datasetService);
tableSchema = converter.getTableSchema();
descriptor = converter.getDescriptor(false);

if (autoUpdateSchema) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is the ideal place to put this. getAppendClientInfo is called whenever the static cache is populated, meaning that on any worker restart, range move, etc. we'll be forced to call this API again. However we have persistent state in this DoFn, so we know if it's a "new" key or not. Can we use that to gate calling this method instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should always perform this check before creating a new StreamWriter , regardless of the reason for its creation. The only exception is if we already have an updated schema stored in state (see first if block above). If I'm following correctly, this method (getAppendClientInfo) will always create a new stream writer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note that the updated schema is ignored when the StreamWriter object's creation time is later than the updated schema's.
i.e. it doesn't matter when the WriteStream itself was created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Newly created Storage API write streams do not recognize the previously updated table schema
2 participants