CLD big message support (WIP)
PATCH 1/1 CLD big message support (WIP)
Below is my current work-in-progress, finishing the packet / message logical separation. This will permit messages larger than a single packet, which, in turn, permits GET and PUT messages to be more easily handled as a single, contiguous message. DATA messages are eliminated.
This is a major network protocol change.
This work eliminates several problems, most notably (to Pete) the problem related to PUT message "dropping dup" errors. This change also simplifies the code nicely, because the client and server code no longer has to think about low-level details.
include/cld_msg.h | 28 +--- include/cldc.h | 30 ++-- lib/cldc.c | 348 ++++++++++++++++++++++-------------------------------- server/cld.h | 9 - server/msg.c | 347 +++++------------------------------------------------ server/server.c | 55 ++++++-- server/session.c | 112 ++++++++++++----- 7 files changed, 330 insertions(+), 599 deletions(-)
include/cld_msg.h +12 -16
@@ -36,7 +36,10 @@ enum {CLD_MAX_USERNAME =32 ,/**< includes req. nul */ CLD_MAX_SECRET_KEY =128 ,/**< includes req. nul */ - CLD_MAX_DATA_MSGS = 1024, /**< max data msgs in a stream */ +CLD_MAX_PKT_MSG_SZ =1024 , +CLD_MAX_PKT_MSG =128 , + CLD_MAX_MSG_SZ = CLD_MAX_PKT_MSG * 1024, /**< maximum total + msg size, including all packets */ };/*
@@ -53,7 +56,6 @@ enum cld_msg_ops { cmo_open =2 ,/**< open file */ cmo_get_meta =3 ,/**< get metadata */ cmo_get =4 ,/**< get metadata + data */ - cmo_data_s =5 ,/**< data message to server */ cmo_put =6 ,/**< put data */ cmo_close =7 ,/**< close file */ cmo_del = 8, /**< delete file */
@@ -67,7 +69,6 @@ enum cld_msg_ops { cmo_ping =30 ,/**< server to client ping */ cmo_not_master =31 ,/**< I am not the master! */ cmo_event = 32, /**< server->cli async event */ - cmo_data_c = 33, /**< data message to client */ };/** CLD error codes */
@@ -118,12 +119,19 @@ enum cld_lock_flags { CLF_SHARED = (1 << 0), /**< a shared (read) lock */ }; +/** CLD packet flags */ +enum cld_packet_flags { +CPF_FIRST = (1 <<0 ),/**< first fragment */ +CPF_LAST = (1 <<1 ),/**< last fragment */ +}; +/** header for each packet */ struct cld_packet {uint8_t magic[CLD_MAGIC_SZ ];/**< magic number; constant */ uint64_t seqid;/**< sequence id */ uint8_t sid[CLD_SID_SZ ];/**< client id */ -uint8_t res[8 ]; +uint32_t flags;/**< CPF_xxx flags */ +uint8_t res[4 ];char user[CLD_MAX_USERNAME ];/**< authenticated user */ };
@@ -184,26 +192,14 @@ struct cld_msg_get_resp {uint64_t time_modify;/**< last modification time */ uint32_t flags;/**< inode flags; CIFL_xxx */ -uint64_t strid;/**< DATA stream id */ -/* inode name */ }; -/** DATA message */ -struct cld_msg_data { -struct cld_msg_hdr hdr; - -uint64_t strid;/**< stream id */ -uint32_t seg;/**< segment number */ -uint32_t seg_len;/**< segment length */ -}; -/** PUT message */ struct cld_msg_put {struct cld_msg_hdr hdr;uint64_t fh;/**< open file handle */ -uint64_t strid;/**< DATA stream id */ uint32_t data_size;/**< total size of data */ };
include/cldc.h +14 -16
@@ -20,27 +20,24 @@ struct cldc_call_opts {union {struct {struct cld_msg_get_resp resp; -char *buf; +const char *buf;unsigned int size;char inode_name[CLD_INODE_NAME_MAX ]; } get; } u; }; -/** internal per-data stream information */ -struct cldc_stream { -uint64_t strid_le;/**< stream id, LE */ -uint32_t size;/**< total bytes in stream */ -uint32_t next_seg;/**< next segment number expected */ -void *bufp;/**< pointer to next input loc */ -uint32_t size_left;/**< bytes remaining */ -struct cldc_call_opts copts;/**< call options */ -char buf[0 ];/**< the raw data stream bytes */ +struct cldc_pkt_info { +int pkt_len; +int retries; + +/* must be at end of struct */ +struct cld_packet pkt; +uint8_t data[0 ]; };/** an outgoing message, from client to server */ struct cldc_msg { -uint64_t seqid;uint64_t xid;struct cldc_session *sess;
@@ -54,12 +51,12 @@ struct cldc_msg {time_t expire_time; -int retries; -int data_len; +int n_pkts; + +struct cldc_pkt_info *pkt_info[CLD_MAX_PKT_MSG ];/* must be at end of struct */ -struct cld_packet pkt;uint8_t data[0 ]; };
@@ -102,8 +99,6 @@ struct cldc_session {GList *out_msg;time_t msg_scan_time; -GList *streams; -time_t expire_time;bool expired;
@@ -115,6 +110,9 @@ struct cldc_session {char secret_key[CLD_MAX_SECRET_KEY ];bool confirmed; + +unsigned int msg_buf_len; +char msg_buf[CLD_MAX_MSG_SZ ]; };/** Information for a single CLD server host */
lib/cldc.c +148 -200
548 lines not on this page · raw message
server/cld.h +4 -5
@@ -70,15 +70,16 @@ struct session {uint64_t next_seqid_in;uint64_t next_seqid_out; -GList *put_q;/* queued PUT pkts */ -GList *data_q;/* queued data pkts */ -GList *out_q;/* outgoing pkts (to client) */ struct timer retry_timer;char user[CLD_MAX_USERNAME ];bool ping_open;/* sent PING, waiting for ack */ + +/* huge buffer should always come last */ +unsigned int msg_buf_len; +char msg_buf[CLD_MAX_MSG_SZ ]; };struct msg_params {
@@ -133,7 +134,6 @@ struct server {extern int inode_lock_rescan (DB_TXN *txn,cldino_t inum);extern void msg_open (struct msg_params *);extern void msg_put (struct msg_params *); -extern void msg_data (struct msg_params *);extern void msg_close (struct msg_params *);extern void msg_del (struct msg_params *);extern void msg_unlock (struct msg_params *);
@@ -143,7 +143,6 @@ extern void msg_get(struct msg_params *, bool);/* session.c */ extern uint64_t next_seqid_le (uint64_t *seq); -extern void pkt_init_sess (struct cld_packet *dest,struct session *sess);extern void pkt_init_pkt (struct cld_packet *dest,const struct cld_packet *src);extern guint sess_hash (gconstpointer v);extern gboolean sess_equal (gconstpointer _a,gconstpointer _b);
server/msg.c +33 -314
411 lines not on this page · raw message
server/server.c +40 -15
114 lines not on this page · raw message
server/session.c +79 -33
163 lines not on this page · raw message
PATCH v2 1/1 CLD big message support (WIP)
Below is my current work-in-progress, finishing the packet / message logical separation. This will permit messages larger than a single packet, which, in turn, permits GET and PUT messages to be more easily handled as a single, contiguous message. DATA messages are eliminated.
This is a major network protocol change.
This work eliminates several problems, most notably (to Pete) the problem related to PUT message "dropping dup" errors. This change also simplifies the code nicely, because the client and server code no longer has to think about low-level details.
rediff'd against 28d97076775b0c4c5fef27621c4579ef70882d6f.
include/cld_msg.h | 36 ++-- include/cldc.h | 30 +-- lib/cldc.c | 372 +++++++++++++++++++++++++------------------------ server/cld.h | 8 - server/msg.c | 347 ++++----------------------------------------- server/server.c | 97 ++++++++++-- server/session.c | 120 +++++++++++---- test/it-works.c | 2 test/load-file-event.c | 2 test/lock-file-event.c | 2 test/save-file-event.c | 2 test/start-daemon | 2 12 files changed, 432 insertions(+), 588 deletions(-)
include/cld_msg.h +20 -16
@@ -36,7 +36,10 @@ enum {CLD_MAX_USERNAME =32 ,/**< includes req. nul */ CLD_MAX_SECRET_KEY =128 ,/**< includes req. nul */ - CLD_MAX_DATA_MSGS = 1024, /**< max data msgs in a stream */ +CLD_MAX_PKT_MSG_SZ =1024 , +CLD_MAX_PKT_MSG =128 , + CLD_MAX_MSG_SZ = CLD_MAX_PKT_MSG * 1024, /**< maximum total + msg size, including all packets */ };/*
@@ -53,7 +56,6 @@ enum cld_msg_ops { cmo_open =2 ,/**< open file */ cmo_get_meta =3 ,/**< get metadata */ cmo_get =4 ,/**< get metadata + data */ - cmo_data_s =5 ,/**< data message to server */ cmo_put =6 ,/**< put data */ cmo_close =7 ,/**< close file */ cmo_del = 8, /**< delete file */
@@ -67,7 +69,7 @@ enum cld_msg_ops { cmo_ping =30 ,/**< server to client ping */ cmo_not_master =31 ,/**< I am not the master! */ cmo_event =32 ,/**< server->cli async event */ - cmo_data_c = 33, /**< data message to client */ + cmo_ack_frag = 33, /**< ack partial msg */ };/** CLD error codes */
@@ -118,12 +120,19 @@ enum cld_lock_flags { CLF_SHARED = (1 << 0), /**< a shared (read) lock */ }; +/** CLD packet flags */ +enum cld_packet_flags { +CPF_FIRST = (1 <<0 ),/**< first fragment */ +CPF_LAST = (1 <<1 ),/**< last fragment */ +}; +/** header for each packet */ struct cld_packet {uint8_t magic[CLD_MAGIC_SZ ];/**< magic number; constant */ uint64_t seqid;/**< sequence id */ uint8_t sid[CLD_SID_SZ ];/**< client id */ -uint8_t res[8 ]; +uint32_t flags;/**< CPF_xxx flags */ +uint8_t res[4 ];char user[CLD_MAX_USERNAME ];/**< authenticated user */ };
@@ -144,6 +153,13 @@ struct cld_msg_resp {uint64_t xid_in;/**< C->S xid */ }; +/** ACK-FRAG message */ +struct cld_msg_ack_frag { +struct cld_msg_hdr hdr; + +uint64_t seqid;/**< sequence id to ack */ +}; +/** OPEN message */ struct cld_msg_open {struct cld_msg_hdr hdr;
@@ -184,26 +200,14 @@ struct cld_msg_get_resp {uint64_t time_modify;/**< last modification time */ uint32_t flags;/**< inode flags; CIFL_xxx */ -uint64_t strid;/**< DATA stream id */ -/* inode name */ }; -/** DATA message */ -struct cld_msg_data { -struct cld_msg_hdr hdr; - -uint64_t strid;/**< stream id */ -uint32_t seg;/**< segment number */ -uint32_t seg_len;/**< segment length */ -}; -/** PUT message */ struct cld_msg_put {struct cld_msg_hdr hdr;uint64_t fh;/**< open file handle */ -uint64_t strid;/**< DATA stream id */ uint32_t data_size;/**< total size of data */ };
include/cldc.h +14 -16
@@ -20,27 +20,24 @@ struct cldc_call_opts {union {struct {struct cld_msg_get_resp resp; -char *buf; +const char *buf;unsigned int size;char inode_name[CLD_INODE_NAME_MAX ]; } get; } u; }; -/** internal per-data stream information */ -struct cldc_stream { -uint64_t strid_le;/**< stream id, LE */ -uint32_t size;/**< total bytes in stream */ -uint32_t next_seg;/**< next segment number expected */ -void *bufp;/**< pointer to next input loc */ -uint32_t size_left;/**< bytes remaining */ -struct cldc_call_opts copts;/**< call options */ -char buf[0 ];/**< the raw data stream bytes */ +struct cldc_pkt_info { +int pkt_len; +int retries; + +/* must be at end of struct */ +struct cld_packet pkt; +uint8_t data[0 ]; };/** an outgoing message, from client to server */ struct cldc_msg { -uint64_t seqid;uint64_t xid;struct cldc_session *sess;
@@ -54,12 +51,12 @@ struct cldc_msg {time_t expire_time; -int retries; -int data_len; +int n_pkts; + +struct cldc_pkt_info *pkt_info[CLD_MAX_PKT_MSG ];/* must be at end of struct */ -struct cld_packet pkt;uint8_t data[0 ]; };
@@ -102,8 +99,6 @@ struct cldc_session {GList *out_msg;time_t msg_scan_time; -GList *streams; -time_t expire_time;bool expired;
@@ -115,6 +110,9 @@ struct cldc_session {char secret_key[CLD_MAX_SECRET_KEY ];bool confirmed; + +unsigned int msg_buf_len; +char msg_buf[CLD_MAX_MSG_SZ ]; };/** Information for a single CLD server host */
lib/cldc.c +190 -182
604 lines not on this page · raw message
server/cld.h +4 -4
@@ -70,9 +70,6 @@ struct session {uint64_t next_seqid_in;uint64_t next_seqid_out; -GList *put_q;/* queued PUT pkts */ -GList *data_q;/* queued data pkts */ -GList *out_q;/* outgoing pkts (to client) */ struct timer retry_timer;
@@ -80,6 +77,10 @@ struct session {bool ping_open;/* sent PING, waiting for ack */ bool dead;/* session has ended */ + +/* huge buffer should always come last */ +unsigned int msg_buf_len; +char msg_buf[CLD_MAX_MSG_SZ ]; };struct msg_params {
@@ -134,7 +135,6 @@ struct server {extern int inode_lock_rescan (DB_TXN *txn,cldino_t inum);extern void msg_open (struct msg_params *);extern void msg_put (struct msg_params *); -extern void msg_data (struct msg_params *);extern void msg_close (struct msg_params *);extern void msg_del (struct msg_params *);extern void msg_unlock (struct msg_params *);
server/msg.c +33 -314
411 lines not on this page · raw message
server/server.c +80 -17
160 lines not on this page · raw message
server/session.c +86 -34
182 lines not on this page · raw message
test/it-works.c +1 -1
@@ -86,7 +86,7 @@ static int init(void)if (rc)return rc; -// udp->sess->verbose = true; + udp->sess->verbose = true;event_set (&udp_ev, udp->fd,EV_READ |EV_PERSIST , udp_event, udp);
test/load-file-event.c +1 -1
@@ -214,7 +214,7 @@ static int init(char *name)if (rc)return rc; -// run.udp->sess->verbose = true; + run.udp->sess->verbose = true;event_set (&run.udp_ev, run.udp->fd,EV_READ |EV_PERSIST , udp_event, &run);
test/lock-file-event.c +1 -1
@@ -224,7 +224,7 @@ static int init(void)if (rc)return rc; -// run.udp->sess->verbose = true; + run.udp->sess->verbose = true;event_set (&run.udp_ev, run.udp->fd,EV_READ |EV_PERSIST , udp_event, &run);
test/save-file-event.c +1 -1
@@ -220,7 +220,7 @@ static int init(char *name)if (rc)return rc; -// run.udp->sess->verbose = true; + run.udp->sess->verbose = true;event_set (&run.udp_ev, run.udp->fd,EV_READ |EV_PERSIST , udp_event, &run);
test/start-daemon +1 -1
@@ -6,7 +6,7 @@ then exit 1 fi -../server/cld -P cld.pid -d "$PWD/data" -p 18181 -E +../server/cld -P cld.pid -d "$PWD/data" -p 18181 -E -D 2 sleep 3
I just committed and pushed out this as
commit f830b4be92f89ad0a48ee0703fd1b829febfaf4a
Author: Jeff Garzik <[email protected]> Date: Fri Aug 7 10:12:39 2009 -0400
Major network protocol change: support multi-packet messages.
This eliminates the need for DATA messages, as all normal messages (GET, PUT etc.) may be up to maximum size (128k currently).