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

bug: fix occasional ordering issue in result in unsafeOptionalDataVia #1611

Merged
merged 1 commit into from
Dec 18, 2024

Conversation

He-Pin
Copy link
Member

@He-Pin He-Pin commented Dec 17, 2024

refs: #1610

Motivation:
Fix flaky test in unsafeOptionalDataVia

Modification:

  1. rewrite with mergeSequence

@He-Pin He-Pin marked this pull request as ready for review December 17, 2024 15:19
Copy link
Contributor

@mdedetrich mdedetrich left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Member

@raboof raboof left a comment

Choose a reason for hiding this comment

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

shouldn't unsafeOptionalDataVia keep the order?

I thought the 'unsafe' aspect was the Flow parameter must be a flow that produces 1 output per input without reordering (and we can't 'safely' express that in the typesystem), but as long as that's the case (as it is here) it should keep order.

Shouldn't we change the implementation rather than the test?

@He-Pin
Copy link
Member Author

He-Pin commented Dec 17, 2024

@raboof That's what's I'm wondering, because the current design ,it can not keep order, not sure if that's how @mdedetrich expected it works.

@mdedetrich
Copy link
Contributor

Let me retract my approval, I didn't pay attention to the change.

Indeed the ordering of the elements should not change, @raboof is correct where the unsafe part pertains to the fact that you could provide a Flow that reorders/drops elements and there isn't any check for this but assuming you provide a flow that only transforms elements than ordering should be retained.

Funnily enough I haven't experienced this in production, ill have a look at it.

@He-Pin
Copy link
Member Author

He-Pin commented Dec 17, 2024

@mdedetrich Can you give some more context of the current design?

Copy link
Contributor

@mdedetrich mdedetrich left a comment

Choose a reason for hiding this comment

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

Blocking for now as the ordering is meant to be determinstic, prob the implementation needs to be fixed.

@mdedetrich
Copy link
Contributor

@mdedetrich Can you give some more context of the current design?

So the context is primarily when using kafka cursors with FlowWithContext/SourceWithContext. This feature lets you provide a flow that only transforms the data portion of the stream while leaving the context part untouched (which is critical when dealing with Kafka and committing cursors).

@He-Pin
Copy link
Member Author

He-Pin commented Dec 17, 2024

Let me update it, I can workout a solution.

@He-Pin He-Pin marked this pull request as draft December 17, 2024 16:05
@He-Pin He-Pin marked this pull request as ready for review December 17, 2024 18:15
@He-Pin He-Pin requested review from mdedetrich and raboof December 17, 2024 18:15
@He-Pin
Copy link
Member Author

He-Pin commented Dec 17, 2024

@raboof @mdedetrich @pjfanning I think it should be OK now, it now track the origin order with an index and then merge back with the same index.

broadcast.out(1) ~> filterUnavailable ~> merge.in(1)
//format: off
s ~> sequence ~> partition.in
partition.out(0).asInstanceOf[Outlet[(Option[FOut], IndexedCtx)]] ~> mergeSequence.in(0)
Copy link
Member Author

Choose a reason for hiding this comment

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

cast here to avoid allocation, it will always be None because of partition

@pjfanning pjfanning changed the title chore: Fix flaky test in unsafeOptionalDataVia bug: fix occasional ordering issue in result in unsafeOptionalDataVia Dec 17, 2024
@pjfanning pjfanning added bug Something isn't working backport labels Dec 17, 2024
@pjfanning
Copy link
Contributor

Do we know if the test runs in PR CI builds? I did a quick check of the test logs and didn't find a match.

@pjfanning
Copy link
Contributor

Do we know if the test runs in PR CI builds? I did a quick check of the test logs and didn't find a match.

I found must Apply a viaFlow with optional elements using unsafeOptionalVia (52 milliseconds) so the test is running.

Copy link
Contributor

@pjfanning pjfanning left a comment

Choose a reason for hiding this comment

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

lgtm


val filterUnavailable = Flow[(Option[SOut], Ctx)].collect {
case (None, ctx) => (Option.empty[FOut], ctx)
case class IndexedCtx(idx: Long, ctx: Ctx)
Copy link
Member Author

Choose a reason for hiding this comment

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

extra allocation here

@He-Pin He-Pin merged commit 7184dad into apache:main Dec 18, 2024
8 checks passed
@He-Pin He-Pin deleted the flasky branch December 18, 2024 02:43
@He-Pin
Copy link
Member Author

He-Pin commented Dec 18, 2024

Thanks for the review

@He-Pin He-Pin added this to the 1.1.3 milestone Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants