Skip to content

Commit

Permalink
refactor verbose level
Browse files Browse the repository at this point in the history
  • Loading branch information
astrophysik committed Jul 6, 2023
1 parent 784b220 commit ac23b3e
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 85 deletions.
2 changes: 1 addition & 1 deletion net/net-dc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int is_same_data_center(struct connection *c, int is_client) {
}

char buffer_local[SOCKADDR_STORAGE_BUFFER_SIZE], buffer_remote[SOCKADDR_STORAGE_BUFFER_SIZE];
vkprintf(3, "check_same_data_center(%d): %s -> %s\n", c->fd, sockaddr_storage_to_buffer(&c->local_endpoint, buffer_local),
vkprintf(4, "check_same_data_center(%d): %s -> %s\n", c->fd, sockaddr_storage_to_buffer(&c->local_endpoint, buffer_local),
sockaddr_storage_to_buffer(&c->remote_endpoint, buffer_remote));
if (c->flags & C_IPV6) { // we don't use it now
assert(c->local_endpoint.ss_family == AF_INET6);
Expand Down
6 changes: 2 additions & 4 deletions net/net-events.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,9 @@ static inline int epoll_fetch_events(int timeout) {
events = 0;
}
if (events < 0) {
tvkprintf(net_events, 0, "epoll_wait(): %m\n");
}
if (verbosity > 2 && events) {
tvkprintf(net_events, 0, "epoll_wait(%d, ...) = %d\n", main_thread_reactor.epoll_fd, events);
tvkprintf(net_events, 4, "epoll_wait(): %m\n");
}
tvkprintf(net_events, 4, "epoll_wait(%d, ...) = %d\n", main_thread_reactor.epoll_fd, events);

net_reactor_fetch_events(&main_thread_reactor, events);

Expand Down
10 changes: 5 additions & 5 deletions net/net-ifnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ unsigned get_my_ipv4() {
}
unsigned ip = ntohl(((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr);
unsigned mask = ntohl(((struct sockaddr_in *)ifa->ifa_netmask)->sin_addr.s_addr);
vkprintf (2, "%08x %08x (%08x == %08x)\t%s\t-> %d,%d\n", ip, mask, (ip & force_ipv4_mask), force_ipv4_ip, ifa->ifa_name, (ip & force_ipv4_mask) == force_ipv4_ip, mask < my_netmask);
vkprintf (4, "%08x %08x (%08x == %08x)\t%s\t-> %d,%d\n", ip, mask, (ip & force_ipv4_mask), force_ipv4_ip, ifa->ifa_name, (ip & force_ipv4_mask) == force_ipv4_ip, mask < my_netmask);
if ((ip & force_ipv4_mask) == force_ipv4_ip && (!my_ip || mask < my_netmask)) {
my_ip = ip;
my_netmask = mask;
Expand All @@ -85,7 +85,7 @@ unsigned get_my_ipv4() {
if (force_ipv4_mask != 0xff000000 || force_ipv4_ip != (10 << 24)) {
assert(my_ip != 0 && "can't choose ip in given subnet");
}
vkprintf (1, "using main IP %d.%d.%d.%d/%d at interface %s\n", (my_ip >> 24), (my_ip >> 16) & 255, (my_ip >> 8) & 255, my_ip & 255,
vkprintf (4, "using main IP %d.%d.%d.%d/%d at interface %s\n", (my_ip >> 24), (my_ip >> 16) & 255, (my_ip >> 8) & 255, my_ip & 255,
__builtin_clz(~my_netmask), my_iface ?: "(none)");
freeifaddrs(ifa_first);
return my_ip;
Expand All @@ -106,10 +106,10 @@ int get_my_ipv6(unsigned char ipv6[16]) {
continue;
}
memcpy(ip, &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr, 16);
vkprintf (2, "test IP %s at interface %s\n", ipv6_to_print(ip), ifa->ifa_name);
vkprintf (4, "test IP %s at interface %s\n", ipv6_to_print(ip), ifa->ifa_name);

if ((ip[0] & 0xf0) != 0x30 && (ip[0] & 0xf0) != 0x20) {
vkprintf (2, "not a global ipv6 address\n");
vkprintf (4, "not a global ipv6 address\n");
continue;
}

Expand Down Expand Up @@ -139,7 +139,7 @@ int get_my_ipv6(unsigned char ipv6[16]) {
m++;
}
}
vkprintf (1, "using main IP %s/%d at interface %s\n", ipv6_to_print(ipv6), m, my_iface);
vkprintf (4, "using main IP %s/%d at interface %s\n", ipv6_to_print(ipv6), m, my_iface);
freeifaddrs(ifa_first);
return 1;
}
10 changes: 5 additions & 5 deletions net/net-memcache-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ static int mcc_parse_execute (struct connection *c) {
D->response_len += len;

if (D->response_flags & 48) {
vkprintf (0, "bad response from memcache server at %s, connection %d\n", sockaddr_storage_to_string(&c->remote_endpoint), c->fd);
kprintf("bad response from memcache server at %s, connection %d\n", sockaddr_storage_to_string(&c->remote_endpoint), c->fd);
c->error = -1;
return 0;
}
Expand Down Expand Up @@ -420,7 +420,7 @@ static int mcc_parse_execute (struct connection *c) {
return 0;
}
} else if (D->response_type == mcrt_NONCE) {
vkprintf (0, "bad response in NONCE from memcache server at %s, connection %d\n", sockaddr_storage_to_string(&c->remote_endpoint), c->fd);
kprintf("bad response in NONCE from memcache server at %s, connection %d\n", sockaddr_storage_to_string(&c->remote_endpoint), c->fd);
c->status = conn_error;
c->error = -1;
return 0;
Expand Down Expand Up @@ -450,7 +450,7 @@ static int mcc_parse_execute (struct connection *c) {
}
if (D->response_flags & 48) {
//write_out (&c->Out, "CLIENT_ERROR\r\n", 14);
vkprintf (0, "bad response from memcache server at %s, connection %d\n", sockaddr_storage_to_string(&c->remote_endpoint), c->fd);
kprintf("bad response from memcache server at %s, connection %d\n", sockaddr_storage_to_string(&c->remote_endpoint), c->fd);
c->status = conn_error;
c->error = -1;
return 0;
Expand All @@ -471,7 +471,7 @@ static int mcc_parse_execute (struct connection *c) {
int mcc_connected (struct connection *c) {
c->last_query_sent_time = precise_now;

vkprintf (2, "connection #%d: connected, crypto_flags = %d\n", c->fd, MCC_DATA(c)->crypto_flags);
vkprintf(4, "connection #%d: connected, crypto_flags = %d\n", c->fd, MCC_DATA(c)->crypto_flags);
if (MCC_FUNC(c)->mc_check_perm) {
int res = MCC_FUNC(c)->mc_check_perm (c);
if (res < 0) {
Expand Down Expand Up @@ -627,7 +627,7 @@ int mcc_start_crypto (struct connection *c, char *key, int key_len) {
int mcc_flush_query (struct connection *c) {
if (c->crypto) {
int pad_bytes = c->type->crypto_needed_output_bytes (c);
vkprintf(2, "mcc_flush_query: padding with %d bytes\n", pad_bytes);
vkprintf(4, "mc: flush query (padding with %d bytes)\n", pad_bytes);
if (pad_bytes > 0) {
static char pad_str[16] = {'\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n'};
assert (pad_bytes <= 15);
Expand Down
21 changes: 10 additions & 11 deletions net/net-memcache-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ int mcs_execute (struct connection *c, int op) {
skip = D->query_len - D->key_offset - D->key_len;
assert (advance_skip_read_ptr (&c->In, skip) == skip);

vkprintf(1, "mc_set: op=%d, key '%s', key_len=%d, flags=%lld, time=%lld, value_len=%lld\n", op, key_buffer, D->key_len, D->args[0], D->args[1], D->args[2]);
vkprintf(4, "mc: set op=%d, key '%s', key_len=%d, flags=%lld, time=%lld, value_len=%lld\n", op, key_buffer, D->key_len, D->args[0], D->args[1], D->args[2]);

restart_set:

Expand Down Expand Up @@ -177,7 +177,7 @@ int mcs_execute (struct connection *c, int op) {
key_buffer[D->key_len] = 0;
D->query_type = op -= mct_set_resume - mct_set;

vkprintf(1, "mc_set_resume: op=%d, key '%s', key_len=%d, flags=%lld, time=%lld, value_len=%lld\n", op, key_buffer, D->key_len, D->args[0], D->args[1], D->args[2]);
vkprintf(4, "mc: set_resume op=%d, key '%s', key_len=%d, flags=%lld, time=%lld, value_len=%lld\n", op, key_buffer, D->key_len, D->args[0], D->args[1], D->args[2]);

goto restart_set;

Expand Down Expand Up @@ -270,10 +270,10 @@ int mcs_execute (struct connection *c, int op) {
key_buffer[D->key_len] = 0;

if (op == mct_delete) {
vkprintf(1, "mc_delete: key '%s', key_len=%d\n", key_buffer, D->key_len);
vkprintf(4, "mc de key '%s', key_len=%d\n", key_buffer, D->key_len);
res = MCS_FUNC(c)->mc_delete (c, key_buffer, D->key_len);
} else {
vkprintf(1, "mc_incr: op=%d, key '%s', key_len=%d, arg=%lld\n", op, key_buffer, D->key_len, D->args[0]);
vkprintf(4, "mc_incr: op=%d, key '%s', key_len=%d, arg=%lld\n", op, key_buffer, D->key_len, D->args[0]);
res = MCS_FUNC(c)->mc_incr (c, op - mct_incr, key_buffer, D->key_len, D->args[0]);
}

Expand Down Expand Up @@ -329,7 +329,7 @@ int mcs_parse_execute (struct connection *c) {
int len;
long long tt;

vkprintf(2, "c->pending_queries = %d, c->status = %d\n", c->pending_queries, c->status);
vkprintf(4, "in mcs_execute c->pending_queries = %d, c->status = %d\n", c->pending_queries, c->status);
while (c->status == conn_expect_query || c->status == conn_reading_query) {
len = nbit_ready_bytes (&c->Q);
ptr = ptr_s = static_cast<char*>(nbit_get_ptr (&c->Q));
Expand Down Expand Up @@ -588,7 +588,7 @@ int mcs_parse_execute (struct connection *c) {
if (!strncmp (key_buffer, "@#$AuTh$#@", 10)) {
assert (advance_skip_read_ptr (&c->In, D->query_len) == D->query_len);

vkprintf(1, "got AUTH: delete '%s'\n", key_buffer);
vkprintf(4, "mc got AUTH: delete '%s'\n", key_buffer);

if (c->In.total_bytes) {
c->status = conn_error;
Expand Down Expand Up @@ -630,9 +630,9 @@ int mcs_parse_execute (struct connection *c) {
if (!MCS_FUNC(c)->execute) {
MCS_FUNC(c)->execute = mcs_execute;
}
vkprintf(2, "c->pending_queries = %d, c->status = %d\n", c->pending_queries, c->status);
vkprintf(4, "mc c->pending_queries = %d, c->status = %d\n", c->pending_queries, c->status);
int res = MCS_FUNC(c)->execute (c, D->query_type);
vkprintf(2, "c->pending_queries = %d, c->status = %d, res = %d\n", c->pending_queries, c->status, res);
vkprintf(4, "mc c->pending_queries = %d, c->status = %d, res = %d\n", c->pending_queries, c->status, res);
if (res > 0) {
c->status = conn_reading_query;
return res; // need more bytes
Expand All @@ -648,7 +648,6 @@ int mcs_parse_execute (struct connection *c) {
c->status = conn_expect_query;
}

vkprintf(2, "c->pending_queries = %d, c->status = %d\n", c->pending_queries, c->status);
assert ((c->pending_queries && (c->status == conn_wait_net || c->status == conn_wait_aio)) || (!c->pending_queries && c->status == conn_expect_query) || c->status == conn_error);

if (c->status == conn_wait_net || c->status == conn_wait_aio) {
Expand Down Expand Up @@ -729,7 +728,7 @@ int return_one_key_list (struct connection *c, const char *key, int key_len, int
const size_t buff_size = 16;
static char buff[buff_size];

vkprintf(1, "result = %d\n", res);
vkprintf(4, "result = %d\n", res);

if (!R_cnt) {
if (res == 0x7fffffff) {
Expand Down Expand Up @@ -802,7 +801,7 @@ int return_one_key_list_long(struct connection *c, const char *key, int key_len,
const size_t buf_size = 16;
static char buff[buf_size];

vkprintf(1, "result = %d\n", res);
vkprintf(4, "result = %d\n", res);

if (!R_cnt) {
if (res == 0x7fffffff) {
Expand Down
44 changes: 22 additions & 22 deletions net/net-mysql-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ int sqlc_flush_packet (struct connection *c, int packet_len) {
}
assert (packet_len == pad_bytes);
}
vkprintf (2, "sqlc_flush_query: padding with %d bytes\n", pad_bytes);
vkprintf(4, "sqlc_flush_query: padding with %d bytes\n", pad_bytes);
if (pad_bytes > 0) {
static char pad_str[16];
assert (pad_bytes <= 15);
Expand All @@ -191,21 +191,21 @@ static int sqlc_inner_authorise (struct connection *c) {
struct mysql_auth_packet_end *T;
char scramble_len = 20;

vkprintf(2, "server_auth_packet received, len=%d\n", D->packet_len);
vkprintf(4, "server_auth_packet received, len=%d\n", D->packet_len);
if (len >= 0x800) {
vkprintf(1, "server_auth_packet too large\n");
vkprintf(4, "server_auth_packet too large\n");
return -1;
}
if (len < 46) {
vkprintf(1, "server_auth_packet too small\n");
vkprintf(4, "server_auth_packet too small\n");
return -1;
}
assert (force_ready_bytes (&c->In, len+4) >= len+4);
p = ((char *)get_read_ptr (&c->In)) + 4;
q = p + len;

if (*p != 10) {
vkprintf(1, "server_auth_packet has bad protocol version\n");
vkprintf(4, "server_auth_packet has bad protocol version\n");
return -1;
}

Expand All @@ -218,7 +218,7 @@ static int sqlc_inner_authorise (struct connection *c) {
}

if (p == q) {
vkprintf(1, "unterminated version string in server_auth_packet\n");
vkprintf(4, "unterminated version string in server_auth_packet\n");
return -1;
}

Expand All @@ -233,27 +233,27 @@ static int sqlc_inner_authorise (struct connection *c) {
size_t expected_length = sizeof (struct mysql_auth_packet_end);
if (((struct mysql_auth_packet_end*)p)->proto_len){
if (strncmp(((struct mysql_auth_packet_end*)p)->proto, "mysql_native_password", 21)){
vkprintf(1, "unknown auth_proto %s\n", ((struct mysql_auth_packet_end*)p)->proto);
vkprintf(4, "unknown auth_proto %s\n", ((struct mysql_auth_packet_end*)p)->proto);
return -1;
}
expected_length += 22;
}

if (q - p != expected_length) {
vkprintf (1, "server_auth_packet has incorrect size\n");
vkprintf(4, "server_auth_packet has incorrect size\n");
return -1;
}

int res = !SQLC_FUNC(c)->is_mysql_same_datacenter_check_disabled() && SQLC_FUNC(c)->sql_check_perm ? SQLC_FUNC(c)->sql_check_perm (c) : 1;

if (res < 0 || !(res &= 3)) {
vkprintf (1, "check_perm forbids access for connection %d\n", c->fd);
vkprintf(4, "check_perm forbids access for connection %d\n", c->fd);
return -1;
}

D->crypto_flags = res;

vkprintf(2, "crypto flags here = %d\n", D->crypto_flags);
vkprintf(4, "crypto flags here = %d\n", D->crypto_flags);

if ((res & 2) && p - r >= 8 && !memcmp(r, "5.0.239-", 8) && SQLC_FUNC(c)->sql_init_crypto && SQLC_FUNC(c)->sql_init_crypto (c, r + 8, p - r - 9) > 0) {
D->crypto_flags &= 2;
Expand All @@ -262,10 +262,10 @@ static int sqlc_inner_authorise (struct connection *c) {
D->crypto_flags &= 1;
}

vkprintf(2, "crypto flags adjusted %d\n", D->crypto_flags);
vkprintf(4, "crypto flags adjusted %d\n", D->crypto_flags);

if (!(D->crypto_flags & 3)) {
vkprintf(1, "unable to initialise cryptography, closing connection %d\n", c->fd);
vkprintf(4, "unable to initialise cryptography, closing connection %d\n", c->fd);
return -1;
}

Expand All @@ -275,7 +275,7 @@ static int sqlc_inner_authorise (struct connection *c) {
const char *sql_user = SQLC_FUNC(c)->sql_get_user(c);
const char *sql_password = SQLC_FUNC(c)->sql_get_password(c);

vkprintf(1, "mysql db: %s; user: %s; password: *\n", sql_database, sql_user);
vkprintf(4, "mysql db: %s; user: %s; password: *\n", sql_database, sql_user);

sha1 ((unsigned char *)sql_password, strlen (sql_password), (unsigned char *)stage1_hash);
memcpy (password_sha1, T->scramble1, 8);
Expand Down Expand Up @@ -310,7 +310,7 @@ int sqlc_parse_execute (struct connection *c) {
struct sqlc_data *D = SQLC_DATA(c);
int len = nbit_total_ready_bytes (&c->Q);
static unsigned int psize;
vkprintf(2, "sqlc_parse_execute(%d), status=%d, bytes=%d, packet_state=%d, packet_len=%d\n", c->fd, c->status, len, D->packet_state, D->packet_len);
vkprintf(4, "sqlc_parse_execute(%d), status=%d, bytes=%d, packet_state=%d, packet_len=%d\n", c->fd, c->status, len, D->packet_state, D->packet_len);
char *p;

while (len > 0 && !(c->flags & (C_FAILED | C_STOPREAD))) {
Expand All @@ -337,7 +337,7 @@ int sqlc_parse_execute (struct connection *c) {
}
/* complete packet ready */
c->last_response_time = precise_now;
vkprintf(2, "client packet ready: len=%d, seq_num=%d\n", D->packet_len, D->packet_seq);
vkprintf(4, "client packet ready: len=%d, seq_num=%d\n", D->packet_len, D->packet_seq);
if (D->auth_state == sql_noauth) {
int res = sqlc_inner_authorise(c);
if (res < 0) {
Expand Down Expand Up @@ -368,19 +368,19 @@ int sqlc_parse_execute (struct connection *c) {
if (SQLC_FUNC(c)->sql_authorized (c)) {
c->status = conn_error;
c->error = -1;
vkprintf(2, "sql authorisation failed\n");
vkprintf(4, "sql authorisation failed\n");
return 0;
}

vkprintf(2, "outcoming authorization successful\n");
vkprintf(4, "outcoming authorization successful\n");

} else
if (D->auth_state == sql_auth_initdb) {
p = ((char *)get_read_ptr (&c->In)) + 4;
if (D->packet_len == 0 || *p) {
c->status = conn_error;
c->error = -1;
vkprintf(2, "ok packet expected in response to initdb\n");
vkprintf(4, "ok packet expected in response to initdb\n");
return 0;
}
D->auth_state = sql_auth_ok;
Expand All @@ -393,7 +393,7 @@ int sqlc_parse_execute (struct connection *c) {
kprintf ("ok packet expected\n");
return 0;
}*/
vkprintf(2, "outcoming initdb successful\n");
vkprintf(4, "outcoming initdb successful\n");
SQLC_FUNC(c)->sql_becomes_ready (c);
return 0;
} else {
Expand All @@ -402,7 +402,7 @@ int sqlc_parse_execute (struct connection *c) {
assert (D->auth_state == sql_auth_ok);

//dump_connection_buffers (c);
vkprintf(2, "execute, op=%d\n", op);
vkprintf(4, "execute, op=%d\n", op);

int keep_total_bytes = c->In.total_bytes;

Expand Down Expand Up @@ -526,7 +526,7 @@ int sqlc_default_check_perm (struct connection *c) {
}

int sqlc_init_crypto (struct connection *c, char *key, int key_len) {
vkprintf(2, "sqlc_init_crypto (%p [fd=%d], '%.*s' [%d])\n", c, c->fd, key_len, key, key_len);
vkprintf(4, "sqlc_init_crypto (%p [fd=%d], '%.*s' [%d])\n", c, c->fd, key_len, key, key_len);

if (c->crypto) {
return -1;
Expand All @@ -544,7 +544,7 @@ int sqlc_init_crypto (struct connection *c, char *key, int key_len) {

int mytime = time (0);

vkprintf(3, "remote time %d, local %d\n", utime, mytime);
vkprintf(4, "remote time %d, local %d\n", utime, mytime);

if (abs (mytime - utime) > 10) {
return -1;
Expand Down
2 changes: 1 addition & 1 deletion net/net-reactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ int net_reactor_run_timers(net_reactor_ctx_t *ctx) {
wait_time = ctx->timer_heap[1]->wakeup_time - precise_now;
if (wait_time > 0) {
// do not remove this useful debug!
tvkprintf(net_events, 3, "%d event timers, next in %.3f seconds\n", ctx->timer_heap_size, wait_time);
tvkprintf(net_events, 4, "%d event timers, next in %.3f seconds\n", ctx->timer_heap_size, wait_time);
return (int)(std::min(100.0, wait_time) * 1000) + 1; // min to prevent integer overflow
}

Expand Down
4 changes: 2 additions & 2 deletions net/net-socket-options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void socket_maximize_sndbuf(int socket, int max) {
}
}

vkprintf(2, "<%d send buffer was %d, now %d\n", socket, old_size, last_good);
vkprintf(4, "<%d send buffer was %d, now %d\n", socket, old_size, last_good);
}

void socket_maximize_rcvbuf(int socket, int max) {
Expand Down Expand Up @@ -185,5 +185,5 @@ void socket_maximize_rcvbuf(int socket, int max) {
}
}

vkprintf(2, ">%d receive buffer was %d, now %d\n", socket, old_size, last_good);
vkprintf(4, ">%d receive buffer was %d, now %d\n", socket, old_size, last_good);
}
Loading

0 comments on commit ac23b3e

Please sign in to comment.