CUBRID Engine  latest
cas_log.c File Reference
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/time.h>
#include <assert.h>
#include "porting.h"
#include "cas_common.h"
#include "cas_log.h"
#include "cas_util.h"
#include "broker_config.h"
#include "cas.h"
#include "cas_execute.h"
#include "broker_env_def.h"
#include "broker_filename.h"
#include "broker_util.h"
#include "dbi.h"
#include "cas_db_inc.h"

Go to the source code of this file.

Macros

#define CAS_LOG_BUFFER_SIZE   (8192)
 
#define SQL_LOG_BUFFER_SIZE   163840
 
#define ACCESS_LOG_IS_DENIED_TYPE(T)   ((T)==ACL_REJECTED)
 

Functions

static const char * get_access_log_type_string (ACCESS_LOG_TYPE type)
 
static char * make_sql_log_filename (T_CUBRID_FILE_ID fid, char *filename_buf, size_t buf_size, const char *br_name)
 
static void cas_log_backup (T_CUBRID_FILE_ID fid)
 
static void cas_log_write_and_set_savedpos (FILE *log_fp, const char *fmt,...)
 
static void cas_log_write_internal (FILE *fp, struct timeval *log_time, unsigned int seq_num, bool do_flush, const char *fmt, va_list ap)
 
static void cas_log_write2_internal (FILE *fp, bool do_flush, const char *fmt, va_list ap)
 
static FILE * access_log_open (char *log_file_name)
 
static bool cas_log_begin_hang_check_time (void)
 
static void cas_log_end_hang_check_time (bool is_prev_time_set)
 
static void cas_log_write_query_string_internal (char *query, int size, bool newline)
 
static size_t cas_fwrite (const void *ptr, size_t size, size_t nmemb, FILE *stream)
 
static INT64 cas_ftell (FILE *stream)
 
static int cas_fseek (FILE *stream, INT64 offset, int whence)
 
static FILE * cas_fopen (const char *path, const char *mode)
 
static int cas_fclose (FILE *fp)
 
static int cas_ftruncate (int fd, off_t length)
 
static int cas_fflush (FILE *stream)
 
static int cas_fileno (FILE *stream)
 
static int cas_fprintf (FILE *stream, const char *format,...)
 
static int cas_fputc (int c, FILE *stream)
 
static int cas_unlink (const char *pathname)
 
static int cas_rename (const char *oldpath, const char *newpath)
 
static int cas_mkdir (const char *pathname, mode_t mode)
 
static void access_log_backup (char *access_log_file, struct tm *ct)
 
void cas_log_open (char *br_name)
 
void cas_log_reset (char *br_name)
 
void cas_log_close (bool flag)
 
void cas_log_end (int mode, int run_time_sec, int run_time_msec)
 
void cas_log_write_nonl (unsigned int seq_num, bool unit_start, const char *fmt,...)
 
static void cas_log_query_cancel (int dummy,...)
 
void cas_log_write (unsigned int seq_num, bool unit_start, const char *fmt,...)
 
void cas_log_write_and_end (unsigned int seq_num, bool unit_start, const char *fmt,...)
 
void cas_log_write2_nonl (const char *fmt,...)
 
void cas_log_write2 (const char *fmt,...)
 
void cas_log_write_value_string (char *value, int size)
 
void cas_log_write_query_string_nonl (char *query, int size)
 
void cas_log_write_query_string (char *query, int size)
 
void cas_log_write_client_ip (const unsigned char *ip_addr)
 
void cas_log_debug (const char *file_name, const int line_no, const char *fmt,...)
 
int cas_access_log (struct timeval *start_time, int as_index, int client_ip_addr, char *dbname, char *dbuser, ACCESS_LOG_TYPE log_type)
 
void cas_log_query_info_init (int id, char is_only_query_plan)
 
char * cas_log_query_plan_file (int id)
 
void cas_slow_log_open (char *br_name)
 
void cas_slow_log_reset (char *br_name)
 
void cas_slow_log_close ()
 
void cas_slow_log_end ()
 
void cas_slow_log_write_and_end (struct timeval *log_time, unsigned int seq_num, const char *fmt,...)
 
void cas_slow_log_write (struct timeval *log_time, unsigned int seq_num, bool unit_start, const char *fmt,...)
 
void cas_slow_log_write2 (const char *fmt,...)
 
void cas_slow_log_write_value_string (char *value, int size)
 
void cas_slow_log_write_query_string (char *query, int size)
 

Variables

static char cas_log_buffer [CAS_LOG_BUFFER_SIZE]
 
static char sql_log_buffer [SQL_LOG_BUFFER_SIZE]
 
static FILE * log_fp = NULL
 
static FILE * slow_log_fp = NULL
 
static char log_filepath [BROKER_PATH_MAX]
 
static char slow_log_filepath [BROKER_PATH_MAX]
 
static INT64 saved_log_fpos = 0
 

Macro Definition Documentation

#define ACCESS_LOG_IS_DENIED_TYPE (   T)    ((T)==ACL_REJECTED)

Definition at line 64 of file cas_log.c.

Referenced by cas_access_log().

#define CAS_LOG_BUFFER_SIZE   (8192)

Definition at line 62 of file cas_log.c.

Referenced by cas_log_write2_internal(), and cas_log_write_internal().

#define SQL_LOG_BUFFER_SIZE   163840

Definition at line 63 of file cas_log.c.

Referenced by cas_log_open().

Function Documentation

static void access_log_backup ( char *  access_log_file,
struct tm *  ct 
)
static

Definition at line 1407 of file cas_log.c.

Referenced by cas_access_log().

Here is the caller graph for this function:

static FILE * access_log_open ( char *  log_file_name)
static

Definition at line 910 of file cas_log.c.

References cas_fopen(), cas_mkdir(), dirname(), NULL, and strdup().

Referenced by cas_access_log(), and cas_log_debug().

Here is the caller graph for this function:

int cas_access_log ( struct timeval *  start_time,
int  as_index,
int  client_ip_addr,
char *  dbname,
char *  dbuser,
ACCESS_LOG_TYPE  log_type 
)
static int cas_fclose ( FILE *  fp)
static

Definition at line 1284 of file cas_log.c.

References cas_log_begin_hang_check_time(), and cas_log_end_hang_check_time().

Referenced by cas_access_log(), cas_log_close(), cas_log_debug(), and cas_slow_log_close().

Here is the caller graph for this function:

static int cas_fflush ( FILE *  stream)
static

Definition at line 1310 of file cas_log.c.

References cas_log_begin_hang_check_time(), and cas_log_end_hang_check_time().

Referenced by cas_log_write2_internal(), cas_log_write_internal(), and cas_slow_log_end().

Here is the caller graph for this function:

static int cas_fileno ( FILE *  stream)
static

Definition at line 1324 of file cas_log.c.

References cas_log_begin_hang_check_time(), and cas_log_end_hang_check_time().

Referenced by cas_log_close().

Here is the caller graph for this function:

static FILE * cas_fopen ( const char *  path,
const char *  mode 
)
static

Definition at line 1237 of file cas_log.c.

References cas_log_begin_hang_check_time(), cas_log_end_hang_check_time(), MAX_RETRY_COUNT, mode, NULL, and SLEEP_MILISEC.

Referenced by access_log_open(), cas_log_open(), and cas_slow_log_open().

Here is the caller graph for this function:

static int cas_fprintf ( FILE *  stream,
const char *  format,
  ... 
)
static

Definition at line 1337 of file cas_log.c.

References cas_log_begin_hang_check_time(), and cas_log_end_hang_check_time().

Referenced by cas_access_log(), and cas_log_debug().

Here is the caller graph for this function:

static int cas_fputc ( int  c,
FILE *  stream 
)
static
static int cas_fseek ( FILE *  stream,
INT64  offset,
int  whence 
)
static

Definition at line 1224 of file cas_log.c.

References cas_log_begin_hang_check_time(), and cas_log_end_hang_check_time().

Referenced by cas_log_close(), cas_log_open(), and cas_log_write_and_set_savedpos().

Here is the caller graph for this function:

static INT64 cas_ftell ( FILE *  stream)
static

Definition at line 1218 of file cas_log.c.

Referenced by cas_log_debug(), cas_log_end(), cas_log_open(), cas_log_write(), cas_log_write_and_end(), cas_log_write_nonl(), and cas_slow_log_end().

Here is the caller graph for this function:

static int cas_ftruncate ( int  fd,
off_t  length 
)
static

Definition at line 1297 of file cas_log.c.

References cas_log_begin_hang_check_time(), and cas_log_end_hang_check_time().

Referenced by cas_log_close().

Here is the caller graph for this function:

static size_t cas_fwrite ( const void *  ptr,
size_t  size,
size_t  nmemb,
FILE *  stream 
)
static
static void cas_log_backup ( T_CUBRID_FILE_ID  fid)
static

Definition at line 252 of file cas_log.c.

References assert, BROKER_PATH_MAX, cas_rename(), cas_unlink(), FID_SLOW_LOG_DIR, FID_SQL_LOG_DIR, log_filepath, NULL, and slow_log_filepath.

Referenced by cas_log_end(), and cas_slow_log_end().

Here is the caller graph for this function:

static bool cas_log_begin_hang_check_time ( void  )
static
void cas_log_close ( bool  flag)

Definition at line 234 of file cas_log.c.

References cas_fclose(), cas_fileno(), cas_fseek(), cas_ftruncate(), log_fp, NULL, and saved_log_fpos.

Referenced by cas_free(), cas_log_end(), cas_log_open(), cas_log_reset(), cas_main(), and shard_cas_main().

Here is the caller graph for this function:

static void cas_log_end_hang_check_time ( bool  is_prev_time_set)
static

Definition at line 1189 of file cas_log.c.

References cas_shard_flag, OFF, and unset_hang_check_time().

Referenced by cas_fclose(), cas_fflush(), cas_fileno(), cas_fopen(), cas_fprintf(), cas_fputc(), cas_fseek(), cas_ftruncate(), cas_fwrite(), cas_mkdir(), cas_rename(), and cas_unlink().

Here is the caller graph for this function:

void cas_log_query_info_init ( int  id,
char  is_only_query_plan 
)

Definition at line 871 of file cas_log.c.

References cas_log_query_plan_file(), cas_unlink(), db_query_plan_dump_file(), and set_optimization_level().

Referenced by fn_get_query_info(), ux_execute(), and ux_prepare().

Here is the caller graph for this function:

char* cas_log_query_plan_file ( int  id)

Definition at line 892 of file cas_log.c.

References assert, BROKER_PATH_MAX, dirname(), FID_CAS_TMP_DIR, get_cubrid_file(), and NULL.

Referenced by cas_log_query_info_init(), srv_handle_rm_tmp_file(), ux_execute(), and ux_get_query_info().

Here is the caller graph for this function:

void cas_log_reset ( char *  br_name)
void cas_log_write2 ( const char *  fmt,
  ... 
)
static void cas_log_write2_internal ( FILE *  fp,
bool  do_flush,
const char *  fmt,
va_list  ap 
)
static

Definition at line 559 of file cas_log.c.

References cas_fflush(), cas_fwrite(), cas_log_buffer, CAS_LOG_BUFFER_SIZE, and p.

Referenced by cas_log_write2(), cas_log_write2_nonl(), and cas_slow_log_write2().

Here is the caller graph for this function:

void cas_log_write2_nonl ( const char *  fmt,
  ... 
)
static void cas_log_write_and_set_savedpos ( FILE *  log_fp,
const char *  fmt,
  ... 
)
static

Definition at line 282 of file cas_log.c.

References assert, BROKER_PATH_MAX, cas_fseek(), cas_log_write_internal(), cas_rename(), log_filepath, NULL, and saved_log_fpos.

Referenced by cas_log_end().

Here is the caller graph for this function:

void cas_log_write_client_ip ( const unsigned char *  ip_addr)

Definition at line 686 of file cas_log.c.

References cas_log_write_and_end(), NULL, and ut_get_ipv4_string().

Referenced by net_read_process().

Here is the caller graph for this function:

static void cas_log_write_internal ( FILE *  fp,
struct timeval *  log_time,
unsigned int  seq_num,
bool  do_flush,
const char *  fmt,
va_list  ap 
)
static
void cas_log_write_nonl ( unsigned int  seq_num,
bool  unit_start,
const char *  fmt,
  ... 
)
void cas_log_write_query_string ( char *  query,
int  size 
)

Definition at line 647 of file cas_log.c.

References cas_log_write_query_string_internal().

Referenced by fn_execute_array(), fn_execute_internal(), and fn_prepare_internal().

Here is the caller graph for this function:

static void cas_log_write_query_string_internal ( char *  query,
int  size,
bool  newline 
)
static
void cas_log_write_query_string_nonl ( char *  query,
int  size 
)

Definition at line 641 of file cas_log.c.

References cas_log_write_query_string_internal().

Referenced by ux_execute_batch().

Here is the caller graph for this function:

void cas_log_write_value_string ( char *  value,
int  size 
)

Definition at line 625 of file cas_log.c.

References as_info, t_shm_appl_server::broker_name, cas_fwrite(), cas_log_open(), t_appl_server_info::cur_sql_log_mode, log_fp, NULL, shm_appl, and SQL_LOG_MODE_NONE.

Referenced by bind_value_print().

Here is the caller graph for this function:

static int cas_mkdir ( const char *  pathname,
mode_t  mode 
)
static

Definition at line 1394 of file cas_log.c.

References cas_log_begin_hang_check_time(), and cas_log_end_hang_check_time().

Referenced by access_log_open().

Here is the caller graph for this function:

static int cas_rename ( const char *  oldpath,
const char *  newpath 
)
static

Definition at line 1381 of file cas_log.c.

References cas_log_begin_hang_check_time(), and cas_log_end_hang_check_time().

Referenced by cas_log_backup(), and cas_log_write_and_set_savedpos().

Here is the caller graph for this function:

void cas_slow_log_close ( void  )

Definition at line 1021 of file cas_log.c.

References cas_fclose(), NULL, and slow_log_fp.

Referenced by cas_free(), cas_main(), cas_slow_log_end(), cas_slow_log_open(), cas_slow_log_reset(), and shard_cas_main().

Here is the caller graph for this function:

void cas_slow_log_write ( struct timeval *  log_time,
unsigned int  seq_num,
bool  unit_start,
const char *  fmt,
  ... 
)
void cas_slow_log_write2 ( const char *  fmt,
  ... 
)
void cas_slow_log_write_and_end ( struct timeval *  log_time,
unsigned int  seq_num,
const char *  fmt,
  ... 
)
void cas_slow_log_write_query_string ( char *  query,
int  size 
)
void cas_slow_log_write_value_string ( char *  value,
int  size 
)

Definition at line 1125 of file cas_log.c.

References as_info, t_shm_appl_server::broker_name, cas_fwrite(), cas_slow_log_open(), t_appl_server_info::cur_slow_log_mode, NULL, shm_appl, slow_log_fp, and SLOW_LOG_MODE_OFF.

Referenced by bind_value_print().

Here is the caller graph for this function:

static int cas_unlink ( const char *  pathname)
static

Definition at line 1368 of file cas_log.c.

References cas_log_begin_hang_check_time(), and cas_log_end_hang_check_time().

Referenced by cas_log_backup(), cas_log_query_info_init(), cas_log_reset(), and cas_slow_log_reset().

Here is the caller graph for this function:

static const char * get_access_log_type_string ( ACCESS_LOG_TYPE  type)
static

Definition at line 1417 of file cas_log.c.

References ACL_REJECTED, assert, CLIENT_CHANGED, and NEW_CONNECTION.

Referenced by cas_access_log().

Here is the caller graph for this function:

static char * make_sql_log_filename ( T_CUBRID_FILE_ID  fid,
char *  filename_buf,
size_t  buf_size,
const char *  br_name 
)
static

Definition at line 114 of file cas_log.c.

References assert, BROKER_PATH_MAX, cas_shard_flag, dirname(), FID_SLOW_LOG_DIR, FID_SQL_LOG_DIR, get_cubrid_file(), NULL, ON, shm_as_index, shm_proxy_id, shm_shard_cas_id, and shm_shard_id.

Referenced by cas_log_open(), and cas_slow_log_open().

Here is the caller graph for this function:

Variable Documentation

char cas_log_buffer[CAS_LOG_BUFFER_SIZE]
static

Definition at line 67 of file cas_log.c.

Referenced by cas_log_write2_internal(), and cas_log_write_internal().

char log_filepath[BROKER_PATH_MAX]
static
char slow_log_filepath[BROKER_PATH_MAX]
static

Definition at line 92 of file cas_log.c.

Referenced by cas_log_backup(), cas_slow_log_open(), and cas_slow_log_reset().

char sql_log_buffer[SQL_LOG_BUFFER_SIZE]
static

Definition at line 68 of file cas_log.c.

Referenced by cas_log_open().