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

Allow clients to drop channel on close or blindly #657

Merged
merged 3 commits into from
Feb 21, 2024

Conversation

sfc-gh-psaha
Copy link
Contributor

This change exposes a new API to drop channels. It can be done either on channel close (verifies that no other client has raced to reopen the channel) or blindly with just a table name.
Note that dropping a channel blindly discards any pending data and will invalidate any already opened channel - so use with caution.

@sfc-gh-psaha sfc-gh-psaha force-pushed the psaha-SNOW-965885-drop-channel-client branch from 53df57f to 06dc34d Compare December 13, 2023 22:57
@sfc-gh-psaha sfc-gh-psaha marked this pull request as ready for review December 14, 2023 22:04
@sfc-gh-psaha sfc-gh-psaha requested review from sfc-gh-tzhang and a team as code owners December 14, 2023 22:04
@sfc-gh-psaha sfc-gh-psaha force-pushed the psaha-SNOW-965885-drop-channel-client branch 2 times, most recently from 3748804 to 7972b1b Compare December 14, 2023 22:06
@sfc-gh-psaha
Copy link
Contributor Author

Note that tests will fail until the API is enabled on the server side.

@sfc-gh-xhuang
Copy link
Contributor

@sfc-gh-psaha do we want to allow this only on primary or both primary and secondary?
I think primary only for replication is standard as we disallow writes and deletes on secondary
https://docs.snowflake.com/en/user-guide/account-replication-considerations#replication-and-snowpipe-streaming

@sfc-gh-psaha
Copy link
Contributor Author

@sfc-gh-psaha do we want to allow this only on primary or both primary and secondary? I think primary only for replication is standard as we disallow writes and deletes on secondary https://docs.snowflake.com/en/user-guide/account-replication-considerations#replication-and-snowpipe-streaming

Currently, we allow it only on the primary - same as open channel. This check is performed server-side.

Copy link
Contributor

@sfc-gh-tzhang sfc-gh-tzhang left a comment

Choose a reason for hiding this comment

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

Thanks for the change! My biggest discussion point is how to expose the API to the customer. To me, it seems more intuitive to support a new channel.close(boolean ifDrop) function instead of specifying it as part of open channel, WDYT? I'm not sure if we have ask this to the customers that requested this feature

Comment on lines 46 to 48
// If true, the channel will be dropped when it is closed after any pending data is fully
// committed.
private final boolean dropOnClose;
Copy link
Contributor

Choose a reason for hiding this comment

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

Another option is to support another .close() which takes this as an input, which one do you think it's better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The original reason I did it this way was because I thought Channel extends AutoCloseable and therefore, we cannot change the signature of close but I was mistaken - only the client extends it. Since users of this class has to call close explicitly anyways, I think your suggestions is the less-intrusive approach. There is still a corner case of someone using try-with using the Client and closing channels that way implicitly without any option to drop them but I think that's likely a rare corner case. We can always go and implement my idea if that is requested.

getName());

} catch (IOException | IngestResponseException e) {
throw new SFException(e, ErrorCode.OPEN_CHANNEL_FAILURE, e.getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

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

DROP_CHANNEL_FAILURE

@@ -291,6 +297,19 @@ public CompletableFuture<Void> close() {
.map(SnowflakeStreamingIngestChannelInternal::getFullyQualifiedName)
.collect(Collectors.toList()));
}
if (this.dropOnClose) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we drop the channel even if it hits the exception above?

Copy link
Contributor

Choose a reason for hiding this comment

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

In theory, I don't see an issue of dropping a closed channel, should this be removed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also what about when a channel becomes invalid, currently we can't close an invalid channel, but we should allow dropping them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think dropping after failing to commit would be a surprising behavior. Typically, when close fails, the caller is supposed to handle it e.g. by retrying etc. Dropping in this specific case would lose uncommitted data.

Copy link
Contributor

@sfc-gh-tzhang sfc-gh-tzhang Jan 4, 2024

Choose a reason for hiding this comment

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

I think it depends, I can imagine a use case where customer always open a new channel with an unique identifier every time the old channel gets invalidated. I guess we can come back to this if needed in the future, basically right now we won't drop any closed and invalid channels, better to add it somewhere in the comment.

@sfc-gh-psaha sfc-gh-psaha force-pushed the psaha-SNOW-965885-drop-channel-client branch from 809e6c1 to 609795d Compare January 3, 2024 20:37
Copy link
Contributor

@sfc-gh-tzhang sfc-gh-tzhang left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Copy link
Contributor

@sfc-gh-xhuang sfc-gh-xhuang left a comment

Choose a reason for hiding this comment

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

let me know if this is ready

@sfc-gh-psaha sfc-gh-psaha force-pushed the psaha-SNOW-965885-drop-channel-client branch from dbdbfda to d3b6ae1 Compare February 21, 2024 22:12
@sfc-gh-psaha
Copy link
Contributor Author

@sfc-gh-tzhang Please take another look.

Copy link
Contributor

@sfc-gh-tzhang sfc-gh-tzhang left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@sfc-gh-tzhang
Copy link
Contributor

The change itself looks good to me, it's just the impact of accidentally dropping the wrong channel worries me as the offset token info will be lost. We need to be careful about documenting this, maybe this is something customer wants to reach out to support before doing this. cc: @sfc-gh-xhuang

@sfc-gh-psaha sfc-gh-psaha merged commit ec5cf9b into master Feb 21, 2024
12 checks passed
@sfc-gh-psaha sfc-gh-psaha deleted the psaha-SNOW-965885-drop-channel-client branch February 21, 2024 23:42
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.

4 participants