Skip to content
Snippets Groups Projects
Commit 6711c3ee authored by Dmitry Simonenko's avatar Dmitry Simonenko
Browse files

client-cat-raw: tarantool --format raw implementation.

parent 7bc868cb
No related branches found
No related tags found
No related merge requests found
......@@ -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[])
......
......@@ -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;
......
......@@ -55,6 +55,7 @@ struct tc_opt {
int space;
int space_set;
const char *format;
int raw;
void *printer;
const char *file;
char **cmdv;
......
......@@ -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;
}
......@@ -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;
}
......
......@@ -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);
......
......@@ -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
......
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment