Skip to content

Commit

Permalink
[CBRD-25369] add new broker parameter - NET_BUF_SIZE (#5222)
Browse files Browse the repository at this point in the history
* [CBRD-25369] add broker parameter - NET_BUF_SIZE

* [CBRD-25369] add broker parameter - NET_BUF_SIZE

* [CBRD-25369] set NET_BUF_SIZE to shared memory

* [CBRD-25369] set/get network buffer size

* [CBRD-25369] avoid compile error for shard proxy
  • Loading branch information
kisoo-han authored May 22, 2024
1 parent bee7aa8 commit 0e110f5
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 2 deletions.
35 changes: 34 additions & 1 deletion src/broker/broker_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ static void read_conf_cache (int cid, bool * acl, int *num_br, int *shm_id, char
static void write_conf_cache (char *file, bool * acl_flag, int *num_broker, int *shm_id, char *alog,
T_BROKER_INFO * br_info, time_t bf_mtime);
static void clear_conf_cache_entry (int cid);
static bool is_invalid_buf_size (int size);

static T_CONF_TABLE tbl_appl_server[] = {
{APPL_SERVER_CAS_TYPE_NAME, APPL_SERVER_CAS},
Expand Down Expand Up @@ -296,7 +297,8 @@ const char *broker_keywords[] = {
"SHARD_PROXY_LOG_DIR",
/* For backword compatibility */
"SQL_LOG2",
"SHARD"
"SHARD",
"NET_BUF_SIZE"
};

int broker_keywords_size = sizeof (broker_keywords) / sizeof (char *);
Expand Down Expand Up @@ -664,6 +666,16 @@ broker_config_read_internal (const char *conf_file, T_BROKER_INFO * br_info, int

br_info[num_brs].appl_server_num = br_info[num_brs].appl_server_min_num;

INI_GETSTR_CHK (s, ini, sec_name, "NET_BUF_SIZE", DEFAULE_NET_BUF_SIZE, &lineno);
strncpy_bufsize (size_str, s);
br_info[num_brs].net_buf_size = (int) ut_size_string_to_kbyte (size_str, "K");

if (is_invalid_buf_size (br_info[num_brs].net_buf_size))
{
errcode = PARAM_BAD_RANGE;
goto conf_error;
}

br_info[num_brs].appl_server_max_num =
ini_getint (ini, sec_name, "MAX_NUM_APPL_SERVER", DEFAULT_AS_MAX_NUM, &lineno);
if (br_info[num_brs].appl_server_max_num > APPL_SERVER_NUM_LIMIT || br_info[num_brs].appl_server_max_num < 1)
Expand Down Expand Up @@ -1833,3 +1845,24 @@ conf_get_value_proxy_log_mode (const char *value)
{
return (get_conf_value (value, tbl_proxy_log_mode));
}

static bool
is_invalid_buf_size (int size)
{
bool ret = false;

// The unit of size is KB.
switch (size)
{
case 16:
case 32:
case 48:
case 64:
break;
default:
ret = true;
break;
}

return ret;
}
3 changes: 3 additions & 0 deletions src/broker/broker_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@

#define DEFAULT_SSL_MODE "OFF"

#define DEFAULE_NET_BUF_SIZE "16K"

#define CGW_LINK_SERVER_NAME_LEN 256
#define CGW_LINK_SERVER_IP_LEN 32
#define CGW_LINK_SERVER_PORT_LEN 10
Expand Down Expand Up @@ -297,6 +299,7 @@ struct t_broker_info

char ignore_shard_hint;
int proxy_timeout;
int net_buf_size;
/* to here, these are used only in shard */

char use_SSL;
Expand Down
1 change: 1 addition & 0 deletions src/broker/broker_shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ broker_shm_initialize_shm_as (T_BROKER_INFO * br_info_p, T_SHM_PROXY * shm_proxy
}

shm_as_p->cci_default_autocommit = br_info_p->cci_default_autocommit;
shm_as_p->net_buf_size = br_info_p->net_buf_size;
shm_as_p->job_queue_size = br_info_p->job_queue_size;
shm_as_p->job_queue[0].id = 0; /* initialize max heap */
shm_as_p->max_prepared_stmt_count = br_info_p->max_prepared_stmt_count;
Expand Down
1 change: 1 addition & 0 deletions src/broker/broker_shm.h
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ struct t_shm_appl_server
#if !defined(WINDOWS)
sem_t acl_sem;
#endif
int net_buf_size;

char cgw_link_server[CGW_LINK_SERVER_NAME_LEN];
char cgw_link_server_ip[CGW_LINK_SERVER_IP_LEN];
Expand Down
17 changes: 17 additions & 0 deletions src/broker/cas_net_buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@
#include "byte_order.h"

static int net_buf_realloc (T_NET_BUF * net_buf, int size);
static int _net_buf_size = INT_DEFAULE_NET_BUF_SIZE;

void
net_buf_init (T_NET_BUF * net_buf, T_BROKER_VERSION client_version)
{
set_net_buf_size ();
net_buf->data = NULL;
net_buf->alloc_size = 0;
net_buf->data_size = 0;
Expand Down Expand Up @@ -873,3 +875,18 @@ net_buf_cp_cas_type_and_charset (T_NET_BUF * net_buf, unsigned char cas_type, un

return 0;
}

int
get_net_buf_size ()
{
return _net_buf_size;
}

void
set_net_buf_size ()
{
_net_buf_size = (shm_appl == NULL
|| shm_appl->net_buf_size <= 0) ? INT_DEFAULE_NET_BUF_SIZE : shm_appl->net_buf_size * ONE_K;

return;
}
7 changes: 6 additions & 1 deletion src/broker/cas_net_buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

#define NET_BUF_KBYTE 1024
#define SHARD_NET_BUF_SIZE (512 * NET_BUF_KBYTE)
#define NET_BUF_SIZE (16 * NET_BUF_KBYTE)
#define NET_BUF_SIZE (get_net_buf_size ())
#define NET_BUF_EXTRA_SIZE (64 * NET_BUF_KBYTE)
#define NET_BUF_ALLOC_SIZE (NET_BUF_SIZE + NET_BUF_EXTRA_SIZE)
#define SHARD_NET_BUF_ALLOC_SIZE (SHARD_NET_BUF_SIZE + NET_BUF_EXTRA_SIZE)
Expand All @@ -88,6 +88,8 @@
#define NET_BUF_TYPE_SIZE(net_buf) (DOES_CLIENT_UNDERSTAND_THE_PROTOCOL \
((net_buf)->client_version, PROTOCOL_V7) ? 2 * NET_SIZE_BYTE : NET_SIZE_BYTE)

#define INT_DEFAULE_NET_BUF_SIZE (16 * NET_BUF_KBYTE)

typedef struct t_net_buf T_NET_BUF;
struct t_net_buf
{
Expand Down Expand Up @@ -167,4 +169,7 @@ extern void net_arg_get_lob_value (DB_VALUE * db_lob, void *arg);
extern void net_arg_put_int (void *arg, int *value);
extern size_t net_error_append_shard_info (char *err_buf, const char *err_msg, int buf_size);
extern int net_buf_cp_cas_type_and_charset (T_NET_BUF * net_buf, unsigned char cas_type, unsigned char charset);
extern T_SHM_APPL_SERVER *shm_appl;
extern int get_net_buf_size (void);
extern void set_net_buf_size (void);
#endif /* _CAS_NET_BUF_H_ */
1 change: 1 addition & 0 deletions src/broker/shard_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
/* SHARD SHM */
int appl_server_shm_id = -1;
T_SHM_APPL_SERVER *shm_as_p = NULL;
T_SHM_APPL_SERVER *shm_appl = NULL;

int proxy_id = -1;
int proxy_shm_id = -1;
Expand Down

0 comments on commit 0e110f5

Please sign in to comment.