Permalink
Browse files

[feature] stdlib: Enabled requestId checking for MongoDriver.send_wit…

…h_reply.
  • Loading branch information...
1 parent 6e63fde commit 959a59f54abcbe86f6fd9743469e4fc078ca67cc @nrs135 nrs135 committed Nov 10, 2011
Showing with 23 additions and 1 deletion.
  1. +3 −0 libbase/mongo.ml
  2. +3 −0 libbase/mongo.mli
  3. +6 −0 opabsl/mlbsl/bslMongo.ml
  4. +11 −1 stdlib/apis/mongo/mongo.opa
View
@@ -111,6 +111,9 @@ struct MsgHeader {
}
*)
+let mongo_buf_requestId mb = geti32 mb.Bson.buf 4
+let mongo_buf_responseTo mb = geti32 mb.Bson.buf 8
+
let header_messageLength s = geti32 s 0
let header_requestId s = geti32 s 4
let header_responseTo s = geti32 s 8
View
@@ -75,3 +75,6 @@ val reply_document_pos : (Buf.buf * int * int) -> int -> (int * int) option
val string_of_message_buf : Buf.buf -> string
val string_of_message_str : string -> string
val string_of_message_reply : Buf.buf * int * int -> string
+
+val mongo_buf_requestId : mongo_buf -> int
+val mongo_buf_responseTo : mongo_buf -> int
@@ -413,4 +413,10 @@ let string_of_cursorID cid = Printf.sprintf "%016Lx" cid
##register is_null_cursorID : Mongo.cursorID -> opa[bool]
let is_null_cursorID cid = ServerLib.wrap_bool (cid = 0L)
+##register mongo_buf_requestId : Mongo.mongo_buf -> int
+let mongo_buf_requestId = Mongo.mongo_buf_requestId
+
+##register mongo_buf_responseTo : Mongo.mongo_buf -> int
+let mongo_buf_responseTo = Mongo.mongo_buf_responseTo
+
##endmodule
@@ -471,6 +471,12 @@ MongoDriver = {{
@private string_of_message = (%% BslMongo.Mongo.string_of_message %% : string -> string)
@private string_of_message_reply = (%% BslMongo.Mongo.string_of_message_reply %% : Mongo.reply -> string)
+ /* Get requestId from Mongo.mongo_buf */
+ @private mongo_buf_requestId = (%% BslMongo.Mongo.mongo_buf_requestId %%: Mongo.mongo_buf -> int)
+
+ /* Get responseTo from Mongo.mongo_buf */
+ @private mongo_buf_responseTo = (%% BslMongo.Mongo.mongo_buf_responseTo %%: Mongo.mongo_buf -> int)
+
/*
* We have the possibility of unbounded recursion here since we
* call ReplSet.connect, which calls us for ismaster. Probably
@@ -530,6 +536,7 @@ MongoDriver = {{
@private
send_with_reply(m,mbuf,name): option(Mongo.reply) =
+ mrid = mongo_buf_requestId(mbuf)
myreconnect() =
if reconnect("send_with_reply",m)
then send_with_reply(m,mbuf,name)
@@ -541,10 +548,13 @@ MongoDriver = {{
mailbox = new_mailbox_(m.bufsize)
(match read_mongo_(conn,m.comms_timeout,mailbox) with
| {success=reply} ->
+ rrt = reply_responseTo(reply)
do reset_mailbox_(mailbox)
do free_(mbuf)
do if m.log then ML.debug("Mongo.receive({name})","\n{string_of_message_reply(reply)}",void)
- {some=reply}
+ if mrid != rrt
+ then ML.error("MongoDriver.send_with_reply","RequestId mismatch, expected {mrid}, got {rrt}",{none})
+ else {some=reply}
| {~failure} ->
do if m.log then ML.info("send_with_reply","failure={failure}",void)
do reset_mailbox_(mailbox)

0 comments on commit 959a59f

Please sign in to comment.