Describe the bug
When we have some events in the database and so the checkpoint for that subscription is not NULL, if we start the application and add 2 events, the first of those is not retrieved and thus not processed by the projections. For our case specifically, we have an Add and an Update event, which are both produced by a single command. When we start the application and handle this command, the Add is not processed and then the Update tries to edit a record which does not exist.
To Reproduce
Have SQL Server as the event store.
Have SQL Server as the projection db.
Start application
Produce events 1 and 2
Stop application
Start application
Produce events 3 and 4
See error
Expected behavior
Events 3 and 4 are sequentially retrieved from the db and processed by the projections.
Screenshots
N/A
Desktop (please complete the following information):
OS: Windows
Version 0.15.0-beta.6
Additional context
We believe we have found the problem and will create a PR shortly.
Where all events are retrieved whose GlobalPosition value is greater than the incoming <checkpoint + 2> value.
We believe that adding 1 to the position makes sense because you only want to get events which are ahead of the checkpoint. But it seems doing a +1 twice is causing it to retrieve events which are ahead of the checkpoint by 2 or more.
Describe the bug When we have some events in the database and so the checkpoint for that subscription is not NULL, if we start the application and add 2 events, the first of those is not retrieved and thus not processed by the projections. For our case specifically, we have an Add and an Update event, which are both produced by a single command. When we start the application and handle this command, the Add is not processed and then the Update tries to edit a record which does not exist.
To Reproduce
Expected behavior Events 3 and 4 are sequentially retrieved from the db and processed by the projections.
Screenshots N/A
Desktop (please complete the following information):
Additional context We believe we have found the problem and will create a PR shortly.
In
SqlServerSubscriptionBase
we see the followingSubscribe
https://github.com/Eventuous/eventuous/blob/a66fb591bb82c68fcba172a3f4ef26f073dedff0/src/SqlServer/src/Eventuous.SqlServer/Subscriptions/SqlServerSubscriptionBase.cs#L37-L43It gets the current checkpoint, adds 1 to it and calls the
PollingQuery
https://github.com/Eventuous/eventuous/blob/a66fb591bb82c68fcba172a3f4ef26f073dedff0/src/SqlServer/src/Eventuous.SqlServer/Subscriptions/SqlServerSubscriptionBase.cs#L63-L72Which receives the <checkpoint + 1> value as
position
and then calls thePrepareCommand
in theSqlServerAllStreamSubscription
(the same happens inSqlServerStreamSubscription
) : https://github.com/Eventuous/eventuous/blob/a66fb591bb82c68fcba172a3f4ef26f073dedff0/src/SqlServer/src/Eventuous.SqlServer/Subscriptions/SqlServerAllStreamSubscription.cs#L25-L28This takes the <checkpoint + 1> value, adds 1 to it again, and passes <checkpoint + 2> to the stored procedure
ReadAllForwards
https://github.com/Eventuous/eventuous/blob/a66fb591bb82c68fcba172a3f4ef26f073dedff0/src/SqlServer/src/Eventuous.SqlServer/Scripts/ReadAllForwards.sql#L1-L15Where all events are retrieved whose
GlobalPosition
value is greater than the incoming <checkpoint + 2> value.We believe that adding 1 to the position makes sense because you only want to get events which are ahead of the checkpoint. But it seems doing a +1 twice is causing it to retrieve events which are ahead of the checkpoint by 2 or more.
We see that the same code flow is present in the Postgres implementation so this might suffer from the same problem: https://github.com/Eventuous/eventuous/blob/a66fb591bb82c68fcba172a3f4ef26f073dedff0/src/Postgres/src/Eventuous.Postgresql/Subscriptions/PostgresSubscriptionBase.cs#L34-L34
https://github.com/Eventuous/eventuous/blob/a66fb591bb82c68fcba172a3f4ef26f073dedff0/src/Postgres/src/Eventuous.Postgresql/Subscriptions/PostgresAllStreamSubscription.cs#L27-L27