Skip to content

Commit

Permalink
feat: fix ob20 problems and add obproxy-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
weihao.twh committed Nov 21, 2022
1 parent 8766f46 commit 07c1c5c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 21 deletions.
4 changes: 4 additions & 0 deletions include/ma_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,10 @@ typedef unsigned long long intptr;
#define RTLD_NOW 1
#endif

#ifndef PROXY_MODE
#define PROXY_MODE 0xfe
#endif

#ifndef OB_MACRO
#define OB_MACRO

Expand Down
19 changes: 17 additions & 2 deletions libmariadb/ma_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,21 @@ static int ma_net_write_buff(NET *net,const char *packet, size_t len)
left_length=(size_t) (net->buff_end - net->write_pos);
}

if (net->use_ob20protocol && len > left_length && net->buf_length < net->max_packet_size - 1) {
size_t write_len = net->write_pos - net->buff;
size_t resize_len = len + write_len;

if (resize_len >= net->max_packet_size) {
resize_len = net->max_packet_size - 1;
}
if (net_realloc(net, resize_len))
{
return 1;
}
net->write_pos += write_len;
left_length=(size_t) (net->buff_end - net->write_pos);
}

if (len > left_length)
{
if (net->write_pos != net->buff)
Expand Down Expand Up @@ -471,8 +486,8 @@ int ma_net_real_write(NET *net, const char *packet, size_t len)
net->last_errno= ER_NET_ERROR_ON_WRITE;
net->reading_or_writing=0;
#ifdef HAVE_COMPRESS
if (net->compress)
free((char*) packet);
if (net->compress && !net->use_ob20protocol)
free((char*) packet); // 2.0协议buffer自管理
#endif
return(1);
}
Expand Down
35 changes: 18 additions & 17 deletions libmariadb/mariadb_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2130,27 +2130,28 @@ static unsigned long mysql_get_version_tool(const char* version_str)
}
static int get_ob_server_version(MYSQL *con)
{
/* Only one thread calls this, so no synchronization is needed */
MYSQL_RES *result;

/* "limit 1" is protection against SQL_SELECT_LIMIT=0 */
char const *sql = con->oracle_mode ? "select @@version_comment, @@version from dual where rownum <= 1" : "select @@version_comment, @@version limit 1";
if (!mysql_query(con, sql) &&
(result = mysql_use_result(con)))
{
MYSQL_ROW cur = mysql_fetch_row(result);
if (cur && cur[0] && cur[1])
if (con->ob_server_version != PROXY_MODE) {
/* Only one thread calls this, so no synchronization is needed */
MYSQL_RES *result;
/* "limit 1" is protection against SQL_SELECT_LIMIT=0 */
char const *sql = con->oracle_mode ? "select @@version_comment, @@version from dual where rownum <= 1" : "select @@version_comment, @@version limit 1";
if (!mysql_query(con, sql) &&
(result = mysql_use_result(con)))
{
// only get ob server version
if (strlen(cur[0]) > 9 && strncasecmp(cur[0], "OceanBase", 9) == 0)
MYSQL_ROW cur = mysql_fetch_row(result);
if (cur && cur[0] && cur[1])
{
con->ob_server_version = mysql_get_version_tool(cur[1]);
// only get ob server version
if (strlen(cur[0]) > 9 && strncasecmp(cur[0], "OceanBase", 9) == 0)
{
con->ob_server_version = mysql_get_version_tool(cur[1]);
}
}
mysql_free_result(result);
} else {
// error
return 1;
}
mysql_free_result(result);
} else {
// error
return 1;
}
return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion libmariadb/ob_protocol20.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,8 @@ int decode_protocol20_header(Ob20Protocol *ob20protocol, uchar *buffer, uint32_t
ret = 1; // error
} else {
//check request id and pkt_seq
if (pkt_seq != ob20protocol->header.pkt_seq + 1) {
ob20protocol->header.pkt_seq++;
if (pkt_seq != ob20protocol->header.pkt_seq) {
// printf("pkt_seq check error, local is %u, header is %u\n", ob20protocol->header.pkt_seq, pkt_seq);
ret = 1; // error
} else {
Expand Down
2 changes: 1 addition & 1 deletion rpm/libobclient-VER.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.0
2.2.1

0 comments on commit 07c1c5c

Please sign in to comment.