Get stream length

Hi,

Is there a built in way of getting stream length, which takes into consideration that streams may have been truncated e.g old items expired?

At first I tried using the C# API with ReadStreamEventsForwardAsync (from event 0) and then using LastEventNumber - FromEventNumber with the slice result, but you have to know what the first actual event number is to get this to work, otherwise the slice reports that FromEventNumber is 0 even if the stream has been truncated.

For reference, I would like to know what stream length is for monitoring purposes e.g. length of parked message streams.

Thanks, Tim.

Stream metadata will have $tb set for truncated streams (unless max age/count)

Hi Greg,

Sounds like I can optimise for the case where $tb is available, and use something like a binary search for the maxAge case. It's not time critical so should be fine.

Thanks, Tim.

Just read the first event and the last event :slight_smile:

Hi Greg,

Reading the first event (event 0) using ReadStreamEventsForwardAsync yields an empty slice for streams that have been truncated. I fear I am missing something obvious here 're. the API.

I would of course optimise for streams that have not been truncated :slight_smile:

Thanks.

Just read the first event and the last event :slight_smile:

Do you want the length of the stream as it would have been it if were not truncated? or the number of events in it?

The number of events remaining in the stream i.e. after truncation.

https://github.com/EventStore/EventStore/blob/dev/src/EventStore.ClientAPI/EventStoreCatchUpSubscription.cs#L392

What are you getting here?

Can take a look later, cheers.