Skip to content

Commit e879801

Browse files
soumyadeep2007avamingli
authored andcommitted
Revamp ic-proxy logging
This is a follow-up to 24140214f21, which was reverted for being too verbose by default, causing CI failures. This reintroduces the gp_log_interconnect GUC to ic-proxy logging and follows the specifications outlined in cdbvars.c. The ic_proxy_log macro is replaced with elog and elogif for WARNINGs/ERRORs and other events respectively. The scheme used: TERSE[LOG]: Server main loop events, signals VERBOSE[LOG]: Startup, (un)register, close/shutdown, EOF receipt etc. DEBUG[DEBUG1]: Special packet (BYE/HELLO) transfer, pause/resume events DEBUG[DEBUG3]: Less interesting packet transfers, caching DEBUG[DEBUG5]: Very low-level tracing info
1 parent af49d1b commit e879801

File tree

9 files changed

+272
-188
lines changed

9 files changed

+272
-188
lines changed

contrib/interconnect/proxy/ic_proxy.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,10 @@
2929
/* send a ack message after a batch of packets*/
3030
#define IC_PROXY_ACK_INTERVAL 10
3131

32-
33-
#ifndef IC_PROXY_LOG_LEVEL
34-
#define IC_PROXY_LOG_LEVEL WARNING
35-
#endif
36-
3732
#define ic_proxy_alloc(size) palloc(size)
3833
#define ic_proxy_free(ptr) pfree(ptr)
3934
#define ic_proxy_new(type) ((type *) ic_proxy_alloc(sizeof(type)))
4035

41-
#define ic_proxy_log(elevel, msg...) do { \
42-
if (elevel >= IC_PROXY_LOG_LEVEL) \
43-
{ \
44-
elog(elevel, msg); \
45-
} \
46-
} while (0)
47-
4836
/*
4937
* Build the domain socket path.
5038
*

contrib/interconnect/proxy/ic_proxy_addr.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ ic_proxy_addr_on_getaddrinfo(uv_getaddrinfo_t *req,
168168
/* the req is cancelled, nothing to do */
169169
}
170170
else
171-
ic_proxy_log(WARNING,
172-
"ic-proxy-addr: seg%d,dbid%d: fail to resolve the hostname \"%s\":%s: %s",
171+
elog(WARNING,
172+
"ic-proxy: seg%d,dbid%d: fail to resolve the hostname \"%s\":%s: %s",
173173
addr->content, addr->dbid,
174174
addr->hostname, addr->service,
175175
uv_strerror(status));
@@ -186,7 +186,7 @@ ic_proxy_addr_on_getaddrinfo(uv_getaddrinfo_t *req,
186186
if (iter->ai_family == AF_UNIX)
187187
continue;
188188

189-
#if IC_PROXY_LOG_LEVEL <= LOG
189+
if (gp_log_interconnect >= GPVARS_VERBOSITY_VERBOSE)
190190
{
191191
char name[HOST_NAME_MAX] = "unknown";
192192
int port = 0;
@@ -196,20 +196,19 @@ ic_proxy_addr_on_getaddrinfo(uv_getaddrinfo_t *req,
196196
ret = ic_proxy_extract_sockaddr(iter->ai_addr, name, sizeof(name),
197197
&port, &family);
198198
if (ret == 0)
199-
ic_proxy_log(LOG,
200-
"ic-proxy-addr: seg%d,dbid%d: resolved address %s:%s -> %s:%d family=%d",
199+
elog(LOG,
200+
"ic-proxy: seg%d,dbid%d: resolved address %s:%s -> %s:%d family=%d",
201201
addr->content, addr->dbid,
202202
addr->hostname, addr->service,
203203
name, port, family);
204204
else
205-
ic_proxy_log(LOG,
206-
"ic-proxy-addr: seg%d,dbid%d: resolved address %s:%s -> %s:%d family=%d (fail to extract the address: %s)",
205+
elog(LOG,
206+
"ic-proxy: seg%d,dbid%d: resolved address %s:%s -> %s:%d family=%d (fail to extract the address: %s)",
207207
addr->content, addr->dbid,
208208
addr->hostname, addr->service,
209209
name, port, family,
210210
uv_strerror(ret));
211211
}
212-
#endif /* IC_PROXY_LOG_LEVEL <= LOG */
213212

214213
memcpy(&addr->sockaddr, iter->ai_addr, iter->ai_addrlen);
215214
ic_proxy_addrs = lappend(ic_proxy_addrs, addr);
@@ -295,8 +294,8 @@ ic_proxy_reload_addresses(uv_loop_t *loop)
295294
if (dbid == GpIdentity.dbid)
296295
ic_proxy_my_addr = addr;
297296

298-
ic_proxy_log(LOG,
299-
"ic-proxy-addr: seg%d,dbid%d: parsed addr: %s:%d",
297+
elogif(gp_log_interconnect >= GPVARS_VERBOSITY_VERBOSE, LOG,
298+
"ic-proxy: seg%d,dbid%d: parsed addr: %s:%d",
300299
content, dbid, hostname, port);
301300

302301
uv_getaddrinfo(loop, &addr->req, ic_proxy_addr_on_getaddrinfo,
@@ -326,7 +325,7 @@ ic_proxy_get_my_addr(void)
326325
if (ic_proxy_my_addr)
327326
return ic_proxy_my_addr;
328327

329-
ic_proxy_log(LOG, "ic-proxy-addr: cannot get my addr");
328+
elogif(gp_log_interconnect >= GPVARS_VERBOSITY_VERBOSE, LOG, "ic-proxy: cannot get my addr");
330329
return NULL;
331330
}
332331

@@ -343,8 +342,8 @@ ic_proxy_addr_get_port(const ICProxyAddr *addr)
343342
else if (addr->sockaddr.ss_family == AF_INET6)
344343
return ntohs(((struct sockaddr_in6 *) addr)->sin6_port);
345344

346-
ic_proxy_log(WARNING,
347-
"ic-proxy-addr: invalid address family %d for seg%d,dbid%d",
345+
elog(WARNING,
346+
"ic-proxy: invalid address family %d for seg%d,dbid%d",
348347
addr->sockaddr.ss_family, addr->content, addr->dbid);
349348
return -1;
350349
}

contrib/interconnect/proxy/ic_proxy_backend.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ ic_proxy_backend_on_close(uv_handle_t *handle)
110110
backend = CONTAINER_OF((void *) handle, ICProxyBackend, pipe);
111111
context = backend->pipe.loop->data;
112112

113-
ic_proxy_log(LOG, "backend %s: backend connection closed, begin to reconnect.",
113+
elogif(gp_log_interconnect >= GPVARS_VERBOSITY_VERBOSE, LOG,
114+
"ic-proxy: backend %s: backend connection closed, begin to reconnect.",
114115
ic_proxy_key_to_str(&backend->key));
115116

116117
/*
@@ -154,10 +155,13 @@ ic_proxy_backend_on_read_hello_ack(uv_stream_t *stream, ssize_t nread, const uv_
154155
{
155156
/* UV_EOF is expected */
156157
if (nread == UV_EOF)
157-
ic_proxy_log(LOG, "backend %s: received EOF while receiving HELLO ACK.",
158-
ic_proxy_key_to_str(&backend->key));
158+
{
159+
elogif(gp_log_interconnect >= GPVARS_VERBOSITY_DEBUG, DEBUG1,
160+
"ic-proxy: backend %s: received EOF while receiving HELLO ACK.",
161+
ic_proxy_key_to_str(&backend->key));
162+
}
159163
else
160-
ic_proxy_log(WARNING, "backend %s: failed to recieve HELLO ACK: %s ",
164+
elog(WARNING, "ic-proxy: backend %s: failed to recieve HELLO ACK: %s ",
161165
ic_proxy_key_to_str(&backend->key), uv_strerror(nread));
162166

163167
/* should close current pipe and try to reconnect */
@@ -234,14 +238,16 @@ ic_proxy_backend_on_sent_hello(uv_write_t *req, int status)
234238

235239
if (status < 0)
236240
{
237-
ic_proxy_log(LOG, "backend %s: backend failed to send HELLO: %s",
241+
elogif(gp_log_interconnect >= GPVARS_VERBOSITY_DEBUG, DEBUG1,
242+
"ic-proxy: backend %s: backend failed to send HELLO: %s",
238243
ic_proxy_key_to_str(&backend->key), uv_strerror(status));
239244
uv_close((uv_handle_t *) &backend->pipe, ic_proxy_backend_on_close);
240245
return;
241246
}
242247

243248
/* recieve hello ack */
244-
ic_proxy_log(LOG, "backend %s: backend connected, receiving HELLO ACK",
249+
elogif(gp_log_interconnect >= GPVARS_VERBOSITY_DEBUG, DEBUG1,
250+
"ic-proxy: backend %s: backend connected, receiving HELLO ACK",
245251
ic_proxy_key_to_str(&backend->key));
246252

247253
backend->offset = 0;
@@ -288,12 +294,13 @@ ic_proxy_backend_on_connected(uv_connect_t *conn, int status)
288294
if (status < 0)
289295
{
290296
/* the proxy might just not get ready yet, retry later */
291-
ic_proxy_log(LOG, "backend %s: backend failed to connect: %s",
297+
elogif(gp_log_interconnect >= GPVARS_VERBOSITY_DEBUG, DEBUG1,
298+
"ic-proxy: backend %s: backend failed to connect: %s",
292299
ic_proxy_key_to_str(&backend->key), uv_strerror(status));
293300

294301
/* retry interval is 100ms and unit of interconnect_setup_timeout is second */
295302
if (interconnect_setup_timeout * 1000 <= backend->retryNum * CONNECT_TIMER_TIMEOUT)
296-
ic_proxy_log(ERROR, "backend %s: Interconnect timeout: Unable to "
303+
elog(ERROR, "ic-proxy: backend %s: Interconnect timeout: Unable to "
297304
"complete setup of connection within time limit %d seconds",
298305
ic_proxy_key_to_str(&backend->key), interconnect_setup_timeout);
299306

@@ -304,7 +311,8 @@ ic_proxy_backend_on_connected(uv_connect_t *conn, int status)
304311
return;
305312
}
306313

307-
ic_proxy_log(LOG, "backend %s: backend connected, sending HELLO message.",
314+
elogif(gp_log_interconnect >= GPVARS_VERBOSITY_DEBUG, DEBUG1,
315+
"ic-proxy: backend %s: backend connected, sending HELLO message.",
308316
ic_proxy_key_to_str(&backend->key));
309317

310318
/*

0 commit comments

Comments
 (0)