From 6711c3ee32aed527a05d63895c89fe01887a5b9a Mon Sep 17 00:00:00 2001 From: Dmitry Simonenko <pmwkaa@gmail.com> Date: Mon, 25 Feb 2013 19:02:40 +0400 Subject: [PATCH] client-cat-raw: tarantool --format raw implementation. https://bugs.launchpad.net/tarantool/+bug/1131755 --- client/tarantool/tc.c | 2 ++ client/tarantool/tc_opt.c | 3 ++- client/tarantool/tc_opt.h | 1 + client/tarantool/tc_print.c | 9 +++++++++ client/tarantool/tc_store.c | 14 +++++++++++++- connector/c/include/tarantool/tnt_request.h | 3 +++ connector/c/tnt/tnt_request.c | 19 +++++++++++++++++++ connector/c/tntrpl/tnt_log.c | 6 +++++- 8 files changed, 54 insertions(+), 3 deletions(-) diff --git a/client/tarantool/tc.c b/client/tarantool/tc.c index 96930fe9db..26aeb00f88 100644 --- a/client/tarantool/tc.c +++ b/client/tarantool/tc.c @@ -105,6 +105,8 @@ static void tc_validate(void) if (tc.opt.printer == NULL) return tc_error("unsupported output format '%s'", tc.opt.format); + if (tc.opt.format && strcmp(tc.opt.format, "raw") == 0) + tc.opt.raw = 1; } int main(int argc, char *argv[]) diff --git a/client/tarantool/tc_opt.c b/client/tarantool/tc_opt.c index 851670aaf0..15d80e3910 100644 --- a/client/tarantool/tc_opt.c +++ b/client/tarantool/tc_opt.c @@ -58,7 +58,7 @@ static const void *tc_options_def = gopt_start( gopt_option('T', GOPT_ARG, gopt_shorts('T'), gopt_longs("to"), " <lsn>", "stop on specified xlog lsn"), gopt_option('M', GOPT_ARG, gopt_shorts('M'), - gopt_longs("format"), " <name>", "cat output format (tarantool)"), + gopt_longs("format"), " <name>", "cat output format (tarantool, raw)"), gopt_option('R', GOPT_ARG, gopt_shorts('R'), gopt_longs("rpl"), " <lsn>", "act as replica for the specified server"), gopt_option('?', 0, gopt_shorts(0), gopt_longs("help"), @@ -137,6 +137,7 @@ enum tc_opt_mode tc_opt_init(struct tc_opt *opt, int argc, char **argv) } /* output format */ + opt->raw = 0; opt->format = NULL; if (gopt_arg(tc_options, 'M', &arg)) opt->format = arg; diff --git a/client/tarantool/tc_opt.h b/client/tarantool/tc_opt.h index 573171d1cf..b5e83a274a 100644 --- a/client/tarantool/tc_opt.h +++ b/client/tarantool/tc_opt.h @@ -55,6 +55,7 @@ struct tc_opt { int space; int space_set; const char *format; + int raw; void *printer; const char *file; char **cmdv; diff --git a/client/tarantool/tc_print.c b/client/tarantool/tc_print.c index 9a6d5fde79..a0479362a1 100644 --- a/client/tarantool/tc_print.c +++ b/client/tarantool/tc_print.c @@ -154,11 +154,20 @@ tc_printer_tarantool(struct tnt_log_header_v11 *hdr, } } +static void +tc_printer_raw(struct tnt_log_header_v11 *hdr, struct tnt_request *r) +{ + fwrite(hdr, sizeof(*hdr), 1, stdout); + fwrite(r->origin, r->origin_size, 1, stdout); +} + tc_printerf_t tc_print_getcb(const char *name) { if (name == NULL) return tc_printer_tarantool; if (!strcasecmp(name, "tarantool")) return tc_printer_tarantool; + if (!strcasecmp(name, "raw")) + return tc_printer_raw; return NULL; } diff --git a/client/tarantool/tc_store.c b/client/tarantool/tc_store.c index 8306bea87f..d212df33bf 100644 --- a/client/tarantool/tc_store.c +++ b/client/tarantool/tc_store.c @@ -123,7 +123,19 @@ static int tc_store_printer(struct tnt_iter *i) { static int tc_snapshot_printer(struct tnt_iter *i) { struct tnt_tuple *tu = TNT_ISTORAGE_TUPLE(i); - tc_print_tuple(tu); + struct tnt_stream_snapshot *ss = + TNT_SSNAPSHOT_CAST(TNT_ISTORAGE_STREAM(i)); + if (tc.opt.raw) { + fwrite(&ss->log.current.row_snap, + sizeof(ss->log.current.row_snap), 1, stdout); + fwrite(tu->data, tu->size, 1, stdout); + } else { + tc_printf("tag: %"PRIu16", cookie: %"PRIu64", space: %"PRIu32"\n", + ss->log.current.row_snap.tag, + ss->log.current.row_snap.cookie, + ss->log.current.row_snap.space); + tc_print_tuple(tu); + } return 0; } diff --git a/connector/c/include/tarantool/tnt_request.h b/connector/c/include/tarantool/tnt_request.h index 02bbc26c3c..f269183d21 100644 --- a/connector/c/include/tarantool/tnt_request.h +++ b/connector/c/include/tarantool/tnt_request.h @@ -78,6 +78,8 @@ struct tnt_request_select { }; struct tnt_request { + char *origin; + size_t origin_size; struct tnt_header h; union { struct tnt_request_insert insert; @@ -92,6 +94,7 @@ struct tnt_request { void tnt_request_init(struct tnt_request *r); void tnt_request_free(struct tnt_request *r); +void tnt_request_setorigin(struct tnt_request *r, char *buf, size_t size); int tnt_request(struct tnt_request *r, char *buf, size_t size, size_t *off, struct tnt_header *hdr); diff --git a/connector/c/tnt/tnt_request.c b/connector/c/tnt/tnt_request.c index 7bd5babb6d..59077f59c0 100644 --- a/connector/c/tnt/tnt_request.c +++ b/connector/c/tnt/tnt_request.c @@ -97,6 +97,25 @@ tnt_request_free(struct tnt_request *r) tnt_mem_free(r->v); r->v = NULL; } + if (r->origin) { + tnt_mem_free(r->origin); + r->origin = NULL; + } +} + +/* + * tnt_request_setorigin() + * + * set buffer of request source, free it with request free; + * + * r - request object pointer + * buf - supplied buffer + * size - buffer size +*/ +void +tnt_request_setorigin(struct tnt_request *r, char *buf, size_t size) { + r->origin = buf; + r->origin_size = size; } static int diff --git a/connector/c/tntrpl/tnt_log.c b/connector/c/tntrpl/tnt_log.c index 5b5c851188..5b92ff3da4 100644 --- a/connector/c/tntrpl/tnt_log.c +++ b/connector/c/tntrpl/tnt_log.c @@ -198,7 +198,11 @@ tnt_log_next_to(struct tnt_log *l, union tnt_log_value *value) { tnt_mem_free(buf); return NULL; } - tnt_mem_free(buf); + if (l->type == TNT_LOG_XLOG) { + tnt_request_setorigin(&value->r, buf, size); + } else { + tnt_mem_free(buf); + } return &l->current; } -- GitLab