You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
eventsByTag may miss event under certain conditions #166
Xn - event number n of aggregate with id X.
All events are tagged with the same tag. No holes.
This is the order of events in the base table according to timestamp B1, A1, B2.
Mat views are asynchronous, so it is possible that the order in which events appeared in mat view is A1, B1, B2.
Source emits A1, but never emits B1, because actual order in view is B1, A1, B2, i.e. the same as in base table.
Reacted by Juan José Vázquez, Guillermo Lammers and Ignasi Marimon-Clos
"find delayed events 2" in {
valt1=LocalDateTime.now(ZoneOffset.UTC).minusMinutes(5)
valw1=UUID.randomUUID().toString
valw2=UUID.randomUUID().toString
valt2= t1.plusSeconds(1)
valeventA1=PersistentRepr("A1", 1L, "a", "", writerUuid = w1)
writeTestEvent(t2, eventA1, Set("T7"))
valsrc= queries.eventsByTag(tag ="T7", offset =NoOffset)
valprobe= src.runWith(TestSink.probe[Any])
probe.request(10)
probe.expectNextPF { case e @EventEnvelope(_, "a", 1L, "A1") => e }
// delayed, timestamp is before A1valeventB1=PersistentRepr("B1", 1L, "b", "", writerUuid = w2)
writeTestEvent(t1, eventB1, Set("T7"))
valt3= t1.plusSeconds(2)
valeventB2=PersistentRepr("B2", 2L, "b", "", writerUuid = w2)
writeTestEvent(t3, eventB2, Set("T7"))
probe.expectNextPF { case e @EventEnvelope(_, "b", 1L, "B1") => e }
probe.expectNextPF { case e @EventEnvelope(_, "b", 2L, "B2") => e }
probe.cancel()
}
That will fail as you describe. The reason B1 is missed here is that we don't know what the sequence number of the first B event is. Therefore it is using the sequence number of the first seen B event as starting point, i.e. B2. Therefore it doesn't detect that B1 is missing.
The following test works:
"find delayed events 3" in {
valt1=LocalDateTime.now(ZoneOffset.UTC).minusMinutes(5)
valw1=UUID.randomUUID().toString
valw2=UUID.randomUUID().toString
valeventB0=PersistentRepr("B0", 1L, "b", "", writerUuid = w2)
writeTestEvent(t1.minusSeconds(1), eventB0, Set("T8"))
valt2= t1.plusSeconds(1)
valeventA1=PersistentRepr("A1", 1L, "a", "", writerUuid = w1)
writeTestEvent(t2, eventA1, Set("T8"))
valsrc= queries.eventsByTag(tag ="T8", offset =NoOffset)
valprobe= src.runWith(TestSink.probe[Any])
probe.request(10)
probe.expectNextPF { case e @EventEnvelope(_, "b", 1L, "B0") => e }
probe.expectNextPF { case e @EventEnvelope(_, "a", 1L, "A1") => e }
// delayed, timestamp is before A1valeventB1=PersistentRepr("B1", 2L, "b", "", writerUuid = w2)
writeTestEvent(t1, eventB1, Set("T8"))
valt3= t1.plusSeconds(2)
valeventB2=PersistentRepr("B2", 3L, "b", "", writerUuid = w2)
writeTestEvent(t3, eventB2, Set("T8"))
probe.expectNextPF { case e @EventEnvelope(_, "b", 2L, "B1") => e }
probe.expectNextPF { case e @EventEnvelope(_, "b", 3L, "B2") => e }
probe.cancel()
}
To mitigate this risk we could perhaps populate the SequenceNumbers history by looking back at old events when starting up the query.
@patriknw thanks for investigation. What strategy of population of SequenceNumbers do you suggest? Folding over SELECT persistence_id, sequence_nr FROM eventsbytag since first timebucket on materialization? Or folding on demand when first event with untracked sequence number is observed?
Easiest would be to just use the existing query (EventsByTagFetcher), which is also used for finding delayed events and missing events. We could get better performance by using something that is only looking at the needed fields (e.g. not fetching and deserializing the event payload). It's probably worth doing the latter.
Activity
patriknw commentedon Mar 31, 2017
First, assuming proper
cassandra-query-journal.delayed-event-timeoutsetting, i.e. not 0s.It's rather easy to write such scenarios in
EventsByTagSpechttps://github.com/akka/akka-persistence-cassandra/blob/master/src/test/scala/akka/persistence/cassandra/query/EventsByTagSpec.scala#L622That will fail as you describe. The reason B1 is missed here is that we don't know what the sequence number of the first B event is. Therefore it is using the sequence number of the first seen B event as starting point, i.e. B2. Therefore it doesn't detect that B1 is missing.
The following test works:
To mitigate this risk we could perhaps populate the
SequenceNumbershistory by looking back at old events when starting up the query.notxcain commentedon Mar 31, 2017
@patriknw thanks for investigation. What strategy of population of
SequenceNumbersdo you suggest? Folding overSELECT persistence_id, sequence_nr FROM eventsbytagsince firsttimebucketon materialization? Or folding on demand when first event with untracked sequence number is observed?patriknw commentedon Mar 31, 2017
Easiest would be to just use the existing query (EventsByTagFetcher), which is also used for finding delayed events and missing events. We could get better performance by using something that is only looking at the needed fields (e.g. not fetching and deserializing the event payload). It's probably worth doing the latter.
improve eventsByTag to find first delayed event, #166
Merge pull request #176 from akka/wip-166-missed-event-patriknw
improve eventsByTag to find first delayed event, #166
patriknw commentedon Apr 5, 2017
@notxcain 0.25 is released with this improvement included