Added:
branches/memcachedb-1.2.0/stats.c
Modified:
branches/memcachedb-1.2.0/ChangeLog
branches/memcachedb-1.2.0/Makefile.am
branches/memcachedb-1.2.0/Makefile.in
branches/memcachedb-1.2.0/bdb.c
branches/memcachedb-1.2.0/memcachedb.c
branches/memcachedb-1.2.0/memcachedb.h
Log:
stats and replication code improved
Modified: branches/memcachedb-1.2.0/ChangeLog
==============================================================================
--- branches/memcachedb-1.2.0/ChangeLog (original)
+++ branches/memcachedb-1.2.0/ChangeLog Thu Oct 9 00:01:13 2008
@@ -1,3 +1,9 @@
+2008-10-08 Steve Chu <stv...@gmail.com>
+ * lots of statistics code clean up; stats command adjusted for better
rendering; now more replication statistics info is provided.
+ * more compact and verbose message for logging
+ * lots of replication code clean up for more reliable electing, a new
option "-n" is added that allows user to customize the votes of electing.
+ * "memcache.py" is nearly patched for recent changes on private
commands. The "mdbtop.py" tool is updated either.
+
2008-09-04 Steve Chu <stv...@gmail.com>
* New option '-e' to set percent of the pages in the cache that should
be clean, used for memp_trickle call(only available when '-T' is presented).
@@ -16,8 +22,8 @@
2008-07-25 Steve Chu <stv...@gmail.com>
* Warning: 'pkget' and 'pvget' private command now has been discarded.
- Memcachedb will be a more memcache protocol compatible daemon(append and
- preppend daemon will be implenmented later), and will not add relatinal
+ MemcacheDB will be a more memcache protocol compatible daemon(append and
+ prepend command will be implemented later), and will not add relational
data model any more, the structural data storage will be issued by
another
project (now internal only).
Modified: branches/memcachedb-1.2.0/Makefile.am
==============================================================================
--- branches/memcachedb-1.2.0/Makefile.am (original)
+++ branches/memcachedb-1.2.0/Makefile.am Thu Oct 9 00:01:13 2008
@@ -1,5 +1,5 @@
bin_PROGRAMS = memcachedb
-memcachedb_SOURCES = memcachedb.c item.c memcachedb.h thread.c bdb.c
+memcachedb_SOURCES = memcachedb.c item.c memcachedb.h thread.c bdb.c
stats.c
SUBDIRS = doc tools
EXTRA_DIST = doc tools CREDITS AUTHORS LICENSE
Modified: branches/memcachedb-1.2.0/Makefile.in
==============================================================================
--- branches/memcachedb-1.2.0/Makefile.in (original)
+++ branches/memcachedb-1.2.0/Makefile.in Thu Oct 9 00:01:13 2008
@@ -49,7 +49,7 @@
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
PROGRAMS = $(bin_PROGRAMS)
am_memcachedb_OBJECTS = memcachedb.$(OBJEXT) item.$(OBJEXT) \
- thread.$(OBJEXT) bdb.$(OBJEXT)
+ thread.$(OBJEXT) bdb.$(OBJEXT) stats.$(OBJEXT)
memcachedb_OBJECTS = $(am_memcachedb_OBJECTS)
memcachedb_LDADD = $(LDADD)
DEFAULT_INCLUDES = -I.@am__isrc@
@@ -168,7 +168,7 @@
target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
-memcachedb_SOURCES = memcachedb.c item.c memcachedb.h thread.c bdb.c
+memcachedb_SOURCES = memcachedb.c item.c memcachedb.h thread.c bdb.c
stats.c
SUBDIRS = doc tools
EXTRA_DIST = doc tools CREDITS AUTHORS LICENSE
all: config.h
@@ -262,6 +262,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bdb.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/item.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memcachedb.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stats.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/thread.Po@am__quote@
.c.o:
Modified: branches/memcachedb-1.2.0/bdb.c
==============================================================================
--- branches/memcachedb-1.2.0/bdb.c (original)
+++ branches/memcachedb-1.2.0/bdb.c Thu Oct 9 00:01:13 2008
@@ -54,34 +54,34 @@
bdb_settings.rep_localport = 31211; /* local port in replication */
bdb_settings.rep_remotehost = NULL; /* local host in replication */
bdb_settings.rep_remoteport = 0; /* local port in replication */
- bdb_settings.rep_is_master = -1; /* 1 on YES, 0 on NO, -1 on UNKNOWN,
for two sites replication */
+ bdb_settings.rep_whoami = MDB_UNKNOWN;
bdb_settings.rep_master_eid = DB_EID_INVALID;
bdb_settings.rep_start_policy = DB_REP_ELECTION;
bdb_settings.rep_nsites = 2;
bdb_settings.rep_ack_policy = DB_REPMGR_ACKS_ONE_PEER;
- bdb_settings.rep_ack_timeout = 20 * 1000;
+ bdb_settings.rep_ack_timeout = 50 * 1000; /* 50ms */
bdb_settings.rep_chkpoint_delay = 0;
- bdb_settings.rep_conn_retry = 30 * 1000 * 1000;
- bdb_settings.rep_elect_timeout = 2 * 1000 * 1000;
- bdb_settings.rep_elect_retry = 10 * 1000 * 1000;
- bdb_settings.rep_heartbeat_monitor = 60 * 1000 * 1000;
- bdb_settings.rep_heartbeat_send = 60 * 1000 * 1000;
- bdb_settings.rep_lease_timeout = 0;
+ bdb_settings.rep_conn_retry = 30 * 1000 * 1000; /* 3 seconds*/
+ bdb_settings.rep_elect_timeout = 5 * 1000 * 1000; /* 5 seconds */
+ bdb_settings.rep_elect_retry = 10 * 1000 * 1000; /* 10 seconds */
+ bdb_settings.rep_heartbeat_monitor = 60 * 1000 * 1000; /* 60 seconds */
+ bdb_settings.rep_heartbeat_send = 60 * 1000 * 1000; /* 60 seconds */
+ bdb_settings.rep_lease_timeout = 0; /* now never used */
bdb_settings.rep_bulk = 1;
- bdb_settings.rep_lease = 0;
+ bdb_settings.rep_lease = 0; /* now never used */
bdb_settings.rep_priority = 100;
bdb_settings.rep_req_min = 40000;
bdb_settings.rep_req_max = 1280000;
- bdb_settings.rep_fast_clock = 102;
+ bdb_settings.rep_fast_clock = 102; /* now never used */
bdb_settings.rep_slow_clock = 100;
- bdb_settings.rep_limit_gbytes = 0;
- bdb_settings.rep_limit_bytes = 10 * 1024 * 1024;
+ bdb_settings.rep_limit_gbytes = 0;
+ bdb_settings.rep_limit_bytes = 10 * 1024 * 1024; /* 10MB */
}
void bdb_env_init(void){
@@ -94,7 +94,7 @@
/* set err&msg display */
env->set_errfile(env, stderr);
- env->set_errpfx(env, "Memcachedb");
+ env->set_errpfx(env, PACKAGE);
env->set_msgfile(env, stderr);
/* set BerkeleyDB verbose*/
@@ -158,24 +158,26 @@
env->rep_set_timeout(env, DB_REP_CONNECTION_RETRY,
bdb_settings.rep_conn_retry);
env->rep_set_timeout(env, DB_REP_ELECTION_TIMEOUT,
bdb_settings.rep_elect_timeout);
env->rep_set_timeout(env, DB_REP_ELECTION_RETRY,
bdb_settings.rep_elect_retry);
- env->rep_set_timeout(env, DB_REP_HEARTBEAT_MONITOR,
bdb_settings.rep_heartbeat_monitor);
- env->rep_set_timeout(env, DB_REP_HEARTBEAT_SEND,
bdb_settings.rep_heartbeat_send);
- //env->rep_set_timeout(env, DB_REP_LEASE_TIMEOUT,
bdb_settings.rep_lease_timeout);
+ // env->rep_set_timeout(env, DB_REP_HEARTBEAT_MONITOR,
bdb_settings.rep_heartbeat_monitor);
+ // env->rep_set_timeout(env, DB_REP_HEARTBEAT_SEND,
bdb_settings.rep_heartbeat_send);
+ /*env->rep_set_timeout(env, DB_REP_LEASE_TIMEOUT,
bdb_settings.rep_lease_timeout);*/
/* set replication configure */
env->rep_set_config(env, DB_REP_CONF_BULK, bdb_settings.rep_bulk);
- //env->rep_set_config(env, DB_REP_CONF_LEASE,
bdb_settings.rep_lease);
+ /*env->rep_set_config(env, DB_REP_CONF_LEASE,
bdb_settings.rep_lease);*/
env->rep_set_priority(env, bdb_settings.rep_priority);
env->rep_set_request(env, bdb_settings.rep_req_min,
bdb_settings.rep_req_max);
- //env->rep_set_clockskew(env, bdb_settings.rep_fast_clock,
bdb_settings.rep_slow_clock);
+ /* env->rep_set_clockskew(env, bdb_settings.rep_fast_clock,
bdb_settings.rep_slow_clock);*/
env->rep_set_limit(env, bdb_settings.rep_limit_gbytes,
bdb_settings.rep_limit_bytes);
+ /* publish the local site */
if ((ret = env->repmgr_set_local_site(env,
bdb_settings.rep_localhost, bdb_settings.rep_localport, 0)) != 0) {
fprintf(stderr, "repmgr_set_local_site[%s:%d]: %s\n",
bdb_settings.rep_localhost,
bdb_settings.rep_localport, db_strerror(ret));
exit(EXIT_FAILURE);
}
+ /* add a remote site, mostly this a master */
if(NULL != bdb_settings.rep_remotehost) {
if ((ret = env->repmgr_add_remote_site(env,
bdb_settings.rep_remotehost, bdb_settings.rep_remoteport, NULL, 0)) != 0) {
fprintf(stderr, "repmgr_add_remote_site[%s:%d]: %s\n",
@@ -183,6 +185,7 @@
exit(EXIT_FAILURE);
}
}
+ /* nsite is important for electing */
if ((ret = env->rep_set_nsites(env, bdb_settings.rep_nsites)) !=
0) {
fprintf(stderr, "rep_set_nsites: %s\n", db_strerror(ret));
exit(EXIT_FAILURE);
@@ -194,7 +197,6 @@
exit(EXIT_FAILURE);
}
-
if(bdb_settings.is_replicated) {
/* repmgr_start must run after daemon !!!*/
if ((ret = env->repmgr_start(env, 3,
bdb_settings.rep_start_policy)) != 0) {
@@ -202,7 +204,8 @@
exit(EXIT_FAILURE);
}
/* sleep 5 second for electing */
- if (bdb_settings.rep_start_policy == DB_REP_ELECTION) {
+ if (bdb_settings.rep_start_policy == DB_REP_ELECTION ||
+ bdb_settings.rep_start_policy == DB_REP_CLIENT) {
sleep(5);
}
}
@@ -216,9 +219,9 @@
while(!db_open) {
/* if replica, just scratch the db file from a master */
if (1 == bdb_settings.is_replicated){
- if (0 == bdb_settings.rep_is_master) {
+ if (MDB_CLIENT == bdb_settings.rep_whoami) {
bdb_settings.db_flags = DB_AUTO_COMMIT;
- }else if (1 == bdb_settings.rep_is_master) {
+ }else if (MDB_MASTER == bdb_settings.rep_whoami) {
bdb_settings.db_flags = DB_CREATE | DB_AUTO_COMMIT;
}else{
/* do nothing */
@@ -309,9 +312,7 @@
if ((ret = dbenv->txn_checkpoint(dbenv, 0, 0, 0)) != 0) {
dbenv->err(dbenv, ret, "checkpoint thread");
}
- if (settings.verbose > 1) {
- dbenv->errx(dbenv, "checkpoint thread: done");
- }
+ dbenv->errx(dbenv, "checkpoint thread: a txn_checkpoint is done");
}
return (NULL);
}
@@ -330,9 +331,7 @@
if ((ret = dbenv->memp_trickle(dbenv,
bdb_settings.memp_trickle_percent, &nwrotep)) != 0) {
dbenv->err(dbenv, ret, "memp_trickle thread");
}
- if (settings.verbose > 1) {
- dbenv->errx(dbenv, "memp_trickle thread: done, writing %d
dirty pages", nwrotep);
- }
+ dbenv->errx(dbenv, "memp_trickle thread: writing %d dirty pages",
nwrotep);
}
return (NULL);
}
@@ -359,31 +358,42 @@
void bdb_event_callback(DB_ENV *env, u_int32_t which, void *info)
{
switch (which) {
+ case DB_EVENT_PANIC:
+ env->errx(env, "evnet: DB_EVENT_PANIC, we got panic, recovery
should be run.");
+ break;
case DB_EVENT_REP_CLIENT:
- fprintf(stderr, "event: DB_EVENT_REP_CLIENT, the local site[%s:%d]
now a replication client.\n",
- bdb_settings.rep_localhost, bdb_settings.rep_localport);
- bdb_settings.rep_is_master = 0;
+ env->errx(env, "event: DB_EVENT_REP_CLIENT, I[%s:%d] am now a
replication client.",
+ bdb_settings.rep_localhost,
bdb_settings.rep_localport);
+ bdb_settings.rep_whoami = MDB_CLIENT;
break;
case DB_EVENT_REP_ELECTED:
- fprintf(stderr, "event: DB_EVENT_REP_ELECTED, The local
replication site[%s:%d] has just won an election.\n",
- bdb_settings.rep_localhost, bdb_settings.rep_localport);
+ env->errx(env, "event: DB_EVENT_REP_ELECTED, I[%s:%d] has just won
an election.",
+ bdb_settings.rep_localhost,
bdb_settings.rep_localport);
break;
case DB_EVENT_REP_MASTER:
- fprintf(stderr, "event: DB_EVENT_REP_MASTER, the local site[%s:%d]
now the master site of its replication group.\n",
bdb_settings.rep_localhost, bdb_settings.rep_localport);
- bdb_settings.rep_is_master = 1;
+ env->errx(env, "event: DB_EVENT_REP_MASTER, I[%s:%d] am now a
replication master.",
+ bdb_settings.rep_localhost,
bdb_settings.rep_localport);
+ bdb_settings.rep_whoami = MDB_MASTER;
bdb_settings.rep_master_eid = BDB_EID_SELF;
break;
case DB_EVENT_REP_NEWMASTER:
- fprintf(stderr, "event: DB_EVENT_REP_NEWMASTER, a new master has
been established, but not me[%s:%d]\n",
- bdb_settings.rep_localhost, bdb_settings.rep_localport);
bdb_settings.rep_master_eid = *(int*)info;
+ env->errx(env, "event: DB_EVENT_REP_NEWMASTER, a new
master[eid: %d] has been established, "
+ "but not me[%s:%d]", bdb_settings.rep_master_eid,
+ bdb_settings.rep_localhost,
bdb_settings.rep_localport);
break;
case DB_EVENT_REP_PERM_FAILED:
- fprintf(stderr, "event: insufficient acks, now I flush the
transcation log buffer\n");
+ env->errx(env, "event: DB_EVENT_REP_PERM_FAILED, insufficient
acks, "
+ "the master will flush the txn log buffer");
break;
- case DB_EVENT_REP_STARTUPDONE: /* FALLTHROUGH */
- case DB_EVENT_PANIC: /* FALLTHROUGH */
- case DB_EVENT_WRITE_FAILED: /* FALLTHROUGH */
+ case DB_EVENT_REP_STARTUPDONE:
+ if (bdb_settings.rep_whoami == MDB_CLIENT){
+ env->errx(env, "event: DB_EVENT_REP_STARTUPDONE, I has
completed startup synchronization and"
+ " is now processing live log records received
from the master.");
+ }
+ break;
+ case DB_EVENT_WRITE_FAILED:
+ env->errx(env, "event: DB_EVENT_WRITE_FAILED, I wrote to stable
storage failed.");
break;
default:
env->errx(env, "ignoring event %d", which);
@@ -423,10 +433,12 @@
void bdb_chkpoint(void)
{
int ret = 0;
- ret = env->txn_checkpoint(env, 0, 0, 0);
- if (0 != ret){
- fprintf(stderr, "env->txn_checkpoint: %s\n", db_strerror(ret));
- }else{
- fprintf(stderr, "env->txn_checkpoint: OK\n");
+ if (env != NULL){
+ ret = env->txn_checkpoint(env, 0, 0, 0);
+ if (0 != ret){
+ fprintf(stderr, "env->txn_checkpoint: %s\n", db_strerror(ret));
+ }else{
+ fprintf(stderr, "env->txn_checkpoint: OK\n");
+ }
}
}
Modified: branches/memcachedb-1.2.0/memcachedb.c
==============================================================================
--- branches/memcachedb-1.2.0/memcachedb.c (original)
+++ branches/memcachedb-1.2.0/memcachedb.c Thu Oct 9 00:01:13 2008
@@ -724,7 +724,7 @@
if (old_it != NULL)
item_free(old_it);
- if (old_it != NULL)
+ if (new_it != NULL)
item_free(new_it);
if (ret == 0) {
@@ -873,182 +873,40 @@
return;
}
+ /* for bdb stats */
if (strcmp(subcommand, "bdb") == 0) {
char temp[512];
- char *pos = temp;
- int ret;
- pos += sprintf(pos, "STAT db_ver %d.%d.%d\r\n",
bdb_version.majver, bdb_version.minver, bdb_version.patch);
- pos += sprintf(pos, "STAT cache_size %u\r\n",
bdb_settings.cache_size);
- /* get page size */
- if((ret = dbp->get_pagesize(dbp, &bdb_settings.page_size)) == 0){
- pos += sprintf(pos, "STAT page_size %u\r\n",
bdb_settings.page_size);
- }
- /* get database type */
- if((ret = dbp->get_type(dbp, &bdb_settings.db_type)) == 0){
- if (bdb_settings.db_type == DB_BTREE){
- pos += sprintf(pos, "STAT db_type btree\r\n");
- }else if (bdb_settings.db_type == DB_HASH){
- pos += sprintf(pos, "STAT db_type hash\r\n");
- }
- }
- pos += sprintf(pos, "STAT txn_lg_bsize %u\r\n",
bdb_settings.txn_lg_bsize);
- pos += sprintf(pos, "STAT txn_nosync %d\r\n",
bdb_settings.txn_nosync);
- pos += sprintf(pos, "STAT dldetect_val %d\r\n",
bdb_settings.dldetect_val);
- pos += sprintf(pos, "STAT chkpoint_val %d\r\n",
bdb_settings.chkpoint_val);
- pos += sprintf(pos, "STAT memp_trickle_val %d\r\n",
bdb_settings.memp_trickle_val);
- pos += sprintf(pos, "STAT memp_trickle_percent %d\r\n",
bdb_settings.memp_trickle_percent);
- pos += sprintf(pos, "END");
+ stats_bdb(temp);
out_string(c, temp);
return;
}
-
- if (strcmp(subcommand, "repcfg") == 0) {
- char temp[512];
- char *pos = temp;
- int ret;
- if (bdb_settings.is_replicated == 1){
- if (env->rep_get_priority(env, &bdb_settings.rep_priority) ==
0){
- pos += sprintf(pos, "STAT rep_priority %d\r\n",
bdb_settings.rep_priority);
- }
- if (env->repmgr_get_ack_policy(env,
&bdb_settings.rep_ack_policy) == 0){
- pos += sprintf(pos, "STAT rep_ack_policy %d\r\n",
bdb_settings.rep_ack_policy);
- }
-
- if (env->rep_get_timeout(env, DB_REP_ACK_TIMEOUT,
&bdb_settings.rep_ack_timeout) == 0){
- pos += sprintf(pos, "STAT rep_ack_timeout %u\r\n",
bdb_settings.rep_ack_timeout);
- }
- if (env->rep_get_timeout(env, DB_REP_CHECKPOINT_DELAY,
&bdb_settings.rep_chkpoint_delay) == 0){
- pos += sprintf(pos, "STAT rep_chkpoint_delay %u\r\n",
bdb_settings.rep_chkpoint_delay);
- }
- if (env->rep_get_timeout(env, DB_REP_CONNECTION_RETRY,
&bdb_settings.rep_conn_retry) == 0){
- pos += sprintf(pos, "STAT rep_conn_retry %u\r\n",
bdb_settings.rep_conn_retry);
- }
- if (env->rep_get_timeout(env, DB_REP_ELECTION_TIMEOUT,
&bdb_settings.rep_elect_timeout) == 0){
- pos += sprintf(pos, "STAT rep_elect_timeout %u\r\n",
bdb_settings.rep_elect_timeout);
- }
- if (env->rep_get_timeout(env, DB_REP_ELECTION_RETRY,
&bdb_settings.rep_elect_retry) == 0){
- pos += sprintf(pos, "STAT rep_elect_retry %u\r\n",
bdb_settings.rep_elect_retry);
- }
- if (env->rep_get_timeout(env, DB_REP_HEARTBEAT_MONITOR,
&bdb_settings.rep_heartbeat_monitor) == 0){
- pos += sprintf(pos, "STAT rep_heartbeat_monitor %u\r\n",
bdb_settings.rep_heartbeat_monitor);
- }
- if (env->rep_get_timeout(env, DB_REP_HEARTBEAT_SEND,
&bdb_settings.rep_heartbeat_send) == 0){
- pos += sprintf(pos, "STAT rep_heartbeat_send %u\r\n",
bdb_settings.rep_heartbeat_send);
- }
- if (env->rep_get_timeout(env, DB_REP_LEASE_TIMEOUT,
&bdb_settings.rep_lease_timeout) == 0){
- pos += sprintf(pos, "STAT rep_lease_timeout %u\r\n",
bdb_settings.rep_lease_timeout);
- }
-
- if (env->rep_get_config(env, DB_REP_CONF_BULK,
&bdb_settings.rep_bulk) == 0){
- pos += sprintf(pos, "STAT rep_bulk %d\r\n",
bdb_settings.rep_bulk);
- }
- if (env->rep_get_config(env, DB_REP_CONF_LEASE,
&bdb_settings.rep_lease) == 0){
- pos += sprintf(pos, "STAT rep_lease %d\r\n",
bdb_settings.rep_lease);
- }
-
- if (env->rep_get_request(env, &bdb_settings.rep_req_min,
&bdb_settings.rep_req_max) == 0){
- pos += sprintf(pos, "STAT rep_request %u/%u\r\n",
bdb_settings.rep_req_min, bdb_settings.rep_req_max);
- }
-
- if (env->rep_get_clockskew(env, &bdb_settings.rep_fast_clock,
&bdb_settings.rep_slow_clock) == 0){
- pos += sprintf(pos, "STAT rep_clock %u/%u\r\n",
bdb_settings.rep_fast_clock, bdb_settings.rep_slow_clock);
- }
-
- if (env->rep_get_limit(env, &bdb_settings.rep_limit_gbytes,
&bdb_settings.rep_limit_bytes) == 0){
- pos += sprintf(pos, "STAT rep_limit %u/%u\r\n",
bdb_settings.rep_limit_gbytes, bdb_settings.rep_limit_bytes);
- }
-
- if (env->rep_get_nsites(env, &bdb_settings.rep_nsites) == 0){
- pos += sprintf(pos, "STAT rep_nsites %u\r\n",
bdb_settings.rep_nsites);
- }
+
+ /* for replication stats */
+ if (bdb_settings.is_replicated){
+ if (strcmp(subcommand, "rep") == 0) {
+ char temp[2048];
+ stats_rep(temp);
+ out_string(c, temp);
+ return;
+ }
+ if (strcmp(subcommand, "repmgr") == 0) {
+ char temp[256];
+ stats_repmgr(temp);
+ out_string(c, temp);
+ return;
+ }
+ if (strcmp(subcommand, "repcfg") == 0) {
+ char temp[512];
+ stats_repcfg(temp);
+ out_string(c, temp);
+ return;
+ }
+ if (strcmp(subcommand, "repms") == 0) {
+ char temp[256];
+ stats_repms(temp);
+ out_string(c, temp);
+ return;
}
- pos += sprintf(pos, "END");
- out_string(c, temp);
- return;
- }
-
- if (strcmp(subcommand, "repgrp") == 0) {
- char temp[1024];
- char *pos = temp;
- int ret;
- if (bdb_settings.is_replicated == 1){
- DB_REPMGR_SITE *list = NULL;
- u_int count, i;
- if ((0 == env->repmgr_site_list(env, &count, &list))) {
- for (i = 0; i < count; ++i) {
- pos += sprintf(pos, "STAT %d/%s:%d/%d\r\n",
list[i].eid, list[i].host, list[i].port, list[i].status);
- }
- }
- if (list != NULL)
- free(list);
- }
- pos += sprintf(pos, "END");
- out_string(c, temp);
- return;
- }
-
- if (strcmp(subcommand, "repms") == 0) {
- char temp[1024];
- char *pos = temp;
- int ret;
- if (bdb_settings.is_replicated == 1){
- DB_REPMGR_SITE *list = NULL;
- u_int count, i;
-
- if (DB_EID_INVALID == bdb_settings.rep_master_eid) {
- pos += sprintf(pos, "STAT rep_whoismaster
REP_UNKNOWN\r\n");
- }
-
- if (BDB_EID_SELF == bdb_settings.rep_master_eid) {
- pos += sprintf(pos, "STAT
rep_whoismaster %s:%d\r\n",bdb_settings.rep_localhost,
bdb_settings.rep_localport);
- }else {
- if ((0 == env->repmgr_site_list(env, &count, &list))) {
- for (i = 0; i < count; ++i) {
- if(bdb_settings.rep_master_eid == list[i].eid) {
- pos += sprintf(pos, "STAT
rep_whoismaster %s:%d\r\n", list[i].host, list[i].port);
- break;
- }
- }
- }
- }
- if (list != NULL)
- free(list);
-
- pos += sprintf(pos, "STAT rep_localhp %s:%d\r\n",
bdb_settings.rep_localhost, bdb_settings.rep_localport);
-
- /* if it is master */
- switch (bdb_settings.rep_is_master) {
- case 1:
- pos += sprintf(pos, "STAT rep_ismaster REP_TRUE\r\n");
- break;
- case 0:
- pos += sprintf(pos, "STAT rep_ismaster REP_FALSE\r\n");
- break;
- default:
- pos += sprintf(pos, "STAT rep_ismaster
REP_UNKNOWN\r\n");
- }
- }
- pos += sprintf(pos, "END");
- out_string(c, temp);
- return;
- }
-
- if (strcmp(subcommand, "replsn") == 0) {
- char temp[128];
- char *pos = temp;
- int ret;
- DB_REP_STAT *statp;
- if (bdb_settings.is_replicated == 1){
- if (env->rep_stat(env, &statp, 0) == 0){
- pos += sprintf(pos, "STAT rep_next_lsn %lu/%lu\r\n",
(u_long)statp->st_next_lsn.file, (u_long)statp->st_next_lsn.offset);
- }
- if (statp != NULL)
- free(statp);
- }
-
- pos += sprintf(pos, "END");
- out_string(c, temp);
- return;
}
#ifdef HAVE_MALLOC_H
@@ -1416,142 +1274,41 @@
assert(c != NULL);
- if (0 == bdb_settings.is_replicated){
- out_string(c, "REP_DISABLE");
- return;
- }
-
- if (ntokens == 2 &&
strcmp(tokens[COMMAND_TOKEN].value, "rep_ismaster") == 0){
- switch (bdb_settings.rep_is_master) {
- case 1:
- out_string(c, "REP_TRUE");
- break;
- case 0:
- out_string(c, "REP_FALSE");
- break;
- default:
- out_string(c, "REP_UNKNOWN");
- }
- return;
-
- }else if (ntokens == 2 &&
strcmp(tokens[COMMAND_TOKEN].value, "rep_whoismaster") == 0){
- DB_REPMGR_SITE *list = NULL;
- u_int count, i;
- char temp[256];
-
- if (0 == bdb_settings.is_replicated){
- out_string(c, "REP_DISABLE");
- return;
- }
-
- if (DB_EID_INVALID == bdb_settings.rep_master_eid) {
- out_string(c, "REP_UNKNOWN");
- return;
- }
-
- if (BDB_EID_SELF == bdb_settings.rep_master_eid) {
- snprintf(temp, 255, "%s:%d",bdb_settings.rep_localhost,
bdb_settings.rep_localport);
- }else {
- if ((0 == env->repmgr_site_list(env, &count, &list))) {
- for (i = 0; i < count; ++i) {
- if(bdb_settings.rep_master_eid == list[i].eid) {
- snprintf(temp,
255, "%s:%d",list[i].host,list[i].port);
- break;
- }
- }
+ if (bdb_settings.is_replicated){
+ if (ntokens == 3 &&
strcmp(tokens[COMMAND_TOKEN].value, "rep_set_priority") == 0){
+ int priority;
+ priority = strtoul(tokens[1].value, NULL, 10);
+ if(errno == ERANGE || priority < 0) {
+ out_string(c, "CLIENT_ERROR bad command line format");
+ return;
}
- }
- out_string(c, temp);
- if (list != NULL)
- free(list);
- return;
-
- }else if (ntokens == 3 &&
strcmp(tokens[COMMAND_TOKEN].value, "rep_set_priority") == 0){
- int priority;
- char temp[32];
- priority = strtoul(tokens[1].value, NULL, 10);
- if(errno == ERANGE || priority < 0) {
- out_string(c, "CLIENT_ERROR bad command line format");
- return;
- }
- bdb_settings.rep_priority = priority > MAX_REP_PRIORITY ?
MAX_REP_PRIORITY : priority;
- if (env->rep_set_priority(env, bdb_settings.rep_priority) != 0){
- out_string(c, "SERVER_ERROR env->rep_set_priority");
+ bdb_settings.rep_priority = priority > MAX_REP_PRIORITY ?
MAX_REP_PRIORITY : priority;
+ if (env->rep_set_priority(env, bdb_settings.rep_priority) !=
0){
+ out_string(c, "SERVER_ERROR env->rep_set_priority");
+ return;
+ }
+ out_string(c, "OK");
return;
- }
- snprintf(temp, 31, "%d", bdb_settings.rep_priority);
- out_string(c, temp);
- }else if (ntokens == 3 &&
strcmp(tokens[COMMAND_TOKEN].value, "rep_set_ack_policy") == 0){
- int ack_policy;
- char temp[32];
- ack_policy = strtoul(tokens[1].value, NULL, 10);
- if(errno == ERANGE || ack_policy <= 0) {
- out_string(c, "CLIENT_ERROR bad command line format");
- return;
- }
- bdb_settings.rep_ack_policy = ack_policy > MAX_REP_ACK_POLICY ?
MAX_REP_ACK_POLICY : ack_policy;
- if (env->repmgr_set_ack_policy(env,
bdb_settings.rep_ack_policy) != 0){
- out_string(c, "SERVER_ERROR env->repmgr_set_ack_policy");
+ } else if (ntokens == 3 &&
strcmp(tokens[COMMAND_TOKEN].value, "rep_set_ack_policy") == 0){
+ int ack_policy;
+ ack_policy = strtoul(tokens[1].value, NULL, 10);
+ if(errno == ERANGE || ack_policy <= 0) {
+ out_string(c, "CLIENT_ERROR bad command line format");
+ return;
+ }
+ bdb_settings.rep_ack_policy = ack_policy >
MAX_REP_ACK_POLICY ? MAX_REP_ACK_POLICY : ack_policy;
+ if (env->repmgr_set_ack_policy(env,
bdb_settings.rep_ack_policy) != 0){
+ out_string(c, "SERVER_ERROR env->repmgr_set_ack_policy");
+ return;
+ }
+ out_string(c, "OK");
return;
- }
- snprintf(temp, 31, "%d", bdb_settings.rep_ack_policy);
- out_string(c, temp);
- }else if (ntokens == 3 &&
strcmp(tokens[COMMAND_TOKEN].value, "rep_set_ack_timeout") == 0){
- u_int32_t ack_timeout;
- char temp[32];
- ack_timeout = strtoul(tokens[1].value, NULL, 10);
- if(errno == ERANGE) {
- out_string(c, "CLIENT_ERROR bad command line format");
- return;
- }
- bdb_settings.rep_ack_timeout = ack_timeout > MAX_REP_ACK_TIMEOUT ?
MAX_REP_ACK_TIMEOUT : ack_timeout;
- if (env->rep_set_timeout(env, DB_REP_ACK_TIMEOUT,
bdb_settings.rep_ack_timeout) != 0){
- out_string(c, "SERVER_ERROR env->repmgr_set_ack_timeout");
- return;
- }
- snprintf(temp, 31, "%d", bdb_settings.rep_ack_timeout);
- out_string(c, temp);
- }else if (ntokens == 3 &&
strcmp(tokens[COMMAND_TOKEN].value, "rep_set_bulk") == 0){
- int bulk;
- char temp[32];
- bulk = strtoul(tokens[1].value, NULL, 10);
- if(errno == ERANGE || bulk < 0) {
- out_string(c, "CLIENT_ERROR bad command line format");
- return;
- }
- bdb_settings.rep_bulk = bulk > MAX_REP_BULK ? MAX_REP_BULK : bulk;
- if (env->rep_set_config(env, DB_REP_CONF_BULK,
bdb_settings.rep_bulk) != 0){
- out_string(c, "SERVER_ERROR env->rep_set_config");
- return;
- }
- snprintf(temp, 31, "%d", bdb_settings.rep_bulk);
- out_string(c, temp);
- }else if (ntokens == 4 &&
strcmp(tokens[COMMAND_TOKEN].value, "rep_set_request") == 0){
- u_int32_t req_min, req_max;
- char temp[32];
- req_min = strtoul(tokens[1].value, NULL, 10);
- if(errno == ERANGE) {
- out_string(c, "CLIENT_ERROR bad command line format");
- return;
- }
- req_max = strtoul(tokens[2].value, NULL, 10);
- if(errno == ERANGE) {
- out_string(c, "CLIENT_ERROR bad command line format");
- return;
- }
-
- bdb_settings.rep_req_min = req_min < MAX_REP_REQUEST_MIN ?
MAX_REP_REQUEST_MIN : req_min;
- bdb_settings.rep_req_max = req_max > MAX_REP_REQUEST_MAX ?
MAX_REP_REQUEST_MAX : req_max;
- if (env->rep_set_request(env, bdb_settings.rep_req_min,
bdb_settings.rep_req_max) != 0){
- out_string(c, "SERVER_ERROR env->set_rep_request");
- return;
+ }else {
+ out_string(c, "ERROR");
}
- snprintf(temp, 31, "%u/%u", bdb_settings.rep_req_min,
bdb_settings.rep_req_max);
- out_string(c, temp);
-
- }else {
+ } else {
out_string(c, "ERROR");
}
return;
@@ -1672,14 +1429,8 @@
process_verbosity_command(c, tokens, ntokens);
- } else if (ntokens >= 2 && ntokens <= 4 &&
- ((strcmp(tokens[COMMAND_TOKEN].value, "rep_ismaster") == 0
) ||
- (strcmp(tokens[COMMAND_TOKEN].value, "rep_whoismaster") ==
0 ) ||
- (strcmp(tokens[COMMAND_TOKEN].value, "rep_set_ack_policy")
== 0 ) ||
-
(strcmp(tokens[COMMAND_TOKEN].value, "rep_set_ack_timeout") == 0 ) ||
- (strcmp(tokens[COMMAND_TOKEN].value, "rep_set_bulk") == 0
) ||
- (strcmp(tokens[COMMAND_TOKEN].value, "rep_set_request") ==
0 ) ||
- (strcmp(tokens[COMMAND_TOKEN].value, "rep_set_priority")
== 0 ))) {
+ } else if (ntokens == 3 &&
((strcmp(tokens[COMMAND_TOKEN].value, "rep_set_ack_policy") == 0) ||
+
(strcmp(tokens[COMMAND_TOKEN].value, "rep_set_priority") == 0) )) {
process_rep_command(c, tokens, ntokens);
@@ -2448,6 +2199,7 @@
printf("-R identifies the host and port used by this site
(required).\n");
printf("-O identifies another site participating in this
replication group\n");
printf("-M/-S start as a master or slave\n");
+ printf("-n number of sites that participat in replication,
default is 2\n");
printf("-----------------------------------------------------------------------\n");
return;
@@ -2649,7 +2401,7 @@
setbuf(stderr, NULL);
/* process arguments */
- while ((c = getopt(argc,
argv, "a:U:p:s:c:hikvl:dru:P:t:b:f:H:B:m:A:L:C:T:e:D:NEMSR:O:")) != -1) {
+ while ((c = getopt(argc,
argv, "a:U:p:s:c:hivl:dru:P:t:b:f:H:B:m:A:L:C:T:e:D:NMSR:O:n:")) != -1) {
switch (c) {
case 'a':
/* access for unix domain socket, as octal mask (like chmod)*/
@@ -2789,6 +2541,9 @@
}
bdb_settings.rep_remoteport = (unsigned short)atoi(portstr);
break;
+ case 'n':
+ bdb_settings.rep_nsites = atoi(optarg);
+ break;
default:
fprintf(stderr, "Illegal argument \"%c\"\n", c);
@@ -2895,30 +2650,6 @@
if (daemonize)
save_pid(getpid(), pid_file);
- /* put all bdb init staff here to make sure all worker thread has beed
initlized*/
- /* here we init bdb env and open db */
- bdb_env_init();
- bdb_db_open();
-
- /* start checkpoint and deadlock detect thread */
- start_chkpoint_thread();
- start_memp_trickle_thread();
- start_dl_detect_thread();
-
- /* register atexit callback function */
- if (0 != atexit(bdb_env_close)) {
- fprintf(stderr, "can not register close_env");
- exit(EXIT_FAILURE);
- }
- if (0 != atexit(bdb_db_close)) {
- fprintf(stderr, "can not register close_db");
- exit(EXIT_FAILURE);
- }
- if (0 != atexit(bdb_chkpoint)) {
- fprintf(stderr, "can not register db_checkpoint");
- exit(EXIT_FAILURE);
- }
-
/* create unix mode sockets after dropping privileges */
if (settings.socketpath != NULL) {
if (server_socket_unix(settings.socketpath,settings.access)) {
@@ -2949,6 +2680,29 @@
exit(EXIT_FAILURE);
}
}
+
+ /* register atexit callback function */
+ if (0 != atexit(bdb_env_close)) {
+ fprintf(stderr, "can not register close_env");
+ exit(EXIT_FAILURE);
+ }
+ if (0 != atexit(bdb_db_close)) {
+ fprintf(stderr, "can not register close_db");
+ exit(EXIT_FAILURE);
+ }
+ if (0 != atexit(bdb_chkpoint)) {
+ fprintf(stderr, "can not register db_checkpoint");
+ exit(EXIT_FAILURE);
+ }
+
+ /* here we init bdb env and open db */
+ bdb_env_init();
+ bdb_db_open();
+
+ /* start checkpoint and deadlock detect thread */
+ start_chkpoint_thread();
+ start_memp_trickle_thread();
+ start_dl_detect_thread();
/* enter the event loop */
event_base_loop(main_base, 0);
Modified: branches/memcachedb-1.2.0/memcachedb.h
==============================================================================
--- branches/memcachedb-1.2.0/memcachedb.h (original)
+++ branches/memcachedb-1.2.0/memcachedb.h Thu Oct 9 00:01:13 2008
@@ -39,10 +39,7 @@
#define MAX_REP_PRIORITY 1000000
#define MAX_REP_ACK_POLICY 6
-#define MAX_REP_ACK_TIMEOUT 3600000000ul
-#define MAX_REP_BULK 1
-#define MAX_REP_REQUEST_MAX 3600000000ul
-#define MAX_REP_REQUEST_MIN 10000ul
+#define MAX_REP_NSITES 1000
/* Default path for a database, and its env home */
#define DBFILE "data.db"
@@ -104,6 +101,8 @@
int patch;
};
+enum mdb_rep_role { MDB_MASTER, MDB_CLIENT, MDB_UNKNOWN };
+
struct bdb_settings {
char *db_file; /* db filename, where dbfile located. */
char *env_home; /* db env home dir path */
@@ -126,7 +125,7 @@
char *rep_remotehost; /* remote host in replication */
int rep_remoteport; /* remote port in replication */
- int rep_is_master; /* 1 on YES, 0 on NO, -1 on UNKNOWN, for two sites
replication */
+ int rep_whoami; /* replication role,
MDB_MASTER/MDB_CLIENT/MDB_UNKNOWN */
int rep_master_eid; /* replication master's eid */
u_int32_t rep_start_policy;
@@ -276,7 +275,7 @@
void bdb_env_close(void);
void bdb_chkpoint(void);
-/* ibuffer management */
+/* item management */
void item_init(void);
item *do_item_from_freelist(void);
int do_item_add_to_freelist(item *it);
@@ -287,6 +286,13 @@
int item_put(char *key, size_t nkey, item *it);
int item_delete(char *key, size_t nkey);
int item_exists(char *key, size_t nkey);
+
+/* bdb related stats */
+void stats_bdb(char *temp);
+void stats_rep(char *temp);
+void stats_repmgr(char *temp);
+void stats_repcfg(char *temp);
+void stats_repms(char *temp);
/* conn management */
conn *do_conn_from_freelist();
Added: branches/memcachedb-1.2.0/stats.c
==============================================================================
--- (empty file)
+++ branches/memcachedb-1.2.0/stats.c Thu Oct 9 00:01:13 2008
@@ -0,0 +1,228 @@
+/*
+ * Copyright 2008 Steve Chu. All rights reserved.
+ *
+ * Use and distribution licensed under the BSD license. See
+ * the LICENSE file for full text.
+ *
+ * Authors:
+ * Steve Chu <stv...@gmail.com>
+ *
+ * $Id: stats.c 2008-10-08 23:08:15Z steve $
+ */
+
+#include "memcachedb.h"
+#include <db.h>
+
+void stats_bdb(char *temp){
+ char *pos = temp;
+ int ret;
+ /* get bdb version */
+ pos += sprintf(pos, "STAT db_ver %d.%d.%d\r\n", bdb_version.majver,
+ bdb_version.minver,
+ bdb_version.patch);
+ /* get page size */
+ if((ret = dbp->get_pagesize(dbp, &bdb_settings.page_size)) == 0){
+ pos += sprintf(pos, "STAT page_size %u\r\n",
bdb_settings.page_size);
+ }
+
+ /* get database type */
+ if((ret = dbp->get_type(dbp, &bdb_settings.db_type)) == 0){
+ if (bdb_settings.db_type == DB_BTREE){
+ pos += sprintf(pos, "STAT db_type btree\r\n");
+ }else if (bdb_settings.db_type == DB_HASH){
+ pos += sprintf(pos, "STAT db_type hash\r\n");
+ }
+ }
+ pos += sprintf(pos, "STAT cache_size %u\r\n", bdb_settings.cache_size);
+ pos += sprintf(pos, "STAT txn_lg_bsize %u\r\n",
bdb_settings.txn_lg_bsize);
+ pos += sprintf(pos, "STAT txn_nosync %d\r\n", bdb_settings.txn_nosync);
+ pos += sprintf(pos, "STAT dldetect_val %d\r\n",
bdb_settings.dldetect_val);
+ pos += sprintf(pos, "STAT chkpoint_val %d\r\n",
bdb_settings.chkpoint_val);
+ pos += sprintf(pos, "STAT memp_trickle_val %d\r\n",
bdb_settings.memp_trickle_val);
+ pos += sprintf(pos, "STAT memp_trickle_percent %d\r\n",
bdb_settings.memp_trickle_percent);
+ pos += sprintf(pos, "END");
+}
+
+void stats_rep(char *temp){
+ char *pos = temp;
+ int ret;
+ DB_REP_STAT *statp = NULL;
+ if (env->rep_stat(env, &statp, 0) == 0){
+ pos += sprintf(pos, "STAT st_bulk_fills %u\r\n",
statp->st_bulk_fills);
+ pos += sprintf(pos, "STAT st_bulk_overflows %u\r\n",
statp->st_bulk_overflows);
+ pos += sprintf(pos, "STAT st_bulk_records %u\r\n",
statp->st_bulk_records);
+ pos += sprintf(pos, "STAT st_bulk_transfers %u\r\n",
statp->st_bulk_transfers);
+ pos += sprintf(pos, "STAT st_client_rerequests %u\r\n",
statp->st_client_rerequests);
+ pos += sprintf(pos, "STAT st_client_svc_miss %u\r\n",
statp->st_client_svc_miss);
+ pos += sprintf(pos, "STAT st_client_svc_req %u\r\n",
statp->st_client_svc_req);
+ pos += sprintf(pos, "STAT st_dupmasters %u\r\n",
statp->st_dupmasters);
+ pos += sprintf(pos, "STAT st_egen %u\r\n", statp->st_egen);
+ pos += sprintf(pos, "STAT st_election_cur_winner %u\r\n",
statp->st_election_cur_winner);
+ pos += sprintf(pos, "STAT st_election_gen %u\r\n",
statp->st_election_gen);
+ pos += sprintf(pos, "STAT st_election_lsn %u/%u\r\n",
statp->st_election_lsn.file,
+
statp->st_election_lsn.offset);
+ pos += sprintf(pos, "STAT st_election_nsites %u\r\n",
statp->st_election_nsites);
+ pos += sprintf(pos, "STAT st_election_nvotes %u\r\n",
statp->st_election_nvotes);
+ pos += sprintf(pos, "STAT st_election_priority %u\r\n",
statp->st_election_priority);
+ pos += sprintf(pos, "STAT st_election_sec %u\r\n",
statp->st_election_sec);
+ pos += sprintf(pos, "STAT st_election_status %u\r\n",
statp->st_election_status);
+ pos += sprintf(pos, "STAT st_election_tiebreaker %u\r\n",
statp->st_election_tiebreaker);
+ pos += sprintf(pos, "STAT st_election_usec %u\r\n",
statp->st_election_usec);
+ pos += sprintf(pos, "STAT st_election_votes %u\r\n",
statp->st_election_votes);
+ pos += sprintf(pos, "STAT st_elections %u\r\n",
statp->st_elections);
+ pos += sprintf(pos, "STAT st_elections_won %u\r\n",
statp->st_elections_won);
+ pos += sprintf(pos, "STAT st_env_id %u\r\n", statp->st_env_id);
+ pos += sprintf(pos, "STAT st_env_priority %u\r\n",
statp->st_env_priority);
+ pos += sprintf(pos, "STAT st_gen %u\r\n", statp->st_gen);
+ pos += sprintf(pos, "STAT st_log_duplicated %u\r\n",
statp->st_log_duplicated);
+ pos += sprintf(pos, "STAT st_log_queued %u\r\n",
statp->st_log_queued);
+ pos += sprintf(pos, "STAT st_log_queued_max %u\r\n",
statp->st_log_queued_max);
+ pos += sprintf(pos, "STAT st_log_queued_total %u\r\n",
statp->st_log_queued_total);
+ pos += sprintf(pos, "STAT st_log_records %u\r\n",
statp->st_log_records);
+ pos += sprintf(pos, "STAT st_log_requested %u\r\n",
statp->st_log_requested);
+ pos += sprintf(pos, "STAT st_master %u\r\n", statp->st_master);
+ pos += sprintf(pos, "STAT st_master_changes %u\r\n",
statp->st_master_changes);
+ pos += sprintf(pos, "STAT st_max_lease_sec %u\r\n",
statp->st_max_lease_sec);
+ pos += sprintf(pos, "STAT st_max_lease_usec %u\r\n",
statp->st_max_lease_usec);
+ pos += sprintf(pos, "STAT st_max_perm_lsn %u/%u\r\n",
statp->st_max_perm_lsn.file,
+
statp->st_max_perm_lsn.offset);
+ pos += sprintf(pos, "STAT st_msgs_badgen %u\r\n",
statp->st_msgs_badgen);
+ pos += sprintf(pos, "STAT st_msgs_processed %u\r\n",
statp->st_msgs_processed);
+ pos += sprintf(pos, "STAT st_msgs_recover %u\r\n",
statp->st_msgs_recover);
+ pos += sprintf(pos, "STAT st_msgs_send_failures %u\r\n",
statp->st_msgs_send_failures);
+ pos += sprintf(pos, "STAT st_msgs_sent %u\r\n",
statp->st_msgs_sent);
+ pos += sprintf(pos, "STAT st_newsites %u\r\n", statp->st_newsites);
+ pos += sprintf(pos, "STAT st_next_lsn %u/%u\r\n",
statp->st_next_lsn.file,
+
statp->st_next_lsn.offset);
+ pos += sprintf(pos, "STAT st_next_pg %u\r\n", statp->st_next_pg);
+ pos += sprintf(pos, "STAT st_nsites %u\r\n", statp->st_nsites);
+ pos += sprintf(pos, "STAT st_nthrottles %u\r\n",
statp->st_nthrottles);
+ pos += sprintf(pos, "STAT st_outdated %u\r\n", statp->st_outdated);
+ pos += sprintf(pos, "STAT st_pg_duplicated %u\r\n",
statp->st_pg_duplicated);
+ pos += sprintf(pos, "STAT st_pg_records %u\r\n",
statp->st_pg_records);
+ pos += sprintf(pos, "STAT st_pg_requested %u\r\n",
statp->st_pg_requested);
+ pos += sprintf(pos, "STAT st_startsync_delayed %u\r\n",
statp->st_startsync_delayed);
+ pos += sprintf(pos, "STAT st_startup_complete %u\r\n",
statp->st_startup_complete);
+ pos += sprintf(pos, "STAT st_status %u\r\n", statp->st_status);
+ pos += sprintf(pos, "STAT st_txns_applied %u\r\n",
statp->st_txns_applied);
+ pos += sprintf(pos, "STAT st_waiting_lsn %u/%u\r\n",
statp->st_waiting_lsn.file,
+
statp->st_waiting_lsn.offset);
+ pos += sprintf(pos, "STAT st_waiting_pg %u\r\n",
statp->st_waiting_pg);
+ }
+ if (statp != NULL)
+ free(statp);
+
+ pos += sprintf(pos, "END");
+}
+
+void stats_repmgr(char *temp){
+ char *pos = temp;
+ int ret;
+ DB_REPMGR_STAT *statp = NULL;
+ if (env->repmgr_stat(env, &statp, 0) == 0){
+ pos += sprintf(pos, "STAT st_perm_failed %u\r\n",
statp->st_perm_failed);
+ pos += sprintf(pos, "STAT st_msgs_queued %u\r\n",
statp->st_msgs_queued);
+ pos += sprintf(pos, "STAT st_msgs_dropped %u\r\n",
statp->st_msgs_dropped);
+ pos += sprintf(pos, "STAT st_connection_drop %u\r\n",
statp->st_connection_drop);
+ pos += sprintf(pos, "STAT st_connect_fail %u\r\n",
statp->st_connect_fail);
+ }
+ if (statp != NULL)
+ free(statp);
+
+ pos += sprintf(pos, "END");
+}
+
+void stats_repcfg(char *temp){
+ char *pos = temp;
+ int ret;
+ if (env->rep_get_priority(env, &bdb_settings.rep_priority) == 0){
+ pos += sprintf(pos, "STAT rep_priority %d\r\n",
bdb_settings.rep_priority);
+ }
+ if (env->repmgr_get_ack_policy(env, &bdb_settings.rep_ack_policy) ==
0){
+ pos += sprintf(pos, "STAT rep_ack_policy %d\r\n",
bdb_settings.rep_ack_policy);
+ }
+ /* timeout configure */
+ if (env->rep_get_timeout(env, DB_REP_ACK_TIMEOUT,
&bdb_settings.rep_ack_timeout) == 0){
+ pos += sprintf(pos, "STAT rep_ack_timeout %u\r\n",
bdb_settings.rep_ack_timeout);
+ }
+ if (env->rep_get_timeout(env, DB_REP_CHECKPOINT_DELAY,
&bdb_settings.rep_chkpoint_delay) == 0){
+ pos += sprintf(pos, "STAT rep_chkpoint_delay %u\r\n",
bdb_settings.rep_chkpoint_delay);
+ }
+ if (env->rep_get_timeout(env, DB_REP_CONNECTION_RETRY,
&bdb_settings.rep_conn_retry) == 0){
+ pos += sprintf(pos, "STAT rep_conn_retry %u\r\n",
bdb_settings.rep_conn_retry);
+ }
+ if (env->rep_get_timeout(env, DB_REP_ELECTION_TIMEOUT,
&bdb_settings.rep_elect_timeout) == 0){
+ pos += sprintf(pos, "STAT rep_elect_timeout %u\r\n",
bdb_settings.rep_elect_timeout);
+ }
+ if (env->rep_get_timeout(env, DB_REP_ELECTION_RETRY,
&bdb_settings.rep_elect_retry) == 0){
+ pos += sprintf(pos, "STAT rep_elect_retry %u\r\n",
bdb_settings.rep_elect_retry);
+ }
+ /*
+ if (env->rep_get_timeout(env, DB_REP_HEARTBEAT_MONITOR,
&bdb_settings.rep_heartbeat_monitor) == 0){
+ pos += sprintf(pos, "STAT rep_heartbeat_monitor %u\r\n",
bdb_settings.rep_heartbeat_monitor);
+ }
+ if (env->rep_get_timeout(env, DB_REP_HEARTBEAT_SEND,
&bdb_settings.rep_heartbeat_send) == 0){
+ pos += sprintf(pos, "STAT rep_heartbeat_send %u\r\n",
bdb_settings.rep_heartbeat_send);
+ }*/
+ /*
+ if (env->rep_get_timeout(env, DB_REP_LEASE_TIMEOUT,
&bdb_settings.rep_lease_timeout) == 0){
+ pos += sprintf(pos, "STAT rep_lease_timeout %u\r\n",
bdb_settings.rep_lease_timeout);
+ }*/
+
+ /* flag configure */
+ if (env->rep_get_config(env, DB_REP_CONF_BULK, &bdb_settings.rep_bulk)
== 0){
+ pos += sprintf(pos, "STAT rep_bulk %d\r\n", bdb_settings.rep_bulk);
+ }
+ /*
+ if (env->rep_get_config(env, DB_REP_CONF_LEASE,
&bdb_settings.rep_lease) == 0){
+ pos += sprintf(pos, "STAT rep_lease %d\r\n",
bdb_settings.rep_lease);
+ }*/
+ if (env->rep_get_request(env, &bdb_settings.rep_req_min,
&bdb_settings.rep_req_max) == 0){
+ pos += sprintf(pos, "STAT rep_request %u/%u\r\n",
bdb_settings.rep_req_min,
+
bdb_settings.rep_req_max);
+ }
+ /*
+ if (env->rep_get_clockskew(env, &bdb_settings.rep_fast_clock,
&bdb_settings.rep_slow_clock) == 0){
+ pos += sprintf(pos, "STAT rep_clock %u/%u\r\n",
bdb_settings.rep_fast_clock,
+
bdb_settings.rep_slow_clock);
+ } */
+ if (env->rep_get_limit(env, &bdb_settings.rep_limit_gbytes,
&bdb_settings.rep_limit_bytes) == 0){
+ pos += sprintf(pos, "STAT rep_limit %u/%u\r\n",
bdb_settings.rep_limit_gbytes,
+
bdb_settings.rep_limit_bytes);
+ }
+ if (env->rep_get_nsites(env, &bdb_settings.rep_nsites) == 0){
+ pos += sprintf(pos, "STAT rep_nsites %u\r\n",
bdb_settings.rep_nsites);
+ }
+ pos += sprintf(pos, "END");
+}
+
+void stats_repms(char *temp){
+ char *pos = temp;
+ int ret;
+ DB_REPMGR_SITE *list = NULL;
+ u_int count, i;
+
+ /* stats myself */
+ if (bdb_settings.rep_master_eid == DB_EID_INVALID){
+ pos += sprintf(pos, "STAT site-00 %s:%d/UNKNOWN/--\r\n",
bdb_settings.rep_localhost,
+
bdb_settings.rep_localport);
+ } else if (bdb_settings.rep_master_eid == BDB_EID_SELF){
+ pos += sprintf(pos, "STAT site-00 %s:%d/MASTER/--\r\n",
bdb_settings.rep_localhost,
+
bdb_settings.rep_localport);
+ } else {
+ pos += sprintf(pos, "STAT site-00 %s:%d/CLIENT/--\r\n",
bdb_settings.rep_localhost,
+
bdb_settings.rep_localport);
+ }
+
+ /* stats others */
+ if ((0 == env->repmgr_site_list(env, &count, &list))) {
+ for (i = 0; i < count; ++i) {
+ pos += sprintf(pos, "STAT site-%02d %s:%d/%s/%s\r\n", i+1,
list[i].host, list[i].port,
+ (bdb_settings.rep_master_eid ==
list[i].eid ? "MASTER" : "CLIENT"),
+ (list[i].status ==
DB_REPMGR_CONNECTED ? "CONNECTED": "DISCONNECTED"));
+ }
+ }
+ if (list != NULL)
+ free(list);
+ pos += sprintf(pos, "END");
+}
\ No newline at end of file