Skip to content

Commit

Permalink
Merge pull request #729 from smukil/proper_quit_cmd_support
Browse files Browse the repository at this point in the history
Support the Redis "QUIT" command properly
  • Loading branch information
smukil authored Oct 20, 2019
2 parents a40ceb5 + 24f3254 commit 46c73f7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
6 changes: 5 additions & 1 deletion src/dyn_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,13 @@ static bool req_filter(struct context *ctx, struct conn *conn,
if (req->quit) {
ASSERT(conn->rmsg == NULL);
log_debug(LOG_VERB, "%s filter quit %s", print_obj(conn), print_obj(req));

// The client expects to receive an "+OK\r\n" response, so make sure
// to do that.
IGNORE_RET_VAL(simulate_ok_rsp(ctx, conn, req));

conn->eof = 1;
conn->recv_ready = 0;
req_put(req);
return true;
}

Expand Down
34 changes: 20 additions & 14 deletions src/dyn_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ static rstatus_t msg_repair(struct context *ctx, struct conn *conn,
*
* Returns a 'msg' with the expected success response.
*/
static struct msg *simulate_ok_rsp(struct context *ctx, struct conn *conn,
static struct msg *craft_ok_rsp(struct context *ctx, struct conn *conn,
struct msg *req) {

ASSERT(req->is_request);
Expand Down Expand Up @@ -951,6 +951,24 @@ static struct msg *simulate_ok_rsp(struct context *ctx, struct conn *conn,
return rsp;
}

rstatus_t simulate_ok_rsp(struct context *ctx, struct conn *conn,
struct msg *msg) {
// Create an OK response.
struct msg *ok_rsp = craft_ok_rsp(ctx, conn, msg);

// Add it to the outstanding messages dictionary, so that 'conn_handle_response'
// can process it appropriately.
dictAdd(conn->outstanding_msgs_dict, &msg->id, msg);

// Enqueue the message in the outbound queue so that the code on the response
// path can find it.
conn_enqueue_outq(ctx, conn, msg);

THROW_STATUS(conn_handle_response(ctx, conn,
msg->parent_id ? msg->parent_id : msg->id, ok_rsp));

return DN_OK;
}

/*
* If the command sent to Dynomite was a special Dynomite configuration
Expand Down Expand Up @@ -979,19 +997,7 @@ static rstatus_t msg_apply_config(struct context *ctx, struct conn *conn,
// Set the consistency to DC_ONE, since this is just a configuration setting.
msg->consistency = DC_ONE;

// Create an OK response.
struct msg *ok_rsp = simulate_ok_rsp(ctx, conn, msg);

// Add it to the outstanding messages dictionary, so that 'conn_handle_response'
// can process it appropriately.
dictAdd(conn->outstanding_msgs_dict, &msg->id, msg);

// Enqueue the message in the outbound queue so that the code on the response
// path can find it.
conn_enqueue_outq(ctx, conn, msg);

THROW_STATUS(conn_handle_response(ctx, conn,
msg->parent_id ? msg->parent_id : msg->id, ok_rsp));
THROW_STATUS(simulate_ok_rsp(ctx, conn, msg));

return DN_OK;
}
Expand Down
10 changes: 10 additions & 0 deletions src/dyn_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,16 @@ rstatus_t dnode_peer_req_forward(struct context *ctx, struct conn *c_conn,
void dnode_peer_gossip_forward(struct context *ctx, struct conn *conn,
struct mbuf *data);

/*
* Simulates a successful response as though the datastore sent it.
* Also, does the necessary to make sure that the response path is
* able to send this response back to the client.
*
* Returns DN_OK on success and an appropriate error otherwise.
*/
rstatus_t simulate_ok_rsp(struct context *ctx, struct conn *conn,
struct msg *msg);

// Returns 'true' if 'msg_type' is a Dynomite configuration command.
bool is_msg_type_dyno_config(msg_type_t msg_type);

Expand Down

0 comments on commit 46c73f7

Please sign in to comment.