Skip to content

Commit

Permalink
[fix] stdlib: Quick fix for dead connection problem.
Browse files Browse the repository at this point in the history
  • Loading branch information
nrs135 authored and OpaOnWindowsNow committed Feb 13, 2012
1 parent ad5eb18 commit 864899f
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 5 deletions.
3 changes: 1 addition & 2 deletions stdlib/apis/mongo/bson.opa
Expand Up @@ -15,6 +15,7 @@
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*/
package stdlib.apis.mongo

/**
* Bson support for MongoDB driver
Expand All @@ -39,8 +40,6 @@

import stdlib.core.{date,map}

package stdlib.apis.mongo

/**
* Some convenience types.
* To use these, just cast the OPA type to this type, for example,
Expand Down
1 change: 1 addition & 0 deletions stdlib/apis/mongo/collection.opa
Expand Up @@ -15,6 +15,7 @@
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*/
package stdlib.apis.mongo

/**
* MongoDB binding for OPA.
Expand Down
1 change: 1 addition & 0 deletions stdlib/apis/mongo/commands.opa
Expand Up @@ -15,6 +15,7 @@
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*/
package stdlib.apis.mongo

/**
* MongoDB binding for OPA.
Expand Down
1 change: 1 addition & 0 deletions stdlib/apis/mongo/common.opa
Expand Up @@ -15,6 +15,7 @@
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*/
package stdlib.apis.mongo

/**
* MongoDB binding for OPA.
Expand Down
1 change: 1 addition & 0 deletions stdlib/apis/mongo/connection.opa
Expand Up @@ -15,6 +15,7 @@
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*/
package stdlib.apis.mongo

/**
* MongoDB binding for OPA.
Expand Down
1 change: 1 addition & 0 deletions stdlib/apis/mongo/cursor.opa
Expand Up @@ -15,6 +15,7 @@
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*/
package stdlib.apis.mongo

/**
* MongoDB binding for OPA.
Expand Down
1 change: 1 addition & 0 deletions stdlib/apis/mongo/dbMongo.opa
Expand Up @@ -16,6 +16,7 @@
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*/
package stdlib.apis.mongo
import stdlib.core.map
import stdlib.system
Expand Down
1 change: 1 addition & 0 deletions stdlib/apis/mongo/log.opa
Expand Up @@ -15,6 +15,7 @@
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*/
package stdlib.apis.mongo

/**
* Logging support for MongoDB driver
Expand Down
15 changes: 12 additions & 3 deletions stdlib/apis/mongo/mongo.opa
Expand Up @@ -15,6 +15,7 @@
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*/
package stdlib.apis.mongo

/**
* MongoDB binding for OPA.
Expand Down Expand Up @@ -88,6 +89,7 @@ type Mongo.srr =
/ {snderrresult:option(Mongo.reply)}
/ {stopresult}
/ {reconnect}
/ {noconnection}

/** Messages for socket pool **/
@private type Mongo.reconnectmsg = {reconnect:(string,Mongo.db)} / {stop}
Expand Down Expand Up @@ -192,6 +194,7 @@ MongoDriver = {{
*/
@private
doreconnect(from:string, m:Mongo.db): bool =
do if m.log then ML.debug("MongoDriver.doreconnect","depth={m.depth}",void)
if m.depth > m.max_depth
then
do if m.log then ML.error("MongoDriver.reconnect({from})","max depth exceeded",void)
Expand Down Expand Up @@ -224,9 +227,10 @@ MongoDriver = {{

@private
reconnect(from, m) =
do if m.log then ML.debug("MongoDriver.reconnect","m={m}",void)
match (Cell.call(m.reconncell,({reconnect=((from,m))}:Mongo.reconnectmsg)):Mongo.reconnectresult) with
| {reconnectresult=tf} -> tf
| _ -> @fail
| _ -> do ML.debug("MongoDriver.reconnect","fail",void) @fail

@private
stoprecon(m) =
Expand Down Expand Up @@ -349,12 +353,14 @@ MongoDriver = {{
| {send=(m,mbuf,name)} -> sr_snr({m with ~conn},mbuf,name)
| {sendrecv=(m,mbuf,name)} -> sr_swr({m with ~conn},mbuf,name)
| {senderror=(m,mbuf,name,ns)} -> sr_swe({m with ~conn},mbuf,name,ns)
| {stop} -> @fail)
| {stop} -> do ML.debug("MongoDriver.srpool","stop",void) @fail)
do SocketPool.release(m.pool,connection)
result
| {~failure} ->
do if m.log then ML.error("MongoDriver.srpool","Can't get pool {C.string_of_failure(failure)}",void)
{reconnect}
if (failure == {Error="Got exception Scheduler.Connection_closed"})
then {noconnection}
else {reconnect}
@private
snd(m,mbuf,name) =
Expand All @@ -367,6 +373,7 @@ MongoDriver = {{
else ML.fatal("MongoDriver.snd({name}):","comms error (Can't reconnect)",-1)
srr = srpool(m,{send=((m,mbuf,name))})
match srr with
| {noconnection} -> false
| {reconnect} -> recon()
| {~sendresult} -> sendresult
| _ -> @fail
Expand All @@ -382,6 +389,7 @@ MongoDriver = {{
else ML.fatal("MongoDriver.sndrcv({name}):","comms error (Can't reconnect)",-1)
srr = srpool(m,{sendrecv=((m,mbuf,name))})
match srr with
| {noconnection} -> none
| {reconnect} -> recon()
| {~sndrcvresult} -> sndrcvresult
| _ -> @fail
Expand All @@ -397,6 +405,7 @@ MongoDriver = {{
else ML.fatal("MongoDriver.snderr({name}):","comms error (Can't reconnect)",-1)
srr = srpool(m,{senderror=((m,mbuf,name,ns))})
match srr with
| {noconnection} -> none
| {reconnect} -> recon()
| {~snderrresult} -> snderrresult
| _ -> @fail
Expand Down
3 changes: 3 additions & 0 deletions stdlib/apis/mongo/replset.opa
Expand Up @@ -15,6 +15,7 @@
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*/
package stdlib.apis.mongo

/**
* MongoDB binding for OPA.
Expand Down Expand Up @@ -204,6 +205,8 @@ MongoReplicaSet = {{
* In practice, this should never happen.
**/
connect(m:Mongo.db): outcome(Mongo.db,Mongo.failure) =
//m = {m with log=true}
do if m.log then ML.debug("MongoReplicaSet.connect","depth={m.depth}",void)
do if m.seeds == [] then ML.fatal("MongoReplicaSet.connect","Tried to connect with no seeds",-1) else void
rec aux(m, seeds) =
match seeds with
Expand Down
1 change: 1 addition & 0 deletions stdlib/apis/mongo/selectupdate.opa
Expand Up @@ -15,6 +15,7 @@
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*/
package stdlib.apis.mongo

/**
* MongoDB binding for OPA.
Expand Down
1 change: 1 addition & 0 deletions stdlib/apis/mongo/socketpool.opa
Expand Up @@ -15,6 +15,7 @@
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*/
package stdlib.apis.mongo

import stdlib.queue

Expand Down
1 change: 1 addition & 0 deletions stdlib/apis/mongo/types.opa
Expand Up @@ -15,6 +15,7 @@
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*/
package stdlib.apis.mongo

/**
* MongoDB binding for OPA.
Expand Down
1 change: 1 addition & 0 deletions stdlib/apis/mongo/view.opa
Expand Up @@ -15,6 +15,7 @@
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*/
package stdlib.apis.mongo

/**
* MongoDB binding for OPA.
Expand Down

0 comments on commit 864899f

Please sign in to comment.