Skip to content
Snippets Groups Projects
Commit 4b756478 authored by Konstantin Osipov's avatar Konstantin Osipov
Browse files

Merge remote-tracking branch 'origin/gh-344-iproto-error-codes'

parents 0c10f2aa de5c537d
No related branches found
No related tags found
No related merge requests found
......@@ -106,7 +106,8 @@ remote_connect(struct recovery_state *r, struct ev_io *coio,
iproto_encode_auth(&row, greeting, uri->login, uri->password);
remote_write_row(coio, &row);
remote_read_row(coio, iobuf, &row);
iproto_decode_error(&row); /* auth failed */
if (row.type != IPROTO_OK)
iproto_decode_error(&row); /* auth failed */
/* auth successed */
say_info("authenticated");
......@@ -142,14 +143,14 @@ replica_bootstrap(struct recovery_state *r)
while (true) {
remote_read_row(&coio, iobuf, &row);
if (iproto_request_is_dml(row.type)) {
/* Regular snapshot row (IPROTO_INSERT) */
recovery_process(r, &row);
} else if (row.type == IPROTO_JOIN) {
if (row.type == IPROTO_OK) {
/* End of stream */
say_info("done");
break;
} else {
} else if (iproto_request_is_dml(row.type)) {
/* Regular snapshot row (IPROTO_INSERT) */
recovery_process(r, &row);
} else /* error or unexpected packet */ {
iproto_decode_error(&row); /* rethrow error */
}
}
......@@ -157,7 +158,7 @@ replica_bootstrap(struct recovery_state *r)
/* Decode end of stream packet */
struct vclock vclock;
vclock_create(&vclock);
assert(row.type == IPROTO_JOIN);
assert(row.type == IPROTO_OK);
iproto_decode_eos(&row, &vclock);
/* Replace server vclock using data from snapshot */
......
......@@ -149,20 +149,7 @@ static inline const char *tnt_errcode_str(uint32_t errcode)
return tnt_error_codes[errcode].errstr;
}
/** Return a 4-byte numeric error code, with status flags. */
static inline uint32_t tnt_errcode_val(uint32_t errcode)
{
uint32_t errflags = errcode < tnt_error_codes_enum_MAX ?
tnt_error_codes[errcode].errflags : 2; /* non-recoverable */
return (errcode << 8) | errflags;
}
/** Return a description of the error. */
static inline const char *tnt_errcode_desc(uint32_t errcode)
{
if (errcode >= tnt_error_codes_enum_MAX)
......
......@@ -357,9 +357,8 @@ iproto_encode_auth(struct iproto_header *packet, const char *greeting,
void
iproto_decode_error(struct iproto_header *row)
{
uint32_t code = row->type >> 8;
if (likely(code == 0))
return;
uint32_t code = row->type & (IPROTO_ERROR_RECOVERABLE - 1);
char error[TNT_ERRMSG_MAX] = { 0 };
const char *pos;
uint32_t map_size;
......@@ -535,5 +534,5 @@ iproto_encode_eos(struct iproto_header *row, const struct vclock *vclock)
row->body[0].iov_base = buf;
row->body[0].iov_len = (data - buf);
row->bodycnt = 1;
row->type = IPROTO_JOIN;
row->type = IPROTO_OK;
}
......@@ -32,6 +32,7 @@
#include <stdint.h>
#include <sys/uio.h> /* struct iovec */
#include <msgpuck/msgpuck.h>
#include "errcode.h"
#if defined(__cplusplus)
extern "C" {
......@@ -106,6 +107,7 @@ iproto_key_bit(unsigned char key)
extern const unsigned char iproto_key_type[IPROTO_KEY_MAX];
enum iproto_request_type {
IPROTO_OK = 0,
IPROTO_SELECT = 1,
IPROTO_INSERT = 2,
IPROTO_REPLACE = 3,
......@@ -116,7 +118,9 @@ enum iproto_request_type {
IPROTO_DML_REQUEST_MAX = 8,
IPROTO_PING = 64,
IPROTO_JOIN = 65,
IPROTO_SUBSCRIBE = 66
IPROTO_SUBSCRIBE = 66,
IPROTO_ERROR_RECOVERABLE = 1 << 14,
IPROTO_ERROR_UNRECOVERABLE = 1 << 15
};
extern const char *iproto_request_type_strs[];
......@@ -145,6 +149,12 @@ iproto_request_is_dml(uint32_t type)
return type < IPROTO_DML_REQUEST_MAX;
}
static inline bool
iproto_request_is_error(uint32_t type)
{
return type >= IPROTO_ERROR_RECOVERABLE;
}
enum {
IPROTO_PACKET_HEAD_IOVMAX = 1,
IPROTO_PACKET_BODY_IOVMAX = 2,
......@@ -177,6 +187,19 @@ iproto_decode_uuid(const char **pos, struct tt_uuid *out);
char *
iproto_encode_uuid(char *pos, const struct tt_uuid *in);
#include <say.h>
/** Return a 4-byte numeric error code, with status flags. */
static inline uint32_t
iproto_encode_error(uint32_t error)
{
if (iproto_request_is_error(error))
return error; /* box.raise() can raise arbitrary error code */
if (tnt_error_codes[error].errflags & 1)
return error | IPROTO_ERROR_RECOVERABLE;
return error | IPROTO_ERROR_UNRECOVERABLE;
}
int
iproto_header_encode(const struct iproto_header *header,
struct iovec *out);
......
......@@ -80,7 +80,7 @@ iproto_reply_error(struct obuf *out, const ClientError *e, uint64_t sync)
uint32_t len = sizeof(header) - 5 + sizeof(body) + msg_len;
header.v_len = mp_bswap_u32(len);
header.v_code = mp_bswap_u32(tnt_errcode_val(e->errcode()));
header.v_code = mp_bswap_u32(iproto_encode_error(e->errcode()));
header.v_sync = mp_bswap_u64(sync);
body.v_data_len = mp_bswap_u32(msg_len);
......
......@@ -11,7 +11,7 @@ require('session').on_connect(f1)
...
greeting: True
fixheader: True
error code: 8194
error code: 32800
error message: [string "function f1() nosuchfunction() end"]:1: attempt to call global 'nosuchfunction' (a nil value)
eof: True
require('session').on_connect(nil, f1)
......
......@@ -48,7 +48,7 @@ call f1()
call dostring('box.raise(33333, "Hey!")')
---
- error:
errcode: ER_UNKNOWN (33333)
errcode: ER_UNKNOWN (565)
errmsg: Hey!
...
......
Subproject commit 0f9d99ecb770586ca011800a6e3921c3353c7459
Subproject commit da85cb7da11e31e4726fbdb9e57ead4a94e72157
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