Skip to content
Browse files

MB-3849 - SERVER_ERROR proxy write to downstream $HOST

Changed the error message to include the downstream host which moxi
could not propagate the request to.

Change-Id: Ia3e0bbc7ccf2f2ae203aaff56b60f571a1036b75
Reviewed-on: http://review.membase.org/6269
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
  • Loading branch information...
1 parent d4879b6 commit 0745b38d134bb6f5cc25800b16fe709a3763a981 @steveyen steveyen committed with alk
Showing with 65 additions and 6 deletions.
  1. +46 −5 cproxy.c
  2. +3 −0 cproxy.h
  3. +1 −0 cproxy_multiget.c
  4. +2 −0 cproxy_protocol_a.c
  5. +4 −0 cproxy_protocol_a2a.c
  6. +7 −0 cproxy_protocol_a2b.c
  7. +1 −0 cproxy_protocol_b2b.c
  8. +1 −1 t/issue-MB-2972.sh
View
51 cproxy.c
@@ -571,6 +571,7 @@ void cproxy_on_close_upstream_conn(conn *c) {
d->upstream_suffix_len = 0;
d->upstream_status = PROTOCOL_BINARY_RESPONSE_SUCCESS;
d->upstream_retry = 0;
+ d->target_host_ident = NULL;
// Don't need to do anything else, as we'll now just
// read and drop any remaining inflight downstream replies.
@@ -735,11 +736,18 @@ void cproxy_on_close_downstream_conn(conn *c) {
if (c->host_ident != NULL) {
char *s = add_conn_suffix(d->upstream_conn);
- snprintf(s, SUFFIX_SIZE - 1,
- "SERVER_ERROR proxy downstream closed %s\r\n",
- c->host_ident);
- s[SUFFIX_SIZE - 1] = '\0';
- d->upstream_suffix = s;
+ if (s != NULL) {
+ snprintf(s, SUFFIX_SIZE - 1,
+ "SERVER_ERROR proxy downstream closed %s\r\n",
+ c->host_ident);
+ s[SUFFIX_SIZE - 1] = '\0';
+ d->upstream_suffix = s;
+
+ s = strchr(s, ':'); // Clip to avoid sending user/pswd.
+ if (s != NULL) {
+ *s = '\0';
+ }
+ }
}
d->upstream_suffix_len = 0;
@@ -748,6 +756,7 @@ void cproxy_on_close_downstream_conn(conn *c) {
}
d->upstream_retry = 0;
+ d->target_host_ident = NULL;
}
// We sometimes see that drive_machine/transmit will not see
@@ -780,6 +789,7 @@ void cproxy_on_close_downstream_conn(conn *c) {
d->upstream_suffix_len = 0;
d->upstream_status = PROTOCOL_BINARY_RESPONSE_SUCCESS;
d->upstream_retry = 0;
+ d->target_host_ident = NULL;
}
}
}
@@ -908,6 +918,7 @@ downstream *cproxy_reserve_downstream(proxy_td *ptd) {
assert(d->upstream_suffix_len == 0);
assert(d->upstream_status == PROTOCOL_BINARY_RESPONSE_SUCCESS);
assert(d->upstream_retry == 0);
+ assert(d->target_host_ident == NULL);
assert(d->downstream_used == 0);
assert(d->downstream_used_start == 0);
assert(d->merger == NULL);
@@ -921,6 +932,7 @@ downstream *cproxy_reserve_downstream(proxy_td *ptd) {
d->upstream_status = PROTOCOL_BINARY_RESPONSE_SUCCESS;
d->upstream_retry = 0;
d->upstream_retries = 0;
+ d->target_host_ident = NULL;
d->usec_start = 0;
d->downstream_used = 0;
d->downstream_used_start = 0;
@@ -1137,6 +1149,7 @@ bool cproxy_release_downstream(downstream *d, bool force) {
d->upstream_status = PROTOCOL_BINARY_RESPONSE_SUCCESS;
d->upstream_retry = 0;
d->upstream_retries = 0;
+ d->target_host_ident = NULL;
d->usec_start = 0;
d->downstream_used = 0;
d->downstream_used_start = 0;
@@ -1446,6 +1459,20 @@ int cproxy_connect_downstream(downstream *d, LIBEVENT_THREAD *thread,
msst_actual,
&d->behaviors_arr[i],
&downstream_conn_max_reached);
+ if (c != NULL &&
+ i == server_index &&
+ d->downstream_conns[i] != NULL &&
+ d->downstream_conns[i] != NULL_CONN &&
+ d->target_host_ident == NULL) {
+ d->target_host_ident = add_conn_suffix(c);
+ if (d->target_host_ident != NULL) {
+ strncpy(d->target_host_ident,
+ msst_actual->hostname,
+ SUFFIX_SIZE);
+ d->target_host_ident[SUFFIX_SIZE - 1] = '\0';
+ }
+ }
+
if (d->downstream_conns[i] != NULL &&
d->downstream_conns[i] != NULL_CONN &&
d->downstream_conns[i]->state == conn_connecting) {
@@ -1861,6 +1888,19 @@ void propagate_error_msg(downstream *d, char *ascii_msg,
protocol_binary_response_status binary_status) {
assert(d != NULL);
+ if (ascii_msg == NULL &&
+ d->upstream_conn != NULL &&
+ d->target_host_ident != NULL) {
+ char *s = add_conn_suffix(d->upstream_conn);
+ if (s != NULL) {
+ snprintf(s, SUFFIX_SIZE - 1,
+ "SERVER_ERROR proxy write to downstream %s\r\n",
+ d->target_host_ident);
+ s[SUFFIX_SIZE - 1] = '\0';
+ ascii_msg = s;
+ }
+ }
+
while (d->upstream_conn != NULL) {
conn *uc = d->upstream_conn;
@@ -2044,6 +2084,7 @@ bool cproxy_dettach_if_noreply(downstream *d, conn *uc) {
d->upstream_suffix_len = 0;
d->upstream_status = PROTOCOL_BINARY_RESPONSE_SUCCESS;
d->upstream_retry = 0;
+ d->target_host_ident = NULL;
cproxy_reset_upstream(uc);
View
3 cproxy.h
@@ -478,6 +478,9 @@ struct downstream {
// asking for successful keys again.
int upstream_retries; // Count number of upstream_retry attempts.
+ // Used when proxying a simple, single-key (non-broadcast) command.
+ char *target_host_ident;
+
genhash_t *multiget; // Keyed by string.
genhash_t *merger; // Keyed by string, for merging replies like STATS.
View
1 cproxy_multiget.c
@@ -361,6 +361,7 @@ bool multiget_ascii_downstream(downstream *d, conn *uc,
d->upstream_suffix_len = 0;
d->upstream_status = PROTOCOL_BINARY_RESPONSE_SUCCESS;
d->upstream_retry = 0;
+ d->target_host_ident = NULL;
cproxy_start_downstream_timeout(d, NULL);
}
View
2 cproxy_protocol_a.c
@@ -490,6 +490,7 @@ bool cproxy_optimize_set_ascii(downstream *d, conn *uc,
d->upstream_suffix_len = 0;
d->upstream_status = PROTOCOL_BINARY_RESPONSE_SUCCESS;
d->upstream_retry = 0;
+ d->target_host_ident = NULL;
out_string(uc, "STORED");
@@ -582,5 +583,6 @@ void cproxy_ascii_broadcast_suffix(downstream *d) {
d->upstream_suffix_len = 0;
d->upstream_status = PROTOCOL_BINARY_RESPONSE_SUCCESS;
d->upstream_retry = 0;
+ d->target_host_ident = NULL;
}
}
View
4 cproxy_protocol_a2a.c
@@ -160,6 +160,9 @@ void cproxy_process_a2a_downstream(conn *c, char *line) {
d->upstream_suffix = "LOCK_ERROR\r\n";
d->upstream_suffix_len = 0;
d->upstream_status = PROTOCOL_BINARY_RESPONSE_ETMPFAIL;
+ d->upstream_retry = 0;
+ d->target_host_ident = NULL;
+
conn_set_state(c, conn_pause);
} else {
conn_set_state(c, conn_pause);
@@ -490,6 +493,7 @@ bool cproxy_broadcast_a2a_downstream(downstream *d,
d->upstream_suffix_len = 0;
d->upstream_status = PROTOCOL_BINARY_RESPONSE_SUCCESS;
d->upstream_retry = 0;
+ d->target_host_ident = NULL;
cproxy_start_downstream_timeout(d, NULL);
} else {
View
7 cproxy_protocol_a2b.c
@@ -756,6 +756,8 @@ void a2b_process_downstream_response(conn *c) {
d->upstream_suffix = "LOCK_ERROR\r\n";
d->upstream_suffix_len = 0;
d->upstream_status = status;
+ d->upstream_retry = 0;
+ d->target_host_ident = NULL;
}
conn_set_state(c, conn_pause);
@@ -1107,6 +1109,7 @@ bool cproxy_forward_a2b_simple_downstream(downstream *d,
d->upstream_suffix_len = 0;
d->upstream_status = PROTOCOL_BINARY_RESPONSE_SUCCESS;
d->upstream_retry = 0;
+ d->target_host_ident = NULL;
}
assert(uc->next == NULL);
@@ -1233,6 +1236,7 @@ bool cproxy_forward_a2b_simple_downstream(downstream *d,
if (local) {
uc->hit_local = true;
}
+
if (cproxy_prep_conn_for_write(c)) {
assert(c->state == conn_pause);
assert(c->wbuf);
@@ -1308,6 +1312,7 @@ bool cproxy_forward_a2b_simple_downstream(downstream *d,
d->upstream_suffix_len = 0;
d->upstream_status = PROTOCOL_BINARY_RESPONSE_ENOMEM;
d->upstream_retry = 0;
+ d->target_host_ident = NULL;
}
}
} else {
@@ -1323,6 +1328,7 @@ bool cproxy_forward_a2b_simple_downstream(downstream *d,
d->upstream_suffix_len = 0;
d->upstream_status = PROTOCOL_BINARY_RESPONSE_EINVAL;
d->upstream_retry = 0;
+ d->target_host_ident = NULL;
}
}
@@ -1485,6 +1491,7 @@ bool cproxy_broadcast_a2b_downstream(downstream *d,
d->upstream_suffix_len = 0;
d->upstream_status = PROTOCOL_BINARY_RESPONSE_SUCCESS;
d->upstream_retry = 0;
+ d->target_host_ident = NULL;
cproxy_start_downstream_timeout(d, NULL);
} else {
View
1 cproxy_protocol_b2b.c
@@ -292,6 +292,7 @@ bool cproxy_broadcast_b2b_downstream(downstream *d, conn *uc) {
d->upstream_suffix = ITEM_data(it);
d->upstream_suffix_len = it->nbytes;
d->upstream_status = PROTOCOL_BINARY_RESPONSE_SUCCESS;
+ d->target_host_ident = NULL;
if (settings.verbose > 2) {
moxi_log_write("%d: b2b broadcast upstream_suffix", uc->sfd);
View
2 t/issue-MB-2972.sh
@@ -84,7 +84,7 @@ sleep 1
echo client request 2 - attempt get when memcached is down
echo get 1 | nc 127.0.0.1 11266 > /tmp/moxi-2972.out
-if ! (echo "SERVER_ERROR proxy write to downstream\r" | diff - /tmp/moxi-2972.out); then \
+if ! (echo "SERVER_ERROR proxy write to downstream 127.0.0.1\r" | diff - /tmp/moxi-2972.out); then \
echo FAIL - did not get expected SERVER_ERROR
killall moxi
exit -1

0 comments on commit 0745b38

Please sign in to comment.
Something went wrong with that request. Please try again.