# DbEnv.rep_elect |

`

###

    import com.sleepycat.db.*;

    public int rep_elect(int nsites, int pri, int timeout);
        throws DbException;

# Description

The DbEnv.rep_elect method holds an election for the master of a replication group, returning the new master's ID in the envid parameter.

The nsites parameter indicates the number of environments that the application believes are in the replication group. This number is used by Berkeley DB to avoid having two masters active simultaneously, even in the case of a network partition. During an election, a new master cannot be elected unless more than half of nsites agree on the new master. Thus, in the face of a network partition, the side of the partition with more than half the environments will elect a new master and continue, while the environments communicating with fewer than half the other environments will fail to find a new master.

The priority parameter is the priority of this environment. It must be a positive integer, or 0 if this environment is not permitted to become a master (see Replication environment priorities for more information).

The timeout parameter specifies a timeout period for an election. If the election has not completed after timeout microseconds, the thread will return Db.DB_REP_UNAVAIL.

The DbEnv.rep_elect method either returns successfully, with the new master's environment ID in the memory pointed to by the envid parameter, or it will return Db.DB_REP_UNAVAIL if the participating group members were unable to elect a new master for any reason. In the event of a successful return, the new master's ID may be the ID of the previous master, or the ID of the current environment. The application is responsible for adjusting its usage of the other environments in the replication group, including directing all database updates to the newly selected master, in accordance with the results of this election.

The thread of control that calls the DbEnv.rep_elect method must not be the thread of control that processes incoming messages; processing the incoming messages is necessary to successfully complete an election.

The DbEnv.rep_elect method throws an exception that encapsulates a non-zero error value on failure.

# Errors

The DbEnv.rep_elect method may fail and throw an exception encapsulating a non-zero error for the following conditions:

DB_REP_UNAVAIL
  The replication group was unable to elect a master.

The DbEnv.rep_elect method may fail and throw an exception for errors specified for other Berkeley DB and C library or system methods. If a catastrophic error has occurred, the DbEnv.rep_elect method may fail and throw a DbRunRecoveryException, in which case all subsequent Berkeley DB calls will fail in the same way.

# Class

DbEnv

# See Also

Replication and Related Methods`

Copyright Sleepycat Software