CUBRID Engine  latest
session.c File Reference
#include <assert.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "system.h"
#include "session.h"
#include "boot_sr.h"
#include "jansson.h"
#include "critical_section.h"
#include "error_manager.h"
#include "system_parameter.h"
#include "environment_variable.h"
#include "db.h"
#include "lock_free.h"
#include "object_primitive.h"
#include "dbtype.h"
#include "string_opfunc.h"
#include "thread_daemon.hpp"
#include "thread_entry_task.hpp"
#include "thread_lockfree_hash_map.hpp"
#include "thread_manager.hpp"
#include "xasl_cache.h"

Go to the source code of this file.

Classes

struct  session_info
 
struct  session_variable
 
struct  prepared_statement
 
struct  session_query_entry
 
struct  session_state
 
struct  active_sessions
 

Macros

#define pthread_mutex_init(a, b)
 
#define pthread_mutex_destroy(a)
 
#define pthread_mutex_lock(a)   0
 
#define pthread_mutex_trylock(a)   0
 
#define pthread_mutex_unlock(a)
 
#define SESSIONS_HASH_SIZE   1000
 
#define MAX_SESSION_VARIABLES_COUNT   20
 
#define MAX_PREPARED_STATEMENTS_COUNT   20
 
#define EXPIRED_SESSION_BUFFER_SIZE   1024
 

Typedefs

typedef struct session_info SESSION_INFO
 
typedef struct session_variable SESSION_VARIABLE
 
typedef struct prepared_statement PREPARED_STATEMENT
 
typedef struct session_query_entry SESSION_QUERY_ENTRY
 
typedef struct session_state SESSION_STATE
 
using session_hashmap_type = cubthread::lockfree_hashmap< SESSION_ID, session_state >
 
using session_hashmap_iterator = session_hashmap_type::iterator
 
typedef struct active_sessions ACTIVE_SESSIONS
 

Functions

static void * session_state_alloc (void)
 
static int session_state_free (void *st)
 
static int session_state_init (void *st)
 
static int session_state_uninit (void *st)
 
static int session_key_copy (void *src, void *dest)
 
static unsigned int session_key_hash (void *key, int hash_table_size)
 
static int session_key_compare (void *k1, void *k2)
 
static int session_key_increment (void *key, void *existing)
 
static int session_remove_expired_sessions (THREAD_ENTRY *thread_p)
 
static int session_check_timeout (SESSION_STATE *session_p, SESSION_INFO *active_sessions, bool *remove)
 
static void session_free_prepared_statement (PREPARED_STATEMENT *stmt_p)
 
static int session_add_variable (SESSION_STATE *state_p, const DB_VALUE *name, DB_VALUE *value)
 
static int session_drop_variable (SESSION_STATE *state_p, const DB_VALUE *name)
 
static void free_session_variable (SESSION_VARIABLE *var)
 
static void update_session_variable (SESSION_VARIABLE *var, const DB_VALUE *new_value)
 
static DB_VALUEdb_value_alloc_and_copy (const DB_VALUE *src)
 
static int session_dump_session (SESSION_STATE *session)
 
static void session_dump_variable (SESSION_VARIABLE *var)
 
static void session_dump_prepared_statement (PREPARED_STATEMENT *stmt_p)
 
static SESSION_QUERY_ENTRYqentry_to_sentry (QMGR_QUERY_ENTRY *qentry_p)
 
static int session_preserve_temporary_files (THREAD_ENTRY *thread_p, SESSION_QUERY_ENTRY *q_entry)
 
static void sentry_to_qentry (const SESSION_QUERY_ENTRY *sentry_p, QMGR_QUERY_ENTRY *qentry_p)
 
static void session_free_sentry_data (THREAD_ENTRY *thread_p, SESSION_QUERY_ENTRY *sentry_p)
 
static void session_set_conn_entry_data (THREAD_ENTRY *thread_p, SESSION_STATE *session_p)
 
static SESSION_STATEsession_get_session_state (THREAD_ENTRY *thread_p)
 
static void session_control_daemon_init ()
 
static void session_control_daemon_destroy ()
 
void session_states_init (THREAD_ENTRY *thread_p)
 
void session_states_finalize (THREAD_ENTRY *thread_p)
 
int session_state_create (THREAD_ENTRY *thread_p, SESSION_ID *id)
 
int session_state_destroy (THREAD_ENTRY *thread_p, const SESSION_ID id)
 
int session_check_session (THREAD_ENTRY *thread_p, const SESSION_ID id)
 
int session_get_session_id (THREAD_ENTRY *thread_p, SESSION_ID *id)
 
int session_get_last_insert_id (THREAD_ENTRY *thread_p, DB_VALUE *value, bool update_last_insert_id)
 
int session_set_cur_insert_id (THREAD_ENTRY *thread_p, const DB_VALUE *value, bool force)
 
int session_reset_cur_insert_id (THREAD_ENTRY *thread_p)
 
int session_begin_insert_values (THREAD_ENTRY *thread_p)
 
int session_set_trigger_state (THREAD_ENTRY *thread_p, bool in_trigger)
 
int session_get_row_count (THREAD_ENTRY *thread_p, int *row_count)
 
int session_set_row_count (THREAD_ENTRY *thread_p, const int row_count)
 
int session_get_session_parameters (THREAD_ENTRY *thread_p, SESSION_PARAM **session_parameters_ptr)
 
int session_set_session_parameters (THREAD_ENTRY *thread_p, SESSION_PARAM *session_parameters)
 
int session_create_prepared_statement (THREAD_ENTRY *thread_p, char *name, char *alias_print, SHA1Hash *sha1, char *info, int info_len)
 
int session_get_prepared_statement (THREAD_ENTRY *thread_p, const char *name, char **info, int *info_len, xasl_cache_ent **xasl_entry)
 
int session_delete_prepared_statement (THREAD_ENTRY *thread_p, const char *name)
 
int login_user (THREAD_ENTRY *thread_p, const char *username)
 
int session_set_session_variables (THREAD_ENTRY *thread_p, DB_VALUE *values, const int count)
 
int session_define_variable (THREAD_ENTRY *thread_p, DB_VALUE *name, DB_VALUE *value, DB_VALUE *result)
 
int session_get_variable (THREAD_ENTRY *thread_p, const DB_VALUE *name, DB_VALUE *result)
 
int session_get_variable_no_copy (THREAD_ENTRY *thread_p, const DB_VALUE *name, DB_VALUE **result)
 
int session_drop_session_variables (THREAD_ENTRY *thread_p, DB_VALUE *values, const int count)
 
int session_get_exec_stats_and_clear (THREAD_ENTRY *thread_p, const DB_VALUE *name, DB_VALUE *result)
 
void session_states_dump (THREAD_ENTRY *thread_p)
 
void session_store_query_entry_info (THREAD_ENTRY *thread_p, QMGR_QUERY_ENTRY *qentry_p)
 
int session_load_query_entry_info (THREAD_ENTRY *thread_p, QMGR_QUERY_ENTRY *qentry_p)
 
int session_remove_query_entry_info (THREAD_ENTRY *thread_p, const QUERY_ID query_id)
 
int session_clear_query_entry_info (THREAD_ENTRY *thread_p, const QUERY_ID query_id)
 
bool session_is_queryid_idle (THREAD_ENTRY *thread_p, const QUERY_ID query_id, QUERY_ID *max_query_id_uses)
 
SESSION_PARAMsession_get_session_parameter (THREAD_ENTRY *thread_p, PARAM_ID id)
 
int session_get_trace_stats (THREAD_ENTRY *thread_p, DB_VALUE *result)
 
int session_set_trace_stats (THREAD_ENTRY *thread_p, char *stats, int format)
 
int session_clear_trace_stats (THREAD_ENTRY *thread_p)
 
TZ_REGIONsession_get_session_tz_region (THREAD_ENTRY *thread_p)
 
int session_get_number_of_holdable_cursors (void)
 
int session_get_private_lru_idx (const void *session_p)
 
int session_set_tran_auto_commit (THREAD_ENTRY *thread_p, bool auto_commit)
 
int session_set_load_session (THREAD_ENTRY *thread_p, load_session *load_session_p)
 
int session_get_load_session (THREAD_ENTRY *thread_p, REFPTR(load_session, load_session_ref_ptr))
 
void session_stop_attached_threads (void *session_arg)
 

Variables

static int rv
 
static LF_ENTRY_DESCRIPTOR session_state_Descriptor
 
static ACTIVE_SESSIONS sessions
 
static cubthread::daemonsession_Control_daemon = NULL
 

Macro Definition Documentation

#define EXPIRED_SESSION_BUFFER_SIZE   1024
#define MAX_PREPARED_STATEMENTS_COUNT   20

Definition at line 68 of file session.c.

Referenced by session_create_prepared_statement().

#define MAX_SESSION_VARIABLES_COUNT   20

Definition at line 67 of file session.c.

Referenced by session_add_variable().

#define pthread_mutex_destroy (   a)

Definition at line 59 of file session.c.

Referenced by session_state_free(), and session_state::~session_state().

#define pthread_mutex_init (   a,
 
)

Definition at line 58 of file session.c.

Referenced by session_state::session_state(), and session_state_alloc().

#define pthread_mutex_lock (   a)    0

Definition at line 60 of file session.c.

#define pthread_mutex_trylock (   a)    0

Definition at line 61 of file session.c.

#define SESSIONS_HASH_SIZE   1000

Definition at line 66 of file session.c.

Referenced by session_states_init().

Typedef Documentation

Definition at line 85 of file session.c.

using session_hashmap_iterator = session_hashmap_type::iterator

Definition at line 175 of file session.c.

typedef struct session_info SESSION_INFO

Definition at line 70 of file session.c.

Definition at line 95 of file session.c.

typedef struct session_state SESSION_STATE

Definition at line 108 of file session.c.

Definition at line 77 of file session.c.

Function Documentation

static void free_session_variable ( SESSION_VARIABLE var)
static
int login_user ( THREAD_ENTRY thread_p,
const char *  username 
)

Definition at line 1917 of file session.c.

References log_tdes::client, LOG_FIND_TDES(), LOG_FIND_THREAD_TRAN_INDEX, NO_ERROR, NULL, and clientids::set_user().

Referenced by xlogin_user().

Here is the caller graph for this function:

int session_begin_insert_values ( THREAD_ENTRY thread_p)

Definition at line 1506 of file session.c.

References ER_FAILED, session_state::is_last_insert_id_generated, session_state::is_trigger_involved, NO_ERROR, NULL, and session_get_session_state().

Referenced by qexec_execute_insert().

Here is the caller graph for this function:

static int session_check_timeout ( SESSION_STATE session_p,
SESSION_INFO active_sessions,
bool remove 
)
static
int session_clear_query_entry_info ( THREAD_ENTRY thread_p,
const QUERY_ID  query_id 
)
int session_clear_trace_stats ( THREAD_ENTRY thread_p)
static void session_control_daemon_destroy ( )
static

Referenced by session_free_prepared_statement(), and session_states_finalize().

Here is the caller graph for this function:

static void session_control_daemon_init ( )
static

Referenced by session_free_prepared_statement(), and session_states_init().

Here is the caller graph for this function:

int session_define_variable ( THREAD_ENTRY thread_p,
DB_VALUE name,
DB_VALUE value,
DB_VALUE result 
)

Definition at line 1970 of file session.c.

References assert, db_make_null(), DB_TYPE_CHAR, DB_VALUE_DOMAIN_TYPE, ER_FAILED, err, NO_ERROR, NULL, pr_clone_value(), session_add_variable(), and session_get_session_state().

Referenced by fetch_peek_arith().

Here is the caller graph for this function:

int session_drop_session_variables ( THREAD_ENTRY thread_p,
DB_VALUE values,
const int  count 
)

Definition at line 2157 of file session.c.

References session_info::count, ER_FAILED, i, NO_ERROR, NULL, session_drop_variable(), and session_get_session_state().

Referenced by xsession_drop_session_variables().

Here is the caller graph for this function:

static int session_drop_variable ( SESSION_STATE state_p,
const DB_VALUE name 
)
static
static void session_dump_prepared_statement ( PREPARED_STATEMENT stmt_p)
static

Definition at line 2303 of file session.c.

References prepared_statement::alias_print, prepared_statement::name, NULL, prepared_statement::sha1, and SHA1_AS_ARGS.

Referenced by session_dump_session().

Here is the caller graph for this function:

static void session_dump_variable ( SESSION_VARIABLE var)
static

Definition at line 2275 of file session.c.

References db_get_string(), db_type_to_db_domain(), DB_TYPE_VARCHAR, db_value_clear(), db_value_coerce(), session_variable::name, NULL, and session_variable::value.

Referenced by session_dump_session().

Here is the caller graph for this function:

static void session_free_sentry_data ( THREAD_ENTRY thread_p,
SESSION_QUERY_ENTRY sentry_p 
)
static
int session_get_exec_stats_and_clear ( THREAD_ENTRY thread_p,
const DB_VALUE name,
DB_VALUE result 
)

Definition at line 2187 of file session.c.

References assert, db_get_string(), db_make_bigint(), DB_TYPE_CHAR, DB_VALUE_DOMAIN_TYPE, and NO_ERROR.

Referenced by fetch_peek_arith().

Here is the caller graph for this function:

int session_get_last_insert_id ( THREAD_ENTRY thread_p,
DB_VALUE value,
bool  update_last_insert_id 
)
int session_get_load_session ( THREAD_ENTRY thread_p,
REFPTR(load_session, load_session_ref_ptr)   
)
int session_get_number_of_holdable_cursors ( void  )

Definition at line 3070 of file session.c.

References active_sessions::num_holdable_cursors.

Referenced by perfmon_get_peek_stats().

Here is the caller graph for this function:

int session_get_private_lru_idx ( const void *  session_p)

Definition at line 3084 of file session.c.

Referenced by css_server_task::execute(), and css_server_external_task::execute().

Here is the caller graph for this function:

int session_get_row_count ( THREAD_ENTRY thread_p,
int *  row_count 
)

Definition at line 1562 of file session.c.

References assert, ER_FAILED, NO_ERROR, NULL, session_state::row_count, and session_get_session_state().

Referenced by fetch_peek_arith(), and xsession_get_row_count().

Here is the caller graph for this function:

int session_get_session_id ( THREAD_ENTRY thread_p,
SESSION_ID id 
)

Definition at line 1347 of file session.c.

References assert, db_Session_id, ER_FAILED, NO_ERROR, and NULL.

Referenced by session_get_session_state(), and session_get_variable_no_copy().

Here is the caller graph for this function:

SESSION_PARAM* session_get_session_parameter ( THREAD_ENTRY thread_p,
PARAM_ID  id 
)
int session_get_session_parameters ( THREAD_ENTRY thread_p,
SESSION_PARAM **  session_parameters_ptr 
)

Definition at line 1613 of file session.c.

References assert, ER_FAILED, free_and_init, NO_ERROR, NULL, session_get_session_state(), and session_state::session_parameters.

Referenced by sysprm_get_id().

Here is the caller graph for this function:

bool session_is_queryid_idle ( THREAD_ENTRY thread_p,
const QUERY_ID  query_id,
QUERY_ID *  max_query_id_uses 
)

Definition at line 2647 of file session.c.

References session_query_entry::next, NULL, session_state::queries, session_query_entry::query_id, and session_get_session_state().

Referenced by qmgr_allocate_query_entry().

Here is the caller graph for this function:

static int session_key_compare ( void *  k1,
void *  k2 
)
static

Definition at line 451 of file session.c.

References assert, and NULL.

static int session_key_copy ( void *  src,
void *  dest 
)
static

Definition at line 410 of file session.c.

References ER_FAILED, NO_ERROR, and NULL.

static unsigned int session_key_hash ( void *  key,
int  hash_table_size 
)
static

Definition at line 438 of file session.c.

static int session_key_increment ( void *  key,
void *  existing 
)
static

Definition at line 484 of file session.c.

References ER_FAILED, NO_ERROR, and NULL.

int session_load_query_entry_info ( THREAD_ENTRY thread_p,
QMGR_QUERY_ENTRY qentry_p 
)
static int session_preserve_temporary_files ( THREAD_ENTRY thread_p,
SESSION_QUERY_ENTRY q_entry 
)
static
int session_remove_query_entry_info ( THREAD_ENTRY thread_p,
const QUERY_ID  query_id 
)
int session_reset_cur_insert_id ( THREAD_ENTRY thread_p)
static void session_set_conn_entry_data ( THREAD_ENTRY thread_p,
SESSION_STATE session_p 
)
static

Definition at line 2685 of file session.c.

References session_state::id, NULL, session_state::private_lru_index, and thread_get_thread_entry_info().

Referenced by session_check_session(), and session_state_create().

Here is the caller graph for this function:

int session_set_load_session ( THREAD_ENTRY thread_p,
load_session load_session_p 
)

Definition at line 3113 of file session.c.

References ER_FAILED, session_state::load_session_p, NO_ERROR, NULL, and session_get_session_state().

Referenced by sloaddb_destroy(), and sloaddb_init().

Here is the caller graph for this function:

int session_set_row_count ( THREAD_ENTRY thread_p,
const int  row_count 
)

Definition at line 1586 of file session.c.

References ARG_FILE_LINE, ER_FAILED, er_log_debug, session_state::id, NO_ERROR, NULL, session_state::row_count, and session_get_session_state().

Referenced by xsession_set_row_count().

Here is the caller graph for this function:

int session_set_session_parameters ( THREAD_ENTRY thread_p,
SESSION_PARAM session_parameters 
)

Definition at line 1641 of file session.c.

References assert, ER_FAILED, NO_ERROR, NULL, session_get_session_state(), and session_state::session_parameters.

Referenced by sysprm_get_id().

Here is the caller graph for this function:

int session_set_session_variables ( THREAD_ENTRY thread_p,
DB_VALUE values,
const int  count 
)

Definition at line 1939 of file session.c.

References assert, session_info::count, ER_FAILED, i, NO_ERROR, NULL, session_add_variable(), and session_get_session_state().

Referenced by xsession_set_session_variables().

Here is the caller graph for this function:

int session_set_trace_stats ( THREAD_ENTRY thread_p,
char *  stats,
int  format 
)

Definition at line 2888 of file session.c.

References ER_FAILED, free_and_init, NO_ERROR, NULL, session_get_session_state(), session_state::trace_format, and session_state::trace_stats.

Referenced by qexec_clear_regu_variable_list().

Here is the caller graph for this function:

int session_set_tran_auto_commit ( THREAD_ENTRY thread_p,
bool  auto_commit 
)

Definition at line 3097 of file session.c.

References session_state::auto_commit, ER_FAILED, NO_ERROR, NULL, and session_get_session_state().

Referenced by xsession_set_tran_auto_commit().

Here is the caller graph for this function:

int session_set_trigger_state ( THREAD_ENTRY thread_p,
bool  in_trigger 
)

Definition at line 1534 of file session.c.

References ER_FAILED, session_state::is_trigger_involved, NO_ERROR, NULL, and session_get_session_state().

Referenced by xqmgr_execute_query(), and xqmgr_prepare_and_execute_query().

Here is the caller graph for this function:

static void * session_state_alloc ( void  )
static

Definition at line 249 of file session.c.

References session_state::mutex, NULL, and pthread_mutex_init.

static int session_state_free ( void *  st)
static

Definition at line 267 of file session.c.

References ER_FAILED, mutex, NO_ERROR, NULL, and pthread_mutex_destroy.

void session_states_dump ( THREAD_ENTRY thread_p)

Definition at line 2208 of file session.c.

References cubthread::lockfree_hashmap< Key, T >::get_element_count(), NULL, session_dump_session(), and active_sessions::states_hashmap.

Referenced by session_states_finalize().

Here is the caller graph for this function:

void session_states_finalize ( THREAD_ENTRY thread_p)
void session_stop_attached_threads ( void *  session_arg)

Definition at line 3150 of file session.c.

References assert, cubload::session::interrupt(), session_state::load_session_p, NULL, and cubload::session::wait_for_completion().

Referenced by session_state_uninit(), and ssession_stop_attached_threads().

Here is the caller graph for this function:

static void update_session_variable ( SESSION_VARIABLE var,
const DB_VALUE new_value 
)
static

Variable Documentation

int rv
static

Definition at line 63 of file session.c.

cubthread::daemon* session_Control_daemon = NULL
static

Definition at line 228 of file session.c.

LF_ENTRY_DESCRIPTOR session_state_Descriptor
static
Initial value:
= {
offsetof (SESSION_STATE, stack),
offsetof (SESSION_STATE, next),
offsetof (SESSION_STATE, del_id),
offsetof (SESSION_STATE, id),
offsetof (SESSION_STATE, mutex),
}
static int session_key_compare(void *k1, void *k2)
Definition: session.c:451
static int session_state_uninit(void *st)
Definition: session.c:323
static API_MUTEX mutex
Definition: api_util.c:72
static unsigned int session_key_hash(void *key, int hash_table_size)
Definition: session.c:438
static void * session_state_alloc(void)
Definition: session.c:249
static int session_state_init(void *st)
Definition: session.c:287
static int session_key_increment(void *key, void *existing)
Definition: session.c:484
static int session_key_copy(void *src, void *dest)
Definition: session.c:410
#define LF_EM_USING_MUTEX
Definition: lock_free.h:60
static int session_state_free(void *st)
Definition: session.c:267

Definition at line 154 of file session.c.

ACTIVE_SESSIONS sessions
static

Definition at line 195 of file session.c.