DB_ENV->repmgr_start()
Prev | Chapter 10. Replication Methods | Next

## DB_ENV->repmgr_start()

    #include <db.h>

    int
    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. Call DB_ENV->repmgr_set_local_site() to configure the local site in the replication group.

2. Call DB_ENV->repmgr_add_remote_site() to configure the remote site(s) in the replication group.

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

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

5. 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 processes.

The `DB_ENV->repmgr_start()` method may not be called before the DB_ENV->open() method is called to open the local environment and the DB_ENV->repmgr_set_local_site() method is called to configure the local site. In addition, the local environment must be opened with the DB_THREAD flag set.

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.

### Parameters

#### flags

The flags parameter must be set to one of the following values:

- `DB_REP_MASTER`

  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.

- `DB_REP_CLIENT`

  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.

#### nthreads

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.

### Errors

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

#### EINVAL

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; or if an invalid flag value or parameter was specified.

### Class

DB_ENV

### See Also

Replication and Related Methods

Prev | Up | Next
DB_ENV->repmgr_site_list() | Home | DB_ENV->repmgr_stat()