-
Notifications
You must be signed in to change notification settings - Fork 57
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
Conversation
53df57f
to
06dc34d
Compare
3748804
to
7972b1b
Compare
Note that tests will fail until the API is enabled on the server side. |
src/main/java/net/snowflake/ingest/streaming/SnowflakeStreamingIngestClient.java
Show resolved
Hide resolved
@sfc-gh-psaha do we want to allow this only on primary or both primary and secondary? |
Currently, we allow it only on the primary - same as open channel. This check is performed server-side. |
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.
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
src/main/java/net/snowflake/ingest/streaming/DropChannelRequest.java
Outdated
Show resolved
Hide resolved
// If true, the channel will be dropped when it is closed after any pending data is fully | ||
// committed. | ||
private final boolean dropOnClose; |
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.
Another option is to support another .close() which takes this as an input, which one do you think it's better?
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.
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.
src/main/java/net/snowflake/ingest/streaming/SnowflakeStreamingIngestClient.java
Show resolved
Hide resolved
src/main/java/net/snowflake/ingest/streaming/internal/DropChannelResponse.java
Show resolved
Hide resolved
...in/java/net/snowflake/ingest/streaming/internal/SnowflakeStreamingIngestChannelInternal.java
Outdated
Show resolved
Hide resolved
getName()); | ||
|
||
} catch (IOException | IngestResponseException e) { | ||
throw new SFException(e, ErrorCode.OPEN_CHANNEL_FAILURE, e.getMessage()); |
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.
DROP_CHANNEL_FAILURE
@@ -291,6 +297,19 @@ public CompletableFuture<Void> close() { | |||
.map(SnowflakeStreamingIngestChannelInternal::getFullyQualifiedName) | |||
.collect(Collectors.toList())); | |||
} | |||
if (this.dropOnClose) { |
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.
should we drop the channel even if it hits the exception above?
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.
In theory, I don't see an issue of dropping a closed channel, should this be removed?
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.
Also what about when a channel becomes invalid, currently we can't close an invalid channel, but we should allow dropping them?
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.
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.
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.
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.
src/test/java/net/snowflake/ingest/streaming/internal/SnowflakeStreamingIngestChannelTest.java
Show resolved
Hide resolved
809e6c1
to
609795d
Compare
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.
LGTM, thanks!
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.
let me know if this is ready
dbdbfda
to
d3b6ae1
Compare
@sfc-gh-tzhang Please take another look. |
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.
LGTM, thanks!
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 |
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.