Hey everyone! We're using <flink-connector-kinesi...
# troubleshooting
a
Hey everyone! We're using flink-connector-kinesis to consume data from multiple AWS Kinesis Streams into our Flink application. Up until this moment we have been adding the streams to our consumer application A before there is any data on them - this is semi automated in our release process when we add a new stream. However, we're now migrating existing streams from being consumed by application A into application B, and we noticed an issue... despite configuring the
STREAM_INITIAL_POSITION
to
LATEST
we're still consuming all the events in the 7 day retention of our Kinesis streams... This means that the
STREAM_INITIAL_POSITION
config is not being respected when we add a new stream. After some tests this seems to be the case only when restoring from a snapshot. After some investigation, the culprit seems to be in
FlinkKinesisConsumer#run
in the code surrounded by
if (sequenceNumsToRestore != null)
which currently works as follows:
Copy code
IF there is restore state for ANY shard
   IF the current shard has restore state
      use offset from restore state
   ELSE
      start from earliest
ELSE 
   start from initial position from configs
where we think the correct behaviour would be
Copy code
IF there is restore state for ANY shard of this particular stream
   IF the current shard has restore state
      use offset from restore state
   ELSE
      start from earliest
ELSE 
   start from initial position from configs
so that when a stream is seen for the firs time, the initial position from the config is used instead of defaulting to earliest. Would love to discuss this further if needed. Let me know if there is a better way to formulate this issue and ask for a fix. Thank you!
h
Hi Antonio, I can confirm that this is a problem with the FlinkKinesisConsumer at the moment.
gratitude thank you 1
We could modify the current state of the Kinesis Consumer to also store the currently configured streams
a
Hey @Hong Teoh! Thanks for confirming πŸ˜„ Instead of storing all the configured streams, I think it's safer to use the set of streams present in the existing
sequenceNumsToRestore
. This way we ensure the two state variables are always in sync and we only need one state variable. The "downside" would be having to iterate over the existing keys to get the stream names, but it looks like the code already iterates over all entries both when restoring from state
#initializeState
and when storing the state
#snapshotState
) so I think it would be fine.
I'm also a bit concerned about how adding an extra check to see if the stream is new or not will impact existing users of the library which may be relying on this behaviour without noticing it is not intentional... would this need to be a new major version... ?
h
I've created a JIRA here
a
Thank you!
h
Instead of storing all the configured streams, I think it's safer to use the set of streams present in the existing
sequenceNumsToRestore
. This way we ensure the two state variables are always in sync and we only need one state variable.
Yep, I've made that suggestion in the JIRA - I've checked we already have sufficient information in
StreamShardMetadata
to figure out what the stream names of previously seen streams are πŸ™‚
πŸ‘ 1
> I'm also a bit concerned about how adding an extra check to see if the stream is new or not will impact existing users of the library which may be relying on this behaviour without noticing it is not intentional... would this need to be a new major version... ? Hmm thats a good consideration, but users can always fallback to existing behaviour by setting StreamInitialPosition to "TRIM_HORIZON".
It should then only affect the new stream. However, technically this is a change in default behaviours...
a
Indeed, just don't want it to surprise anyone by changing existing behaviour on a minor/fix version.
Yeah, it is limited to this specific set of conditions: β€’ using snapshots to manage state β€’ previously consuming data from other Kinesis streams β€’ adding a new stream with existing data β€’ using something other than TRIM_HORIZON for initial position
πŸ‘ 3
h
Yeah I think a new major version would be more aligned with our versioning strategy. (cc: @Danny Cranmer @Aleksandr Pilipenko WDYT?)
Thanks for reporting this @Antonio Silva!
a
No problem! Do you know usually how long it takes for these issues to be picked up, fixed and released ?
If it helps, I can fork the repo and get an MR up pretty soon but not sure about how long it takes to run/add tests and the overall review and release process... this would be my first Flink contribution πŸ˜…
h
No problem! Do you know usually how long it takes for these issues to be picked up, fixed and released ?
Hmm, it's flexible, and we can push a release if we need to. There are some release candidate preparation / voting that needs to be done. Probably O(months)?
If it helps, I can fork the repo and get an MR up pretty soon but not sure about how long it takes to run/add tests and the overall review and release process... this would be my first Flink contribution
Sure thing! I can help with the review if you want. Just let me know
a
If this behaviour can be made configurable, with current one being default and state remains compatible - I don't see the need in major version change
πŸ‘ 1
h
True, we could hide it behind a config with default to existing behavior, then swap the default in the new major version
βž• 1
βœ… 1
a
Probably O(months)?
In that case we need some workaround for now - we're leaning towards having an extra property in our app to indicate if it is a new stream being onboarded, then we check if the stream the event is coming from is in the list and in that case ignore all events until a specific timestamp/offset. When we have a working solution I can update this thread or the jira ticket to help others who may face the same issue in the meantime.
I can help with the review if you want
Do I need a Jira account to assign the ticket or I can i leave it as unassigned as long as I reference it in the PR title ?
h
Yes, a hack you can do for now is to customize the DeserializationSchema + return null when you want to skip the record. It has access to both time and source stream name
βœ… 1
a
Yeah we already have our own deserialization schema doing something similar for records that we want filtered out!
πŸ‘ 1
h
Do I need a Jira account to assign the ticket or I can i leave it as unassigned as long as I reference it in the PR title ?
Yeah, you would need to request a ASF Jira account, then I can assign the issue to you, but you should be able to write a PR anyways. Do let me know when you start work on it though, so I can assign the JIRA to prevent duplicate work
I can also take a look
Sorry - another thought here - a better workaround here might be to just use another instance of the FlinkKinesisConsumer for the new streams. That would mitigate your problem and would be more in-line with our policy for new KinesisSource (We are deprecating multi-stream support). (cc: @Aleksandr Pilipenko)
a
we thought about it but were concerned about the performance hit of having to "merge" the multiple data streams after consuming
but if you're deprecating multi-stream support I'm assuming there is a good way to "merge" the multiple data streams into a single stream afterwards that we're not aware of πŸ€”
h
we thought about it but were concerned about the performance hit of having to "merge" the multiple data streams after consuming
I think the logic here is that we do a
keyBy
/
HASH
after the source anyways to redistribute the records across multiple downstream subtasks. So single consumer (multiple streams) vs multiple consumers would not have much difference
Did you manage to show a the performance impact between the two configurations?
a
I think the logic here is that we do a
keyBy
/
HASH
after the source anyways to redistribute the records across multiple downstream subtasks.
Not sure where that is being done, we are using an explicit
rebalance
to redistribute the records otherwise they were only handled by the consuming subtasks
Maybe its an opt-in feature and we're missing the config?
h
either REBALANCE / HASH will mean the events get redistributed, so it doesn't matter whether a single operator reads multiple streams OR if multiple operations read single stream each
Maybe its an opt-in feature and we're missing the config?
I'm not sure what feature you're talking about!
a
Oh when you said
I think the logic here is that we do a
keyBy
/
HASH
after the source anyways to redistribute the records across multiple downstream subtasks
I thought you meant the flink kinesis connector was already doing this πŸ™‚
A bug/feature request related to this bug we're tackling is that once that the snapshot is aware of the offset of a stream, there is no way to make it forget it so that we can start from LATEST or go back to EARLIEST (for some specific stream(s) only, if we wanted to do this for all I'm sure we could find a way to rename the task or something that would reset the state)
h
I guess for some specific use cases, additional operator will include additional subtasks and associated overhead (additional network buffer) However, we could probably manage the parallelism of each source stream individually
a
I guess if you're deprecating multi stream support the intial position config may already be per stream, so we can probably leverage that or even add a flag to ignore the state for a particular stream.
h
A bug/feature request related to this bug we're tackling is that once that the snapshot is aware of the offset of a stream, there is no way to make it forget it so that we can start from LATEST or go back to EARLIEST (for some specific stream(s) only, if we wanted to do this for all I'm sure we could find a way to rename the task or something that would reset the state)
Yes, thats why we are considering deprecating the multi-stream use case. IMO it introduces too much complexity on the source for too little benefit
I guess if you're deprecating multi stream support the intial position config may already be per stream, so we can probably leverage that or even add a flag to ignore the state for a particular stream.
We are doing this as part of migration to the "new" Source V2 API (FLIP-27) - so it would be a hard cut - there will be new configs etc.!
❀️ 1
πŸ‘οΈ 1
a
I'm trying to run the tests locally on
main
without my changes and I still see a lot of tests fail. Are the tests also ran in any pipeline when I open the PR, or do I need to ensure they are all passing locally before opening the PR ?
a
Tests are executed when you open PR, yes. But it is better to ensure that tests are also passing locally to speed up feedback loop from build process.
gratitude thank you 1
a
β€’ java.lang.RuntimeException: PowerMock internal error: Should never throw exception at this level β€’ java.lang.IllegalStateException: Could not find a valid Docker environment. Please see logs and check configuration
I guess my local setup is not ready for these tests πŸ˜„ Will try the PR route first, and if a lot are failing I'll try to work on getting these to run locally. I'll be changing machines soon so I don't want to spent too much time setting up Docker and alike right now...
a
Tests also should be executed when you push commit to your local fork, so you might verify this before opening PR.
a
I'm not very used to the github UI but I can't find any tests running on https://github.com/apache/flink-connector-aws/pull/140 or on my fork https://github.com/antssilva96/flink-connector-aws/tree/FLINK-35299-respect-stream-initial-position-for-new-streams Can you point me in the right direction ?
I'm assuming on the PR it might not run if its marked as draft ?
h
It's fine, I need to approve it to start the approval workflows
I've just started it
gratitude thank you 1
a
Thanks Hong! I'll be back later to check on the status and fix/add tests for this.
managed to run FlinkKinesisConsumerTest locally βœ… Once I add new tests I'll let you guys know
πŸ‘ 1
Hey @Hong Teoh! Sorry for the long time it took me to get those tests setup
I've updated the PR with the tests, I was wondering if you could trigger the pipeline 🀞
Let me know if I'm missing something before this get reviewed or if its good to go!
I've also created a new jira user
antssilva96
so the ticket can be assigned to someone and prevent duplicate work, but I guess I don't have permission to change the assignee.
d
Assigned to you @Antonio Silva πŸ˜‰
a
Thanks @Danny Cranmer! Looking forward for reviews on this PR πŸ˜„
@Hong Teoh (or anyone else with permissions) could you re-trigger the pipeline in the PR ? It failed for codestyle but has been fixed
Any updates on the pipeline/reviews for this change?
Also, I saw that Flink 1.19 is the last on this major version, meaning the next will be 2.0. I was wondering if this could be included or if the new connectors you guys mentioned in this thread will be used instead, making this PR obsolete for > 2.0.
Any news on this?