Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
Yao Yue committed Jul 18, 2019
1 parent 9fdc42b commit 79f7fb0
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 52 deletions.
3 changes: 0 additions & 3 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
.dirstamp

# binaries
broadbill_slimcache
1 change: 1 addition & 0 deletions src/core/admin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set(SOURCE
${SOURCE}
${CMAKE_CURRENT_SOURCE_DIR}/admin.c
${CMAKE_CURRENT_SOURCE_DIR}/debug.c
PARENT_SCOPE)
46 changes: 8 additions & 38 deletions src/core/admin/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "core/context.h"

#include "protocol/debug/debug_include.h"
#include "protocol/admin/admin_include.h"
#include "util/util.h"

#include <buffer/cc_buf.h>
Expand Down Expand Up @@ -116,7 +116,7 @@ _debug_post_read(struct buf_sock *s)
{
parse_rstatus_e status;

debug_request_reset(&req);
admin_request_reset(&req);

while (buf_rsize(s->rbuf) > 0) {
int n;
Expand All @@ -138,11 +138,11 @@ _debug_post_read(struct buf_sock *s)
goto done;
}

debug_response_reset(&rsp);
admin_response_reset(&rsp);

debug_process_request(&rsp, &req);
admin_process_request(&rsp, &req);

n = debug_compose_rsp(&s->wbuf, &rsp);
n = admin_compose_rsp(&s->wbuf, &rsp);
if (n < 0) {
log_error("compose response error");
goto error;
Expand Down Expand Up @@ -195,17 +195,13 @@ _debug_event(void *arg, uint32_t events)
}

void
core_debug_setup(debug_options_st *options)
core_debug_setup(core_debug_options_st *options)
{
struct tcp_conn *c;
struct timeout tick;
char *host = DEBUG_HOST;
char *port = DEBUG_PORT;
int timeout = DEBUG_TIMEOUT;
int nevent = DEBUG_NEVENT;
uint64_t tick_ms = DEBUG_TW_TICK;
size_t cap = DEBUG_TW_CAP;
size_t ntick = DEBUG_TW_NTICK;

log_info("set up the %s module", DEBUG_MODULE_NAME);

Expand All @@ -219,9 +215,6 @@ core_debug_setup(debug_options_st *options)
port = option_str(&options->debug_port);
timeout = option_uint(&options->debug_timeout);
nevent = option_uint(&options->debug_nevent);
tick_ms = option_uint(&options->debug_tw_tick);
cap = option_uint(&options->debug_tw_cap);
ntick = option_uint(&options->debug_tw_ntick);
}

ctx->timeout = timeout;
Expand Down Expand Up @@ -261,14 +254,6 @@ core_debug_setup(debug_options_st *options)
c->level = CHANNEL_META;
event_add_read(ctx->evb, hdl->rid(c), debug_sock);

timeout_set_ms(&tick, tick_ms);
tw = timing_wheel_create(&tick, cap, ntick);
if (tw == NULL) {
log_crit("create timing wheel failed");
goto error;
}
timing_wheel_start(tw);

debug_init = true;

return;
Expand All @@ -286,26 +271,13 @@ core_debug_teardown(void)
if (!debug_init) {
log_warn("%s has never been setup", DEBUG_MODULE_NAME);
} else {
timing_wheel_stop(tw);
timing_wheel_destroy(&tw);
event_base_destroy(&(ctx->evb));
freeaddrinfo(debug_ai);
buf_sock_destroy(&debug_sock);
}
debug_init = false;
}

struct timeout_event *
core_debug_register(uint64_t intvl_ms, timeout_cb_fn cb, void *arg)
{
struct timeout delay;

ASSERT(debug_init);

timeout_set_ms(&delay, intvl_ms);
return timing_wheel_insert(tw, &delay, true, cb, arg);
}

static rstatus_i
_debug_evwait(void)
{
Expand All @@ -319,16 +291,14 @@ _debug_evwait(void)
return CC_OK;
}

void
core_debug_evloop(void)
void *
core_debug_evloop(void *arg)
{
for(;;) {
if (_debug_evwait() != CC_OK) {
log_crit("debug loop exited due to failure");
break;
}

timing_wheel_execute(tw);
}

exit(1);
Expand Down
10 changes: 5 additions & 5 deletions src/core/admin/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
#define DEBUG_NEVENT 1

/* name type default description */
#define DEBUG_OPTION(ACTION) \
#define CORE_DEBUG_OPTION(ACTION) \
ACTION( debug_host, OPTION_TYPE_STR, DEBUG_HOST, "debug interfaces listening on")\
ACTION( debug_port, OPTION_TYPE_STR, DEBUG_PORT, "debug port" )\
ACTION( debug_timeout, OPTION_TYPE_UINT, DEBUG_TIMEOUT, "evwait timeout" )\
ACTION( debug_nevent, OPTION_TYPE_UINT, DEBUG_NEVENT, "evwait max nevent returned" )

typedef struct {
DEBUG_OPTION(OPTION_DECLARE)
} debug_options_st;
CORE_DEBUG_OPTION(OPTION_DECLARE)
} core_debug_options_st;

void core_debug_setup(debug_options_st *options);
void core_debug_setup(core_debug_options_st *options);
void core_debug_teardown(void);

void core_debug_evloop(void);
void *core_debug_evloop(void *arg);
1 change: 1 addition & 0 deletions src/core/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ struct context {
bool admin_init;
bool server_init;
bool worker_init;
bool debug_init;
17 changes: 16 additions & 1 deletion src/core/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
void
core_run(void *arg_worker)
{
pthread_t worker, server;
pthread_t worker, server, debug;
int ret;

if (!admin_init || !server_init || !worker_init) {
Expand All @@ -24,12 +24,27 @@ core_run(void *arg_worker)
if (ret != 0) {
log_crit("pthread create failed for worker thread: %s", strerror(ret));
goto error;
} else {
log_info("worker thread of ID %d has been created", worker);
}


ret = pthread_create(&server, NULL, core_server_evloop, NULL);
if (ret != 0) {
log_crit("pthread create failed for server thread: %s", strerror(ret));
goto error;
} else {
log_info("server thread of ID %d has been created", server);
}

if (debug_init) {
ret = pthread_create(&debug, NULL, core_debug_evloop, NULL);
if (ret != 0) {
log_crit("pthread create failed for debug thread: %s", strerror(ret));
goto error;
} else {
log_info("debug thread of ID %d has been created", debug);
}
}

core_admin_evloop();
Expand Down
1 change: 1 addition & 0 deletions src/core/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include "admin/admin.h"
#include "admin/debug.h"
#include "data/shared.h"
#include "data/server.h"
#include "data/worker.h"
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/admin/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#define METRIC_DESCRIBE_LEN 120 /* 34 (name) + 16 (type) + 68 (description) + CRLF */
#define METRIC_END "END\r\n"
#define METRIC_END_LEN (sizeof(METRIC_END) - 1)
#define CENSUS_COUNT_FMT "item count: %zu %zu %zu\r\n"
#define CENSUS_COUNT_LEN 34 /* 12 (name string) + 20 + CRLF */
#define CENSUS_COUNT_FMT "item: %zu, total: %zu\r\n"
#define CENSUS_COUNT_LEN 56 /* 14 (name string) + 20 * 2 + CRLF */
#define CENSUS_KEY_FMT "key min: %zu, max: %zu, total: %zu\r\n"
#define CENSUS_KEY_LEN 87 /* 9 + 7 + 9 (name strings) + 20 * 3 + CRLF */
#define CENSUS_VAL_FMT "val min: %zu, max: %zu, total: %zu\r\n"
Expand Down
3 changes: 3 additions & 0 deletions src/protocol/admin/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ _get_req_type(struct request *req, struct bstring *type)
break;
}

break;

case 6:
if (str6cmp(type->data, 'c', 'e', 'n', 's', 'u', 's')) {
req->type = REQ_CENSUS;
break;
Expand Down
6 changes: 3 additions & 3 deletions src/server/twemcache/admin/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ _key_census(struct response *rsp, struct request *req)
req->arg.len--;
req->arg.data++;
}
log_info("census on keys with prefix %.*s", req->arg.len, req->arg.data);
log_info("census on keys with prefix '%.*s'", req->arg.len, req->arg.data);

item_census(&nkey, &ktotal, &kmin, &kmax, &vtotal, &vmin, &vmax, &req->arg);
rsp->type = RSP_GENERIC;
ret = cc_scnprintf(buf, cap, CENSUS_FMT, nkey, ktotal, kmin, kmax, vtotal,
vmin, vmax);
ret = cc_scnprintf(buf, cap, CENSUS_FMT, nkey, ktotal + vtotal, kmin, kmax,
ktotal, vmin, vmax, vtotal);
if (ret < 0) {
rsp->data = str2bstr("ERROR: cannot format key census result");
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/server/twemcache/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ teardown(void)
{
core_worker_teardown();
core_server_teardown();
core_debug_teardown();
core_admin_teardown();
admin_process_teardown();
process_teardown();
Expand Down Expand Up @@ -127,6 +128,7 @@ setup(void)
process_setup(&setting.process, &stats.process);
admin_process_setup();
core_admin_setup(&setting.admin);
core_debug_setup(&setting.core_debug);
core_server_setup(&setting.server, &stats.server);
core_worker_setup(&setting.worker, &stats.worker);

Expand Down
1 change: 1 addition & 0 deletions src/server/twemcache/setting.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
struct setting setting = {
{ TWEMCACHE_OPTION(OPTION_INIT) },
{ ADMIN_OPTION(OPTION_INIT) },
{ CORE_DEBUG_OPTION(OPTION_INIT)},
{ SERVER_OPTION(OPTION_INIT) },
{ WORKER_OPTION(OPTION_INIT) },
{ PROCESS_OPTION(OPTION_INIT) },
Expand Down
1 change: 1 addition & 0 deletions src/server/twemcache/setting.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct setting {
twemcache_options_st twemcache;
/* application modules */
admin_options_st admin;
core_debug_options_st core_debug;
server_options_st server;
worker_options_st worker;
process_options_st process;
Expand Down

0 comments on commit 79f7fb0

Please sign in to comment.