Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CBRD-25700] Modify the behavior to retain the session when automatically restarting due to the CAS memory size limit #5717

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/base/xserver_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ extern int xlocator_upgrade_instances_domain (THREAD_ENTRY * thread_p, OID * cla

extern int xsession_create_new (THREAD_ENTRY * thread_p, SESSION_ID * id);
extern int xsession_check_session (THREAD_ENTRY * thread_p, const SESSION_ID id);
extern int xsession_end_session (THREAD_ENTRY * thread, const SESSION_ID id);
extern int xsession_end_session (THREAD_ENTRY * thread, const SESSION_ID id, bool is_keep_session);

extern int xsession_set_row_count (THREAD_ENTRY * thread_p, int row_count);
extern int xsession_get_row_count (THREAD_ENTRY * thread_p, int *row_count);
Expand Down
8 changes: 8 additions & 0 deletions src/broker/cas.c
Original file line number Diff line number Diff line change
Expand Up @@ -1974,11 +1974,13 @@ process_request (SOCKET sock_fd, T_NET_BUF * net_buf, T_REQ_INFO * req_info)
cas_log_msg = "RESET";
cas_log_write_and_end (0, true, cas_log_msg);
fn_ret = FN_KEEP_SESS;
db_set_keep_session (true);
}
if (as_info->con_status == CON_STATUS_CLOSE_AND_CONNECT)
{
cas_log_msg = "CHANGE CLIENT";
fn_ret = FN_KEEP_SESS;
db_set_keep_session (true);
}

if (cas_log_msg == NULL)
Expand Down Expand Up @@ -2170,6 +2172,10 @@ process_request (SOCKET sock_fd, T_NET_BUF * net_buf, T_REQ_INFO * req_info)
net_buf->client_version = req_info->client_version;
set_hang_check_time ();
fn_ret = (*server_fn) (sock_fd, argc, argv, net_buf, req_info);
if (fn_ret == FN_KEEP_SESS)
{
db_set_keep_session (true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기서 db_set_keep_session(true)를 호출해 주어야 하는 이유가 뭔가요?

}
set_hang_check_time ();

#if !defined(CAS_FOR_ORACLE) && !defined(CAS_FOR_MYSQL)
Expand Down Expand Up @@ -2242,6 +2248,7 @@ process_request (SOCKET sock_fd, T_NET_BUF * net_buf, T_REQ_INFO * req_info)
else if (restart_is_needed ())
{
fn_ret = FN_KEEP_SESS;
db_set_keep_session (true);
}
if (shm_appl->sql_log2 != as_info->cur_sql_log2)
{
Expand Down Expand Up @@ -2352,6 +2359,7 @@ process_request (SOCKET sock_fd, T_NET_BUF * net_buf, T_REQ_INFO * req_info)
{
cas_log_debug (ARG_FILE_LINE, "process_request: reset_flag && !CON_STATUS_IN_TRAN");
fn_ret = FN_KEEP_SESS;
db_set_keep_session (true);
goto exit_on_end;
}

Expand Down
7 changes: 4 additions & 3 deletions src/communication/network_interface_cl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4736,20 +4736,21 @@ csession_find_or_create_session (SESSION_ID * session_id, int *row_count, char *
* session_id (in) : the id of the session to end
*/
int
csession_end_session (SESSION_ID session_id)
csession_end_session (SESSION_ID session_id, bool is_keep_session)
{
#if defined (CS_MODE)
int req_error;
OR_ALIGNED_BUF (OR_INT_SIZE) a_reply;
char *reply;
OR_ALIGNED_BUF (OR_INT_SIZE) a_request;
OR_ALIGNED_BUF (OR_INT_SIZE * 2) a_request;
char *request;
char *ptr;

reply = OR_ALIGNED_BUF_START (a_reply);
request = OR_ALIGNED_BUF_START (a_request);

ptr = or_pack_int (request, session_id);
ptr = or_pack_int (ptr, is_keep_session);

req_error =
net_client_request (NET_SERVER_SES_END_SESSION, request, OR_ALIGNED_BUF_SIZE (a_request), reply,
Expand All @@ -4765,7 +4766,7 @@ csession_end_session (SESSION_ID session_id)

THREAD_ENTRY *thread_p = enter_server ();

result = xsession_end_session (thread_p, session_id);
result = xsession_end_session (thread_p, session_id, is_keep_session);

exit_server (*thread_p);

Expand Down
2 changes: 1 addition & 1 deletion src/communication/network_interface_cl.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ extern int boot_get_server_timezone_checksum (char *timezone_checksum);
/* session state API */
extern int csession_find_or_create_session (SESSION_ID * session_id, int *row_count, char *server_session_key,
const char *db_user, const char *host, const char *program_name);
extern int csession_end_session (SESSION_ID session_id);
extern int csession_end_session (SESSION_ID session_id, bool is_keep_session);
extern int csession_set_row_count (int rows);
extern int csession_get_row_count (int *rows);
extern int csession_get_last_insert_id (DB_VALUE * value, bool update_last_insert_id);
Expand Down
6 changes: 4 additions & 2 deletions src/communication/network_interface_sr.c
Original file line number Diff line number Diff line change
Expand Up @@ -8986,14 +8986,16 @@ void
ssession_end_session (THREAD_ENTRY * thread_p, unsigned int rid, char *request, int reqlen)
{
int err = NO_ERROR;
int is_keep_session;
SESSION_ID id;
OR_ALIGNED_BUF (OR_INT_SIZE) a_reply;
char *reply = OR_ALIGNED_BUF_START (a_reply);
char *ptr = NULL;

(void) or_unpack_int (request, (int *) &id);
ptr = or_unpack_int (request, (int *) &id);
ptr = or_unpack_int (ptr, (int *) &is_keep_session);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ptr = or_unpack_int (ptr, (int *) &is_keep_session);
ptr = or_unpack_int (ptr, &is_keep_session);


err = xsession_end_session (thread_p, id);
err = xsession_end_session (thread_p, id, (bool) is_keep_session);

ptr = or_pack_int (reply, err);
css_send_data_to_client (thread_p->conn_entry, rid, reply, OR_ALIGNED_BUF_SIZE (a_reply));
Expand Down
1 change: 1 addition & 0 deletions src/compat/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
extern int db_Connect_status;

extern SESSION_ID db_Session_id;
extern bool db_Keep_session;

extern int db_Row_count;

Expand Down
22 changes: 21 additions & 1 deletion src/compat/db_admin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ db_end_session (void)

CHECK_CONNECT_ERROR ();

retval = csession_end_session (db_get_session_id ());
retval = csession_end_session (db_get_session_id (), db_get_keep_session ());

cubmethod::get_callback_handler ()->free_query_handle_all (true);

Expand Down Expand Up @@ -3073,6 +3073,26 @@ db_set_session_id (const SESSION_ID session_id)
db_Session_id = session_id;
}

/*
* db_get_keep_session () - get keep session flag
*/
bool
db_get_keep_session (void)
{
return db_Keep_session;
}

/*
* db_set_keep_session () - set keep session flag
* return : void
* keep_session (in): keep session flag
*/
void
db_set_keep_session (const bool keep_session)
{
db_Keep_session = keep_session;
}

/*
* db_find_or_create_session - check if current session is still active
* if not, create a new session
Expand Down
1 change: 1 addition & 0 deletions src/compat/db_macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct valcnv_buffer
};

SESSION_ID db_Session_id = DB_EMPTY_SESSION;
bool db_Keep_session = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cas의 FN_KEEP_SESS 처리를 위해 필요한 전역 변수가 이곳에 선언될 필요가 있는지 의문입니다. 혹시 어떤 기준으로 이곳에 선언했는지 추가 설명 가능할까요? 추가적으로 다음 부분 역시 의견드립니다.

  1. cas.c 수준에서 전역변수를 선언하는게 어떨까요?
  2. 이 정보는 cas에서 설정되는 FN_KEEP_SESS를 위해 유효하기 때문에 외부로 노출할 필요는 없어 보입니다. 나머지 부분에서 db_get_keep_session() 등을 호출하기 보다는 명시적으로 false를 넘겨주는게 어떨까요?
  3. bool is_keep_session 파라미터는 ux_end_session()과 db_end_session() 인터페이스를 통해 전달되는게 어떨까요? cas에서 FN_KEEP_SESS 검사 후 ux_end_session() -> db_end_session()이 호출되는데, 명시적으로 session 유지 여부를 인자로 넘겨주는게 직관적 입니다.


int db_Row_count = DB_ROW_COUNT_NOT_SET;

Expand Down
2 changes: 2 additions & 0 deletions src/compat/dbi.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ extern "C"
extern char *db_get_server_session_key (void);
extern SESSION_ID db_get_session_id (void);
extern void db_set_session_id (const SESSION_ID session_id);
extern bool db_get_keep_session (void);
extern void db_set_keep_session (const bool keep_session);
extern int db_end_session (void);
extern int db_find_or_create_session (const char *db_user, const char *program_name);
extern int db_get_row_count_cache (void);
Expand Down
2 changes: 2 additions & 0 deletions src/compat/dbi_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ extern "C"
const char *preferred_hosts, int client_type);
extern SESSION_ID db_get_session_id (void);
extern void db_set_session_id (const SESSION_ID session_id);
extern bool db_get_keep_session (void);
extern void db_set_keep_session (const bool keep_session);
extern int db_find_or_create_session (const char *db_user, const char *program_name);
extern int db_get_row_count_cache (void);
extern void db_update_row_count_cache (const int row_count);
Expand Down
27 changes: 23 additions & 4 deletions src/session/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ struct session_state
pthread_mutex_t mutex; /* state mutex */
UINT64 del_id; /* delete transaction ID (for lock free) */

bool is_keep_session;
bool is_trigger_involved;
bool is_last_insert_id_generated;
bool auto_commit;
Expand Down Expand Up @@ -302,6 +303,7 @@ session_state_init (void *st)
/* initialize fields */
db_make_null (&session_p->cur_insert_id);
db_make_null (&session_p->last_insert_id);
session_p->is_keep_session = false;
session_p->is_trigger_involved = false;
session_p->is_last_insert_id_generated = false;
session_p->row_count = -1;
Expand Down Expand Up @@ -743,9 +745,10 @@ session_state_create (THREAD_ENTRY * thread_p, SESSION_ID * id)
* session_state_destroy () - close a session state
* return : NO_ERROR or error code
* id(in) : the identifier for the session
* is_keep_session(in) : whether to keep the session
*/
int
session_state_destroy (THREAD_ENTRY * thread_p, const SESSION_ID id)
session_state_destroy (THREAD_ENTRY * thread_p, const SESSION_ID id, bool is_keep_session)
{
SESSION_STATE *session_p;
int error = NO_ERROR, success = 0;
Expand All @@ -762,6 +765,13 @@ session_state_destroy (THREAD_ENTRY * thread_p, const SESSION_ID id)
return ER_SES_SESSION_EXPIRED;
}

if (is_keep_session == true)
{
session_p->is_keep_session = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true로 설정된 이후 다시 client와 연결되었을 때 언제 false로 리셋되나요?

pthread_mutex_unlock (&session_p->mutex);
return NO_ERROR;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기존과 동일한 처리를 위해 이곳에서 return 하는 것으로 알고 있습니다. 다만, session 정보는 유지되지만 연결은 끊어진 상태인데 ref_count 등을 처리하지 않아도 문제가 되지 않는지 검증 되었나요?

session_remove_expired_sessions() 함수에서 if (state->is_keep_session == true) 검사 이전에 assert (state->ref_count == 0); 조건이 검사되어 지고 있습니다. 참고하세요.

}

#if defined (SERVER_MODE)
assert (session_p->ref_count > 0);

Expand Down Expand Up @@ -934,10 +944,19 @@ session_remove_expired_sessions (THREAD_ENTRY * thread_p)
/* Now we can destroy this session */
assert (state->ref_count == 0);

expired_sid_buffer[n_expired_sids++] = state->id;
if (state->is_keep_session == true)
{
/* keep session */
pthread_mutex_unlock (&state->mutex);
continue;
}
else
{
expired_sid_buffer[n_expired_sids++] = state->id;

/* Destroy the session related resources like session parameters */
(void) session_state_uninit (state);
/* Destroy the session related resources like session parameters */
(void) session_state_uninit (state);
}

if (n_expired_sids == EXPIRED_SESSION_BUFFER_SIZE)
{
Expand Down
2 changes: 1 addition & 1 deletion src/session/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct xasl_cache_ent;
extern void session_states_init (THREAD_ENTRY * thread_p);
extern void session_states_finalize (THREAD_ENTRY * thread_p);
extern int session_state_create (THREAD_ENTRY * thread_p, SESSION_ID * id);
extern int session_state_destroy (THREAD_ENTRY * thread_p, const SESSION_ID id);
extern int session_state_destroy (THREAD_ENTRY * thread_p, const SESSION_ID id, bool is_keep_session);
extern int session_check_session (THREAD_ENTRY * thread_p, const SESSION_ID id);
extern int session_get_session_id (THREAD_ENTRY * thread_p, SESSION_ID * id);
extern int session_get_last_insert_id (THREAD_ENTRY * thread_p, DB_VALUE * value, bool update_last_insert_id);
Expand Down
5 changes: 3 additions & 2 deletions src/session/session_sr.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ xsession_check_session (THREAD_ENTRY * thread_p, const SESSION_ID id)
* return : error code
* id (in) : session id
* thread_p (in)
* is_keep_session (in) : whether to keep the session
*/
int
xsession_end_session (THREAD_ENTRY * thread_p, const SESSION_ID id)
xsession_end_session (THREAD_ENTRY * thread_p, const SESSION_ID id, bool is_keep_session)
{
return session_state_destroy (thread_p, id);
return session_state_destroy (thread_p, id, is_keep_session);
}

/*
Expand Down
2 changes: 2 additions & 0 deletions win/cubridcs/cubridcs.def
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ EXPORTS
db_restart_ex
db_set_session_id
db_get_session_id
db_set_keep_session
db_get_keep_session
db_find_or_create_session
db_end_session
db_set_connect_status
Expand Down
2 changes: 2 additions & 0 deletions win/cubridsa/cubridsa.def
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ EXPORTS
db_restart_ex
db_set_session_id
db_get_session_id
db_set_keep_session
db_get_keep_session
db_find_or_create_session
db_end_session
db_set_server_session_key
Expand Down
Loading