yevhen / Streamstone

Event store for Azure Table Storage
Other
395 stars 64 forks source link

Possible for read StreamSlice header to have a lower version than number of retrieved events? #49

Closed Davidsv closed 6 years ago

Davidsv commented 6 years ago

Hi, imagine this scenario:

This is difficult to test due to small time window where this could happen which is why I'm asking if it's even possible. I think batch writes are atomic, but are reads (within one GET)?

StreamSlice<DynamicTableEntity> read = await Stream.ReadAsync<DynamicTableEntity>(partition, 1);
Int32? lastEventsVersion = read.Events.LastOrDefault()?.Properties["Version"].Int32Value;
if (read.Stream.Version < lastEventsVersion)
{
    Console.WriteLine("inconsistent");
}
yevhen commented 6 years ago

Hi,

Ye, I think it's totally possible.

Nevertheless, I never intended the returned stream header to be consistent with the number of events in the slice. The stream header is returned along with the slice only for informational purposes, like what is the current state of the stream at the time of reading a slice.

That's why ReadAsync() api method doesn't require you to pass the header and only uses stream version. So, when reading use the version of the last event in the current slice to read the next slice.

Davidsv commented 6 years ago

Thanks. In my case, I'll have to account for this. I understand it's just the way table storage works though.