CUBRID Engine  latest
checksumdb.c File Reference
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include "authenticate.h"
#include "error_code.h"
#include "system_parameter.h"
#include "message_catalog.h"
#include "db.h"
#include "utility.h"
#include "parser.h"
#include "object_print.h"
#include "schema_manager.h"
#include "transaction_cl.h"
#include "util_func.h"
#include "client_support.h"
#include "connection_support.h"
#include "environment_variable.h"
#include "network_interface_cl.h"
#include "locator_cl.h"
#include "db_value_printer.hpp"
#include "mem_block.hpp"
#include "string_buffer.hpp"
#include "dbtype.h"

Go to the source code of this file.

Classes

struct  chksum_result
 
struct  chksum_arg
 

Macros

#define CHKSUM_DEFAULT_LIST_SIZE   10
 
#define CHKSUM_MIN_CHUNK_SIZE   100
 
#define CHKSUM_DEFAULT_TABLE_NAME   "db_ha_checksum"
 
#define CHKSUM_SCHEMA_TABLE_SUFFIX   "_schema"
 
#define CHKSUM_TABLE_CLASS_NAME_COL   "class_name"
 
#define CHKSUM_TABLE_CHUNK_ID_COL   "chunk_id"
 
#define CHKSUM_TABLE_LOWER_BOUND_COL   "chunk_lower_bound"
 
#define CHKSUM_TABLE_CHUNK_CHECKSUM_COL   "chunk_checksum"
 
#define CHKSUM_TABLE_COUNT_COL   "chunk_count"
 
#define CHKSUM_TABLE_MASTER_CHEKSUM_COL   "master_checksum"
 
#define CHKSUM_TABLE_BEGINS_AT_COL   "begins_at"
 
#define CHKSUM_TABLE_ELAPSED_TIME_COL   "elapsed_time"
 
#define CHKSUM_TABLE_MASTER_SCHEMA_COL   "master_schema_def"
 
#define CHKSUM_TABLE_SCHEMA_COL   "schema_def"
 
#define CHKSUM_TABLE_SCHEMA_TIME_COL   "collected_time"
 
#define CHKSUM_TABLE_SCHEMA_REPID_COL   "representation_id"
 
#define CHKSUM_STOP_ON_ERROR(err, arg)
 
#define CHKSUM_PRINT_AND_LOG(fp, ...)
 
#define QUERY_BUF_SIZE   1024
 
#define QUERY_BUF_SIZE   1024
 
#define QUERY_BUF_SIZE   1024
 
#define QUERY_BUF_SIZE   2048
 
#define QUERY_BUF_SIZE   2048
 
#define QUERY_BUF_SIZE   2048
 
#define QUERY_BUF_SIZE   2048
 

Typedefs

typedef struct chksum_result CHKSUM_RESULT
 
typedef struct chksum_arg CHKSUM_ARG
 

Functions

static int chksum_drop_and_create_checksum_table (void)
 
static int chksum_init_checksum_tables (bool resume)
 
static int chksum_get_prev_checksum_results (void)
 
static CHKSUM_RESULTchksum_get_checksum_result (const char *table_name)
 
static void chksum_free_results (CHKSUM_RESULT *results)
 
static bool chksum_need_skip_table (const char *table_name, CHKSUM_ARG *chksum_arg)
 
static int chksum_set_initial_chunk_id_and_lower_bound (PARSER_CONTEXT *parser, const char *table_name, DB_CONSTRAINT *pk_cons, int *chunk_id, PARSER_VARCHAR **lower_bound)
 
static PARSER_VARCHARchksum_print_pk_list (PARSER_CONTEXT *parser, DB_CONSTRAINT *pk, int *pk_col_cnt, bool include_decs)
 
static PARSER_VARCHARchksum_print_select_last_chunk (PARSER_CONTEXT *parser, const char *table_name, PARSER_VARCHAR *pk_list, PARSER_VARCHAR *pk_orderby, PARSER_VARCHAR *prev_lower_bound, int limit)
 
static PARSER_VARCHARchksum_print_checksum_query (PARSER_CONTEXT *parser, const char *table_name, DB_ATTRIBUTE *attributes, PARSER_VARCHAR *lower_bound, int chunk_id, int chunk_size)
 
static PARSER_VARCHARchksum_print_lower_bound_string (PARSER_CONTEXT *parser, DB_VALUE values[], DB_CONSTRAINT *pk, int pk_col_cnt)
 
static PARSER_VARCHARchksum_get_quote_escaped_lower_bound (PARSER_CONTEXT *parser, PARSER_VARCHAR *orig_lower_bound)
 
static PARSER_VARCHARchksum_print_attribute_list (PARSER_CONTEXT *parser, DB_ATTRIBUTE *attributes)
 
static PARSER_VARCHARchksum_get_next_lower_bound (PARSER_CONTEXT *parser, const char *table_name, DB_CONSTRAINT *pk_cons, PARSER_VARCHAR *prev_lower_bound, int chunk_size, int *exec_error)
 
static PARSER_VARCHARchksum_get_initial_lower_bound (PARSER_CONTEXT *parser, const char *table_name, DB_CONSTRAINT *pk_cons, int *exec_error)
 
static PARSER_VARCHARchksum_print_select_master_checksum (PARSER_CONTEXT *parser, const char *table_name, int chunk_id)
 
static PARSER_VARCHARchksum_print_update_master_checksum (PARSER_CONTEXT *parser, const char *table_name, int chunk_id, int master_checksum)
 
static int chksum_update_master_checksum (PARSER_CONTEXT *parser, const char *table_name, int chunk_id)
 
static int chksum_set_repl_info_and_demote_table_lock (const char *table_name, const char *checksum_query, const OID *class_oidp)
 
static int chksum_update_current_schema_definition (const char *table_name, int repid)
 
static int chksum_insert_schema_definition (const char *table_name, int repid)
 
static int chksum_calculate_checksum (PARSER_CONTEXT *parser, const OID *class_oidp, const char *table_name, DB_ATTRIBUTE *attributes, PARSER_VARCHAR *lower_bound, int chunk_id, int chunk_size)
 
static int chksum_start (CHKSUM_ARG *chksum_arg)
 
static int chksum_report (const char *command_name, const char *database)
 
static int chksum_report_summary (FILE *fp)
 
static int chksum_report_diff (FILE *fp)
 
static int chksum_report_schema_diff (FILE *fp)
 
static void chksum_report_header (FILE *fp, const char *database)
 
static FILE * chksum_report_open_file (const char *command_name)
 
int checksumdb (UTIL_FUNCTION_ARG *arg)
 

Variables

CHKSUM_RESULTchksum_Prev_results = NULL
 
char chksum_result_Table_name [SM_MAX_IDENTIFIER_LENGTH]
 
char chksum_schema_Table_name [SM_MAX_IDENTIFIER_LENGTH]
 

Macro Definition Documentation

#define CHKSUM_DEFAULT_LIST_SIZE   10

Definition at line 54 of file checksumdb.c.

Referenced by checksumdb().

#define CHKSUM_DEFAULT_TABLE_NAME   "db_ha_checksum"

Definition at line 56 of file checksumdb.c.

Referenced by checksumdb().

#define CHKSUM_MIN_CHUNK_SIZE   100

Definition at line 55 of file checksumdb.c.

Referenced by checksumdb().

#define CHKSUM_PRINT_AND_LOG (   fp,
  ... 
)
Value:
do {\
fprintf(stdout, __VA_ARGS__);\
fprintf(fp, __VA_ARGS__);\
}while (0)

Definition at line 77 of file checksumdb.c.

Referenced by chksum_report_diff(), chksum_report_header(), chksum_report_schema_diff(), and chksum_report_summary().

#define CHKSUM_SCHEMA_TABLE_SUFFIX   "_schema"

Definition at line 57 of file checksumdb.c.

Referenced by checksumdb().

#define CHKSUM_STOP_ON_ERROR (   err,
  arg 
)
Value:
(((err) != NO_ERROR) && \
((ER_IS_SERVER_DOWN_ERROR(err) == true) || \
((arg)->cont_on_err == false)))
#define NO_ERROR
Definition: error_code.h:46
#define err(fd,...)
Definition: porting.h:431
#define ER_IS_SERVER_DOWN_ERROR(err)

Definition at line 73 of file checksumdb.c.

Referenced by chksum_start().

#define CHKSUM_TABLE_BEGINS_AT_COL   "begins_at"
#define CHKSUM_TABLE_CHUNK_CHECKSUM_COL   "chunk_checksum"
#define CHKSUM_TABLE_COUNT_COL   "chunk_count"
#define CHKSUM_TABLE_ELAPSED_TIME_COL   "elapsed_time"
#define CHKSUM_TABLE_LOWER_BOUND_COL   "chunk_lower_bound"
#define CHKSUM_TABLE_MASTER_CHEKSUM_COL   "master_checksum"
#define CHKSUM_TABLE_MASTER_SCHEMA_COL   "master_schema_def"
#define CHKSUM_TABLE_SCHEMA_COL   "schema_def"
#define CHKSUM_TABLE_SCHEMA_REPID_COL   "representation_id"
#define CHKSUM_TABLE_SCHEMA_TIME_COL   "collected_time"
#define QUERY_BUF_SIZE   1024
#define QUERY_BUF_SIZE   1024
#define QUERY_BUF_SIZE   2048
#define QUERY_BUF_SIZE   2048
#define QUERY_BUF_SIZE   2048
#define QUERY_BUF_SIZE   2048

Typedef Documentation

typedef struct chksum_arg CHKSUM_ARG

Definition at line 93 of file checksumdb.c.

typedef struct chksum_result CHKSUM_RESULT

Definition at line 83 of file checksumdb.c.

Function Documentation

int checksumdb ( UTIL_FUNCTION_ARG arg)

Definition at line 2068 of file checksumdb.c.

References UTIL_FUNCTION_ARG::arg_map, UTIL_FUNCTION_ARG::argv0, assert, AU_DISABLE_PASSWORDS, basename(), begin(), check_database_name(), CHECKSUM_CHUNK_SIZE_S, CHECKSUM_CONT_ON_ERROR_S, CHECKSUM_EXCLUDE_CLASS_FILE_S, CHECKSUM_INCLUDE_CLASS_FILE_S, CHECKSUM_REPORT_ONLY_S, CHECKSUM_RESUME_S, CHECKSUM_SCHEMA_ONLY_S, CHECKSUM_SLEEP_S, CHECKSUM_TABLE_NAME_S, CHECKSUM_TIMEOUT_S, CHECKSUMDB_MSG_HA_NOT_SUPPORT, CHECKSUMDB_MSG_INVALID_INPUT_FILE, CHECKSUMDB_MSG_MUST_RUN_ON_ACTIVE, CHECKSUMDB_MSG_NOT_IN_STANDALONE, CHECKSUMDB_MSG_USAGE, CHKSUM_DEFAULT_LIST_SIZE, CHKSUM_DEFAULT_TABLE_NAME, CHKSUM_MIN_CHUNK_SIZE, chksum_report(), chksum_result_Table_name, chksum_schema_Table_name, CHKSUM_SCHEMA_TABLE_SUFFIX, chksum_start(), chksum_arg::chunk_size, UTIL_FUNCTION_ARG::command_name, chksum_arg::cont_on_err, css_ha_server_state(), css_ha_server_state_string(), da_create(), da_destroy(), database_name, DB_CLIENT_TYPE_ADMIN_UTILITY, db_error_string(), db_login(), db_restart(), db_set_client_type(), db_set_isolation(), db_set_lock_timeout(), db_shutdown(), ER_FAILED, er_init(), ER_NEVER_EXIT, error(), chksum_arg::exclude_list, HA_SERVER_STATE_ACTIVE, HA_SERVER_STATE_NA, chksum_arg::include_list, MSGCAT_CATALOG_UTILS, msgcat_message(), MSGCAT_UTIL_GENERIC_INVALID_ARGUMENT, MSGCAT_UTIL_GENERIC_SERVICE_PROPERTY_FAIL, MSGCAT_UTIL_SET_CHECKSUMDB, NO_ERROR, NULL, OPTION_STRING_TABLE, PRINT_AND_LOG_ERR_MSG, chksum_arg::resume, chksum_arg::schema_only, chksum_arg::sleep_msecs, sm_check_name(), SM_MAX_IDENTIFIER_LENGTH, SYSPRM_LOAD_ALL, sysprm_load_and_init(), chksum_arg::timeout_msecs, TRAN_REPEATABLE_READ, TRUE, util_get_table_list_from_file(), util_log_write_errid(), utility_get_option_bool_value(), utility_get_option_int_value(), utility_get_option_string_table_size(), and utility_get_option_string_value().

static int chksum_calculate_checksum ( PARSER_CONTEXT parser,
const OID class_oidp,
const char *  table_name,
DB_ATTRIBUTE attributes,
PARSER_VARCHAR lower_bound,
int  chunk_id,
int  chunk_size 
)
static
static void chksum_free_results ( CHKSUM_RESULT results)
static

Definition at line 739 of file checksumdb.c.

References free_and_init, chksum_result::last_lower_bound, chksum_result::next, and NULL.

Referenced by chksum_get_prev_checksum_results(), and chksum_start().

Here is the caller graph for this function:

static CHKSUM_RESULT * chksum_get_checksum_result ( const char *  table_name)
static

Definition at line 768 of file checksumdb.c.

References chksum_Prev_results, chksum_result::class_name, chksum_result::next, and NULL.

Referenced by chksum_set_initial_chunk_id_and_lower_bound().

Here is the caller graph for this function:

static PARSER_VARCHAR * chksum_get_initial_lower_bound ( PARSER_CONTEXT parser,
const char *  table_name,
DB_CONSTRAINT pk_cons,
int *  exec_error 
)
static

Definition at line 1407 of file checksumdb.c.

References chksum_get_next_lower_bound(), and NULL.

Referenced by chksum_set_initial_chunk_id_and_lower_bound().

Here is the caller graph for this function:

static PARSER_VARCHAR * chksum_get_quote_escaped_lower_bound ( PARSER_CONTEXT parser,
PARSER_VARCHAR orig_lower_bound 
)
static

Definition at line 1254 of file checksumdb.c.

References assert, parser_varchar::bytes, parser_varchar::length, NULL, pt_append_bytes(), and pt_append_nulstring().

Referenced by chksum_print_checksum_query().

Here is the caller graph for this function:

static int chksum_insert_schema_definition ( const char *  table_name,
int  repid 
)
static

Definition at line 1627 of file checksumdb.c.

References chksum_schema_Table_name, chksum_update_current_schema_definition(), db_execute(), db_query_end(), error(), NO_ERROR, NULL, and QUERY_BUF_SIZE.

Referenced by chksum_start().

Here is the caller graph for this function:

static bool chksum_need_skip_table ( const char *  table_name,
CHKSUM_ARG chksum_arg 
)
static

Definition at line 1734 of file checksumdb.c.

References assert, chksum_result_Table_name, chksum_schema_Table_name, da_get(), da_size(), chksum_arg::exclude_list, i, chksum_arg::include_list, NULL, and SM_MAX_IDENTIFIER_LENGTH.

Referenced by chksum_start().

Here is the caller graph for this function:

static PARSER_VARCHAR * chksum_print_attribute_list ( PARSER_CONTEXT parser,
DB_ATTRIBUTE attributes 
)
static

Definition at line 1219 of file checksumdb.c.

References db_attribute_name(), db_attribute_next(), NULL, and pt_append_nulstring().

Referenced by chksum_print_checksum_query().

Here is the caller graph for this function:

static PARSER_VARCHAR * chksum_print_checksum_query ( PARSER_CONTEXT parser,
const char *  table_name,
DB_ATTRIBUTE attributes,
PARSER_VARCHAR lower_bound,
int  chunk_id,
int  chunk_size 
)
static
static PARSER_VARCHAR * chksum_print_lower_bound_string ( PARSER_CONTEXT parser,
DB_VALUE  values[],
DB_CONSTRAINT pk,
int  pk_col_cnt 
)
static
static PARSER_VARCHAR * chksum_print_pk_list ( PARSER_CONTEXT parser,
DB_CONSTRAINT pk,
int *  pk_col_cnt,
bool  include_decs 
)
static

Definition at line 961 of file checksumdb.c.

References db_attribute_name(), db_constraint_asc_desc(), db_constraint_attributes(), i, NULL, and pt_append_nulstring().

Referenced by chksum_get_next_lower_bound().

Here is the caller graph for this function:

static PARSER_VARCHAR * chksum_print_select_last_chunk ( PARSER_CONTEXT parser,
const char *  table_name,
PARSER_VARCHAR pk_list,
PARSER_VARCHAR pk_orderby,
PARSER_VARCHAR prev_lower_bound,
int  limit 
)
static

Definition at line 1020 of file checksumdb.c.

References NULL, pt_append_nulstring(), and pt_append_varchar().

Referenced by chksum_get_next_lower_bound().

Here is the caller graph for this function:

static PARSER_VARCHAR * chksum_print_select_master_checksum ( PARSER_CONTEXT parser,
const char *  table_name,
int  chunk_id 
)
static

Definition at line 1422 of file checksumdb.c.

References chksum_result_Table_name, NULL, and pt_append_nulstring().

Referenced by chksum_update_master_checksum().

Here is the caller graph for this function:

static PARSER_VARCHAR * chksum_print_update_master_checksum ( PARSER_CONTEXT parser,
const char *  table_name,
int  chunk_id,
int  master_checksum 
)
static
static int chksum_report ( const char *  command_name,
const char *  database 
)
static
static void chksum_report_header ( FILE *  fp,
const char *  database 
)
static

Definition at line 174 of file checksumdb.c.

References CHKSUM_PRINT_AND_LOG, chksum_result_Table_name, chksum_schema_Table_name, css_ha_server_state(), css_ha_server_state_string(), HA_SERVER_STATE_NA, and NULL.

Referenced by chksum_report().

Here is the caller graph for this function:

static FILE * chksum_report_open_file ( const char *  command_name)
static

Definition at line 159 of file checksumdb.c.

References envvar_logdir_file().

Referenced by chksum_report().

Here is the caller graph for this function:

static int chksum_set_initial_chunk_id_and_lower_bound ( PARSER_CONTEXT parser,
const char *  table_name,
DB_CONSTRAINT pk_cons,
int *  chunk_id,
PARSER_VARCHAR **  lower_bound 
)
static
static int chksum_set_repl_info_and_demote_table_lock ( const char *  table_name,
const char *  checksum_query,
const OID class_oidp 
)
static
static int chksum_update_current_schema_definition ( const char *  table_name,
int  repid 
)
static

Variable Documentation

CHKSUM_RESULT* chksum_Prev_results = NULL

Definition at line 106 of file checksumdb.c.

Referenced by chksum_get_checksum_result(), and chksum_get_prev_checksum_results().