CLD replication (WIP)
PATCH 1/1 CLD replication (WIP)
[resend #1... not sure where first try went]
Attached is the current CLD replication patch, which takes CLD from being a single-node service to a fully replicated, highly available service.
The server implementation should be complete.
The current merge blocker is needed code in libcldc, which does not yet properly "hunt" for a master, among a group of peer CLD replicas in a CLD cell.
This will be a big milestone for CLD, when merged. The next milestone will be adding the needed strict-cache-coherence caching semantics to CLD server and client lib.
This patch was generated against git commit 511b8dafb233ee85e60ddf7eda212f87963e150c.
Quoted 10 lines
server/cld.h | 20 +++ server/cldb.c | 69 +++++++++++-- server/cldb.h | 9 + server/cldbadm.c | 8 - server/server.c | 286 +++++++++++++++++++++++++++++++++++++++++++++++++++--- test/pid-exists | 13 +- test/prep-db | 19 ++- test/start-daemon | 26 ++++ test/stop-daemon | 32 ++++-- 9 files changed, 428 insertions(+), 54 deletions(-)
server/cld.h +20 -0
@@ -91,6 +91,15 @@ struct msg_params {size_t msg_len; }; +enum st_cldb { +ST_CLDB_INIT , +ST_CLDB_OPEN , +ST_CLDB_ACTIVE , +ST_CLDB_MASTER , +ST_CLDB_SLAVE , +ST_CLDBNUM +}; +struct server_stats {unsigned long poll;/* number polls */ unsigned long event;/* events dispatched */
@@ -114,6 +123,17 @@ struct server {int pid_fd;char *port;/* bind port */ +unsigned short rep_port;/* db4 replication port */ + +char *myhost; +char *force_myhost; +GList *rep_remotes; + +unsigned int n_peers;/* total peers in cell */ + +int rep_pipe[2 ]; + +enum st_cldb state_cldb, state_cldb_new;struct cldb cldb;/* database info */
server/cldb.c +61 -8
119 lines not on this page · raw message
server/cldb.h +8 -1
@@ -107,6 +107,11 @@ enum db_event { CLDB_EV_NONE, CLDB_EV_CLIENT, CLDB_EV_MASTER, CLDB_EV_ELECTED }; +struct db_remote {/* remotes for cldb_init */ +char *host; +unsigned short port; +}; +struct cldb {bool is_master;bool keyed;/* using encryption? */
@@ -133,7 +138,9 @@ struct cldb {extern int cldb_init (struct cldb *cldb,const char *db_home,const char *db_password,unsigned int env_flags,const char *errpfx,bool do_syslog, -unsigned int flags,void (*cb)(enum db_event )); +GList *remotes,char *rep_host,unsigned short rep_port, +int n_peers,void (*cb)(enum db_event )); +extern int cldb_up (struct cldb *cldb,unsigned int flags);extern void cldb_down (struct cldb *cldb);extern void cldb_fini (struct cldb *cldb);
server/cldbadm.c +5 -3
@@ -78,7 +78,8 @@ int main(int argc, char *argv[]) }if (cldb_init (&cld_adm.cldb, cld_adm.data_dir,NULL , -DB_RECOVER ,"cldbadm" , false,0 ,NULL )) +DB_RECOVER ,"cldbadm" , false, +NULL ,NULL ,0 ,0 ,NULL )) goto err_dbopen;switch (cld_adm.mode) {
@@ -142,8 +143,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)* Stubs for contents of cldb.c */ int cldb_init (struct cldb *cldb,const char *db_home,const char *db_password, -unsigned int env_flags,const char *errpfx,bool do_syslog, -unsigned int flags,void (*cb)(enum db_event )) +unsigned int env_flags,const char *errpfx,bool do_syslog, +GList *remotes,char *rep_host,unsigned short rep_port, +int n_peers,void (*cb)(enum db_event )) {return 0 ;
server/server.c +271 -15
404 lines not on this page · raw message
test/pid-exists +8 -5
@@ -1,9 +1,12 @@ #!/bin/sh -if [ ! -f cld.pid ] -then - echo "pid file not found." - exit 1 -fi +for n in 1 2 3 +do + if [ ! -f cld$n.pid ] + then + echo "cld$n.pid not found." + exit 1 + fi +done exit 0
test/prep-db +11 -8
@@ -2,13 +2,16 @@ DATADIR=data -mkdir -p $DATADIR - -if [ ! -d $DATADIR ] -then - rm -rf $DATADIR - echo "test database dir not found." - exit 1 -fi +for n in 1 2 3 +do + mkdir -p $DATADIR/n$n/data + + if [ ! -d $DATADIR/n$n/data ] + then + rm -rf $DATADIR + echo "test database dir for node $n not found." + exit 1 + fi +done exit 0
test/start-daemon +22 -4
@@ -1,13 +1,31 @@ #!/bin/sh -if [ -f cld.pid ] +if [ -f cld1.pid -o -f cld2.pid -o -f cld3.pid ] then - echo "pid file found. daemon still running?" + echo "pid file found. daemons still running?" exit 1 fi -../server/cld -P cld.pid -d "$PWD/data" -p 18181 -E +../server/cld -d "$PWD/data/n1/data" -p 18181 -r 19181 -P cld1.pid -E \ + -D 2 -S 3 \ + -m localhost.localdomain \ + -R localhost.localdomain:19182 \ + -R localhost.localdomain:19183 -sleep 3 +../server/cld -d "$PWD/data/n2/data" -p 18182 -r 19182 -P cld2.pid -E \ + -D 2 -S 3 \ + -m localhost.localdomain \ + -R localhost.localdomain:19181 \ + -R localhost.localdomain:19183 + +../server/cld -d "$PWD/data/n3/data" -p 18183 -r 19183 -P cld3.pid -E \ + -D 2 -S 3 \ + -m localhost.localdomain \ + -R localhost.localdomain:19181 \ + -R localhost.localdomain:19182 +sleep 1 + +echo " start-daemon: Waiting 20s, for daemons to start up..." +sleep 20 exit 0
test/stop-daemon +22 -10
@@ -1,23 +1,35 @@ #!/bin/sh -if [ ! -f cld.pid ] -then - echo no daemon pid file found. - exit 1 -fi +for n in 1 2 3 +do + if [ ! -f cld$n.pid ] + then + echo " stop-daemon: cld$n.pid not found." + exit 1 + fi +done + -kill `cat cld.pid` +kill `cat cld1.pid cld2.pid cld3.pid` for ((n = 0; n < 10; n++)) do - if [ ! -f cld.pid ] + if [ -f cld1.pid -o -f cld2.pid -o -f cld3.pid ] then + sleep 1 + else exit 0 fi - sleep 1 done -echo "PID file not removed, after signal sent." -rm -f cld.pid +for n in 1 2 3 +do + if [ -f cld$n.pid ] + then + echo " stop-daemon: cld$n.pid found, after signal sent." + fi +done + +rm -f cld?.pid exit 1
PATCH v2 1/1 CLD replication (WIP)
Attached is the current CLD replication patch, which takes CLD from being a single-node service to a fully replicated, highly available service.
The server implementation should be complete.
The current merge blocker is needed code in libcldc, which does not yet properly "hunt" for a master, among a group of peer CLD replicas in a CLD cell.
This will be a big milestone for CLD, when merged. The next milestone will be adding the needed strict-cache-coherence caching semantics to CLD server and client lib.
This patch was generated against git commit 924b04dde2792c19dbace6e66aae456eff8a8829.
Changes since last posting:
- rediff for current upstream
Quoted 10 lines
server/cld.h | 20 +++ server/cldb.c | 69 +++++++++++-- server/cldb.h | 9 + server/cldbadm.c | 8 - server/server.c | 286 +++++++++++++++++++++++++++++++++++++++++++++++++++--- test/pid-exists | 13 +- test/prep-db | 19 ++- test/start-daemon | 26 ++++ test/stop-daemon | 16 +-- 9 files changed, 414 insertions(+), 52 deletions(-)
server/cld.h +20 -0
@@ -91,6 +91,15 @@ struct msg_params {size_t msg_len; }; +enum st_cldb { +ST_CLDB_INIT , +ST_CLDB_OPEN , +ST_CLDB_ACTIVE , +ST_CLDB_MASTER , +ST_CLDB_SLAVE , +ST_CLDBNUM +}; +struct server_stats {unsigned long poll;/* number polls */ unsigned long event;/* events dispatched */
@@ -114,6 +123,17 @@ struct server {int pid_fd;char *port;/* bind port */ +unsigned short rep_port;/* db4 replication port */ + +char *myhost; +char *force_myhost; +GList *rep_remotes; + +unsigned int n_peers;/* total peers in cell */ + +int rep_pipe[2 ]; + +enum st_cldb state_cldb, state_cldb_new;struct cldb cldb;/* database info */
server/cldb.c +61 -8
119 lines not on this page · raw message
server/cldb.h +8 -1
@@ -107,6 +107,11 @@ enum db_event { CLDB_EV_NONE, CLDB_EV_CLIENT, CLDB_EV_MASTER, CLDB_EV_ELECTED }; +struct db_remote {/* remotes for cldb_init */ +char *host; +unsigned short port; +}; +struct cldb {bool is_master;bool keyed;/* using encryption? */
@@ -133,7 +138,9 @@ struct cldb {extern int cldb_init (struct cldb *cldb,const char *db_home,const char *db_password,unsigned int env_flags,const char *errpfx,bool do_syslog, -unsigned int flags,void (*cb)(enum db_event )); +GList *remotes,char *rep_host,unsigned short rep_port, +int n_peers,void (*cb)(enum db_event )); +extern int cldb_up (struct cldb *cldb,unsigned int flags);extern void cldb_down (struct cldb *cldb);extern void cldb_fini (struct cldb *cldb);
server/cldbadm.c +5 -3
@@ -78,7 +78,8 @@ int main(int argc, char *argv[]) }if (cldb_init (&cld_adm.cldb, cld_adm.data_dir,NULL , -DB_RECOVER ,"cldbadm" , false,0 ,NULL )) +DB_RECOVER ,"cldbadm" , false, +NULL ,NULL ,0 ,0 ,NULL )) goto err_dbopen;switch (cld_adm.mode) {
@@ -142,8 +143,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)* Stubs for contents of cldb.c */ int cldb_init (struct cldb *cldb,const char *db_home,const char *db_password, -unsigned int env_flags,const char *errpfx,bool do_syslog, -unsigned int flags,void (*cb)(enum db_event )) +unsigned int env_flags,const char *errpfx,bool do_syslog, +GList *remotes,char *rep_host,unsigned short rep_port, +int n_peers,void (*cb)(enum db_event )) {return 0 ;
server/server.c +271 -15
403 lines not on this page · raw message
test/pid-exists +8 -5
@@ -1,9 +1,12 @@ #!/bin/sh -if [ ! -f cld.pid ] -then - echo "pid file not found." - exit 1 -fi +for n in 1 2 3 +do + if [ ! -f cld$n.pid ] + then + echo "cld$n.pid not found." + exit 1 + fi +done exit 0
test/prep-db +11 -8
@@ -2,13 +2,16 @@ DATADIR=data -mkdir -p $DATADIR - -if [ ! -d $DATADIR ] -then - rm -rf $DATADIR - echo "test database dir not found." - exit 1 -fi +for n in 1 2 3 +do + mkdir -p $DATADIR/n$n/data + + if [ ! -d $DATADIR/n$n/data ] + then + rm -rf $DATADIR + echo "test database dir for node $n not found." + exit 1 + fi +done exit 0
test/start-daemon +22 -4
@@ -1,13 +1,31 @@ #!/bin/sh -if [ -f cld.pid ] +if [ -f cld1.pid -o -f cld2.pid -o -f cld3.pid ] then - echo "pid file found. daemon still running?" + echo "pid file found. daemons still running?" exit 1 fi -../server/cld -P cld.pid -d "$PWD/data" -p 18181 -E +../server/cld -d "$PWD/data/n1/data" -p 18181 -r 19181 -P cld1.pid -E \ + -D 2 -S 3 \ + -m localhost.localdomain \ + -R localhost.localdomain:19182 \ + -R localhost.localdomain:19183 -sleep 3 +../server/cld -d "$PWD/data/n2/data" -p 18182 -r 19182 -P cld2.pid -E \ + -D 2 -S 3 \ + -m localhost.localdomain \ + -R localhost.localdomain:19181 \ + -R localhost.localdomain:19183 + +../server/cld -d "$PWD/data/n3/data" -p 18183 -r 19183 -P cld3.pid -E \ + -D 2 -S 3 \ + -m localhost.localdomain \ + -R localhost.localdomain:19181 \ + -R localhost.localdomain:19182 +sleep 1 + +echo " start-daemon: Waiting 20s, for daemons to start up..." +sleep 20 exit 0
test/stop-daemon +8 -8
@@ -1,23 +1,23 @@ #!/bin/sh -if [ ! -f cld.pid ] +if [ ! -f cld1.pid -o ! -f cld2.pid -o ! -f cld3.pid ] then - echo no daemon pid file found. + echo at least one daemon pid file missing. exit 1 fi -kill `cat cld.pid` +kill `cat cld*.pid` for n in 0 1 2 3 4 5 6 7 8 9 do - if [ ! -f cld.pid ] + if [ -f cld1.pid -o -f cld2.pid -o -f cld3.pid ] then + sleep 1 + else exit 0 fi - - sleep 1 done -echo "PID file not removed, after signal sent." -rm -f cld.pid +echo "PID file(s) not removed, after signal sent." +rm -f cld*.pid exit 1