#include <db_cxx.h> int DbEnv::repmgr_start(int nthreads, u_int32_t flags);
The DbEnv::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:
Use DbEnv::repmgr_site() to obtain a DbSite handle, then use that handle to configure the sites in your replication group.
Use DbSite::set_config() to configure sites in your replication group.
Use DbSite::remove() to remove a site from the replication group.
Call DbEnv::repmgr_set_ack_policy() to configure the message acknowledgment policy which best supports the replication group's transactional needs.
Call DbEnv::rep_set_priority() to configure the local site's election priority.
Call DbEnv::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
DbEnv::repmgr_start()
method automatically opens the socket in the
first process to call it, and skips this step in the later calls from other processes.
The DbEnv::repmgr_start()
method
may not be called before the DbEnv::open() method is
called to open. In addition, this method may not be called before
your replication sites have been configured using the
DbSite class.
In addition, the local environment must be opened with the
DB_THREAD
flag set.
The DbEnv::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
DbEnv::repmgr_start()
method either returns a non-zero error value or throws an
exception that encapsulates a non-zero error value on
failure, and returns 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 flags parameter must be set to one of the following values:
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 site, and do not call for an election.
DB_REP_ELECTION
Start as a client, and call for an election if no master is found.
The DbEnv::repmgr_start()
method may fail and throw a DbException
exception, encapsulating one of the following non-zero errors, or return one
of the following non-zero errors: