Loading...
Searching...
No Matches
Mongo Sync Pool API
Mongo Sync API

These commands implement connection pooling over the mongo_sync family of commands. More...

Collaboration diagram for Mongo Sync Pool API:

## Functions

mongo_sync_pool * | mongo_sync_pool_new (const gchar *host, gint port, gint nmasters, gint nslaves)
| Create a new synchronous connection pool.
void | mongo_sync_pool_free (mongo_sync_pool *pool)
| Close and free a synchronous connection pool.
mongo_sync_pool_connection * | mongo_sync_pool_pick (mongo_sync_pool *pool, gboolean want_master)
| Pick a connection from a synchronous connection pool.
gboolean | mongo_sync_pool_return (mongo_sync_pool *pool, mongo_sync_pool_connection *conn)
| Return a connection to the synchronous connection pool.

## Detailed Description

These commands implement connection pooling over the mongo_sync family of commands.

Once a pool is set up, one can pick and return connections at one's leisure. Picking is done in a round-robin fashion (excluding connections that have been picked but not returned yet).

## Function Documentation

## mongo_sync_pool_free()

void mongo_sync_pool_free | ( | mongo_sync_pool * | pool | ) |

Close and free a synchronous connection pool.

Parameters

  pool | is the pool to shut down.

Note
  The object will be freed, and shall not be used afterwards!

## mongo_sync_pool_new()

mongo_sync_pool * mongo_sync_pool_new | ( | const gchar * | host,
|  | gint | port,
|  | gint | nmasters,
|  | gint | nslaves )

Create a new synchronous connection pool.

Sets up a connection pool towards a given MongoDB server, and all its secondaries (if any).

Parameters

  host | is the address of the server.
  port | is the port to connect to.
  nmasters | is the number of connections to make towards the master.
  nslaves | is the number of connections to make towards the secondaries.

Note
  Either nmasters or nslaves can be zero, but not both at the same time.
  The host MUST be a master, otherwise the function will return an error.

Returns
  A newly allocated mongo_sync_pool object, or NULL on error. It is the responsibility of the caller to close and free the pool when appropriate.

## mongo_sync_pool_pick()

mongo_sync_pool_connection * mongo_sync_pool_pick | ( | mongo_sync_pool * | pool,
|  | gboolean | want_master )

Pick a connection from a synchronous connection pool.

Based on given preferences, selects a free connection object from the pool, and returns it.

Parameters

  pool | is the pool to select from.
  want_master | flags whether the caller wants a master connection, or secondaries are acceptable too.

Note
  For write operations, always select a master!

Returns
  A connection object from the pool.

Note
  The returned object can be safely casted to mongo_sync_connection, and passed to any of the mongo_sync family of commands. Do note however, that one shall not close or otherwise free a connection object returned by this function.

## mongo_sync_pool_return()

gboolean mongo_sync_pool_return | ( | mongo_sync_pool * | pool,
|  | mongo_sync_pool_connection * | conn )

Return a connection to the synchronous connection pool.

Once one is not using a connection anymore, it should be returned to the pool using this function.

Parameters

  pool | is the pool to return to.
  conn | is the connection to return.

Returns
  TRUE on success, FALSE otherwise.

Note
  The returned connection should not be used afterwards.