chunkd: add objcache
PATCH 3/4 chunkd: add objcache
This a mechanism by which self-check may know what objects were updated and thus should not be disturbed if their checksums fail.
--- include/Makefile.am | 2 include/objcache.h | 72 +++++++++++++++++++++++ server/Makefile.am | 3 server/chunkd.h | 3 server/objcache.c | 128 +++++++++++++++++++++++++++++++++++++++++ server/object.c | 9 ++ server/server.c | 7 ++ test/.gitignore | 1 test/Makefile.am | 5 + test/objcache-unit.c | 58 ++++++++++++++++++ 10 files changed, 285 insertions(+), 3 deletions(-)
commit ab575b65211f00c73feffd4c8c58044142b1163f
Author: Master <[email protected]> Date: Sun Dec 27 16:04:43 2009 -0700
Add the objcache.
include/Makefile.am +1 -1
@@ -1,5 +1,5 @@ include_HEADERS = chunkc.h chunk_msg.h -EXTRA_DIST = elist.h chunk_msg.h chunksrv.h chunk-private.h +EXTRA_DIST = elist.h chunk_msg.h chunksrv.h chunk-private.h objcache.h
include/objcache.h new file +72 -0
72 lines not on this page · raw message
server/Makefile.am +2 -1
@@ -6,7 +6,8 @@ sbin_PROGRAMS = chunkd chunkd_SOURCES = chunkd.h \ ../lib/chunksrv.c \ - be-fs.c object.c server.c config.c cldu.c util.c + be-fs.c object.c server.c config.c cldu.c util.c \ + objcache.c chunkd_LDADD = \ @CLDC_LIBS@ @GLIB_LIBS@ @CRYPTO_LIBS@ \ @SSL_LIBS@ @EVENT_LIBS@ @TOKYOCABINET_LIBS@
server/chunkd.h +3 -0
@@ -28,6 +28,7 @@#include <chunk_msg.h> #include <hail_log.h> #include <tchdb.h> +#include <objcache.h> #ifndef ARRAY_SIZE #define ARRAY_SIZE (arr) (sizeof(arr) / sizeof((arr)[0]))
@@ -118,6 +119,7 @@ struct client {long out_len;struct backend_obj *out_bo; +struct objcache_entry *out_ce;long in_len;struct backend_obj *in_obj;
@@ -210,6 +212,7 @@ struct server {struct geo loc;TCHDB *tbl_master; +struct objcache actives;struct server_stats stats;/* global statistics */ };
server/objcache.c new file +128 -0
128 lines not on this page · raw message
server/object.c +9 -0
@@ -73,6 +73,10 @@ void cli_out_end(struct client *cli)fs_obj_free (cli->out_bo); cli->out_bo =NULL ; } +if (cli->out_ce) { +objcache_put (&chunkd_srv.actives, cli->out_ce); + cli->out_ce =NULL ; + }free (cli->out_user); cli->out_user =NULL ;
@@ -217,6 +221,11 @@ bool object_put(struct client *cli)if (!user)return cli_err (cli, che_AccessDenied, true); + cli->out_ce =objcache_get_dirty (&chunkd_srv.actives, + cli->key, cli->key_len); +if (!cli->out_ce) +return cli_err (cli, che_InternalError, true); + cli->out_bo =fs_obj_new (cli->table_id, cli->key, cli->key_len, &err);if (!cli->out_bo)return cli_err (cli, err, true);
server/server.c +7 -0
@@ -1659,6 +1659,11 @@ int main (int argc, char *argv[]) goto err_out_session; } +if (objcache_init (&chunkd_srv.actives) !=0 ) { + rc =1 ; + goto err_out_objcache; + } +INIT_LIST_HEAD (&chunkd_srv.wr_trash); chunkd_srv.trash_sz =0 ;
@@ -1692,6 +1697,8 @@ err_out_listen: err_out_cld:fs_close (); err_out_fs: +objcache_fini (&chunkd_srv.actives); +err_out_objcache:if (strict_free)g_hash_table_destroy (chunkd_srv.fd_info); err_out_session:
test/.gitignore +1 -0
@@ -4,6 +4,7 @@ it-works large-object lotsa-objects nop +objcache-unit .libs libtest.a
test/Makefile.am +4 -1
@@ -15,6 +15,7 @@ EXTRA_DIST = \ ssl-key.pem ssl-cert.pem TESTS = \ + objcache-unit \ prep-db \ start-daemon \ pid-exists \
@@ -29,7 +30,7 @@ TESTS = \ clean-db check_PROGRAMS = auth basic-object it-works large-object \ - lotsa-objects nop + lotsa-objects nop objcache-unit TESTLDADD = ../lib/libchunkdc.la \ libtest.a \
@@ -42,6 +43,8 @@ large_object_LDADD = $(TESTLDADD) lotsa_objects_LDADD = $(TESTLDADD) nop_LDADD = $(TESTLDADD) +objcache_unit_LDADD = @GLIB_LIBS@ + noinst_LIBRARIES = libtest.a libtest_a_SOURCES = libtest.c
test/objcache-unit.c new file +58 -0
58 lines not on this page · raw message
[Patch 5/4] chunkd: switch objcache to hash
On second thought, let's switch objcache from list to hash. This should help the lookup times if there's a large number of outstanding I/Os.
This also adds the objcache_count for self-testing purpoes. And a few comments.
--- include/objcache.h | 9 +++++--- server/objcache.c | 42 +++++++++++++++++++++++++---------------- test/objcache-unit.c | 8 ++++++- 3 files changed, 39 insertions(+), 20 deletions(-)
I think you mentioned that your scripts dealt with 5/4 patch numbering. Just in case, setting references by replying to a previous patch mail.
commit 6238aa7321335b0a3aba9736ee1467777bdd6861
Author: Master <[email protected]> Date: Wed Jan 6 22:04:20 2010 -0700
Switch objcache from list to hash to make lookups faster.
include/objcache.h +6 -3
@@ -20,16 +20,14 @@#define _CHUNKD_OBJCACHE_H_#include <glib.h> -#include <elist.h> #include <stdbool.h> struct objcache { -struct list_head head;GMutex *lock; +GHashTable *table; };struct objcache_entry { -struct list_head link;unsigned int hash;unsigned int flags;int ref;
@@ -60,6 +58,11 @@ extern bool objcache_test_dirty(struct objcache *cache,extern void objcache_put (struct objcache *cache,struct objcache_entry *entry);/* +* Count objects in the cache. Can be slow, and used only for debugging. +*/ +extern int objcache_count (struct objcache *cache); + +/* * Init a cache. Call once. May fail since it allocates a mutex. */ extern int objcache_init (struct objcache *cache);
server/objcache.c +26 -16
83 lines not on this page · raw message
test/objcache-unit.c +7 -1
@@ -42,7 +42,10 @@ int main(int argc, char *argv[]) ep3 =objcache_get (&cache, k3,sizeof (k3));OK (ep3 !=NULL ); -OK (ep1->ref ==1 );/* no collisions */ + rc =objcache_count (&cache); +OK (rc ==3 ); + +OK (ep1->ref ==1 );/* no collisions, else improve hash */ objcache_put (&cache, ep1);objcache_put (&cache, ep2);
@@ -53,6 +56,9 @@ int main(int argc, char *argv[])OK (ep2->ref ==1 );/* new */ objcache_put (&cache, ep2); + rc =objcache_count (&cache); +OK (rc ==0 ); +objcache_fini (&cache);return 0 ; }