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

Buffered writer for exactly once sink #156

Merged
merged 10 commits into from
Sep 20, 2024

Conversation

jayehwhyehentee
Copy link
Collaborator

@jayehwhyehentee jayehwhyehentee commented Sep 18, 2024

Create writer used by exactly once sink, following the two-phase commit protocol. This writer uses BQ's buffered stream for appending data to the table.

Note to reviewers: this PR is bloated by tests

/gcbrun

@jayehwhyehentee
Copy link
Collaborator Author

@clmccart kindly review this PR

try {
writeClient = BigQueryServicesFactory.instance(connectOptions).storageWrite();
return writeClient.createStreamWriter(streamName, protoSchema, enableConnectionPool);
logger.debug("Creating BigQuery StreamWriter in subtask {}", subtaskId);

Choose a reason for hiding this comment

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

i think it might be worth logging this at the info level. thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

} catch (IOException e) {
logger.error("Unable to create StreamWriter for stream {}", streamName);
throw new BigQueryConnectorException("Unable to create StreamWriter", e);
}
}

/** Creates a write stream and StreamWriter for appending to BigQuery table. */
void createWriteStreamAndStreamWriter(

Choose a reason for hiding this comment

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

is there a simple way to refactor this so that it invokes createStreamWriter + some additional logic instead of duplicating code here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, thanks

@Override
public void write(IN element, Context context) {
totalRecordsSeen++;

Choose a reason for hiding this comment

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

this might be out of scope for this PR but it might be worth trcking the element sizes here as well

Choose a reason for hiding this comment

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

ie, totalRecordsSeenSize

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@prashastia this should go into our document tracking Flink metrics

public void throttle() {
int waitSeconds = writerId % MAX_BUCKETS;
try {
// Sleep does nothing if input is 0 or less.

Choose a reason for hiding this comment

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

we should probably log here that we're throttling and for how long

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

*/
public class WriteStreamCreationThrottler implements Throttler {

public static final int MAX_BUCKETS = BigQueryExactlyOnceSink.MAX_SINK_PARALLELISM / 3;

Choose a reason for hiding this comment

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

i dont see where BigQueryExactlyOnceSink.MAX_SINK_PARALLELISM is defined. looks like it's not apart of this PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

public class WriteStreamCreationThrottlerTest {

@Test
public void testThrottle() {

Choose a reason for hiding this comment

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

can we add a few more tests here for some of the edge cases (ie, weird subtaskid values, etc)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@jayehwhyehentee jayehwhyehentee merged commit 6a40c09 into GoogleCloudDataproc:main Sep 20, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants