#include <db.h>

DB_ENV->repmgr_start(DB_ENV *env, int nthreads, u_int32_t flags);  

The DB_ENV->repmgr_start() method starts the Replication Manager.

There are two ways to build Berkeley DB replication applications: the most common approach is to use the Berkeley DB library Replication Manager, where the Berkeley DB library manages the replication group, including network transport, all replication message processing and acknowledgment, and group elections. Applications using the Replication Manager generally make the following calls:

  1. Use DB_ENV->repmgr_site() to obtain a DB_SITE handle, then use that handle to configure the sites in the replication group.

    1. Use DB_SITE->set_config() to configure sites in the replication group.

    2. Use DB_SITE->remove() to remove a site from the replication group.

  2. Call DB_ENV->repmgr_set_ack_policy() to configure the message acknowledgment policy which best supports the replication group's transactional needs.

  3. Call DB_ENV->rep_set_priority() to configure the local site's election priority.

  4. Call DB_ENV->repmgr_start() to start the replication application.

For more information on building Replication Manager applications, please see the Replication Getting Started Guide included in the Berkeley DB documentation.

Applications with special needs (for example, applications using network protocols not supported by the Berkeley DB Replication Manager), must perform additional configuration and call other Berkeley DB replication Base API methods. For more information on building Base API applications, please see the Base API Methods section in the Berkeley DB Programmer's Reference Guide.

Starting the Replication Manager consists of opening the TCP/IP listening socket to accept incoming connections, and starting all necessary background threads. When multiple processes share a database environment, only one process can open the listening socket; the DB_ENV->repmgr_start() method automatically opens the socket in the first process to call it, and skips this step in the later calls from other subordinate processes.

The DB_ENV->repmgr_start() method may not be called before the DB_ENV->open() method is called to open the environment. In addition, this method may not be called before at least one replication site has been configured using the DB_SITE class. In addition, the local environment must be opened with the DB_THREAD flag set. If you are starting a view, you must call the DB_ENV->rep_set_view() method before opening the local environment.

The DB_ENV->repmgr_start() method will return DB_REP_IGNORE as an informational, non-error return code, if another process has previously become the TCP/IP listener (though the current call has nevertheless successfully started Replication Manager's background threads). Unless otherwise specified, the DB_ENV->repmgr_start() method returns a non-zero error value on failure and 0 on success.



Specify the number of threads of control created and dedicated to processing replication messages. In addition to these message processing threads, the Replication Manager creates and manages a few of its own threads of control. The TCP/IP listener process can change this value after the Replication Manager is started with a subsequent call to the DB_ENV->repmgr_start() method.


The flags parameter must be set to one of the following values when first starting the Replication Manager:


    Start as a master site, and do not call for an election. Note there must never be more than a single master in any replication group, and only one site at a time should ever be started with the DB_REP_MASTER flag specified.


    Start as a client, view, or preferred master site, and do not call for an election.


    Start as a client, and call for an election if no master is found.

If the Replication Manager is already started, a flags value of 0 can be used when making a subsequent call to change the value of nthreads or when starting a subordinate process.


The DB_ENV->repmgr_start() method may fail and return one of the following non-zero errors:


The local site tried to join the group, but was unable to do so for some reason (because a master site is not available, or because insufficient clients are running to acknowledge the new site). When that happens the application should pause and retry adding the site until it completes successfully.


If the database environment was not already opened or was opened without the DB_THREAD flag set; a local site has not already been configured, this method is called from a Base API application; a view is being started without having called the DB_ENV->rep_set_view() method before opening the database environment; or if an invalid flag value or parameter was specified.



See Also

Replication and Related Methods