Skip to contentSkip to conversation

chunk: add CP operation

PATCH New Jeff Garzik 1 participant 1 message Jul 7, 2010 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 chunk: add CP operation

This patch

* adds local, intra-table copy operation to chunkd/libhail
* illustrates what files need updating, when adding a new op to chunk
* adds some 'worker' infrastructure which should help with future ops, notably remote copy (RCP)
* should assist tabled's implementation of S3 copy (x-amz-copy-source)

 chunkd/chunkd.h         |   19 +++++++
 chunkd/object.c         |  117 ++++++++++++++++++++++++++++++++++++++++++++++
 chunkd/server.c         |  122 ++++++++++++++++++++++++++++++++++++++++++++----
 doc/chcli.8             |   13 ++++-
 include/chunk_msg.h     |    2 
 include/chunkc.h        |   10 +++
 lib/chunkdc.c           |   56 ++++++++++++++++++++++
 test/chunkd/Makefile.am |    5 +
 tools/chcli.c           |   77 ++++++++++++++++++++++++++++++
 9 files changed, 409 insertions(+), 12 deletions(-)
chunkd/chunkd.h +19 -0
index e019f0d..5d39353 100644
@@ -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;	/* len of vari len record */
+	bool			second_var;	/* inside 2nd vari len rec? */
 
 	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,14 @@ struct volume_entry {
 	char			*owner;		/* obj owner username */
 };
 
+struct worker_info {
+	enum chunk_errcode	err;		/* error returned to pipe */
+	struct client		*cli;		/* associated client conn */
+
+	void			(*thr_ev)(struct worker_info *);
+	void			(*pipe_ev)(struct worker_info *);
+};
+
 struct server_stats {
 	unsigned long		poll;		/* number polls */
 	unsigned long		event;		/* events dispatched */
@@ -209,6 +220,10 @@ struct server {
 
 	GHashTable		*fd_info;
 
+	GThreadPool		*workers;	/* global thread worker pool */
+	int			max_workers;
+	int			worker_pipe[2];
+
 	struct list_head	wr_trash;
 	unsigned int		trash_sz;
 
@@ -278,6 +293,7 @@ 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 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 +330,15 @@ extern bool cli_err(struct client *cli, enum chunk_errcode code, bool recycle_ok
 extern 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 worker_pipe_signal(struct worker_info *wi);
+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 +117 -0

126 lines not on this page · raw message

chunkd/server.c +112 -10

208 lines not on this page · raw message

doc/chcli.8 +12 -1
index 477d8d4..0de059b 100644
@@ -86,7 +86,14 @@ than the command line.
 Obtain key portion of a key/value pair from the specified file,
 rather than the command line.  Keys provided on the command line
 (as opposed to via -k) are stored with a C-style nul terminating
-character appended, adding 1 byte to each key.
+character appended, adding 1 byte to each key.  If the command is copy (CP),
+this represents the destination key.
+.TP
+.B \-s \-\-src
+Obtain source-key portion of a source-key/source-value pair from the
+specified file, rather than the command line.  Keys provided on the
+command line (as opposed to via -s) are stored with a C-style nul
+terminating character appended, adding 1 byte to each key.
 .TP
 .B \-\-list-cmds
 List all supported commands, and a short command usage synopsis.
@@ -131,6 +138,10 @@ Fetch status of server self-check
 .B CHECKSTART
 Begin server self-check
 .TP
+.B CP dest-key src-key
+Copy object represented by 'src-key' into new object referenced
+by 'dest-key'
+.TP
 Keys provided on the command line (as opposed to via -k) are stored
 with a C-style nul terminating character appended, adding 1 byte to
 each key.
include/chunk_msg.h +2 -0
index 4a3c15d..3ee1c6a 100644
@@ -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
index 683992e..1fd7066 100644
@@ -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) + 1,
+		      src_key, strlen(src_key) + 1);
+}
+
 #endif /* __STC_H__ */
lib/chunkdc.c +56 -0

62 lines not on this page · raw message

test/chunkd/Makefile.am +4 -1
index 1cb9875..def9b36 100644
@@ -1,5 +1,6 @@
 
 INCLUDES	= -I$(top_srcdir)/include	\
+		  -I$(top_srcdir)/lib		\
 		  @GLIB_CFLAGS@ @XML_CPPFLAGS@
 
 EXTRA_DIST =			\
@@ -24,13 +25,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 +40,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)
tools/chcli.c +77 -0

125 lines not on this page · raw message