Skip to content
Browse files

[fix] stdlib: Enforce pool_max >= 1.

  • Loading branch information...
1 parent ea3fad6 commit c12e9b4631f046235a64290135cf6bfb95e71a35 @nrs135 nrs135 committed Nov 29, 2011
Showing with 8 additions and 12 deletions.
  1. +4 −4 stdlib/apis/mongo/connection.opa
  2. +4 −8 stdlib/apis/mongo/mongo.opa
View
8 stdlib/apis/mongo/connection.opa
@@ -164,19 +164,19 @@ MongoConnection = {{
names = ["--mongo-buf-size", "--mongobufsize", "--mb", "-mb"]
description = "Hint for initial MongoDB connection buffer size"
param_doc = "<int>"
- on_param(p) = parser n={Rule.natural} -> {no_params = add_param((p -> { p with bufsize = n }),p)}
+ on_param(p) = parser n={Rule.natural} -> {no_params = add_param((p -> { p with bufsize=n }),p)}
},
{CommandLine.default_parser with
names = ["--mongo-socket-pool", "--mongosocketpool", "--mp", "-mp"]
description = "Number of sockets in socket pool (>=2 enables socket pool)"
param_doc = "<int>"
- on_param(p) = parser n={Rule.natural} -> {no_params = add_param((p -> { p with pool_max = n }),p)}
+ on_param(p) = parser n={Rule.natural} -> {no_params = add_param((p -> { p with pool_max=Int.max(n,1) }),p)}
},
{CommandLine.default_parser with
names = ["--mongo-log", "--mongolog", "--ml", "-ml"]
description = "Enable MongoLog logging"
param_doc = "<bool>"
- on_param(p) = parser b={Rule.bool} -> {no_params = add_param((p -> { p with log = b }),p)}
+ on_param(p) = parser b={Rule.bool} -> {no_params = add_param((p -> { p with log=b }),p)}
},
{CommandLine.default_parser with
names = ["--mongo-seed", "--mongoseed", "--ms", "-ms"]
@@ -339,7 +339,7 @@ MongoConnection = {{
/** Change the pool size **/
pool_max(db:Mongo.mongodb, pool_max:int): Mongo.mongodb =
- { db with mongo={ db.mongo with ~pool_max } }
+ { db with mongo={ db.mongo with pool_max=Int.max(pool_max,1) } }
/** Chenge the bufsize hint (only applies to newly created buffers) **/
bufsize(db:Mongo.mongodb, bufsize:int): Mongo.mongodb =
View
12 stdlib/apis/mongo/mongo.opa
@@ -405,7 +405,7 @@ MongoDriver = {{
{ conn={none};
reconncell=(Cell.make(void, reconfn):Cell.cell(Mongo.reconnectmsg,Mongo.reconnectresult));
pool=SocketPool.make(("localhost",default_port),pool_max,log);
- ~pool_max; ~bufsize; ~log;
+ pool_max=Int.max(pool_max,1); ~bufsize; ~log;
seeds=[]; name=""; ~reconnectable;
reconnect_wait=2000; max_attempts=30; comms_timeout=3600000;
depth=0; max_depth=2;
@@ -424,12 +424,8 @@ MongoDriver = {{
**/
connect(m:Mongo.db, addr:string, port:int): outcome(Mongo.db,Mongo.failure) =
do if m.log then ML.info("MongoDriver.connect","bufsize={m.bufsize} addr={addr} port={port} log={m.log}",void)
- if m.pool_max > 1
- then
- do SocketPool.reconnect(m.pool,(addr,port))
- {success=m}
- else
- C.failErr("MongoDriver.connect: Pool requires pool_max > 1 (actually: {m.pool_max})")
+ do SocketPool.reconnect(m.pool,(addr,port))
+ {success=m}
/**
* Force a reconnection. Should only be needed if the basic parameters have changed.
@@ -470,7 +466,7 @@ MongoDriver = {{
*
* Note that some of these will have no effect until reconnection.
**/
- set_pool_max(m:Mongo.db, pool_max:int): Mongo.db = { m with ~pool_max }
+ set_pool_max(m:Mongo.db, pool_max:int): Mongo.db = { m with pool_max=Int.max(pool_max,1) }
set_bufsize(m:Mongo.db, bufsize:int): Mongo.db = { m with ~bufsize }
set_log(m:Mongo.db, log:bool): Mongo.db = { m with ~log }
add_seed(m:Mongo.db, seed:Mongo.mongo_host): Mongo.db = { m with seeds=seed +> m.seeds }

0 comments on commit c12e9b4

Please sign in to comment.
Something went wrong with that request. Please try again.