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.