Skip to content

Commit

Permalink
added lots of debug outputs (enabled by the --with-debug option while…
Browse files Browse the repository at this point in the history
… building nginx), inspired by github issue #10.
  • Loading branch information
agentzh committed Aug 22, 2011
1 parent 31b0f23 commit 26d1b81
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 67 deletions.
1 change: 1 addition & 0 deletions src/ngx_http_drizzle_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ ngx_http_drizzle_query(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)

methods = 0xFFFF;
query = dlcf->default_query;

} else {
/* method-specific query */
dd("method-specific query");
Expand Down
7 changes: 4 additions & 3 deletions src/ngx_http_drizzle_output.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* Copyright (C) agentzh */

#ifndef DDEBUG
#define DDEBUG 0
#endif
#include "ddebug.h"

#include "ngx_http_drizzle_module.h"
Expand Down Expand Up @@ -57,8 +59,6 @@ ngx_http_drizzle_output_result_header(ngx_http_request_t *r,

ngx_http_upstream_drizzle_peer_data_t *dp = u->peer.data;

dd("enter output header XXX");

errcode = drizzle_result_error_code(res);

if (dp->enable_charset && ! dp->has_set_names) {
Expand Down Expand Up @@ -87,7 +87,7 @@ ngx_http_drizzle_output_result_header(ngx_http_request_t *r,

errstr = drizzle_result_error(res);

errstr_len = (uint16_t) strlen(errstr);
errstr_len = (uint16_t) ngx_strlen(errstr);

col_count = drizzle_result_column_count(res);

Expand Down Expand Up @@ -178,6 +178,7 @@ ngx_http_drizzle_output_result_header(ngx_http_request_t *r,
dd("about to be done...");
ngx_http_upstream_drizzle_done(r, u, dp, NGX_DONE);
dd("i am returning DONE");

return NGX_DONE;
}

Expand Down
72 changes: 41 additions & 31 deletions src/ngx_http_drizzle_processor.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* Copyright (C) chaoslawful */
/* Copyright (C) agentzh */

#ifndef DDEBUG
#define DDEBUG 0
#endif
#include "ddebug.h"

#include "ngx_http_drizzle_processor.h"
Expand Down Expand Up @@ -47,7 +49,8 @@ ngx_http_drizzle_process_events(ngx_http_request_t *r)

dp = u->peer.data;

dd("drizzle process events, state: %d", dp->state);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"drizzle process events, state: %d", dp->state);

if ( ! ngx_http_upstream_drizzle_is_my_peer(&u->peer)) {
ngx_log_error(NGX_LOG_ERR, c->log, 0,
Expand Down Expand Up @@ -118,12 +121,15 @@ ngx_http_upstream_drizzle_connect(ngx_http_request_t *r,
{
drizzle_return_t ret;

dd("drizzle connect: user %s, password %s", dc->user, dc->password);
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
"drizzle connect: user %s, password %s", dc->user, dc->password);

ret = drizzle_con_connect(dc);

if (ret == DRIZZLE_RETURN_IO_WAIT) {
dd("libdrizzle returned IO_WAIT while connecting");
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
"drizzle libdrizzle returned IO_WAIT while connecting");

return NGX_AGAIN;
}

Expand Down Expand Up @@ -156,28 +162,33 @@ ngx_http_upstream_drizzle_send_query(ngx_http_request_t *r,
ngx_http_upstream_t *u = r->upstream;
drizzle_return_t ret;
ngx_int_t rc;
u_char *query_data;
size_t query_len;
ngx_str_t query;
ngx_flag_t has_set_names = 0;
ngx_flag_t enable_charset = 0;

dd("enable charset: %d", (int) dp->enable_charset);

if (dp->enable_charset && ! dp->has_set_names) {
query_len = dp->set_names_query->len;
query_data = dp->set_names_query->data;
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
"drizzle enables connection charset setting");

query.len = dp->set_names_query->len;
query.data = dp->set_names_query->data;

} else {
query_data = dp->query.data;
query_len = dp->query.len;
query.data = dp->query.data;
query.len = dp->query.len;
}

dd("drizzle send query: %.*s", (int) query_len, query_data);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
"drizzle sending query \"%V\"", &query);

(void) drizzle_query(dc, &dp->drizzle_res, (const char *) query_data,
query_len, &ret);
(void) drizzle_query(dc, &dp->drizzle_res, (const char *) query.data,
query.len, &ret);

if (ret == DRIZZLE_RETURN_IO_WAIT) {
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
"drizzle libdrizzle returned IO_WAIT while sending query");

if (dp->state != state_db_send_query) {
dp->state = state_db_send_query;
Expand All @@ -200,11 +211,9 @@ ngx_http_upstream_drizzle_send_query(ngx_http_request_t *r,
#if 1
if (ret == DRIZZLE_RETURN_ERROR_CODE) {
if (drizzle_error_code(dc->drizzle) == MYSQL_ER_NO_SUCH_TABLE) {
dd("XXX no such talbe");

ngx_log_error(NGX_LOG_NOTICE, c->log, 0,
"failed to send query: %d (%d): %s",
(int) ret, drizzle_error_code(dc->drizzle),
"failed to send query: %i (%d): %s",
ret, drizzle_error_code(dc->drizzle),
drizzle_error(dc->drizzle));

if (dp->enable_charset && ! dp->has_set_names) {
Expand Down Expand Up @@ -243,10 +252,6 @@ ngx_http_upstream_drizzle_send_query(ngx_http_request_t *r,

rc = ngx_http_drizzle_output_result_header(r, &dp->drizzle_res);

dd("after output result header YYY");

dd("output result header ret %d", (int) rc);

if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
return rc;
}
Expand Down Expand Up @@ -280,7 +285,8 @@ ngx_http_upstream_drizzle_recv_cols(ngx_http_request_t *r,
ngx_int_t rc;
drizzle_return_t ret;

dd("drizzle recv cols");
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
"drizzle receive resultset columns");

for (;;) {
col = drizzle_column_read(&dp->drizzle_res, &dp->drizzle_col, &ret);
Expand Down Expand Up @@ -319,6 +325,7 @@ ngx_http_upstream_drizzle_recv_cols(ngx_http_request_t *r,
if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
return rc;
}

} else { /* after the last column */
if (c->read->timer_set) {
ngx_del_timer(c->read);
Expand Down Expand Up @@ -350,10 +357,13 @@ ngx_http_upstream_drizzle_recv_rows(ngx_http_request_t *r,
size_t total;
drizzle_field_t field;

dd("drizzle recv rows");
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
"drizzle receive resultset rows");

for (;;) {
dd("row: %d", (int) dp->drizzle_row);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
"drizzle receive resultset row %uL", dp->drizzle_row);

if (dp->drizzle_row == 0) {
dp->drizzle_row = drizzle_row_read(&dp->drizzle_res, &ret);

Expand Down Expand Up @@ -401,8 +411,6 @@ ngx_http_upstream_drizzle_recv_rows(ngx_http_request_t *r,
ngx_http_upstream_drizzle_done(r, u, dp, NGX_DONE);
return NGX_DONE;
}

dd("drizzle row: %" PRId64 "\n", dp->drizzle_row);
}

/* dp->drizzle_row != 0 */
Expand All @@ -411,8 +419,9 @@ ngx_http_upstream_drizzle_recv_rows(ngx_http_request_t *r,
field = drizzle_field_read(&dp->drizzle_res, &offset, &len,
&total, &ret);

dd("drizzle field: %p (offset %d, len %d)", field, (int) offset,
(int) len);
ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0,
"drizzle field read: %p (offset %z, len %z)", field,
offset, len);

if (ret == DRIZZLE_RETURN_IO_WAIT) {
goto io_wait;
Expand Down Expand Up @@ -445,7 +454,8 @@ ngx_http_upstream_drizzle_recv_rows(ngx_http_request_t *r,
}

if (field) {
dd("drizzle field value: %.*s", (int) len, field);
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
"drizzle field value read: %*s", len, field);
}
}

Expand Down Expand Up @@ -477,12 +487,11 @@ ngx_http_upstream_drizzle_done(ngx_http_request_t *r,
{
ngx_connection_t *c;

dd("enter");
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"drizzle upstream done");

(void) ngx_http_drizzle_output_bufs(r, dp);

dd("after output bufs");

/* to persuade Maxim Dounin's ngx_http_upstream_keepalive
* module to cache the current connection */

Expand All @@ -492,6 +501,7 @@ ngx_http_upstream_drizzle_done(ngx_http_request_t *r,
u->header_sent = 1;
u->headers_in.status_n = NGX_HTTP_OK;
rc = NGX_OK;

} else {
r->headers_out.status = rc;
u->headers_in.status_n = rc;
Expand Down
Loading

0 comments on commit 26d1b81

Please sign in to comment.