MongoChangeStreamCursor.getResumeToken() should be initialized on open
A newly opened change stream cursor returns null for getResumeToken()
. This makes fault tolerance cumbersome and full of corner cases during the period before the cursor acquires its resume token, which can take a long time on a quiescent database.
There exists a way to cause a change stream cursor to acquire a resume token immediately, even before it sees its first event, by calling tryNext
. However, this also causes the cursor to block for the polling period (maxAwaitTime
), and shortening the polling period has other adverse effects.
Fault tolerance and recovery logic would be significantly simpler if successfully opening a change stream cursor also caused it to have a valid resume token. Corner cases in this kind of recovery logic are particularly tricky to test, and particularly costly if the logic fails in production.
![](https://secure.gravatar.com/avatar/448ff8d0ae7cf7011026531a2e62133c?size=40&default=https%3A%2F%2Fassets.uvcdn.com%2Fpkg%2Fadmin%2Ficons%2Fuser_70-6bcf9e08938533adb9bac95c3e487cb2a6d4a32f890ca6fdc82e3072e0ea0368.png)