Metadata replication in tabled
I worked on fixing the metadata replication in tabled. There were some difficulties in existing code, in particular the aliasing between the hostname used to identify nodes and the hostname used in bind() for listening was impossible to work around in repmgr. In the end I gave up on repmgr and switched tabled to the "Base" API. So, the replication works now... for some values of "works", which is still a progress.
We essentially have a tabled that can really be considered as replicated. Before, it was only data replication, which was great and all but useless against disk failues in the tabled's database. I think it's a major treshold for tabled.
Unfortunately, the code is rather ugly. I tried to create a kind of an optional replication layer, so that tdbadm could be built without it. Although I succeeded, the result is a hideous mess of methods and callbacks, functions with side effects, and a bunch of poorly laid out state machines. In places I cannot wrap my own head around what's going on without a help of pencil and paper.
So, while working, it's not ready for going in. Still, I'm going to throw it here in case I get hit by a bus, or if anyone wants an example of using db4 replication early.
-- Pete
include/tdb.h +11 -9
@@ -22,6 +22,8 @@#include <stdint.h> #include <stdbool.h> #include <glib.h> +#include <event.h> +#include <elist.h> #include <db.h> #define MAXWAY 3
@@ -100,6 +102,9 @@ struct tabledb {const char *home;/* database home dir */ void (*state_cb)(enum db_event ); +const char *errpfx; +bool do_syslog; +DB_ENV *env;/* db4 env ptr */ DB *passwd;/* user/password db */ DB *buckets;/* bucket db */
@@ -109,15 +114,12 @@ struct tabledb {DB *oids;/* object ID db */ }; -struct db_remote {/* remotes for tdb_init */ -char *host; -unsigned short port; -}; - -extern int tdb_init (struct tabledb *tdb,const char *home,const char *pass, -unsigned int env_flags,const char *errpfx,bool do_syslog, -GList *remotes,char *rep_host,unsigned short rep_port, -void (*cb)(enum db_event )); +extern int tdb_init (struct tabledb *tdb,const char *db_home, +const char *db_password,const char *errpfx,bool do_syslog, +int rep_our_id, +int (*rep_send)(DB_ENV *dbenv,const DBT *ctl,const DBT *rec, +const DB_LSN *lsnp,int envid,uint32_t flags), +bool we_are_master,void (*cb)(enum db_event ));extern int tdb_up (struct tabledb *tdb,unsigned int open_flags);extern void tdb_down (struct tabledb *tdb);extern void tdb_fini (struct tabledb *tdb);
lib/tdb.c +99 -71
282 lines not on this page · raw message
server/Makefile.am +1 -1
@@ -4,7 +4,7 @@ INCLUDES = -I$(top_srcdir)/include @GLIB_CFLAGS@ @CHUNKDC_CFLAGS@ @CLDC_CFLAGS@ sbin_PROGRAMS = tabled tdbadm tabled_SOURCES = tabled.h \ - bucket.c cldu.c config.c object.c replica.c \ + bucket.c cldu.c config.c object.c metarep.c replica.c \ server.c status.c storage.c storparse.c util.c tabled_LDADD = ../lib/libhttputil.a ../lib/libtdb.a \ @CHUNKDC_LIBS@ @CLDC_LIBS@ @PCRE_LIBS@ @GLIB_LIBS@ \
server/bucket.c +17 -17
@@ -43,11 +43,11 @@ bool has_access(const char *user, const char *bucket, const char *key,size_t alloc_len, key_len =0 ;struct db_acl_key *acl_key;struct db_acl_ent *acl; -DB_ENV *dbenv = tdb.env; +DB_ENV *dbenv = tdbrep.tdb.env;DB_TXN *txn =NULL ;DBT pkey, pval;DBC *cur =NULL ; -DB *acls = tdb.acls; +DB *acls = tdbrep.tdb.acls;if (user ==NULL ) user =DB_ACL_ANON ;
@@ -132,7 +132,7 @@ err_out:static int add_access_user (DB_TXN *txn,const char *bucket,const char *key,const char *user,const char *perms) { -DB *acls = tdb.acls; +DB *acls = tdbrep.tdb.acls;int key_len;int acl_len;struct db_acl_ent *acl;
@@ -203,8 +203,8 @@ bool service_list(struct client *cli, const char *user)bool rcb;DB_TXN *txn =NULL ;DBC *cur =NULL ; -DB_ENV *dbenv = tdb.env; -DB *bidx = tdb.buckets_idx; +DB_ENV *dbenv = tdbrep.tdb.env; +DB *bidx = tdbrep.tdb.buckets_idx;DBT skey, pkey, pval; if (asprintf(&s,
@@ -348,7 +348,7 @@ bool bucket_valid(const char *bucket)static int bucket_find (DB_TXN *txn,const char *bucket,char *owner,int owner_len) { -DB *buckets = tdb.buckets; +DB *buckets = tdbrep.tdb.buckets;DBT key, val;struct db_bucket_ent ent;int rc;
@@ -455,9 +455,9 @@ bool bucket_add(struct client *cli, const char *user, const char *bucket)struct db_bucket_ent ent;bool setacl;/* is ok to put pre-existing bucket */ enum ReqACLC canacl; -DB *buckets = tdb.buckets; -DB *acls = tdb.acls; -DB_ENV *dbenv = tdb.env; +DB *buckets = tdbrep.tdb.buckets; +DB *acls = tdbrep.tdb.acls; +DB_ENV *dbenv = tdbrep.tdb.env;DB_TXN *txn =NULL ;DBT key, val;
@@ -589,11 +589,11 @@ bool bucket_del(struct client *cli, const char *user, const char *bucket)enum errcode err = InternalError;int rc;struct db_bucket_ent ent; -DB_ENV *dbenv = tdb.env; +DB_ENV *dbenv = tdbrep.tdb.env;DB_TXN *txn =NULL ; -DB *buckets = tdb.buckets; -DB *acls = tdb.acls; -DB *objs = tdb.objs; +DB *buckets = tdbrep.tdb.buckets; +DB *acls = tdbrep.tdb.acls; +DB *objs = tdbrep.tdb.objs;DBC *cur =NULL ;DBT key, val;char structbuf[sizeof (struct db_acl_key ) +32 ];
@@ -922,9 +922,9 @@ static bool bucket_list_keys(struct client *cli, const char *user,size_t pfx_len;struct bucket_list_info bli;bool rcb; -DB_ENV *dbenv = tdb.env; +DB_ENV *dbenv = tdbrep.tdb.env;DB_TXN *txn =NULL ; -DB *objs = tdb.objs; +DB *objs = tdbrep.tdb.objs;DBC *cur =NULL ;DBT pkey, pval;struct db_obj_key *obj_key;
@@ -1159,8 +1159,8 @@ bool access_list(struct client *cli, const char *bucket, const char *key,GHashTable *param;enum errcode err = InternalError; -DB_ENV *dbenv = tdb.env; -DB *acls = tdb.acls; +DB_ENV *dbenv = tdbrep.tdb.env; +DB *acls = tdbrep.tdb.acls;int alloc_len;char owner[64 ];GList *res;
server/cldu.c +312 -43
454 lines not on this page · raw message
server/metarep.c new file +1175 -0
1,175 lines not on this page · raw message
server/object.c +11 -11
@@ -39,7 +39,7 @@static int object_find (DB_TXN *txn,const char *bucket,const char *key,struct db_obj_ent *pobj) { -DB *objs = tdb.objs; +DB *objs = tdbrep.tdb.objs;struct db_obj_key *okey;size_t alloc_len;DBT pkey, pval;
@@ -72,7 +72,7 @@ static int object_find(DB_TXN *txn, const char *bucket, const char *key,static bool __object_del (DB_TXN *txn,const char *bucket,const char *key) { -DB *objs = tdb.objs; +DB *objs = tdbrep.tdb.objs;struct db_obj_key *okey;size_t okey_len;DBT pkey;
@@ -100,7 +100,7 @@ static bool __object_del(DB_TXN *txn, const char *bucket, const char *key)bool object_del_acls (DB_TXN *txn,const char *bucket,const char *key) { -DB *acls = tdb.acls; +DB *acls = tdbrep.tdb.acls;struct db_acl_key *akey;size_t alloc_len;DBT pkey;
@@ -163,8 +163,8 @@ bool object_del(struct client *cli, const char *user,int rc;enum errcode err = InternalError;size_t alloc_len; -DB_ENV *dbenv = tdb.env; -DB *objs = tdb.objs; +DB_ENV *dbenv = tdbrep.tdb.env; +DB *objs = tdbrep.tdb.objs;struct db_obj_key *okey;struct db_obj_ent obje;DBT pkey, pval;
@@ -326,9 +326,9 @@ static bool object_put_end(struct client *cli)struct db_obj_ent oldobj;bool delobj;size_t alloc_len; -DB_ENV *dbenv = tdb.env; +DB_ENV *dbenv = tdbrep.tdb.env;DBT pkey, pval; -DB *objs = tdb.objs; +DB *objs = tdbrep.tdb.objs;DB_TXN *txn =NULL ;GByteArray *string_data;GArray *string_lens;
@@ -781,7 +781,7 @@ static bool object_put_body(struct client *cli, const char *user,return cli_err (cli, InternalError); } - objid =objid_next (&tabled_srv.object_count, &tdb); + objid =objid_next (&tabled_srv.object_count, &tdbrep.tdb); rc =open_chunks (&cli->out_ch, &tabled_srv.all_stor, cli, objid, content_len);
@@ -860,9 +860,9 @@ static bool object_put_acls(struct client *cli, const char *user, {enum errcode err = InternalError;enum ReqACLC canacl; -DB_ENV *dbenv = tdb.env; +DB_ENV *dbenv = tdbrep.tdb.env;DB_TXN *txn =NULL ; -DB *objs = tdb.objs; +DB *objs = tdbrep.tdb.objs;char *hdr;char timestr[64 ];int rc;
@@ -1114,7 +1114,7 @@ static bool object_get_body(struct client *cli, const char *user,bool access_ok, modified = true;GString *extra_hdr;size_t alloc_len; -DB *objs = tdb.objs; +DB *objs = tdbrep.tdb.objs;struct db_obj_key *okey;struct db_obj_ent *obj =NULL ;DBT pkey, pval;
server/replica.c +4 -11
@@ -601,13 +601,6 @@ static void rep_scan_verify(struct rep_arg *arg, oid =GUINT64_FROM_LE (obj->d.a.oid); -applog (LOG_INFO ,"bucket %s key %s oid %llX n(%u,%u,%u): all %d ok %d" , - bucket_name, object_name, (long long ) oid, -GUINT32_FROM_LE (obj->d.a.nidv[0 ]), -GUINT32_FROM_LE (obj->d.a.nidv[1 ]), -GUINT32_FROM_LE (obj->d.a.nidv[2 ]), - allcnt, redcnt); -if (redcnt <MAXWAY ) {/* maybe have MINWAY too? */ rep_job_start (arg, cp->klen, cp->key, oid,GUINT64_FROM_LE (obj->size), redcnt, redvec);
@@ -619,8 +612,8 @@ static void rep_scan_verify(struct rep_arg *arg,static void rep_add_nid (unsigned int klen,struct db_obj_key *key,uint32_t nid) { -DB_ENV *db_env = tdb.env; -DB *db_objs = tdb.objs; +DB_ENV *db_env = tdbrep.tdb.env; +DB *db_objs = tdbrep.tdb.objs;DB_TXN *db_txn;DBT pkey, pval;struct db_obj_ent *obj;
@@ -756,8 +749,8 @@ static void rep_scan(struct rep_arg *arg)g_mutex_unlock (kscan_mutex);memset (&cur,0 ,sizeof (struct cursor ));/* enough to construct */ - cur.db_env = tdb.env; - cur.db_objs = tdb.objs; + cur.db_env = tdbrep.tdb.env; + cur.db_objs = tdbrep.tdb.objs; kcnt =0 ;for (;;) {
server/server.c +253 -49
455 lines not on this page · raw message
server/tabled.h +83 -2
127 lines not on this page · raw message
server/tdbadm.c +12 -39
94 lines not on this page · raw message
test/start-daemon +4 -0
@@ -18,6 +18,10 @@ fi # May be different on Solaris... like /usr/libexec or such. cld -d data/cld -P cld.pid -p auto --port-file=cld.port -E + +# With great sadness we have to use a delay, or else "100 s" happens. +sleep 3 + chunkd -C $top_srcdir/test/chunkd-test.conf -E ../server/tabled -C $top_srcdir/test/tabled-test.conf -E
test/wait-for-listen.c +2 -5
@@ -133,12 +133,9 @@ int main(int argc, char **argv)* Vote in DB4 replication takes about 12-13s. * In addition we may have retries when tabled polls for * Chunk daemons to come up. On busy boxes we may miss 20s. -* So, 25s should be plenty, and we used that for a while, -* but sometimes a daemon can fail establishing a session -* with CLD and a retry takes a minute. */ -if (time (NULL ) >= start_time +100 ) { -fprintf (stderr,"server is not up after 100 s\n" ); +if (time (NULL ) >= start_time +25 ) { +fprintf (stderr,"server is not up after 25 s\n" );exit (1 ); }
Quoted 11 lines · Pete Zaitcev
I worked on fixing the metadata replication in tabled. There were some difficulties in existing code, in particular the aliasing between the hostname used to identify nodes and the hostname used in
bind()for listening was impossible to work around in repmgr. In the end I gave up on repmgr and switched tabled to the "Base" API. So, the replication works now... for some values of "works", which is still a progress.We essentially have a tabled that can really be considered as replicated. Before, it was only data replication, which was great and all but useless against disk failues in the tabled's database. I think it's a major treshold for tabled.
er, huh? In addition to data replication, we already have metadata replication via db4 repmgr in tabled.git, which ensures metadata db integrity in the case of disk or tabled node failure.
The core problem with current tabled.git is that S3 clients expect all nodes to support PUT/DELETE as well as GET. Our current use w/ db4 slave mode does not fulfill this client requirement.
Your work here, moving to the base replication API, eliminates several obstacles on the path to making all tabled nodes support PUT/DELETE. But it is not true to say that metadata replication did not exist prior to this patch.
With either repmgr or base API, we still need to make failover more transparent to our S3 clients.
Quoted 10 lines
Unfortunately, the code is rather ugly. I tried to create a kind of an optional replication layer, so that tdbadm could be built without it. Although I succeeded, the result is a hideous mess of methods and callbacks, functions with side effects, and a bunch of poorly laid out state machines. In places I cannot wrap my own head around what's going on without a help of pencil and paper.
So, while working, it's not ready for going in. Still, I'm going to throw it here in case I get hit by a bus, or if anyone wants an example of using db4 replication early.
Based on a quick read, it seems straightforward, and looks like something I can try tomorrow...
Very excited to try this :)
Jeff
Quoted 7 lines · Jeff Garzik
Quoted 4 lines · Pete Zaitcev
We essentially have a tabled that can really be considered as replicated. Before, it was only data replication, which was great and all but useless against disk failues in the tabled's database. I think it's a major treshold for tabled.
Quoted 8 lines
er, huh? In addition to data replication, we already have metadata replication via db4 repmgr in tabled.git, which ensures metadata db integrity in the case of disk or tabled node failure.
Your work here, moving to the base replication API, eliminates several obstacles on the path to making all tabled nodes support PUT/DELETE. But it is not true to say that metadata replication did not exist prior to this patch.
I think it did not work in practice. We had the code, e.g. set all the right flags for DB operations, cleaned up all calls to make them DB_THREAD compatible, provided all the right callbacks for the state change. But when I tried to demonstrate the slave replication and fail-over, it turned out that a few small parts were simply forgotten. Most importantly, tabled would not boot right away into the Slave. There was something in cldu.c that precluded it. Admittedly it's possible that I broke it at some point in the past. I fixed that up first, before running into this /etc/hosts thing.
-- Pete
Quoted 19 lines · Pete Zaitcev
I worked on fixing the metadata replication in tabled. There were some difficulties in existing code, in particular the aliasing between the hostname used to identify nodes and the hostname used in
bind()for listening was impossible to work around in repmgr. In the end I gave up on repmgr and switched tabled to the "Base" API. So, the replication works now... for some values of "works", which is still a progress.We essentially have a tabled that can really be considered as replicated. Before, it was only data replication, which was great and all but useless against disk failues in the tabled's database. I think it's a major treshold for tabled.
Unfortunately, the code is rather ugly. I tried to create a kind of an optional replication layer, so that tdbadm could be built without it. Although I succeeded, the result is a hideous mess of methods and callbacks, functions with side effects, and a bunch of poorly laid out state machines. In places I cannot wrap my own head around what's going on without a help of pencil and paper.
Quoted 3 lines
So, while working, it's not ready for going in. Still, I'm going to throw it here in case I get hit by a bus, or if anyone wants an example of using db4 replication early.
Interesting stuff. I have two questions/issues.
First, it seems like trying to do stuff "under" BDB replication, letting them control the flow, is proving to be rather painful - over a thousand lines in metarep.c plus other bits elsewhere, all constrained by their expectations wrt blocking, dropping messages, etc. Might it not be simpler to handle the replication *above* BDB instead, shipping the operations ourselves to single-node BDB instances? Simpler still might be to let a general framework like Gizzard handle the N-way replication and failover, or switch to a data store that's designed from the ground up around that need. It's not like we make very advanced use of BDB's transaction or query functionality, which would tie us to their data/operational model. Anyway, that's probably a whole different discussion.
Second, I have a few concerns about the specific implementation and use of cldu_get_master in the patch.
(a) The minor problem is that if the second (inner) check for "nrp->length < 3" fails, then we return directly - leaking *nrp. Perhaps we should jump to the ncld_read_free at the end instead.
(b) I'd also question whether checking nrp->length this way is necessary at all, since cldu_parse_master should fail in those cases anyway. Why not just rearrange the loop to catch such errors that way?
(c) Lastly, regarding the comment about the gap between lock and write, I think single retry of only the read doesn't buy us much. Instead, multiple retry of the entire trylock/read sequence would seem like the way to go. It's not too hard to imagine a node taking the lock and then taking more than two seconds to do the write, e.g. due to a transient network glitch, and in that case the other node that only waited two seconds would abort. At the other end of the scale, it's also not hard to imagine a node managing to take the lock and then itself aborting before the write, again causing other nodes to fail. What should happen in this second case, I'd argue, is that CLD should eventually detect the failure and break the lock, which would allow another waiting node to take it. While I hesitate to suggest making any such loop truly infinite, if its total duration is greater than the CLD session-failure time then that should assure correct behavior in the cases of interest. It's also still possible that two or more nodes could, in succession,
take the lock and then fail before writing, so making the total duration N times the session timeout might make even more sense.
Quoted 9 lines · On Mon, 28 Jun 2010 08:37:51 -0400 Jeff Darcy <[email protected]> wrote:
First, it seems like trying to do stuff "under" BDB replication, letting them control the flow, is proving to be rather painful - over a thousand lines in
metarep.cplus other bits elsewhere, all constrained by their expectations wrt blocking, dropping messages, etc. Might it not be simpler to handle the replication *above* BDB instead, shipping the operations ourselves to single-node BDB instances? Simpler still might be to let a general framework like Gizzard handle the N-way replication and failover, or switch to a data store that's designed from the ground up around that need. []
I thought of it a little and decided to try the base API approach first, for a couple of reasons.
First, I am ignorant of things like Gizzard, so when I started imagining how the update forwarding and leases would actually work, it started looking way longer than a 1000 lines of C.
Second, I am afraid that people will point and ask "why didn't you use rep_start()". We already reap NIH critique with Zookeeper. Now if I tried, found bugs in db4/BDB, and documented that, it would be different and my conscience would be clear.
Getting all of the replication exposed in tabled is really tempting. For one thing, if we do it, we can replace db4 with TC or anything else. But it's just... too much. I don't have the balls to tackle it now. Honestly I expected to finish it all in 1 week, but actually took 3+. The roll-my-own replication would take me forever (how about 6 months?). Do you want tabled working for you or always in progress?
Quoted 3 lines
(a) The minor problem is that if the second (inner) check for "
nrp->length< 3" fails, then we return directly - leaking *nrp. Perhaps we should jump to thencld_read_freeat the end instead.
Awww, that was silly. Thanks.
Quoted 3 lines
(b) I'd also question whether checking
nrp->lengththis way is necessary at all, sincecldu_parse_mastershould fail in those cases anyway. Why not just rearrange the loop to catch such errors that way?
The idea was to special-case the "empty" so I can see a printout. A syntax error is different - maybe a version mismatch. I even wanted the would-be masters try and truncate the MASTER file before trying to lock it.
Quoted 8 lines
(c) Lastly, regarding the comment about the gap between lock and write, I think single retry of only the read doesn't buy us much. [...] At the other end of the scale, it's also not hard
to imagine a node managing to take the lock and then itself aborting before the write, again causing other nodes to fail. What should happen in this second case, I'd argue, is that CLD should eventually detect the failure and break the lock, which would allow another waiting node to take it.
Well, yeah... I guess I was too lazy and reluctant to create yet another state machine for this. Maybe I should just bite the bullet and make tabled fully multi-threaded. It was likely to come next anyway since you complained about the abysmal performance (I do not know yet what the issues with performance are, but threads are likely to participate). But if so, a thread may just easily loop, as ncld API intends.
-- Pete
Quoted 7 lines · Pete Zaitcev
Well, yeah... I guess I was too lazy and reluctant to create yet another state machine for this. Maybe I should just bite the bullet and make tabled fully multi-threaded. It was likely to come next anyway since you complained about the abysmal performance (I do not know yet what the issues with performance are, but threads are likely to participate). But if so, a thread may just easily loop, as ncld API intends.
With my wikipedia corpus testing, part of the issue seems to be a lack of ready-and-waiting-to-write/read chunkd connections. Ideally you want to have an already-open, initialized connection to a chunkd server ready.
Back in the days when I slung NNTP news across the galaxy, having multiple TCP connections to a single server was critical for performance, in particular mitigating the overhead of connection and authentication initialization.
Jeff