本文整理汇总了C++中DB_ENV::repmgr_add_remote_site方法的典型用法代码示例。如果您正苦于以下问题:C++ DB_ENV::repmgr_add_remote_site方法的具体用法?C++ DB_ENV::repmgr_add_remote_site怎么用?C++ DB_ENV::repmgr_add_remote_site使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DB_ENV
的用法示例。
在下文中一共展示了DB_ENV::repmgr_add_remote_site方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
int
main(int argc, char *argv[])
{
DB_ENV *dbenv;
extern char *optarg;
const char *home;
char ch, *host, *portstr;
int local_is_set, ret, totalsites;
u_int16_t port;
/* Used to track whether this is a replica or a master. */
APP_DATA my_app_data;
dbenv = NULL;
ret = local_is_set = totalsites = 0;
home = NULL;
my_app_data.is_master = 0; /* Assume that we start as a replica */
if ((ret = create_env(progname, &dbenv)) != 0)
goto err;
/* Make APP_DATA available through the environment handle. */
dbenv->app_private = &my_app_data;
/* Default priority is 100. */
dbenv->rep_set_priority(dbenv, 100);
/* Permanent messages require at least one ack. */
dbenv->repmgr_set_ack_policy(dbenv, DB_REPMGR_ACKS_ONE);
/* Give 500 microseconds to receive the ack. */
dbenv->rep_set_timeout(dbenv, DB_REP_ACK_TIMEOUT, 500);
/* Collect the command line options. */
while ((ch = getopt(argc, argv, "h:l:n:p:r:")) != EOF)
switch (ch) {
case 'h':
home = optarg;
break;
/* Set the host and port used by this environment. */
case 'l':
host = strtok(optarg, ":");
if ((portstr = strtok(NULL, ":")) == NULL) {
fprintf(stderr, "Bad host specification.\n");
goto err;
}
port = (unsigned short)atoi(portstr);
if (dbenv->repmgr_set_local_site(dbenv, host, port, 0) != 0) {
fprintf(stderr,
"Could not set local address %s.\n", host);
goto err;
}
local_is_set = 1;
break;
/* Set the number of sites in this replication group. */
case 'n':
totalsites = atoi(optarg);
if ((ret = dbenv->rep_set_nsites(dbenv, totalsites)) != 0)
dbenv->err(dbenv, ret, "set_nsites");
break;
/* Set this replica's election priority. */
case 'p':
dbenv->rep_set_priority(dbenv, atoi(optarg));
break;
/* Identify another site in the replication group. */
case 'r':
host = strtok(optarg, ":");
if ((portstr = strtok(NULL, ":")) == NULL) {
fprintf(stderr, "Bad host specification.\n");
goto err;
}
port = (unsigned short)atoi(portstr);
if (dbenv->repmgr_add_remote_site(dbenv, host, port, 0, 0) != 0) {
fprintf(stderr,
"Could not add site %s.\n", host);
goto err;
}
break;
case '?':
default:
usage();
}
/* Error check command line. */
if (home == NULL || !local_is_set || !totalsites)
usage();
if ((ret = env_init(dbenv, home)) != 0)
goto err;
if ((ret = dbenv->repmgr_start(dbenv, 3, DB_REP_ELECTION)) != 0)
goto err;
if ((ret = doloop(dbenv)) != 0) {
dbenv->err(dbenv, ret, "Application failed");
goto err;
}
err: if (dbenv != NULL)
(void)dbenv->close(dbenv, 0);
return (ret);
//.........这里部分代码省略.........