Skip to content

Commit

Permalink
[CBRD-25768] Separate server requests to the master between the serve…
Browse files Browse the repository at this point in the history
  • Loading branch information
YeunjunLee authored Jan 4, 2025
1 parent 852ff15 commit 2aa1f07
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/connection/connection_cl.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ css_connect_to_master_server (int master_port_id, const char *server_name, int n
}

/* select the connection protocol, for PC's this will always be new */
connection_protocol = ((css_Server_use_new_connection_protocol) ? SERVER_REQUEST_NEW : SERVER_REQUEST);
connection_protocol = ((css_Server_use_new_connection_protocol) ? SERVER_REQUEST_NEW : SERVER_REQUEST_FROM_CLIENT);

if (css_common_connect (hname, conn, connection_protocol, server_name, name_length, master_port_id, 0, &rid, true)
== NULL)
Expand Down
4 changes: 2 additions & 2 deletions src/connection/connection_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ enum css_command_type
NULL_REQUEST = 0,
INFO_REQUEST = 1, /* get runtime info from the master server */
DATA_REQUEST = 2, /* get data from the database server */
SERVER_REQUEST = 3, /* let new server attach */
UNUSED_REQUEST = 4, /* unused request - leave it for compatibility */
SERVER_REQUEST_FROM_SERVER = 3, /* let new server attach */
SERVER_REQUEST_FROM_CLIENT = 4, /* let new client process attach */
SERVER_REQUEST_NEW = 5, /* new-style server request */
MAX_REQUEST
};
Expand Down
2 changes: 1 addition & 1 deletion src/connection/connection_sr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ css_connect_to_master_server (int master_port_id, const char *server_name, int n
else
{
// Linux and Unix
connection_protocol = SERVER_REQUEST;
connection_protocol = SERVER_REQUEST_FROM_SERVER;
css_set_proc_register (server_name, name_length, &proc_register);
data = (const char *) &proc_register;
data_length = sizeof (proc_register);
Expand Down
49 changes: 32 additions & 17 deletions src/executables/master.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ static int css_master_init (int cport, SOCKET * clientfd);
static void css_reject_client_request (CSS_CONN_ENTRY * conn, unsigned short rid, int reason);
static void css_reject_server_request (CSS_CONN_ENTRY * conn, int reason);
static void css_accept_server_request (CSS_CONN_ENTRY * conn, int reason);
static void css_accept_new_request (CSS_CONN_ENTRY * conn, unsigned short rid, char *buffer, int buffer_length);
static void css_accept_new_request (CSS_CONN_ENTRY * conn, unsigned short rid, char *buffer, int buffer_length,
bool is_client);
static void css_accept_old_request (CSS_CONN_ENTRY * conn, unsigned short rid, SOCKET_QUEUE_ENTRY * entry,
char *server_name, int server_name_length);
static void css_register_new_server (CSS_CONN_ENTRY * conn, unsigned short rid);
static void css_register_new_server (CSS_CONN_ENTRY * conn, unsigned short rid, bool is_client);
static void css_register_new_server2 (CSS_CONN_ENTRY * conn, unsigned short rid);
static bool css_send_new_request_to_server (SOCKET server_fd, SOCKET client_fd, unsigned short rid,
CSS_SERVER_REQUEST request);
Expand Down Expand Up @@ -321,18 +322,22 @@ css_accept_server_request (CSS_CONN_ENTRY * conn, int reason)
* conn(in)
* rid(in)
* buffer(in)
* buffer_length(in)
* is_client(in)
*
*/
static void
css_accept_new_request (CSS_CONN_ENTRY * conn, unsigned short rid, char *buffer, int buffer_length)
css_accept_new_request (CSS_CONN_ENTRY * conn, unsigned short rid, char *buffer, int buffer_length, bool is_client)
{
char *datagram;
char *server_name;
int datagram_length;
SOCKET server_fd = INVALID_SOCKET;
int length;
int server_name_length;
CSS_CONN_ENTRY *datagram_conn;
SOCKET_QUEUE_ENTRY *entry;
CSS_SERVER_PROC_REGISTER *proc_register;

datagram = NULL;
datagram_length = 0;
Expand All @@ -348,7 +353,20 @@ css_accept_new_request (CSS_CONN_ENTRY * conn, unsigned short rid, char *buffer,
#if defined(DEBUG)
css_Active_server_count++;
#endif
server_name = buffer;
if (is_client)
{
server_name = buffer;
server_name_length = buffer_length;
}
else
{
assert (buffer != NULL);
proc_register = (CSS_SERVER_PROC_REGISTER *) buffer;

assert (proc_register->server_name != NULL);
server_name = proc_register->server_name;
server_name_length = proc_register->server_name_length;
}
length = (int) strlen (server_name) + 1;
css_add_request_to_socket_queue (datagram_conn, false, server_name, server_fd, READ_WRITE, 0,
&css_Master_socket_anchor);
Expand All @@ -359,9 +377,8 @@ css_accept_new_request (CSS_CONN_ENTRY * conn, unsigned short rid, char *buffer,

assert (length <= DB_MAX_IDENTIFIER_LENGTH);

if (length < buffer_length)
if (length < server_name_length)
{

entry = css_return_entry_of_server (server_name, css_Master_socket_anchor);
if (entry != NULL)
{
Expand Down Expand Up @@ -394,13 +411,8 @@ css_accept_new_request (CSS_CONN_ENTRY * conn, unsigned short rid, char *buffer,
#if !defined(WINDOWS)
if (auto_Restart_server)
{
// TODO : Currently, server and client has different format of data payload to connect process to master.
// Since both process is handled by this function, it could make confusion when requesting connection from process.
// Two solution could be considered.
// 1. Separte the request for server and client. (SERVER_REQUEST_FROM_CLIENT, SERVER_REQUEST_FROM_SERVER)
// 2. Modify the data payload so that master can distinguish the request from server and client. (e.g. add flag character at the beginning of data)
assert (!is_client);

CSS_SERVER_PROC_REGISTER *proc_register = (CSS_SERVER_PROC_REGISTER *) buffer;
/* *INDENT-OFF* */
master_Server_monitor->produce_job (server_monitor::job_type::REGISTER_SERVER, proc_register->pid,
proc_register->exec_path, proc_register->args, proc_register->server_name);
Expand Down Expand Up @@ -468,11 +480,12 @@ css_accept_old_request (CSS_CONN_ENTRY * conn, unsigned short rid, SOCKET_QUEUE_
* return: none
* conn(in)
* rid(in)
* is_client(in)
*
* Note: This will allow us to pass fds for future requests to the server.
*/
static void
css_register_new_server (CSS_CONN_ENTRY * conn, unsigned short rid)
css_register_new_server (CSS_CONN_ENTRY * conn, unsigned short rid, bool is_client)
{
int data_length;
char *data = NULL;
Expand All @@ -483,7 +496,6 @@ css_register_new_server (CSS_CONN_ENTRY * conn, unsigned short rid)
// 2. When a new cub_server requests to register itself to cub_master.
// For the first situation, css_register_new_server() receives the server name as data.
// For the second situation, css_register_new_server() receives CSS_SERVER_PROC_REGISTER as data.
// css_register_new_server determines which case it is by checking if the entry is NULL or not.

if (css_receive_data (conn, rid, &data, &data_length, -1) == NO_ERRORS)
{
Expand Down Expand Up @@ -512,7 +524,7 @@ css_register_new_server (CSS_CONN_ENTRY * conn, unsigned short rid)

#else /* ! WINDOWS */
/* accept a request from a new server */
css_accept_new_request (conn, rid, data, data_length);
css_accept_new_request (conn, rid, data, data_length, is_client);
#endif /* ! WINDOWS */
}
}
Expand Down Expand Up @@ -794,8 +806,11 @@ css_process_new_connection (SOCKET fd)
case DATA_REQUEST: /* request from a remote client */
css_send_to_existing_server (conn, rid, SERVER_START_NEW_CLIENT);
break;
case SERVER_REQUEST: /* request from a new server */
css_register_new_server (conn, rid);
case SERVER_REQUEST_FROM_SERVER: /* request from a new server */
css_register_new_server (conn, rid, false);
break;
case SERVER_REQUEST_FROM_CLIENT: /* request from a new server */
css_register_new_server (conn, rid, true);
break;
case SERVER_REQUEST_NEW: /* request from a new server */
/* here the server wants to manage its own connection port */
Expand Down

0 comments on commit 2aa1f07

Please sign in to comment.