Fix crash when stopping slave
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/5 Fix crash when stopping slave
When a slave is shut down, it crashes, because we cannot call tdb_down without tdb_up, and that obviously only happens on a master. Also, plug a problem inside rtdb_fini (needs a better fix but should do for now).
--- server/metarep.c | 9 ++++++++- server/server.c | 11 +++-------- 2 files changed, 11 insertions(+), 9 deletions(-)
commit dd6ed2529efa71902f7ac1958f01a2541b4f9133
Author: Pete Zaitcev <[email protected]> Date: Thu Aug 12 12:27:48 2010 -0600
Crash on tdb_down if slave.
server/metarep.c +8 -1
@@ -1240,6 +1240,13 @@ int rtdb_restart(struct tablerep *rtdb, bool we_are_master)void rtdb_fini (struct tablerep *rtdb) {__rtdb_fini (rtdb); -tdb_fini (&rtdb->tdb); +/* +* This check is ewwww, but unfortunately there's potentially a gap +* between DB going master and us bringing up the environment. +* If we condition the tdb_fini on DB status, we'll end crashing +* if the server terminates during the gap. +*/ +if (rtdb->tdb.env) +tdb_fini (&rtdb->tdb); }
server/server.c +3 -8
@@ -2326,18 +2326,13 @@ int main (int argc, char *argv[])applog (LOG_INFO ,"shutting down" ); rc =0 ; - +if (tabled_srv.state_tdb ==ST_TDB_MASTER ) +tdb_down (&tdbrep.tdb);cld_end (); err_cld_session:/* net_close(); */ err_out_net: -if (tabled_srv.state_tdb ==ST_TDB_MASTER || - tabled_srv.state_tdb ==ST_TDB_SLAVE ) { -tdb_down (&tdbrep.tdb); -rtdb_fini (&tdbrep); - }else if (tabled_srv.state_tdb ==ST_TDB_OPEN ) { -rtdb_fini (&tdbrep); - } +rtdb_fini (&tdbrep); err_rtdb:event_del (&tabled_srv.pevt); err_pevt:
PATCH 2/5 Clean name vs host
In reply to a message not in the archiveMop up small problems from the name/host split. In one place we printed "slave (null)". In other place printing name made more sense.
Most importantly, while CLD client used name correctly, we sent a slave login using host (argument to rtdb_start), which was incorrect. Swap that to replication name.
--- server/metarep.c | 2 +- server/server.c | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-)
commit 294393ed1a0789b71b673f894232ba1b5cdb9dc3
Author: Pete Zaitcev <[email protected]> Date: Thu Aug 12 12:30:45 2010 -0600
Cleanup of name vs host.
server/metarep.c +1 -1
@@ -884,7 +884,7 @@ static int rtdb_master_login_reply(struct db_conn *dbc, unsigned char *msgbuf) }if (debugging)applog (LOG_DEBUG ,"Link login, slave %s dbid %d" , - slave->host, slave->dbid); + slave->name, slave->dbid);/* * Dispose of all existing connections. Our current implementation
server/server.c +6 -4
@@ -399,7 +399,7 @@ static void stats_dump(void)applog (LOG_INFO ,"TDB: group %s state %s host %s rep_port %d dbid %d%s" , tabled_srv.group, state_name_tdb[tabled_srv.state_tdb], - tabled_srv.ourhost, tabled_srv.rep_port, tdbrep.thisid, + tabled_srv.rep_name, tabled_srv.rep_port, tdbrep.thisid, (tabled_srv.mc_delay)?" mc_delay" :"" );for (tmp = tabled_srv.rep_remotes; tmp; tmp = tmp->next) { rp = tmp->data;
@@ -447,7 +447,7 @@ bool stat_status(struct client *cli, GList *content)"<p>TDB: group %s " "state %s host %s rep_port %d dbid %d%s</p>\r\n" , tabled_srv.group, state_name_tdb[tabled_srv.state_tdb], - tabled_srv.ourhost, tabled_srv.rep_port, tdbrep.thisid, + tabled_srv.rep_name, tabled_srv.rep_port, tdbrep.thisid, (tabled_srv.mc_delay)? " mc_delay": "") < 0) return false; content =g_list_append (content, str);
@@ -1719,7 +1719,7 @@ int tdb_slave_login_cb(int srcid)if (rtdb_start (&tdbrep, tabled_srv.tdb_dir, false, master, - tabled_srv.rep_port, tdb_state_cb)) { +0 , tdb_state_cb)) { tabled_srv.state_tdb =ST_TDB_INIT ;applog (LOG_ERR ,"Failed to open TDB, limping" );return -1 ;
@@ -2248,6 +2248,8 @@ int main (int argc, char *argv[])else if (debugging)applog (LOG_INFO ,"Forcing local hostname to %s" , tabled_srv.ourhost); +if (!tabled_srv.rep_name) + tabled_srv.rep_name = tabled_srv.ourhost;/* * background outselves, write PID file ASAP
@@ -2294,7 +2296,7 @@ int main (int argc, char *argv[]) }/* late-construct structures with allocations */ -if (rtdb_init (&tdbrep, tabled_srv.ourhost)) { +if (rtdb_init (&tdbrep, tabled_srv.rep_name)) {applog (LOG_WARNING ,"rtdb_init" ); rc =1 ; goto err_rtdb;
PATCH 3/5 cleanup a call to closelog()
In reply to a message not in the archiveSince we're on it, only call closelog() if openlog() was called. There is no crash if we do that, but still it's not very correct.
--- server/server.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
commit ae8ac067adde81a34c9d6114cfbaa1f95c9b48da
Author: Pete Zaitcev <[email protected]> Date: Thu Aug 12 12:33:39 2010 -0600
Syslog cleanup.
server/server.c +2 -1
@@ -2344,7 +2344,8 @@ err_evpipe:unlink (tabled_srv.pid_file);close (tabled_srv.pid_fd); err_out: -closelog (); +if (use_syslog) +closelog ();return rc; }
PATCH 4/5 Support "auto" replicaton port
In reply to a message not in the archiveAllow random ports for replication master to listen on.
The patch is somewhat larger than expected, because before we had the MASTER file written right after locking. Now we may have it written without listening parameters, and the slaves must be ready to deal with it.
Unlike the auto client port, we do not need to write any "accessor" files, because we already report the host and port through CLD.
Listening on random ports has security implications.
--- doc/etc.tabled.conf | 16 ++- server/cldu.c | 166 ++++++++++++++++++++++++++-------------- server/config.c | 22 +++-- server/metarep.c | 34 ++++++++ server/tabled.h | 1 test/tabled-test.conf | 2 6 files changed, 173 insertions(+), 68 deletions(-)
commit 7ca8a587348e315ab7c6c9e32476d8fa387718d5
Author: Pete Zaitcev <[email protected]> Date: Thu Aug 12 12:37:27 2010 -0600
TDBRepPort "auto".
doc/etc.tabled.conf +12 -4
@@ -12,14 +12,22 @@ </Listen> <!-- - One group per DB, don't skimp on groups. Also, make sure the replication - ports do not conflict when you make boxes to host several groups or use - replication instances iwth TDBRepName. + One group per DB, don't skimp on groups. --> <Group>ultracart2</Group> + <TDB>/path/tabled-uc2/</TDB> <!-- mkdir -p /path/tabled-uc2 --> -<!-- <TDBRepName>12345.my_local_node_name.example.com</TDBRepName> --> + +<!-- + The usual practice is to set a fixed TDBRepPort (8083) because this + permits to configure a firewall easily. Remember that replication + has no authentication and authorization whatsoever for now! + When running two test instances on the same host, you may use "auto". + But if so, do not forget to set replication instances with TDBRepName. + By default, a hostname serves fine as an instance name, port is "auto". + --> <TDBRepPort>8083</TDBRepPort> +<!-- <TDBRepName>inst-b.my_local_node_name.example.com</TDBRepName> --> <!-- The clause <CLD> is not to be used in production configurations.
server/cldu.c +112 -54
239 lines not on this page · raw message
server/config.c +13 -9
@@ -211,15 +211,20 @@ static void cfg_elm_end (GMarkupParseContext *context,return ; } - n =strtol (cc->text,NULL ,10 ); -if (n <=0 || n >=65536 ) { -applog (LOG_WARNING , -"TDBRepPort '%s' invalid, ignoring" , cc->text); -free (cc->text); - cc->text =NULL ; -return ; +if (!strcmp (cc->text,"auto" )) { + tabled_srv.rep_port =0 ; + }else { + n =strtol (cc->text,NULL ,10 ); +if (n <=0 || n >=65536 ) { +applog (LOG_WARNING , +"TDBRepPort '%s' invalid, ignoring" , + cc->text); +free (cc->text); + cc->text =NULL ; +return ; + } + tabled_srv.rep_port = n; } - tabled_srv.rep_port = n;free (cc->text); cc->text =NULL ; }
@@ -432,7 +437,6 @@ void read_config(void)memset (&ctx,0 ,sizeof (struct config_context )); tabled_srv.port =strdup ("8080" ); - tabled_srv.rep_port =8083 ;if (!g_file_get_contents (tabled_srv.config, &text, &len,NULL )) { applog(LOG_ERR, "failed to read config file %s",
server/metarep.c +34 -0
@@ -676,6 +676,7 @@ static int rtdb_rep_listen(struct tablerep *rtdb, unsigned short port) {struct sockaddr_in addr4;struct sockaddr_in6 addr6; +socklen_t addr_len;int rc;memset (&addr6,0 ,sizeof (addr6));
@@ -694,6 +695,16 @@ static int rtdb_rep_listen(struct tablerep *rtdb, unsigned short port) tdb_conn_event, rtdb);if (event_add (&rtdb->lsev6,NULL ) <0 )applog (LOG_ERR ,"event_add failed" ); + +if (!port) { + addr_len =sizeof (addr6); +if (getsockname (rtdb->sockfd6, &addr6, &addr_len) <0 ) { +applog (LOG_ERR ,"getsockname failed: %s" , +strerror (errno)); + }else { + port =ntohs (addr6.sin6_port); + } + } }memset (&addr4,0 ,sizeof (addr4));
@@ -712,8 +723,21 @@ static int rtdb_rep_listen(struct tablerep *rtdb, unsigned short port) tdb_conn_event, rtdb);if (event_add (&rtdb->lsev4,NULL ) <0 )applog (LOG_ERR ,"event_add failed" ); + +if (!port) { + addr_len =sizeof (addr4); +if (getsockname (rtdb->sockfd4, &addr4, &addr_len) <0 ) { +applog (LOG_ERR ,"getsockname failed: %s" , +strerror (errno)); + }else { + port =ntohs (addr4.sin_port); + } + } } +if (port) +cld_post_rep_conn (tabled_srv.ourhost, port); +return 0 ; }
@@ -1053,6 +1077,11 @@ static int rtdb_rep_connect(struct db_conn *dbc)return 0 ; } +/* +* Sadly, this has to be idempotent, because it's called for cleanup +* in rtdb_start, and because various link resets may invoke this, then fail. +* So, clear all the tested flags. +*/ static void __rtdb_fini (struct tablerep *rtdb) {struct db_conn *dbc;
@@ -1097,6 +1126,11 @@ static int __rtdb_start(struct tablerep *rtdb, bool we_are_master,applog (LOG_INFO ,"No master yet" );/* P3 */ return -1 ; } +if (!rep_master->host || !rep_master->port) { +/* FIXME This should be retried quicker than usual. */ +applog (LOG_INFO ,"Master not up yet" );/* P3 */ +return -1 ; + }if (!rtdb->mdbc) { dbc =dbc_alloc (rtdb, rep_master);if (!dbc)
server/tabled.h +1 -0
@@ -370,6 +370,7 @@ extern void cld_init(void);extern int cld_begin (const char *fqdn,const char *group,const char *name,int verbose);extern void cldu_add_host (const char *host,unsigned int port); +extern void cld_post_rep_conn (const char *rep_host,unsigned int rep_port);extern void cld_end (void );/* util.c */
test/tabled-test.conf +1 -1
@@ -6,7 +6,7 @@ <PortFile>tabled.acc</PortFile> </Listen> <TDB>data/tdb</TDB> -<TDBRepPort>18083</TDBRepPort> +<TDBRepPort>auto</TDBRepPort> <CLD> <PortFile>cld.port</PortFile>
Re: [tabled patch 4/5] Support "auto" replicaton port
Quoted 7 lines · Pete Zaitcev
Allow random ports for replication master to listen on.
The patch is somewhat larger than expected, because before we had the MASTER file written right after locking. Now we may have it written without listening parameters, and the slaves must be ready to deal with it.
Quoted 6 lines
Unlike the auto client port, we do not need to write any "accessor" files, because we already report the host and port through CLD.
Listening on random ports has security implications.
Signed-off-by Pete Zaitcev<[email protected]>
applied 1-4 of 5
PATCH 5/5 Metadata replication test
In reply to a message not in the archiveThis patch adds a build-time test for the metadata replication feature. Note that this is not a complete test, in particular it does not verify that the database was synched correctly at the slave. But it verifies quite a bit.
--- server/metarep.c | 2 +- test/Makefile.am | 2 + test/metadata-rep | 48 ++++++++++++++++++++++++++++++++++++ test/prep-db | 2 + test/stop-daemon | 15 ++++++++--- test/tabled-test-bis.conf | 21 +++++++++++++++ test/wait-for-listen.c | 11 +++++++- 6 files changed, 94 insertions(+), 5 deletions(-)
commit 5a8b74d5541bbdf111f037246883182efaf637ba
Author: Pete Zaitcev <[email protected]> Date: Thu Aug 12 12:44:30 2010 -0600
Test for metadata replication (incomlete - does not verify key integrity, just that server thinks it went slave).
test/Makefile.am +2 -0
@@ -7,6 +7,7 @@ EXTRA_DIST = \ users.data \ chunkd-test.conf \ tabled-test.conf \ + tabled-test-bis.conf \ prep-db \ start-daemon \ pid-exists \
@@ -26,6 +27,7 @@ TESTS = \ large-object \ hdr-content-type \ hdr-meta \ + metadata-rep \ stop-daemon \ clean-db
test/metadata-rep new file +48 -0
48 lines not on this page · raw message
test/prep-db +2 -0
@@ -2,10 +2,12 @@ DATADIR=data TDBDIR=$DATADIR/tdb +TDB2DIR=$DATADIR/tdb-bis CLDDIR=$DATADIR/cld CHUNKDIR=$DATADIR/chunk mkdir -p $TDBDIR +mkdir -p $TDB2DIR mkdir -p $CLDDIR mkdir -p $CHUNKDIR
test/stop-daemon +11 -4
@@ -19,28 +19,35 @@ killpid () { return 1 } -rm -f cld.port tabled.acc +rm -f cld.port tabled.acc tabled-bis.acc tabled-bis.log ret=0 if [ ! -f tabled.pid ] then # Just a warning. Previous test somehow made the daemon to die. - echo "No tabled PID file found." >&2 + echo "No tabled.pid file found." >&2 else killpid tabled.pid || ret=1 fi +if [ ! -f tabled-bis.pid ] +then + echo "No tabled-bis.pid file found." >&2 +else + killpid tabled-bis.pid || ret=1 +fi + if [ ! -f chunkd.pid ] then - echo "No chunkd PID file found." >&2 + echo "No chunkd.pid file found." >&2 else killpid chunkd.pid || ret=1 fi if [ ! -f cld.pid ] then - echo "No cld PID file found." >&2 + echo "No cld.pid file found." >&2 else killpid cld.pid || ret=1 fi
test/tabled-test-bis.conf new file +21 -0
@@ -0,0 +1,21 @@ + +<PID>tabled-bis.pid</PID> +<ForceHost>localhost.localdomain</ForceHost> +<Listen> + <Port>auto</Port> + <PortFile>tabled-bis.acc</PortFile> +</Listen> +<TDB>data/tdb-bis</TDB> +<TDBRepPort>auto</TDBRepPort> +<TDBRepName>bis.localhost.localdomain</TDBRepName> + +<CLD> + <PortFile>cld.port</PortFile> + <Host>localhost</Host> +</CLD> + +<ChunkUser>testuser</ChunkUser> +<ChunkKey>testuser</ChunkKey> + +<!-- Setting "default" just to make sure tabled configures it correctly. --> +<Group>default</Group>
test/wait-for-listen.c +10 -1
@@ -86,13 +86,22 @@ int main(int argc, char **argv) {struct server_node snode, *sn = &snode;time_t start_time; -const static char accname[] =TEST_FILE_TB ; +char *accname;char accbuf[80 ];char *s;int cnt;int sfd;int rc; +if (argc ==2 ) { + accname = argv[1 ]; + }else if (argc ==1 ) { + accname =TEST_FILE_TB ; + }else { +fprintf (stderr,"Usage: wait-for-listen [accessor.file]\n" ); +exit (1 ); + } + cnt =0 ;for (;;) { rc =tb_readport (accname, accbuf,sizeof (accbuf));