Esempio n. 1
0
void
recv_command(char *command)
{
	struct tnt_iter i;
	tnt_iter_reply(&i, tnt);
	while (tnt_next(&i)) {
		struct tnt_reply *r = TNT_IREPLY_PTR(&i);
		printf("%s: respond %s (op: %"PRIu32", reqid: %"PRIu32", code: %"PRIu32", count: %"PRIu32")\n",
			command, tnt_strerror(tnt),
			r->op,
			r->reqid,
			r->code,
			r->count);
		struct tnt_iter it;
		tnt_iter_list(&it, TNT_REPLY_LIST(r));
		while (tnt_next(&it)) {
			struct tnt_tuple *tu = TNT_ILIST_TUPLE(&it);
			print_tuple(tu);
		}
		tnt_iter_free(&it);
	}
	if (i.status == TNT_ITER_FAIL)
		fail_tnt_perror("tnt_next");
	tnt_iter_free(&i);
}
Esempio n. 2
0
/*
 * tnt_select()
 *
 * write select request to stream;
 *
 * s     - stream pointer
 * ns    - space
 * index - request index
 * offset- request offset
 * limit - request limit
 * keys  - list of tuples keys
 * 
 * returns number of bytes written, or -1 on error.
*/
ssize_t
tnt_select(struct tnt_stream *s,
	   uint32_t ns,
	   uint32_t index, uint32_t offset, uint32_t limit,
	   struct tnt_list *keys)
{
	/* calculating tuples sizes */
	size_t size = 0;
	struct tnt_iter i;
	tnt_iter_list(&i, keys);
	while (tnt_next(&i)) {
		struct tnt_tuple *t = TNT_ILIST_TUPLE(&i);
		size += t->size;
	}
	/* filling major header */
	struct tnt_header hdr;
	hdr.type = TNT_OP_SELECT;
	hdr.len = sizeof(struct tnt_header_select) + 4 + size;
	hdr.reqid = s->reqid;
	/* filling select header */
	struct tnt_header_select hdr_sel;
	hdr_sel.ns = ns;
	hdr_sel.index = index;
	hdr_sel.offset = offset;
	hdr_sel.limit = limit;
	/* allocating write vector */
	int vc = 3 + keys->count;
	struct iovec *v = tnt_mem_alloc(sizeof(struct iovec) * vc);
	if (v == NULL) {
		tnt_iter_free(&i);
		return -1;
	}
	/* filling write vector */
	v[0].iov_base = &hdr;
	v[0].iov_len  = sizeof(struct tnt_header);
	v[1].iov_base = &hdr_sel;
	v[1].iov_len  = sizeof(struct tnt_header_select);
	v[2].iov_base = &keys->count;
	v[2].iov_len  = 4;
	int vi = 3;
	tnt_rewind(&i);
	while (tnt_next(&i)) {
		struct tnt_tuple *t = TNT_ILIST_TUPLE(&i);
		v[vi].iov_base = t->data;
		v[vi].iov_len  = t->size;
		vi++;
	}
	tnt_iter_free(&i);
	/* writing data to stream */
	ssize_t rc = s->writev(s, v, vc);
	tnt_mem_free(v);
	return rc;
}
Esempio n. 3
0
void tc_print_tuple(struct tnt_tuple *tu)
{
	struct tnt_iter ifl;
	tnt_iter(&ifl, tu);
	printf("[");
	while (tnt_next(&ifl)) {
		if (TNT_IFIELD_IDX(&ifl) != 0)
			printf(", ");
		char *data = TNT_IFIELD_DATA(&ifl);
		uint32_t size = TNT_IFIELD_SIZE(&ifl);
		if (!isprint(data[0]) && (size == 4 || size == 8)) {
			if (size == 4) {
				uint32_t i = *((uint32_t*)data);
				printf("%"PRIu32, i);
			} else {
				uint64_t i = *((uint64_t*)data);
				printf("%"PRIu64, i);
			}
		} else {
			printf("'%-.*s'", size, data);
		}
	}
	if (ifl.status == TNT_ITER_FAIL)
		printf("<parsing error>");
	printf("]\n");
	tnt_iter_free(&ifl);
}
Esempio n. 4
0
void tc_print_list(struct tnt_list *l)
{
	struct tnt_iter it;
	tnt_iter_list(&it, l);
	while (tnt_next(&it)) {
		struct tnt_tuple *tu = TNT_ILIST_TUPLE(&it);
		tc_print_tuple(tu);
	}
	tnt_iter_free(&it);
}
Esempio n. 5
0
static int tc_wal_foreach(struct tnt_stream *s, tc_wal_t cb) {
	struct tnt_iter i;
	tnt_iter_request(&i, s);
	while (tnt_next(&i)) {
		if (cb(&i) == -1) {
			tnt_iter_free(&i);
			return -1;
		}
	}
	int rc = 0;
	if (i.status == TNT_ITER_FAIL)
		rc = tc_wal_error("parsing failed");
	tnt_iter_free(&i);
	return rc;
}
Esempio n. 6
0
/*
 * tnt_field()
 *
 * set or create iterator to the specified tuple field;
 *
 * i     - tuple iterator pointer
 * t     - tuple pointer
 * index - tuple field index
 *
 * returns tuple iterator pointer if field found, NULL otherwise.
*/
struct tnt_iter*
tnt_field(struct tnt_iter *i, struct tnt_tuple *t, uint32_t index)
{
	int allocated = i == NULL;
	if (i == NULL) {
		i = tnt_iter(i, t);
		if (i == NULL)
			return NULL;
	} else
		tnt_rewind(i);
	while (tnt_next(i))
		if (TNT_IFIELD_IDX(i) == index)
			return i;
	if (allocated)
		tnt_iter_free(i);
	return NULL;
}
Esempio n. 7
0
int tc_verify_process(struct tc_spaces *s, uint64_t lsn, char *snap_dir)
{
	char path[1024];
	snprintf(path, sizeof(path), "%s/%020llu.snap", snap_dir,
		(long long unsigned)lsn);

	printf("(snapshot) %s\n", path);

	struct tnt_stream st;
	tnt_snapshot(&st);
	if (tnt_snapshot_open(&st, path) == -1) {
		printf("failed to open snapshot file\n");
		tnt_stream_free(&st);
		return -1;
	}

	struct tnt_iter i;
	tnt_iter_storage(&i, &st);
	int errors = 0;
	int rc = 0;
	while (tnt_next(&i)) {
		struct tnt_iter_storage *is = TNT_ISTORAGE(&i);
		struct tnt_stream_snapshot *ss =
			TNT_SSNAPSHOT_CAST(TNT_IREQUEST_STREAM(&i));
		int result = tc_verify_cmp(s, lsn, is, ss);
		if (result == -1)
			errors++;
	}
	if (i.status == TNT_ITER_FAIL) {
		printf("snapshot parsing failed: %s\n", tnt_snapshot_strerror(&st));
		rc = -1;
	}
	if (errors)
		rc = -1;
	tnt_iter_free(&i);
	tnt_stream_free(&st);
	return rc;
}
Esempio n. 8
0
void
print_tuple(struct tnt_tuple *tuple)
{
	bool is_first = true;
	printf("(");

	struct tnt_iter ifl;
	tnt_iter(&ifl, tuple);
	while (tnt_next(&ifl)) {
		char *data = TNT_IFIELD_DATA(&ifl);
		uint32_t size = TNT_IFIELD_SIZE(&ifl);
		if (!is_first) {
			printf(", ");
		}
		is_first = false;

		switch(size) {
		case 1:
			printf("%"PRIi8" (0x%02"PRIx8")", *(int8_t *)data, *(int8_t *)data);
			break;
		case 2:
			printf("%"PRIi16" (0x%04"PRIx16")", *(int16_t *)data, *(int16_t *)data);
			break;
		case 4:
			printf("%"PRIi32" (0x%08"PRIx32")", *(int32_t *)data, *(int32_t *)data);
			break;
		case 8:
			printf("%"PRIi64" (0x%016"PRIx64")", *(int64_t *)data, *(int64_t *)data);
			break;
		default:
			printf("'%.*s'", size, data);
			break;
		}
	}
	fail_if(ifl.status == TNT_ITER_FAIL);
	tnt_iter_free(&ifl);
	printf(")\n");
}
Esempio n. 9
0
int tc_query_foreach(tc_query_t cb, void *cba, char **e)
{
    int rc = -1;
    struct tnt_iter i;
    tnt_iter_reply(&i, tc.net);
    while (tnt_next(&i)) {
        struct tnt_reply *r = TNT_IREPLY_PTR(&i);
        if (tnt_error(tc.net) != TNT_EOK) {
            *e = tc_query_error("%s ERROR, %s",
                                tc_query_op(r),
                                tnt_strerror(tc.net));
            goto error;
        } else if (r->code != 0) {
            *e = tc_query_error("%s ERROR, %s (%s)",
                                tc_query_op(r), ((r->error) ? r->error : ""),
                                tnt_errcode_str(r->code >> 8));
            goto error;
        }
        /* invoking callback if supplied */
        if (cb) {
            if (cb(r, cba, e) == -1)
                goto error;
        }
    }