chunkd: add cp command, for local intra-table copies
PATCH 1/1 chunkd: add cp command, for local intra-table copies
The following patch, against current hail.git, adds the "CP" command to chunkd, permitting copying from object->object inside a single table.
It also adds a worker thread pool that may be used by other background tasks as well.
chunkd/chunkd.h +22 -0
@@ -104,6 +104,8 @@ struct client {unsigned int req_used;/* amount of req_buf in use */ void *req_ptr;/* start of unexamined data */ uint16_t key_len; +unsigned int var_len; +bool second_var;char *hdr_start;/* current hdr start */ char *hdr_end;/* current hdr end (so far) */
@@ -124,6 +126,7 @@ struct client {char netbuf_out[CLI_DATA_BUF_SZ ];char key[CHD_KEY_SZ ];char table[CHD_KEY_SZ ]; +char key2[CHD_KEY_SZ ]; };struct backend_obj {
@@ -162,6 +165,16 @@ struct volume_entry {char *owner;/* obj owner username */ }; +enum chunk_worker_op { +CW_CP ,/* local obj copy */ +}; + +struct worker_info { +enum chunk_worker_op op; +struct client *cli; +enum chunk_errcode err; +}; +struct server_stats {unsigned long poll;/* number polls */ unsigned long event;/* events dispatched */
@@ -209,6 +222,10 @@ struct server {GHashTable *fd_info; +GThreadPool *workers; +int max_workers; +int worker_pipe[2 ]; +struct list_head wr_trash;unsigned int trash_sz;
@@ -278,6 +295,9 @@ extern int fs_obj_do_sum(const char *fn, unsigned int klen, char **csump);extern bool object_del (struct client *cli);extern bool object_put (struct client *cli);extern bool object_get (struct client *cli,bool want_body); +extern bool object_cp (struct client *cli); +extern void worker_cp_thr (struct worker_info *wi); +extern void worker_cp_pipe (struct worker_info *wi);extern bool cli_evt_data_in (struct client *cli,unsigned int events);extern void cli_out_end (struct client *cli);extern void cli_in_end (struct client *cli);
@@ -314,12 +334,14 @@ extern bool cli_err(struct client *cli, enum chunk_errcode code, bool recycle_okextern int cli_writeq (struct client *cli,const void *buf,unsigned int buflen,cli_write_func cb,void *cb_data);extern bool cli_wr_sendfile (struct client *,cli_write_func ); +extern bool cli_rd_set_poll (struct client *cli,bool readable);extern void cli_wr_set_poll (struct client *cli,bool writable);extern bool cli_cb_free (struct client *cli,struct client_write *wr,bool done);extern bool cli_write_start (struct client *cli);extern int cli_req_avail (struct client *cli);extern int cli_poll_mod (struct client *cli); +extern bool tcp_cli_event (int fd,short events,void *userdata);extern void resp_init_req (struct chunksrv_resp *resp,const struct chunksrv_req *req);
chunkd/object.c +100 -0
109 lines not on this page · raw message
chunkd/server.c +100 -10
196 lines not on this page · raw message
include/chunk_msg.h +2 -0
@@ -48,6 +48,8 @@ enum chunksrv_ops {* functions' success/failure is sufficient indication. */ CHO_START_TLS =10 ,/* Encrypt all subsequent msgs */ + + CHO_CP = 11, /* local object copy (intra-table) */ }; enum chunk_errcode {
include/chunkc.h +10 -0
@@ -85,6 +85,9 @@ extern bool stc_put_sync(struct st_client *stc);extern bool stc_put_inline (struct st_client *stc,const void *key,size_t key_len,void *data,uint64_t len,uint32_t flags); +extern bool stc_cp (struct st_client *stc, +const void *dest_key,size_t dest_key_len, +const void *src_key,size_t src_key_len);extern bool stc_del (struct st_client *stc,const void *key,size_t key_len);extern bool stc_ping (struct st_client *stc);
@@ -133,4 +136,11 @@ static inline bool stc_table_openz(struct st_client *stc, const char *key, return stc_table_open(stc, key, strlen(key) + 1, flags); } +static inline bool stc_cpz (struct st_client *stc, +const char *dest_key,const char *src_key) +{ +return stc_cp (stc, dest_key,strlen (dest_key), + src_key,strlen (src_key)); +} +#endif /* __STC_H__ */
lib/chunkdc.c +56 -0
62 lines not on this page · raw message
test/chunkd/Makefile.am +3 -1
@@ -24,13 +24,14 @@ TESTS = \ nop \ basic-object \ auth \ + cp \ large-object \ lotsa-objects \ selfcheck-unit \ stop-daemon \ clean-db -check_PROGRAMS = auth basic-object it-works large-object \ +check_PROGRAMS = auth basic-object cp it-works large-object \ lotsa-objects nop objcache-unit selfcheck-unit TESTLDADD = ../../lib/libhail.la \
@@ -38,6 +39,7 @@ TESTLDADD = ../../lib/libhail.la \ @GLIB_LIBS@ @CRYPTO_LIBS@ \ @XML_LIBS@ @SSL_LIBS@ basic_object_LDADD = $(TESTLDADD) +cp_LDADD = $(TESTLDADD) auth_LDADD = $(TESTLDADD) it_works_LDADD = $(TESTLDADD) large_object_LDADD = $(TESTLDADD)
test/chunkd/cp.c new file +116 -0
116 lines not on this page · raw message
Quoted 2 lines · On Tue, 6 Jul 2010 03:24:29 -0400 Jeff Garzik <[email protected]> wrote:
The following patch, against current hail.git, adds the "CP" command to chunkd, permitting copying from
object->objectinside a single table.
What is it for?
-- Pete
Quoted 7 lines · Pete Zaitcev
Quoted 2 lines · On Tue, 6 Jul 2010 03:24:29 -0400 Jeff Garzik<[email protected]> wrote:
The following patch, against current hail.git, adds the "CP" command to chunkd, permitting copying from
object->objectinside a single table.What is it for?
Fun! :)
More seriously, it is mainly an infrastructure patch, adding things that the upcoming RCP command will use. As CP is far less complex, this allows me to verify several bits of machinery before moving forward. I imagine CP will be tangentially helpful, but not a crucial feature in and of itself.
Jeff
Quoted 7 lines · Pete Zaitcev
Quoted 2 lines · On Tue, 6 Jul 2010 03:24:29 -0400 Jeff Garzik<[email protected]> wrote:
The following patch, against current hail.git, adds the "CP" command to chunkd, permitting copying from
object->objectinside a single table.What is it for?
Here's a real-world example.
Quoting from the S3 documentation, this describes the "PUT (copy)" operation, something that tabled does not yet support, but should:
This implementation of the PUT operation creates a copy of an object that is already stored in Amazon S3. A PUT copy operation is the same as performing a GET and then a PUT. Adding the request header, x-amz-copy-source, makes the PUT operation copy the source object into the destination bucket.
Assuming that a given tabled object is already fully replicated -- HOPEFULLY the common case for us -- the least expensive way to implement this is
for each chunkd containing object OLD_KEY CHO_CP(object OLD_KEY -> object NEW_KEY)
Assuming each chunkd node has the necessary free space, this method totally avoids using network bandwidth, when creating a copy of an object
Jeff