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

fix: unexpected events when controlling replication with consumer filter #1133

Merged
merged 2 commits into from
Mar 4, 2024

Conversation

patriknw
Copy link
Member

@patriknw patriknw commented Feb 28, 2024

  • filters are not used in replay requests, because the change of consumer
    filter is typically what triggers a replay request (missing preceding events)
  • but that means that a replica may receive unexpected events, so
    apply the filters after the sequence number that triggered the replay

entityRefC.ask(TestEntity.UpdateItem("C", 3, _)).futureValue

(1 to 20).foreach { n =>
entityRefB.ask(TestEntity.Get).futureValue shouldBe TestEntity.State(Map("A" -> 1, "B" -> 2), Set(DCA.id))
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the unexpected failure. The additional event is received by B from C.

  • B receives event from C because that event was originally scoped for B
    • Rejecting unknown sequence number [4] for pid [items|two|DCC] (might be accepted later)
    • triggers a replay request
  • C will replay all events, including the last scope change, and thereby B will receive all events

Have to think about a solution, but one way might be to have an upper sequence number on the replay requests, at least when filters are defined

Copy link
Member Author

Choose a reason for hiding this comment

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

another observation is that it seems to be triggered by a backtracking event, because there is a delay before this happens and I have confirmed that this delay lines up with the backtracking.behind-current-time

* filters are not used in replay requests, because the change of consumer
  filter is typically what triggers a replay request (missing preceding events)
* but that means that a replica may receive unexpected events, so
  apply the filters after the sequence number that triggered the replay
@patriknw patriknw changed the title wip: testing unexpected event fix: unexpected events when controlling replication with consumer filter Feb 29, 2024
@@ -75,7 +75,14 @@ message FilterReq {

// Replay events for given entities.
message ReplayReq {
repeated PersistenceIdSeqNr persistence_id_offset = 1;
repeated ReplayPersistenceId replay_persistence_ids = 1;
Copy link
Member Author

Choose a reason for hiding this comment

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

this should be a wire compatible change, but I will verify with a sample to be sure

Copy link
Member

Choose a reason for hiding this comment

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

Are you sure about that, the original was a string + uint64, now it is a message (length delimited) + uint64 so old version messages can't be parsed out of data serialized from this.

Copy link
Member Author

Choose a reason for hiding this comment

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

you are right, it's not compatible (I tried with the sample)

Would have to keep the old persistence_id_offset as it was, and add the new replay_persistence_ids, then include the data in both, and read from both. Not sure if it's worth the trouble? What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed to the wire compatible solution in e10c881

Not too messy.

/**
* Explicit request to replay events for given entities.
*/
final case class ReplayWithFilter(streamId: String, replayPersistenceIds: Set[ReplayPersistenceId])
Copy link
Member Author

Choose a reason for hiding this comment

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

Replay is public, so I added a new one instead of changing


// Note: we do not apply the filter before filterAfterSeqNr as that may be what triggered the replay.
// replicatedEventOriginFilter not used for replay.
if (env.sequenceNr < filterAfterSeqNr || producerFilter(env) && filter.matches(env)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

this is where the new filterAfterSeqNr is used

@patriknw patriknw marked this pull request as ready for review February 29, 2024 14:58
Copy link
Member

@johanandren johanandren left a comment

Choose a reason for hiding this comment

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

LGTM

@johanandren johanandren merged commit aa6f961 into main Mar 4, 2024
21 checks passed
@johanandren johanandren deleted the wip-extra-event-patriknw branch March 4, 2024 13:27
@johanandren johanandren added this to the 1.5.3 milestone Mar 4, 2024
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.

None yet

2 participants