[Pharo-dev] MongoCursor>>#execute and MongoTalk changes

Holger Freyther holger at freyther.de
Sun Apr 10 16:19:13 EDT 2016

Hi guys,

I am tracking down a Voyage issue where query/reply is going out of sync when used concurrently. The Mongo wire protocol allows to specify a unique requestId and the response includes it as "responseTo" identifier. Mongo>>#nextRequestID helps in getting a new/unique id and it is already used but the responseTo field is never used.

I have modified Mongo>>#cursorQuery: to return the 'id' instead of 'self' and have modified Mongo>>#getMore:collection:chunkSize: to request a new requestId instead of truncating the 64bit cursorId to 32bit and then return the 'id'.

Next I modified MongoCursor>>#execute to remember the requestId and then compare it to the response id. This way the code will not treat a response for something else as legitimate response. It is using self error to signal the failure.

For the comparison to work in a reliable way even after many requests we need to make sure that Mongo requestID stays within 32bit. Otherwise our internal number will be a LargePositiveInteger using more than four bytes and when we get a reply it will be truncated to a number with four bytes only and the comparison will fail. For my use the failure would occur with < 125 days of operation. I have added a bitAnd: 16r3F...F (which is SmallInteger maxVal on 32bit images) to truncate it to 30 bit.

I have put that into the MongoTalk repository. If anything is wrong with the code (unit tests pass) please ping me and I will try my best to fix it.

kind regards

More information about the Pharo-dev mailing list