merge Spider 3.2.4

This commit is contained in:
Kentoku SHIBA 2014-06-08 19:52:11 +09:00
commit 29cf8fb348
22 changed files with 1295 additions and 325 deletions

View file

@ -54,6 +54,10 @@
extern handlerton *spider_hton_ptr;
extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE];
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
extern HASH spider_open_tables;
#endif
extern pthread_mutex_t spider_lgtm_tblhnd_share_mutex;
ha_spider::ha_spider(
) : handler(spider_hton_ptr, NULL)
@ -152,6 +156,7 @@ ha_spider::ha_spider(
result_list.tmp_pos_row_first = NULL;
#ifdef HANDLER_HAS_DIRECT_AGGREGATE
result_list.direct_aggregate = FALSE;
result_list.snap_direct_aggregate = FALSE;
#endif
result_list.casual_read = NULL;
result_list.use_both_key = FALSE;
@ -257,6 +262,7 @@ ha_spider::ha_spider(
result_list.tmp_pos_row_first = NULL;
#ifdef HANDLER_HAS_DIRECT_AGGREGATE
result_list.direct_aggregate = FALSE;
result_list.snap_direct_aggregate = FALSE;
#endif
result_list.casual_read = NULL;
result_list.use_both_key = FALSE;
@ -1236,13 +1242,13 @@ int ha_spider::external_lock(
#ifdef HA_CAN_BULK_ACCESS
external_lock_cnt++;
#endif
if (store_error_num)
DBUG_RETURN(store_error_num);
if (
lock_type == F_UNLCK &&
sql_command != SQLCOM_UNLOCK_TABLES
)
DBUG_RETURN(0);
if (store_error_num)
DBUG_RETURN(store_error_num);
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
if ((conn_kinds & SPIDER_CONN_KIND_MYSQL))
{
@ -1577,6 +1583,7 @@ int ha_spider::reset()
direct_aggregate_item_current = direct_aggregate_item_current->next;
}
result_list.direct_aggregate = FALSE;
result_list.snap_direct_aggregate = FALSE;
#endif
store_error_num = 0;
#ifdef WITH_PARTITION_STORAGE_ENGINE
@ -1716,6 +1723,7 @@ int ha_spider::reset()
insert_delayed = FALSE;
use_pre_call = FALSE;
use_pre_records = FALSE;
pre_bitmap_checked = FALSE;
bulk_insert = FALSE;
clone_bitmap_init = FALSE;
result_list.tmp_table_join = FALSE;
@ -1877,25 +1885,29 @@ int ha_spider::index_init(
init_index_handler = FALSE;
use_spatial_index = FALSE;
if (result_list.lock_type == F_WRLCK)
{
pk_update = FALSE;
if (pre_bitmap_checked)
pre_bitmap_checked = FALSE;
else {
if (result_list.lock_type == F_WRLCK)
{
pk_update = FALSE;
/*
check_and_start_bulk_update(SPD_BU_START_BY_INDEX_OR_RND_INIT);
check_and_start_bulk_update(SPD_BU_START_BY_INDEX_OR_RND_INIT);
*/
if (
update_request &&
share->have_recovery_link &&
(pk_update = spider_check_pk_update(table))
) {
bitmap_set_all(table->read_set);
if (is_clone)
memset(searched_bitmap, 0xFF, no_bytes_in_map(table->read_set));
if (
update_request &&
share->have_recovery_link &&
(pk_update = spider_check_pk_update(table))
) {
bitmap_set_all(table->read_set);
if (is_clone)
memset(searched_bitmap, 0xFF, no_bytes_in_map(table->read_set));
}
}
}
if (!is_clone)
set_select_column_mode();
if (!is_clone)
set_select_column_mode();
}
if ((error_num = reset_sql_sql(
SPIDER_SQL_TYPE_SELECT_SQL | SPIDER_SQL_TYPE_HANDLER)))
@ -4199,6 +4211,31 @@ ha_rows ha_spider::multi_range_read_info_const(
{
DBUG_ENTER("ha_spider::multi_range_read_info_const");
DBUG_PRINT("info",("spider this=%p", this));
if (!pre_bitmap_checked)
{
if (result_list.lock_type == F_WRLCK)
{
pk_update = FALSE;
if (
update_request &&
share->have_recovery_link &&
(pk_update = spider_check_pk_update(table))
) {
bitmap_set_all(table->read_set);
if (is_clone)
memset(searched_bitmap, 0xFF, no_bytes_in_map(table->read_set));
}
}
if (!is_clone)
set_select_column_mode();
pre_bitmap_checked = TRUE;
}
/*
multi_range_num = n_ranges;
mrr_have_range = FALSE;
*/
ha_rows rows =
handler::multi_range_read_info_const(
keyno,
@ -4238,6 +4275,31 @@ ha_rows ha_spider::multi_range_read_info(
{
DBUG_ENTER("ha_spider::multi_range_read_info");
DBUG_PRINT("info",("spider this=%p", this));
if (!pre_bitmap_checked)
{
if (result_list.lock_type == F_WRLCK)
{
pk_update = FALSE;
if (
update_request &&
share->have_recovery_link &&
(pk_update = spider_check_pk_update(table))
) {
bitmap_set_all(table->read_set);
if (is_clone)
memset(searched_bitmap, 0xFF, no_bytes_in_map(table->read_set));
}
}
if (!is_clone)
set_select_column_mode();
pre_bitmap_checked = TRUE;
}
/*
multi_range_num = n_ranges;
mrr_have_range = FALSE;
*/
ha_rows rows =
handler::multi_range_read_info(
keyno,
@ -4266,6 +4328,7 @@ int ha_spider::multi_range_read_init(
DBUG_PRINT("info",("spider this=%p", this));
DBUG_PRINT("info",("spider n_ranges=%u", n_ranges));
multi_range_num = n_ranges;
mrr_have_range = FALSE;
DBUG_RETURN(
handler::multi_range_read_init(
seq,
@ -4360,6 +4423,9 @@ int ha_spider::read_multi_range_first_internal(
#endif
result_list.key_info = &table->key_info[active_index];
if (
#ifdef HA_MRR_USE_DEFAULT_IMPL
multi_range_num == 1 ||
#endif
result_list.multi_split_read <= 1 ||
(sql_kinds & SPIDER_SQL_KIND_HANDLER)
) {
@ -4380,6 +4446,7 @@ int ha_spider::read_multi_range_first_internal(
DBUG_RETURN(error_num);
set_where_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL);
#ifdef HA_MRR_USE_DEFAULT_IMPL
error_num = HA_ERR_END_OF_FILE;
while (!(range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range)))
#else
for (
@ -4663,6 +4730,8 @@ int ha_spider::read_multi_range_first_internal(
#ifndef WITHOUT_SPIDER_BG_SEARCH
}
#endif
if (error_num)
break;
}
if (error_num)
{
@ -5749,12 +5818,23 @@ int ha_spider::read_multi_range_next(
pt_clone_source_handler->pt_clone_last_searcher = this;
}
if (
#ifdef HA_MRR_USE_DEFAULT_IMPL
multi_range_num == 1 ||
#endif
result_list.multi_split_read <= 1 ||
(sql_kinds & SPIDER_SQL_KIND_HANDLER)
) {
if (!(error_num = spider_db_seek_next(table->record[0], this,
search_link_idx, table)))
DBUG_RETURN(check_ha_range_eof());
{
#ifdef HA_MRR_USE_DEFAULT_IMPL
*range_info = (char *) mrr_cur_range.ptr;
#else
*found_range_p = multi_range_curr;
#endif
DBUG_RETURN(0);
}
#ifdef HA_MRR_USE_DEFAULT_IMPL
range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range);
DBUG_PRINT("info",("spider range_res1=%d", range_res));
@ -6073,6 +6153,8 @@ int ha_spider::read_multi_range_next(
#ifndef WITHOUT_SPIDER_BG_SEARCH
}
#endif
if (error_num)
break;
}
if (error_num)
{
@ -7526,7 +7608,7 @@ void ha_spider::position(
if (select_column_mode)
{
spider_db_handler *dbton_hdl =
dbton_handler[result_list.current->result->dbton_id];
dbton_handler[result_list.current->dbton_id];
dbton_hdl->copy_minimum_select_bitmap(position_bitmap);
}
position_bitmap_init = TRUE;
@ -8102,14 +8184,19 @@ int ha_spider::info(
#endif
sql_command = thd_sql_command(thd);
if (
/*
sql_command == SQLCOM_DROP_TABLE ||
sql_command == SQLCOM_ALTER_TABLE ||
sql_command == SQLCOM_SHOW_CREATE
*/
sql_command == SQLCOM_DROP_TABLE ||
sql_command == SQLCOM_ALTER_TABLE
) {
if (flag & HA_STATUS_AUTO)
{
if (share->auto_increment_value)
stats.auto_increment_value = share->auto_increment_value;
if (share->lgtm_tblhnd_share->auto_increment_value)
stats.auto_increment_value =
share->lgtm_tblhnd_share->auto_increment_value;
else {
stats.auto_increment_value = 1;
#ifdef HANDLER_HAS_CAN_USE_FOR_AUTO_INC_INIT
@ -8174,7 +8261,7 @@ int ha_spider::info(
share->partition_share &&
#endif
tmp_auto_increment_mode == 1 &&
!share->auto_increment_init
!share->lgtm_tblhnd_share->auto_increment_init
) {
sts_interval = 0;
#ifdef WITH_PARTITION_STORAGE_ENGINE
@ -8339,23 +8426,30 @@ int ha_spider::info(
)
) {
get_auto_increment(0, 0, 0, &first_value, &nb_reserved_values);
share->auto_increment_value = first_value;
share->auto_increment_lclval = first_value;
share->auto_increment_init = TRUE;
share->lgtm_tblhnd_share->auto_increment_value = first_value;
share->lgtm_tblhnd_share->auto_increment_lclval = first_value;
share->lgtm_tblhnd_share->auto_increment_init = TRUE;
DBUG_PRINT("info",("spider init auto_increment_lclval=%llu",
share->auto_increment_lclval));
share->lgtm_tblhnd_share->auto_increment_lclval));
DBUG_PRINT("info",("spider auto_increment_value=%llu",
share->lgtm_tblhnd_share->auto_increment_value));
stats.auto_increment_value = first_value;
} else if (tmp_auto_increment_mode == 1 && !share->auto_increment_init)
} else if (tmp_auto_increment_mode == 1 &&
!share->lgtm_tblhnd_share->auto_increment_init)
{
share->auto_increment_lclval = share->auto_increment_value;
share->auto_increment_init = TRUE;
stats.auto_increment_value = share->auto_increment_value;
share->lgtm_tblhnd_share->auto_increment_lclval =
share->lgtm_tblhnd_share->auto_increment_value;
share->lgtm_tblhnd_share->auto_increment_init = TRUE;
stats.auto_increment_value =
share->lgtm_tblhnd_share->auto_increment_value;
} else {
stats.auto_increment_value = share->auto_increment_value;
stats.auto_increment_value =
share->lgtm_tblhnd_share->auto_increment_value;
}
} else {
#endif
stats.auto_increment_value = share->auto_increment_value;
stats.auto_increment_value =
share->lgtm_tblhnd_share->auto_increment_value;
#ifdef WITH_PARTITION_STORAGE_ENGINE
}
#endif
@ -8774,6 +8868,10 @@ int ha_spider::pre_records()
{
DBUG_RETURN(0);
}
if (!(share->additional_table_flags & HA_HAS_RECORDS))
{
DBUG_RETURN(0);
}
THD *thd = trx->thd;
if (
spider_param_sync_autocommit(thd) &&
@ -8801,6 +8899,10 @@ ha_rows ha_spider::records()
use_pre_records = FALSE;
DBUG_RETURN(0);
}
if (!(share->additional_table_flags & HA_HAS_RECORDS))
{
DBUG_RETURN(handler::records());
}
if (!use_pre_records)
{
THD *thd = trx->thd;
@ -8851,7 +8953,6 @@ ulonglong ha_spider::table_flags() const
HA_NO_COPY_ON_ALTER |
HA_BINLOG_ROW_CAPABLE |
HA_BINLOG_STMT_CAPABLE |
HA_HAS_RECORDS |
HA_PARTIAL_COLUMN_READ |
#ifdef HA_CAN_BULK_ACCESS
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
@ -9011,25 +9112,28 @@ int ha_spider::update_auto_increment()
)
) {
lock_here = TRUE;
pthread_mutex_lock(&share->auto_increment_mutex);
next_insert_id = share->auto_increment_value;
pthread_mutex_lock(&share->lgtm_tblhnd_share->auto_increment_mutex);
next_insert_id = share->lgtm_tblhnd_share->auto_increment_value;
}
if ((error_num = handler::update_auto_increment()))
{
if (lock_here)
pthread_mutex_unlock(&share->auto_increment_mutex);
pthread_mutex_unlock(&share->lgtm_tblhnd_share->auto_increment_mutex);
DBUG_RETURN(check_error_mode(error_num));
}
if (lock_here)
{
if (insert_id_for_cur_row)
{
share->auto_increment_lclval = insert_id_for_cur_row + 1;
share->auto_increment_value = next_insert_id;
share->lgtm_tblhnd_share->auto_increment_lclval =
insert_id_for_cur_row + 1;
share->lgtm_tblhnd_share->auto_increment_value = next_insert_id;
DBUG_PRINT("info",("spider after auto_increment_lclval=%llu",
share->auto_increment_lclval));
share->lgtm_tblhnd_share->auto_increment_lclval));
DBUG_PRINT("info",("spider auto_increment_value=%llu",
share->lgtm_tblhnd_share->auto_increment_value));
}
pthread_mutex_unlock(&share->auto_increment_mutex);
pthread_mutex_unlock(&share->lgtm_tblhnd_share->auto_increment_mutex);
}
if (!store_last_insert_id)
{
@ -9085,15 +9189,16 @@ error_index_init:
DBUG_VOID_RETURN;
} else {
if (auto_increment_mode != 1)
pthread_mutex_lock(&share->auto_increment_mutex);
pthread_mutex_lock(&share->lgtm_tblhnd_share->auto_increment_mutex);
DBUG_PRINT("info",("spider before auto_increment_lclval=%llu",
share->auto_increment_lclval));
*first_value = share->auto_increment_lclval;
share->auto_increment_lclval += nb_desired_values * increment;
share->lgtm_tblhnd_share->auto_increment_lclval));
*first_value = share->lgtm_tblhnd_share->auto_increment_lclval;
share->lgtm_tblhnd_share->auto_increment_lclval +=
nb_desired_values * increment;
DBUG_PRINT("info",("spider after auto_increment_lclval=%llu",
share->auto_increment_lclval));
share->lgtm_tblhnd_share->auto_increment_lclval));
if (auto_increment_mode != 1)
pthread_mutex_unlock(&share->auto_increment_mutex);
pthread_mutex_unlock(&share->lgtm_tblhnd_share->auto_increment_mutex);
}
DBUG_VOID_RETURN;
}
@ -9105,12 +9210,12 @@ int ha_spider::reset_auto_increment(
DBUG_PRINT("info",("spider this=%p", this));
if (table->next_number_field)
{
pthread_mutex_lock(&share->auto_increment_mutex);
share->auto_increment_lclval = value;
share->auto_increment_init = TRUE;
pthread_mutex_lock(&share->lgtm_tblhnd_share->auto_increment_mutex);
share->lgtm_tblhnd_share->auto_increment_lclval = value;
share->lgtm_tblhnd_share->auto_increment_init = TRUE;
DBUG_PRINT("info",("spider init auto_increment_lclval=%llu",
share->auto_increment_lclval));
pthread_mutex_unlock(&share->auto_increment_mutex);
share->lgtm_tblhnd_share->auto_increment_lclval));
pthread_mutex_unlock(&share->lgtm_tblhnd_share->auto_increment_mutex);
}
DBUG_RETURN(0);
}
@ -9245,18 +9350,19 @@ int ha_spider::write_row(
force_auto_increment = FALSE;
table->file->insert_id_for_cur_row = 0;
} else {
if (!share->auto_increment_init)
if (!share->lgtm_tblhnd_share->auto_increment_init)
{
pthread_mutex_lock(&share->auto_increment_mutex);
if (!share->auto_increment_init)
pthread_mutex_lock(&share->lgtm_tblhnd_share->auto_increment_mutex);
if (!share->lgtm_tblhnd_share->auto_increment_init)
{
info(HA_STATUS_AUTO);
share->auto_increment_lclval = stats.auto_increment_value;
share->auto_increment_init = TRUE;
share->lgtm_tblhnd_share->auto_increment_lclval =
stats.auto_increment_value;
share->lgtm_tblhnd_share->auto_increment_init = TRUE;
DBUG_PRINT("info",("spider init auto_increment_lclval=%llu",
share->auto_increment_lclval));
share->lgtm_tblhnd_share->auto_increment_lclval));
}
pthread_mutex_unlock(&share->auto_increment_mutex);
pthread_mutex_unlock(&share->lgtm_tblhnd_share->auto_increment_mutex);
}
if ((error_num = update_auto_increment()))
DBUG_RETURN(error_num);
@ -9451,14 +9557,15 @@ int ha_spider::update_row(
new_data == table->record[0] &&
!table->s->next_number_keypart
) {
pthread_mutex_lock(&share->auto_increment_mutex);
if (!share->auto_increment_init)
pthread_mutex_lock(&share->lgtm_tblhnd_share->auto_increment_mutex);
if (!share->lgtm_tblhnd_share->auto_increment_init)
{
info(HA_STATUS_AUTO);
share->auto_increment_lclval = stats.auto_increment_value;
share->auto_increment_init = TRUE;
share->lgtm_tblhnd_share->auto_increment_lclval =
stats.auto_increment_value;
share->lgtm_tblhnd_share->auto_increment_init = TRUE;
DBUG_PRINT("info",("spider init auto_increment_lclval=%llu",
share->auto_increment_lclval));
share->lgtm_tblhnd_share->auto_increment_lclval));
}
ulonglong tmp_auto_increment;
if (((Field_num *) table->found_next_number_field)->unsigned_flag)
@ -9473,14 +9580,16 @@ int ha_spider::update_row(
else
tmp_auto_increment = 0;
}
if (tmp_auto_increment >= share->auto_increment_lclval)
if (tmp_auto_increment >= share->lgtm_tblhnd_share->auto_increment_lclval)
{
share->auto_increment_lclval = tmp_auto_increment + 1;
share->auto_increment_value = tmp_auto_increment + 1;
share->lgtm_tblhnd_share->auto_increment_lclval = tmp_auto_increment + 1;
share->lgtm_tblhnd_share->auto_increment_value = tmp_auto_increment + 1;
DBUG_PRINT("info",("spider after auto_increment_lclval=%llu",
share->auto_increment_lclval));
share->lgtm_tblhnd_share->auto_increment_lclval));
DBUG_PRINT("info",("spider auto_increment_value=%llu",
share->lgtm_tblhnd_share->auto_increment_value));
}
pthread_mutex_unlock(&share->auto_increment_mutex);
pthread_mutex_unlock(&share->lgtm_tblhnd_share->auto_increment_mutex);
}
DBUG_RETURN(0);
}
@ -10013,13 +10122,15 @@ int ha_spider::delete_all_rows()
if (sql_command == SQLCOM_TRUNCATE && table->found_next_number_field)
{
DBUG_PRINT("info",("spider reset auto increment"));
pthread_mutex_lock(&share->auto_increment_mutex);
share->auto_increment_lclval = 1;
share->auto_increment_init = FALSE;
share->auto_increment_value = 1;
pthread_mutex_lock(&share->lgtm_tblhnd_share->auto_increment_mutex);
share->lgtm_tblhnd_share->auto_increment_lclval = 1;
share->lgtm_tblhnd_share->auto_increment_init = FALSE;
share->lgtm_tblhnd_share->auto_increment_value = 1;
DBUG_PRINT("info",("spider init auto_increment_lclval=%llu",
share->auto_increment_lclval));
pthread_mutex_unlock(&share->auto_increment_mutex);
share->lgtm_tblhnd_share->auto_increment_lclval));
DBUG_PRINT("info",("spider auto_increment_value=%llu",
share->lgtm_tblhnd_share->auto_increment_value));
pthread_mutex_unlock(&share->lgtm_tblhnd_share->auto_increment_mutex);
}
DBUG_RETURN(0);
}
@ -10053,13 +10164,15 @@ int ha_spider::truncate()
if (sql_command == SQLCOM_TRUNCATE && table->found_next_number_field)
{
DBUG_PRINT("info",("spider reset auto increment"));
pthread_mutex_lock(&share->auto_increment_mutex);
share->auto_increment_lclval = 1;
share->auto_increment_init = FALSE;
share->auto_increment_value = 1;
pthread_mutex_lock(&share->lgtm_tblhnd_share->auto_increment_mutex);
share->lgtm_tblhnd_share->auto_increment_lclval = 1;
share->lgtm_tblhnd_share->auto_increment_init = FALSE;
share->lgtm_tblhnd_share->auto_increment_value = 1;
DBUG_PRINT("info",("spider init auto_increment_lclval=%llu",
share->auto_increment_lclval));
pthread_mutex_unlock(&share->auto_increment_mutex);
share->lgtm_tblhnd_share->auto_increment_lclval));
DBUG_PRINT("info",("spider auto_increment_value=%llu",
share->lgtm_tblhnd_share->auto_increment_value));
pthread_mutex_unlock(&share->lgtm_tblhnd_share->auto_increment_mutex);
}
DBUG_RETURN(0);
}
@ -10223,6 +10336,20 @@ int ha_spider::create(
memset(&tmp_share, 0, sizeof(SPIDER_SHARE));
tmp_share.table_name = (char*) name;
tmp_share.table_name_length = strlen(name);
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
tmp_share.table_name_hash_value = my_calc_hash(&trx->trx_alter_table_hash,
(uchar*) tmp_share.table_name, tmp_share.table_name_length);
tmp_share.lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share(
name, tmp_share.table_name_length, tmp_share.table_name_hash_value,
FALSE, TRUE, &error_num);
#else
tmp_share.lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share(
name, tmp_share.table_name_length, FALSE, TRUE, &error_num);
#endif
if (!tmp_share.lgtm_tblhnd_share)
{
goto error;
}
if (form->s->keys > 0 &&
!(tmp_share.key_hint = new spider_string[form->s->keys])
) {
@ -10269,8 +10396,6 @@ int ha_spider::create(
trx->query_id = thd->query_id;
}
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
tmp_share.table_name_hash_value = my_calc_hash(&trx->trx_alter_table_hash,
(uchar*) tmp_share.table_name, tmp_share.table_name_length);;
if (!(alter_table =
(SPIDER_ALTER_TABLE*) my_hash_search_using_hash_value(
&trx->trx_alter_table_hash, tmp_share.table_name_hash_value,
@ -10318,6 +10443,23 @@ int ha_spider::create(
}
}
if (
(
(info->used_fields & HA_CREATE_USED_AUTO) ||
sql_command == SQLCOM_ALTER_TABLE ||
sql_command == SQLCOM_CREATE_INDEX ||
sql_command == SQLCOM_RENAME_TABLE
) &&
info->auto_increment_value > 0
) {
pthread_mutex_lock(&tmp_share.lgtm_tblhnd_share->auto_increment_mutex);
tmp_share.lgtm_tblhnd_share->auto_increment_value =
info->auto_increment_value;
DBUG_PRINT("info",("spider auto_increment_value=%llu",
tmp_share.lgtm_tblhnd_share->auto_increment_value));
pthread_mutex_unlock(&tmp_share.lgtm_tblhnd_share->auto_increment_mutex);
}
spider_free_share_alloc(&tmp_share);
DBUG_RETURN(0);
@ -10325,6 +10467,8 @@ error:
if (table_tables)
spider_close_sys_table(current_thd, table_tables,
&open_tables_backup, need_lock);
if (tmp_share.lgtm_tblhnd_share)
spider_free_lgtm_tblhnd_share_alloc(tmp_share.lgtm_tblhnd_share, FALSE);
spider_free_share_alloc(&tmp_share);
error_alter_before_unlock:
error_get_trx:
@ -10334,6 +10478,7 @@ error_get_trx:
void ha_spider::update_create_info(
HA_CREATE_INFO* create_info
) {
THD *thd = ha_thd();
DBUG_ENTER("ha_spider::update_create_info");
DBUG_PRINT("info",("spider this=%p", this));
if (!create_info->connect_string.str)
@ -10344,6 +10489,19 @@ void ha_spider::update_create_info(
DBUG_PRINT("info",
("spider create_info->connect_string=%s",
create_info->connect_string.str));
if (
!(create_info->used_fields & HA_CREATE_USED_AUTO)
) {
info(HA_STATUS_AUTO);
create_info->auto_increment_value = stats.auto_increment_value;
}
if (
thd->is_error() &&
thd_sql_command(thd) == SQLCOM_SHOW_CREATE
) {
DBUG_PRINT("info", ("spider clear_error"));
thd->clear_error();
}
DBUG_VOID_RETURN;
}
@ -10351,12 +10509,20 @@ int ha_spider::rename_table(
const char *from,
const char *to
) {
int error_num, roop_count, old_link_count, from_len = strlen(from);
int error_num, roop_count, old_link_count, from_len = strlen(from),
to_len = strlen(to), tmp_error_num;
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
my_hash_value_type from_hash_value = my_calc_hash(&spider_open_tables,
(uchar*) from, from_len);
my_hash_value_type to_hash_value = my_calc_hash(&spider_open_tables,
(uchar*) to, to_len);
#endif
THD *thd = ha_thd();
uint sql_command = thd_sql_command(thd);
SPIDER_TRX *trx;
TABLE *table_tables = NULL;
SPIDER_ALTER_TABLE *alter_table_from, *alter_table_to;
SPIDER_LGTM_TBLHND_SHARE *from_lgtm_tblhnd_share, *to_lgtm_tblhnd_share;
#if MYSQL_VERSION_ID < 50500
Open_tables_state open_tables_backup;
#else
@ -10414,7 +10580,6 @@ int ha_spider::rename_table(
spider_release_ping_table_mon_list(from, from_len, roop_count);
} else if (sql_command == SQLCOM_ALTER_TABLE)
{
int to_len = strlen(to);
DBUG_PRINT("info",("spider alter_table_from=%p", alter_table_from));
if ((alter_table_to =
(SPIDER_ALTER_TABLE*) my_hash_search(&trx->trx_alter_table_hash,
@ -10496,6 +10661,37 @@ int ha_spider::rename_table(
*/
}
pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex);
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
from_lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share(
from, from_len, from_hash_value, TRUE, FALSE, &error_num);
#else
from_lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share(
from, from_len, TRUE, FALSE, &error_num);
#endif
if (from_lgtm_tblhnd_share)
{
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
to_lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share(
to, to_len, to_hash_value, TRUE, TRUE, &error_num);
#else
to_lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share(
to, to_len, TRUE, TRUE, &error_num);
#endif
if (!to_lgtm_tblhnd_share)
{
pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex);
goto error;
}
to_lgtm_tblhnd_share->auto_increment_init =
from_lgtm_tblhnd_share->auto_increment_init;
to_lgtm_tblhnd_share->auto_increment_lclval =
from_lgtm_tblhnd_share->auto_increment_lclval;
to_lgtm_tblhnd_share->auto_increment_value =
from_lgtm_tblhnd_share->auto_increment_value;
spider_free_lgtm_tblhnd_share_alloc(from_lgtm_tblhnd_share, TRUE);
}
pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex);
spider_delete_init_error_table(from);
DBUG_RETURN(0);
@ -10503,6 +10699,17 @@ error:
if (table_tables)
spider_close_sys_table(current_thd, table_tables,
&open_tables_backup, need_lock);
pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex);
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
to_lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share(
to, to_len, to_hash_value, TRUE, FALSE, &tmp_error_num);
#else
to_lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share(
to, to_len, TRUE, FALSE, &tmp_error_num);
#endif
if (to_lgtm_tblhnd_share)
spider_free_lgtm_tblhnd_share_alloc(to_lgtm_tblhnd_share, TRUE);
pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex);
DBUG_RETURN(error_num);
}
@ -10549,12 +10756,24 @@ int ha_spider::delete_table(
sql_command == SQLCOM_ALTER_TABLE ||
sql_command == SQLCOM_CREATE_TABLE)
{
SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share;
int roop_count, old_link_count = 0, name_len = strlen(name);
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
my_hash_value_type hash_value = my_calc_hash(&spider_open_tables,
(uchar*) name, name_len);
#endif
if (
sql_command == SQLCOM_ALTER_TABLE &&
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
(alter_table =
(SPIDER_ALTER_TABLE*) my_hash_search_using_hash_value(
&trx->trx_alter_table_hash,
hash_value, (uchar*) name, name_len)) &&
#else
(alter_table =
(SPIDER_ALTER_TABLE*) my_hash_search(&trx->trx_alter_table_hash,
(uchar*) name, name_len)) &&
#endif
alter_table->now_create
)
DBUG_RETURN(0);
@ -10594,6 +10813,18 @@ int ha_spider::delete_table(
/* release table mon list */
for (roop_count = 0; roop_count < old_link_count; roop_count++)
spider_release_ping_table_mon_list(name, name_len, roop_count);
pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex);
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share(
name, name_len, hash_value, TRUE, FALSE, &error_num);
#else
lgtm_tblhnd_share = spider_get_lgtm_tblhnd_share(
name, name_len, TRUE, FALSE, &error_num);
#endif
if (lgtm_tblhnd_share)
spider_free_lgtm_tblhnd_share_alloc(lgtm_tblhnd_share, TRUE);
pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex);
}
spider_delete_init_error_table(name);
@ -10973,7 +11204,9 @@ int ha_spider::info_push(
case INFO_KIND_FORCE_LIMIT_BEGIN:
DBUG_PRINT("info",("spider INFO_KIND_FORCE_LIMIT_BEGIN"));
info_limit = *((longlong *) info);
/*
trx->direct_aggregate_count++;
*/
break;
case INFO_KIND_FORCE_LIMIT_END:
DBUG_PRINT("info",("spider INFO_KIND_FORCE_LIMIT_END"));
@ -13357,6 +13590,7 @@ int ha_spider::append_sum_select_sql_part(
DBUG_RETURN(error_num);
}
}
trx->direct_aggregate_count++;
DBUG_RETURN(0);
}
#endif

View file

@ -167,6 +167,7 @@ public:
bool insert_delayed;
bool use_pre_call;
bool use_pre_records;
bool pre_bitmap_checked;
enum thr_lock_type lock_type;
int lock_mode;
uint sql_command;

View file

@ -48,31 +48,31 @@ COUNT(*)
5
SHOW STATUS LIKE 'Spider_direct_aggregate';
Variable_name Value
Spider_direct_aggregate 1
Spider_direct_aggregate 0
SELECT MAX(a) FROM ta_l;
MAX(a)
5
SHOW STATUS LIKE 'Spider_direct_aggregate';
Variable_name Value
Spider_direct_aggregate 1
Spider_direct_aggregate 0
SELECT MIN(a) FROM ta_l;
MIN(a)
1
SHOW STATUS LIKE 'Spider_direct_aggregate';
Variable_name Value
Spider_direct_aggregate 1
Spider_direct_aggregate 0
SELECT MAX(a) FROM ta_l WHERE a < 5;
MAX(a)
4
SHOW STATUS LIKE 'Spider_direct_aggregate';
Variable_name Value
Spider_direct_aggregate 1
Spider_direct_aggregate 0
SELECT MIN(a) FROM ta_l WHERE a > 1;
MIN(a)
2
SHOW STATUS LIKE 'Spider_direct_aggregate';
Variable_name Value
Spider_direct_aggregate 1
Spider_direct_aggregate 0
deinit
DROP DATABASE IF EXISTS auto_test_local;

View file

@ -39,31 +39,31 @@ COUNT(*)
5
SHOW STATUS LIKE 'Spider_direct_aggregate';
Variable_name Value
Spider_direct_aggregate 2
Spider_direct_aggregate 0
SELECT MAX(a) FROM ta_l2;
MAX(a)
5
SHOW STATUS LIKE 'Spider_direct_aggregate';
Variable_name Value
Spider_direct_aggregate 2
Spider_direct_aggregate 0
SELECT MIN(a) FROM ta_l2;
MIN(a)
1
SHOW STATUS LIKE 'Spider_direct_aggregate';
Variable_name Value
Spider_direct_aggregate 2
Spider_direct_aggregate 0
SELECT MAX(a) FROM ta_l2 WHERE a < 5;
MAX(a)
4
SHOW STATUS LIKE 'Spider_direct_aggregate';
Variable_name Value
Spider_direct_aggregate 2
Spider_direct_aggregate 0
SELECT MIN(a) FROM ta_l2 WHERE a > 1;
MIN(a)
2
SHOW STATUS LIKE 'Spider_direct_aggregate';
Variable_name Value
Spider_direct_aggregate 2
Spider_direct_aggregate 0
deinit
DROP DATABASE IF EXISTS auto_test_local;

View file

@ -414,7 +414,6 @@ id
Warnings:
Error 12702 Remote table 'auto_test_remote.ter1_1' is not found
Error 1146 Table 'auto_test_remote.ter1_1' doesn't exist
Error 1146 Table 'auto_test_remote.ter1_1' doesn't exist
INSERT INTO t1 (id) VALUES (1);
Warnings:
Error 1146 Table 'auto_test_remote.ter1_1' doesn't exist

View file

@ -48,31 +48,31 @@ COUNT(*)
5
SHOW STATUS LIKE 'Spider_direct_aggregate';
Variable_name Value
Spider_direct_aggregate 1
Spider_direct_aggregate 0
SELECT MAX(a) FROM ta_l;
MAX(a)
5
SHOW STATUS LIKE 'Spider_direct_aggregate';
Variable_name Value
Spider_direct_aggregate 1
Spider_direct_aggregate 0
SELECT MIN(a) FROM ta_l;
MIN(a)
1
SHOW STATUS LIKE 'Spider_direct_aggregate';
Variable_name Value
Spider_direct_aggregate 1
Spider_direct_aggregate 0
SELECT MAX(a) FROM ta_l WHERE a < 5;
MAX(a)
4
SHOW STATUS LIKE 'Spider_direct_aggregate';
Variable_name Value
Spider_direct_aggregate 1
Spider_direct_aggregate 0
SELECT MIN(a) FROM ta_l WHERE a > 1;
MIN(a)
2
SHOW STATUS LIKE 'Spider_direct_aggregate';
Variable_name Value
Spider_direct_aggregate 1
Spider_direct_aggregate 0
deinit
DROP DATABASE IF EXISTS auto_test_local;

View file

@ -39,31 +39,31 @@ COUNT(*)
5
SHOW STATUS LIKE 'Spider_direct_aggregate';
Variable_name Value
Spider_direct_aggregate 2
Spider_direct_aggregate 0
SELECT MAX(a) FROM ta_l2;
MAX(a)
5
SHOW STATUS LIKE 'Spider_direct_aggregate';
Variable_name Value
Spider_direct_aggregate 2
Spider_direct_aggregate 0
SELECT MIN(a) FROM ta_l2;
MIN(a)
1
SHOW STATUS LIKE 'Spider_direct_aggregate';
Variable_name Value
Spider_direct_aggregate 2
Spider_direct_aggregate 0
SELECT MAX(a) FROM ta_l2 WHERE a < 5;
MAX(a)
4
SHOW STATUS LIKE 'Spider_direct_aggregate';
Variable_name Value
Spider_direct_aggregate 2
Spider_direct_aggregate 0
SELECT MIN(a) FROM ta_l2 WHERE a > 1;
MIN(a)
2
SHOW STATUS LIKE 'Spider_direct_aggregate';
Variable_name Value
Spider_direct_aggregate 2
Spider_direct_aggregate 0
deinit
DROP DATABASE IF EXISTS auto_test_local;

View file

@ -245,7 +245,7 @@ a b c
direct order limit
SHOW STATUS LIKE 'Spider_direct_order_limit';
Variable_name Value
Spider_direct_order_limit 0
Spider_direct_order_limit 2
SELECT a, b, c FROM ta_l_int ORDER BY a LIMIT 3;
a b c
1 2 4
@ -253,7 +253,7 @@ a b c
3 4 5
SHOW STATUS LIKE 'Spider_direct_order_limit';
Variable_name Value
Spider_direct_order_limit 0
Spider_direct_order_limit 3
2.26
lock tables
@ -297,79 +297,83 @@ PRIMARY KEY (id)
INSERT INTO t1 () VALUES ();
SELECT LAST_INSERT_ID();
LAST_INSERT_ID()
777
2
SELECT MAX(id) FROM t1;
MAX(id)
777
2
INSERT INTO t1 () VALUES ();
SELECT LAST_INSERT_ID();
LAST_INSERT_ID()
1554
6
SELECT MAX(id) FROM t1;
MAX(id)
1554
6
INSERT INTO t1 (id) VALUES (null);
SELECT LAST_INSERT_ID();
LAST_INSERT_ID()
2331
10
SELECT MAX(id) FROM t1;
MAX(id)
2331
10
INSERT INTO t1 (id) VALUES (null);
SELECT LAST_INSERT_ID();
LAST_INSERT_ID()
3108
14
SELECT MAX(id) FROM t1;
MAX(id)
3108
14
INSERT INTO t1 () VALUES (),(),(),();
Warnings:
Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value
Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value
Note 12520 Binlog's auto-inc value is probably different from linked table's auto-inc value
SELECT LAST_INSERT_ID();
LAST_INSERT_ID()
3885
18
SELECT id FROM t1 ORDER BY id;
id
777
1554
2331
3108
3885
4662
5439
6216
2
6
10
14
18
22
26
30
SET INSERT_ID=5000;
INSERT INTO t1 () VALUES ();
SELECT LAST_INSERT_ID();
LAST_INSERT_ID()
5000
34
SELECT MAX(id) FROM t1;
MAX(id)
6216
34
INSERT INTO t1 (id) VALUES (10000);
SELECT LAST_INSERT_ID();
LAST_INSERT_ID()
5000
38
SELECT MAX(id) FROM t1;
MAX(id)
10000
38
INSERT INTO t1 (id) VALUES (1000);
SELECT LAST_INSERT_ID();
LAST_INSERT_ID()
5000
42
SELECT MAX(id) FROM t1;
MAX(id)
10000
42
SELECT id FROM t1 ORDER BY id;
id
2
6
10
14
18
34
777
1000
1554
2331
3108
3885
4662
5000
5439
6216
10000
read only
@ -380,22 +384,22 @@ PRIMARY KEY (id)
) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_READONLY1_1
SELECT id FROM t1 ORDER BY id;
id
777
1000
1554
2331
3108
3885
4662
5000
5439
6216
10000
2
6
10
14
18
22
26
30
34
38
42
INSERT INTO t1 (id) VALUES (1);
ERROR HY000: Table 'auto_test_local.t1' is read only
UPDATE t1 SET id = 4 WHERE id = 777;
UPDATE t1 SET id = 4 WHERE id = 2;
ERROR HY000: Table 'auto_test_local.t1' is read only
DELETE FROM t1 WHERE id = 777;
DELETE FROM t1 WHERE id = 2;
ERROR HY000: Table 'auto_test_local.t1' is read only
DELETE FROM t1;
ERROR HY000: Table 'auto_test_local.t1' is read only
@ -414,13 +418,13 @@ id
Warnings:
Error 12702 Remote table 'auto_test_remote.ter1_1' is not found
Error 1146 Table 'auto_test_remote.ter1_1' doesn't exist
Error 1146 Table 'auto_test_remote.ter1_1' doesn't exist
INSERT INTO t1 (id) VALUES (1);
Warnings:
Error 1146 Table 'auto_test_remote.ter1_1' doesn't exist
DELETE FROM t1;
Warnings:
Error 12702 Remote table 'auto_test_remote.ter1_1' is not found
Error 12702 Remote table 'auto_test_remote.ter1_1' is not found
Error 1146 Table 'auto_test_remote.ter1_1' doesn't exist
TRUNCATE t1;
Warnings:

View file

@ -62,6 +62,7 @@ extern PSI_cond_key spd_key_cond_bg_sts_sync;
extern PSI_cond_key spd_key_cond_bg_crd;
extern PSI_cond_key spd_key_cond_bg_crd_sync;
extern PSI_cond_key spd_key_cond_bg_mon;
extern PSI_cond_key spd_key_cond_bg_mon_sleep;
extern PSI_thread_key spd_key_thd_bg;
extern PSI_thread_key spd_key_thd_bg_sts;
extern PSI_thread_key spd_key_thd_bg_crd;
@ -3425,6 +3426,8 @@ int spider_create_mon_threads(
&share->bg_mon_mutexes, sizeof(pthread_mutex_t) *
share->all_link_count,
&share->bg_mon_conds, sizeof(pthread_cond_t) * share->all_link_count,
&share->bg_mon_sleep_conds,
sizeof(pthread_cond_t) * share->all_link_count,
NullS))
) {
error_num = HA_ERR_OUT_OF_MEM;
@ -3463,6 +3466,22 @@ int spider_create_mon_threads(
goto error_cond_init;
}
}
for (roop_count = 0; roop_count < (int) share->all_link_count;
roop_count++)
{
if (
share->monitoring_bg_kind[roop_count] &&
#if MYSQL_VERSION_ID < 50500
pthread_cond_init(&share->bg_mon_sleep_conds[roop_count], NULL)
#else
mysql_cond_init(spd_key_cond_bg_mon_sleep,
&share->bg_mon_sleep_conds[roop_count], NULL)
#endif
) {
error_num = HA_ERR_OUT_OF_MEM;
goto error_sleep_cond_init;
}
}
link_pack.share = share;
for (roop_count = 0; roop_count < (int) share->all_link_count;
roop_count++)
@ -3514,6 +3533,13 @@ error_thread_create:
}
share->bg_mon_kill = FALSE;
roop_count = share->all_link_count;
error_sleep_cond_init:
for (roop_count--; roop_count >= 0; roop_count--)
{
if (share->monitoring_bg_kind[roop_count])
pthread_cond_destroy(&share->bg_mon_sleep_conds[roop_count]);
}
roop_count = share->all_link_count;
error_cond_init:
for (roop_count--; roop_count >= 0; roop_count--)
{
@ -3540,6 +3566,16 @@ void spider_free_mon_threads(
DBUG_ENTER("spider_free_mon_threads");
if (share->bg_mon_init)
{
for (roop_count = 0; roop_count < (int) share->all_link_count;
roop_count++)
{
if (
share->monitoring_bg_kind[roop_count] &&
share->bg_mon_thds[roop_count]
) {
share->bg_mon_thds[roop_count]->killed = SPIDER_THD_KILL_CONNECTION;
}
}
for (roop_count = 0; roop_count < (int) share->all_link_count;
roop_count++)
{
@ -3552,11 +3588,13 @@ void spider_free_mon_threads(
{
if (share->monitoring_bg_kind[roop_count])
{
pthread_cond_signal(&share->bg_mon_sleep_conds[roop_count]);
pthread_cond_wait(&share->bg_mon_conds[roop_count],
&share->bg_mon_mutexes[roop_count]);
pthread_mutex_unlock(&share->bg_mon_mutexes[roop_count]);
pthread_join(share->bg_mon_threads[roop_count], NULL);
pthread_cond_destroy(&share->bg_mon_conds[roop_count]);
pthread_cond_destroy(&share->bg_mon_sleep_conds[roop_count]);
pthread_mutex_destroy(&share->bg_mon_mutexes[roop_count]);
}
}
@ -3614,7 +3652,9 @@ void *spider_bg_mon_action(
}
share->bg_mon_thds[link_idx] = thd;
pthread_cond_signal(&share->bg_mon_conds[link_idx]);
/*
pthread_mutex_unlock(&share->bg_mon_mutexes[link_idx]);
*/
/* init end */
while (TRUE)
@ -3622,12 +3662,23 @@ void *spider_bg_mon_action(
DBUG_PRINT("info",("spider bg mon sleep %lld",
share->monitoring_bg_interval[link_idx]));
if (!share->bg_mon_kill)
{
struct timespec abstime;
set_timespec_nsec(abstime,
share->monitoring_bg_interval[link_idx] * 1000);
pthread_cond_timedwait(&share->bg_mon_sleep_conds[link_idx],
&share->bg_mon_mutexes[link_idx], &abstime);
/*
my_sleep((ulong) share->monitoring_bg_interval[link_idx]);
*/
}
DBUG_PRINT("info",("spider bg mon roop start"));
if (share->bg_mon_kill)
{
DBUG_PRINT("info",("spider bg mon kill start"));
/*
pthread_mutex_lock(&share->bg_mon_mutexes[link_idx]);
*/
pthread_cond_signal(&share->bg_mon_conds[link_idx]);
pthread_mutex_unlock(&share->bg_mon_mutexes[link_idx]);
spider_free_trx(trx, TRUE);

View file

@ -2490,6 +2490,7 @@ int spider_db_fetch_for_item_sum_func(
) {
int error_num;
SPIDER_SHARE *share = spider->share;
THD *thd = spider->trx->thd;
DBUG_ENTER("spider_db_fetch_for_item_sum_func");
DBUG_PRINT("info",("spider Sumfunctype = %d", item_sum->sum_func()));
switch (item_sum->sum_func())
@ -2556,10 +2557,12 @@ int spider_db_fetch_for_item_sum_func(
}
if (!spider->direct_aggregate_item_current->item)
{
Item *free_list = thd->free_list;
spider->direct_aggregate_item_current->item =
new Item_string(share->access_charset);
if (!spider->direct_aggregate_item_current->item)
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
thd->free_list = free_list;
}
Item_sum_hybrid *item_hybrid = (Item_sum_hybrid *) item_sum;
@ -3678,6 +3681,7 @@ int spider_db_store_result(
pthread_mutex_unlock(&conn->mta_conn_mutex);
}
current->record_num = current->result->num_rows();
current->dbton_id = current->result->dbton_id;
result_list->record_num += current->record_num;
DBUG_PRINT("info",("spider current->record_num=%lld",
current->record_num));
@ -3754,6 +3758,7 @@ int spider_db_store_result(
pthread_mutex_unlock(&conn->mta_conn_mutex);
}
}
current->dbton_id = current->result->dbton_id;
SPIDER_DB_ROW *row;
if (!(row = current->result->fetch_row()))
{
@ -5861,8 +5866,10 @@ int spider_db_update_auto_increment(
}
#endif
DBUG_PRINT("info",("spider last_insert_id=%llu", last_insert_id));
share->auto_increment_value =
share->lgtm_tblhnd_share->auto_increment_value =
last_insert_id + affected_rows;
DBUG_PRINT("info",("spider auto_increment_value=%llu",
share->lgtm_tblhnd_share->auto_increment_value));
/*
thd->record_first_successful_insert_id_in_cur_stmt(last_insert_id);
*/
@ -8047,11 +8054,10 @@ int spider_db_open_item_string(
tmp_str.mem_calc();
str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
if (
str->get_str()->append_for_single_quote(tmp_str2) ||
str->append_for_single_quote(tmp_str2) ||
str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN)
)
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
str->mem_calc();
str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
}
DBUG_RETURN(0);
@ -9033,11 +9039,13 @@ int spider_db_udf_ping_table(
uint tmp_conn_link_idx = 0;
ha_spider spider;
uchar db_request_phase = 0;
ulonglong db_request_id = 0;
spider.share = share;
spider.trx = trx;
spider.need_mons = &need_mon;
spider.conn_link_idx = &tmp_conn_link_idx;
spider.db_request_phase = &db_request_phase;
spider.db_request_id = &db_request_id;
pthread_mutex_lock(&conn->mta_conn_mutex);
SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
conn->need_mon = &need_mon;
@ -9192,8 +9200,7 @@ int spider_db_udf_ping_table_append_mon_next(
str->q_append(SPIDER_SQL_SELECT_STR, SPIDER_SQL_SELECT_LEN);
str->q_append(SPIDER_SQL_PING_TABLE_STR, SPIDER_SQL_PING_TABLE_LEN);
str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
str->get_str()->append_for_single_quote(child_table_name_str.get_str());
str->mem_calc();
str->append_for_single_quote(child_table_name_str.get_str());
str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN);
str->qs_append(link_id);
@ -9203,8 +9210,7 @@ int spider_db_udf_ping_table_append_mon_next(
str->q_append(limit_str, limit_str_length);
str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN);
str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
str->get_str()->append_for_single_quote(where_clause_str.get_str());
str->mem_calc();
str->append_for_single_quote(where_clause_str.get_str());
str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN);
str->q_append(sid_str, sid_str_length);
@ -9255,9 +9261,11 @@ int spider_db_udf_ping_table_append_select(
SPIDER_SQL_LIMIT_LEN + limit_str_length
))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
if (use_where)
str->get_str()->append_for_single_quote(where_str->get_str());
str->mem_calc();
if (
use_where &&
str->append_for_single_quote(where_str->get_str())
)
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
str->q_append(SPIDER_SQL_LIMIT_STR, SPIDER_SQL_LIMIT_LEN);
str->q_append(limit_str, limit_str_length);
DBUG_RETURN(0);

View file

@ -820,6 +820,16 @@ int spider_db_handlersocket_result::fetch_index_for_discover_table_structure(
DBUG_PRINT("info",("spider this=%p", this));
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
}
int spider_db_handlersocket_result::fetch_table_for_discover_table_structure(
spider_string *str,
SPIDER_SHARE *spider_share,
CHARSET_INFO *access_charset
) {
DBUG_ENTER("spider_db_handlersocket_result::fetch_table_for_discover_table_structure");
DBUG_PRINT("info",("spider this=%p", this));
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
}
#endif
spider_db_handlersocket::spider_db_handlersocket(
@ -963,8 +973,11 @@ int spider_db_handlersocket::connect(
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
while (hs_conn->get_error_code())
{
if (!connect_retry_count)
{
THD *thd = current_thd;
if (
!connect_retry_count ||
(thd && thd->killed)
) {
my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0),
conn->tgt_host);
DBUG_RETURN(ER_CONNECT_TO_FOREIGN_DATA_SOURCE);
@ -3481,8 +3494,8 @@ int spider_db_handlersocket_util::append_escaped_util(
) {
DBUG_ENTER("spider_db_handlersocket_util::append_escaped_util");
DBUG_PRINT("info",("spider this=%p", this));
append_escaped(to->get_str(), from);
to->mem_calc();
if (to->append_for_single_quote(from))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
DBUG_RETURN(0);
}
@ -4088,7 +4101,9 @@ int spider_handlersocket_handler::append_minimum_select_without_quote(
{
if (minimum_select_bit_is_set((*field)->field_index))
{
/*
spider_set_bit(minimum_select_bitmap, (*field)->field_index);
*/
field_length =
handlersocket_share->column_name_str[(*field)->field_index].length();
if (str->reserve(field_length + SPIDER_SQL_COMMA_LEN))
@ -5283,6 +5298,7 @@ int spider_handlersocket_handler::show_table_status(
) {
spider_db_handlersocket_result res;
SPIDER_SHARE *share = spider->share;
ulonglong auto_increment_value = 0;
DBUG_ENTER("spider_handlersocket_show_table_status");
res.fetch_table_status(
sts_mode,
@ -5291,11 +5307,17 @@ int spider_handlersocket_handler::show_table_status(
share->data_file_length,
share->max_data_file_length,
share->index_file_length,
share->auto_increment_value,
auto_increment_value,
share->create_time,
share->update_time,
share->check_time
);
if (auto_increment_value > share->lgtm_tblhnd_share->auto_increment_value)
{
share->lgtm_tblhnd_share->auto_increment_value = auto_increment_value;
DBUG_PRINT("info",("spider auto_increment_value=%llu",
share->lgtm_tblhnd_share->auto_increment_value));
}
DBUG_RETURN(0);
}

View file

@ -220,6 +220,11 @@ public:
spider_string *str,
CHARSET_INFO *access_charset
);
int fetch_table_for_discover_table_structure(
spider_string *str,
SPIDER_SHARE *spider_share,
CHARSET_INFO *access_charset
);
#endif
};

View file

@ -159,6 +159,8 @@ typedef st_spider_result SPIDER_RESULT;
#define SPIDER_SQL_CREATE_TABLE_LEN (sizeof(SPIDER_SQL_CREATE_TABLE_STR) - 1)
#define SPIDER_SQL_DEFAULT_CHARSET_STR " default charset "
#define SPIDER_SQL_DEFAULT_CHARSET_LEN (sizeof(SPIDER_SQL_DEFAULT_CHARSET_STR) - 1)
#define SPIDER_SQL_CHARACTER_SET_STR " character set "
#define SPIDER_SQL_CHARACTER_SET_LEN (sizeof(SPIDER_SQL_CHARACTER_SET_STR) - 1)
#define SPIDER_SQL_COLLATE_STR " collate "
#define SPIDER_SQL_COLLATE_LEN (sizeof(SPIDER_SQL_COLLATE_STR) - 1)
#define SPIDER_SQL_COMMENT_STR " comment "
@ -496,6 +498,12 @@ public:
const char *st,
uint len
);
bool append_for_single_quote(
const String *s
);
bool append_for_single_quote(
const char *st
);
#endif
void print(
String *print
@ -778,6 +786,11 @@ public:
spider_string *str,
CHARSET_INFO *access_charset
) = 0;
virtual int fetch_table_for_discover_table_structure(
spider_string *str,
SPIDER_SHARE *spider_share,
CHARSET_INFO *access_charset
) = 0;
#endif
};
@ -1538,6 +1551,7 @@ typedef struct st_spider_condition
typedef struct st_spider_result
{
uint dbton_id;
SPIDER_DB_RESULT *result;
#ifndef WITHOUT_SPIDER_BG_SEARCH
volatile

View file

@ -115,6 +115,19 @@ static const char *name_quote_str = SPIDER_SQL_NAME_QUOTE_STR;
#ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE
#define SPIDER_SQL_SHOW_COLUMNS_STR "show columns from "
#define SPIDER_SQL_SHOW_COLUMNS_LEN sizeof(SPIDER_SQL_SHOW_COLUMNS_STR) - 1
#define SPIDER_SQL_SELECT_COLUMNS_STR "select `column_name`,`column_default`,`is_nullable`,`character_set_name`,`collation_name`,`column_type`,`extra` from `information_schema`.`columns` where `table_schema` = "
#define SPIDER_SQL_SELECT_COLUMNS_LEN sizeof(SPIDER_SQL_SELECT_COLUMNS_STR) - 1
#define SPIDER_SQL_AUTO_INCREMENT_STR " auto_increment"
#define SPIDER_SQL_AUTO_INCREMENT_LEN sizeof(SPIDER_SQL_AUTO_INCREMENT_STR) - 1
#define SPIDER_SQL_ORDINAL_POSITION_STR "ordinal_position"
#define SPIDER_SQL_ORDINAL_POSITION_LEN sizeof(SPIDER_SQL_ORDINAL_POSITION_STR) - 1
#define SPIDER_SQL_FULLTEXT_STR "fulltext"
#define SPIDER_SQL_FULLTEXT_LEN sizeof(SPIDER_SQL_FULLTEXT_STR) - 1
#define SPIDER_SQL_SPATIAL_STR "spatial"
#define SPIDER_SQL_SPATIAL_LEN sizeof(SPIDER_SQL_SPATIAL_STR) - 1
#define SPIDER_SQL_USING_HASH_STR " using hash"
#define SPIDER_SQL_USING_HASH_LEN sizeof(SPIDER_SQL_USING_HASH_STR) - 1
#endif
#define SPIDER_SQL_LIKE_STR " like "
@ -1051,9 +1064,9 @@ int spider_db_mysql_result::fetch_columns_for_discover_table_structure(
DBUG_PRINT("info",("spider fetch row is null"));
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
if (num_fields() != 6)
if (num_fields() != 7)
{
DBUG_PRINT("info",("spider num_fields != 6"));
DBUG_PRINT("info",("spider num_fields != 7"));
my_printf_error(ER_SPIDER_UNKNOWN_NUM, ER_SPIDER_UNKNOWN_STR, MYF(0));
DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM);
}
@ -1073,10 +1086,28 @@ int spider_db_mysql_result::fetch_columns_for_discover_table_structure(
}
str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN);
str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN);
if (str->append(mysql_row[1], strlen(mysql_row[1]), access_charset))
if (str->append(mysql_row[5], strlen(mysql_row[5]), access_charset))
{
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
if (mysql_row[3])
{
if (str->reserve(SPIDER_SQL_CHARACTER_SET_LEN))
{
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
str->q_append(SPIDER_SQL_CHARACTER_SET_STR, SPIDER_SQL_CHARACTER_SET_LEN);
str->q_append(mysql_row[3], strlen(mysql_row[3]));
}
if (mysql_row[4])
{
if (str->reserve(SPIDER_SQL_COLLATE_LEN))
{
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
str->q_append(SPIDER_SQL_COLLATE_STR, SPIDER_SQL_COLLATE_LEN);
str->q_append(mysql_row[4], strlen(mysql_row[4]));
}
if (!strcmp(mysql_row[2], "NO"))
{
if (str->reserve(SPIDER_SQL_NOT_NULL_LEN))
@ -1084,7 +1115,7 @@ int spider_db_mysql_result::fetch_columns_for_discover_table_structure(
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
str->q_append(SPIDER_SQL_NOT_NULL_STR, SPIDER_SQL_NOT_NULL_LEN);
if (mysql_row[4])
if (mysql_row[1])
{
if (str->reserve(SPIDER_SQL_DEFAULT_LEN))
{
@ -1094,7 +1125,7 @@ int spider_db_mysql_result::fetch_columns_for_discover_table_structure(
if (str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
if (str->append(mysql_row[4], strlen(mysql_row[4]), access_charset))
if (str->append(mysql_row[1], strlen(mysql_row[1]), access_charset))
{
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
@ -1108,12 +1139,12 @@ int spider_db_mysql_result::fetch_columns_for_discover_table_structure(
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
str->q_append(SPIDER_SQL_DEFAULT_STR, SPIDER_SQL_DEFAULT_LEN);
if (mysql_row[4])
if (mysql_row[1])
{
if (str->reserve(SPIDER_SQL_VALUE_QUOTE_LEN))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
str->q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
if (str->append(mysql_row[4], strlen(mysql_row[4]), access_charset))
if (str->append(mysql_row[1], strlen(mysql_row[1]), access_charset))
{
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
@ -1128,6 +1159,12 @@ int spider_db_mysql_result::fetch_columns_for_discover_table_structure(
str->q_append(SPIDER_SQL_NULL_STR, SPIDER_SQL_NULL_LEN);
}
}
if (mysql_row[6] && !strcmp(mysql_row[6], "auto_increment"))
{
if (str->reserve(SPIDER_SQL_AUTO_INCREMENT_LEN))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
str->q_append(SPIDER_SQL_AUTO_INCREMENT_STR, SPIDER_SQL_AUTO_INCREMENT_LEN);
}
if (str->reserve(SPIDER_SQL_COMMA_LEN))
{
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
@ -1147,7 +1184,11 @@ int spider_db_mysql_result::fetch_index_for_discover_table_structure(
if (!(mysql_row = mysql_fetch_row(db_result)))
{
DBUG_PRINT("info",("spider fetch row is null"));
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
if (mysql_errno(db_result->handle))
{
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
DBUG_RETURN(0);
}
if (num_fields() != 13)
{
@ -1156,18 +1197,24 @@ int spider_db_mysql_result::fetch_index_for_discover_table_structure(
DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM);
}
bool first = TRUE;
bool without_size = FALSE;
bool using_hash = FALSE;
do {
if (!strcmp(mysql_row[3], "1"))
{
without_size = FALSE;
if (first)
{
first = FALSE;
} else {
if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_COMMA_LEN))
if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_COMMA_LEN +
(using_hash ? SPIDER_SQL_USING_HASH_LEN : 0)))
{
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN);
if (using_hash)
str->q_append(SPIDER_SQL_USING_HASH_STR, SPIDER_SQL_USING_HASH_LEN);
str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN);
}
/* new index */
@ -1189,6 +1236,25 @@ int spider_db_mysql_result::fetch_index_for_discover_table_structure(
}
str->q_append(SPIDER_DB_UNIQUE_NAME_STR, SPIDER_DB_UNIQUE_NAME_LEN);
str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN);
} else if (mysql_row[10] && !strcmp(mysql_row[10], "FULLTEXT"))
{
/* fulltext key */
if (str->reserve(SPIDER_SQL_FULLTEXT_LEN + SPIDER_SQL_SPACE_LEN))
{
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
str->q_append(SPIDER_SQL_FULLTEXT_STR, SPIDER_SQL_FULLTEXT_LEN);
str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN);
} else if (mysql_row[10] && !strcmp(mysql_row[10], "SPATIAL"))
{
/* spatial key */
without_size = TRUE;
if (str->reserve(SPIDER_SQL_SPATIAL_LEN + SPIDER_SQL_SPACE_LEN))
{
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
str->q_append(SPIDER_SQL_SPATIAL_STR, SPIDER_SQL_SPATIAL_LEN);
str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN);
}
if (str->reserve(SPIDER_DB_KEY_NAME_LEN + SPIDER_SQL_SPACE_LEN))
{
@ -1232,7 +1298,7 @@ int spider_db_mysql_result::fetch_index_for_discover_table_structure(
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN);
if (mysql_row[7])
if (mysql_row[7] && !without_size)
{
if (str->reserve(SPIDER_SQL_OPEN_PAREN_LEN))
{
@ -1265,7 +1331,7 @@ int spider_db_mysql_result::fetch_index_for_discover_table_structure(
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
str->q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN);
if (mysql_row[7])
if (mysql_row[7] && !without_size)
{
if (str->reserve(SPIDER_SQL_OPEN_PAREN_LEN))
{
@ -1283,18 +1349,58 @@ int spider_db_mysql_result::fetch_index_for_discover_table_structure(
str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN);
}
}
if (mysql_row[10] && !strcmp(mysql_row[10], "HASH"))
using_hash = TRUE;
else
using_hash = FALSE;
} while ((mysql_row = mysql_fetch_row(db_result)));
if (!first)
{
if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_COMMA_LEN))
if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_COMMA_LEN +
(using_hash ? SPIDER_SQL_USING_HASH_LEN : 0)))
{
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN);
if (using_hash)
str->q_append(SPIDER_SQL_USING_HASH_STR, SPIDER_SQL_USING_HASH_LEN);
str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN);
}
DBUG_RETURN(0);
}
int spider_db_mysql_result::fetch_table_for_discover_table_structure(
spider_string *str,
SPIDER_SHARE *spider_share,
CHARSET_INFO *access_charset
) {
MYSQL_ROW mysql_row;
DBUG_ENTER("spider_db_mysql_result::fetch_table_for_discover_table_structure");
DBUG_PRINT("info",("spider this=%p", this));
if (!(mysql_row = mysql_fetch_row(db_result)))
{
DBUG_PRINT("info",("spider fetch row is null"));
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
if (num_fields() != 18)
{
DBUG_PRINT("info",("spider num_fields != 18"));
my_printf_error(ER_SPIDER_UNKNOWN_NUM, ER_SPIDER_UNKNOWN_STR, MYF(0));
DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM);
}
if (!mysql_row[14])
{
DBUG_PRINT("info",("spider mysql_row[14] is null"));
my_printf_error(ER_SPIDER_UNKNOWN_NUM, ER_SPIDER_UNKNOWN_STR, MYF(0));
DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM);
}
DBUG_PRINT("info",("spider mysql_row[14]=%s", mysql_row[14]));
if (!spider_share->table_share->table_charset)
{
spider_share->table_share->table_charset = get_charset_by_name(mysql_row[14], MYF(MY_WME));
}
DBUG_RETURN(0);
}
#endif
spider_db_mysql::spider_db_mysql(
@ -1394,6 +1500,18 @@ int spider_db_mysql::connect(
DBUG_PRINT("info",("spider this=%p", this));
while (TRUE)
{
THD *thd = current_thd;
DBUG_PRINT("info",("spider thd->killed=%s",
thd ? (thd->killed ? "TRUE" : "FALSE") : "NULL"));
DBUG_PRINT("info",("spider abort_loop=%s",
abort_loop ? "TRUE" : "FALSE"));
if (
(thd && thd->killed) ||
abort_loop
) {
DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
}
if (!db_conn)
{
if (!(db_conn = mysql_init(NULL)))
@ -1460,6 +1578,16 @@ int spider_db_mysql::connect(
pthread_mutex_unlock(&spider_open_conn_mutex);
error_num = mysql_errno(db_conn);
disconnect();
DBUG_PRINT("info",("spider thd->killed=%s",
thd ? (thd->killed ? "TRUE" : "FALSE") : "NULL"));
DBUG_PRINT("info",("spider abort_loop=%s",
abort_loop ? "TRUE" : "FALSE"));
if (
(thd && thd->killed) ||
abort_loop
) {
DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
}
if (
(
error_num != CR_CONN_HOST_ERROR &&
@ -3868,8 +3996,8 @@ int spider_db_mysql_util::append_escaped_util(
) {
DBUG_ENTER("spider_db_mysql_util::append_escaped_util");
DBUG_PRINT("info",("spider this=%p", this));
to->get_str()->append_for_single_quote(from);
to->mem_calc();
if (to->append_for_single_quote(from))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
DBUG_RETURN(0);
}
@ -4628,22 +4756,54 @@ int spider_mysql_share::discover_table_structure(
str->length(strlen);
sql_str.length(0);
if (sql_str.reserve(
SPIDER_SQL_SHOW_COLUMNS_LEN + db_names_str[roop_count].length() +
SPIDER_SQL_DOT_LEN + table_names_str[roop_count].length() +
/* SPIDER_SQL_NAME_QUOTE_LEN */ 4 +
SPIDER_SQL_SELECT_COLUMNS_LEN + db_names_str[roop_count].length() +
SPIDER_SQL_AND_LEN + SPIDER_SQL_TABLE_NAME_LEN + SPIDER_SQL_EQUAL_LEN +
table_names_str[roop_count].length() + SPIDER_SQL_ORDER_LEN +
SPIDER_SQL_ORDINAL_POSITION_LEN +
/* SPIDER_SQL_VALUE_QUOTE_LEN */ 8 +
SPIDER_SQL_SEMICOLON_LEN +
SPIDER_SQL_SHOW_INDEX_LEN + db_names_str[roop_count].length() +
SPIDER_SQL_DOT_LEN + table_names_str[roop_count].length() +
/* SPIDER_SQL_NAME_QUOTE_LEN */ 4 +
SPIDER_SQL_SEMICOLON_LEN +
SPIDER_SQL_SHOW_TABLE_STATUS_LEN + db_names_str[roop_count].length() +
SPIDER_SQL_LIKE_LEN + table_names_str[roop_count].length() +
/* SPIDER_SQL_NAME_QUOTE_LEN */ 4
)) {
DBUG_PRINT("info",("spider alloc sql_str error"));
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
sql_str.q_append(SPIDER_SQL_SHOW_COLUMNS_STR, SPIDER_SQL_SHOW_COLUMNS_LEN);
append_table_name(&sql_str, roop_count);
sql_str.q_append(SPIDER_SQL_SELECT_COLUMNS_STR,
SPIDER_SQL_SELECT_COLUMNS_LEN);
sql_str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
sql_str.q_append(db_names_str[roop_count].ptr(),
db_names_str[roop_count].length());
sql_str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
sql_str.q_append(SPIDER_SQL_AND_STR, SPIDER_SQL_AND_LEN);
sql_str.q_append(SPIDER_SQL_TABLE_NAME_STR, SPIDER_SQL_TABLE_NAME_LEN);
sql_str.q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN);
sql_str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
sql_str.q_append(table_names_str[roop_count].ptr(),
table_names_str[roop_count].length());
sql_str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
sql_str.q_append(SPIDER_SQL_ORDER_STR, SPIDER_SQL_ORDER_LEN);
sql_str.q_append(SPIDER_SQL_ORDINAL_POSITION_STR,
SPIDER_SQL_ORDINAL_POSITION_LEN);
sql_str.q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN);
sql_str.q_append(SPIDER_SQL_SHOW_INDEX_STR, SPIDER_SQL_SHOW_INDEX_LEN);
append_table_name(&sql_str, roop_count);
sql_str.q_append(SPIDER_SQL_SEMICOLON_STR, SPIDER_SQL_SEMICOLON_LEN);
sql_str.q_append(
SPIDER_SQL_SHOW_TABLE_STATUS_STR, SPIDER_SQL_SHOW_TABLE_STATUS_LEN);
sql_str.q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN);
sql_str.q_append(db_names_str[roop_count].ptr(),
db_names_str[roop_count].length());
sql_str.q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN);
sql_str.q_append(SPIDER_SQL_LIKE_STR, SPIDER_SQL_LIKE_LEN);
sql_str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
sql_str.q_append(table_names_str[roop_count].ptr(),
table_names_str[roop_count].length());
sql_str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
SPIDER_CONN *conn;
int need_mon;
@ -4765,6 +4925,49 @@ int spider_mysql_share::discover_table_structure(
}
res->free_result();
delete res;
if (conn->db_conn->next_result())
{
DBUG_PRINT("info",("spider dual result error"));
conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
pthread_mutex_unlock(&conn->mta_conn_mutex);
continue;
}
/* get table info */
if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num)))
{
if (error_num || (error_num = spider_db_errorno(conn)))
{
DBUG_PRINT("info",("spider table store error"));
conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
pthread_mutex_unlock(&conn->mta_conn_mutex);
continue;
}
/* no record */
DBUG_PRINT("info",("spider table no record error"));
conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
pthread_mutex_unlock(&conn->mta_conn_mutex);
continue;
}
if ((error_num = res->fetch_table_for_discover_table_structure(str,
spider_share, spider_share->access_charset)))
{
DBUG_PRINT("info",("spider table fetch error"));
res->free_result();
delete res;
conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
pthread_mutex_unlock(&conn->mta_conn_mutex);
continue;
}
res->free_result();
delete res;
conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
@ -6037,7 +6240,23 @@ int spider_mysql_handler::append_select(
if (result_list->lock_type != F_WRLCK && spider->lock_mode < 1)
{
/* no lock */
if (spider->share->query_cache == 1)
st_select_lex *select_lex = &spider->trx->thd->lex->select_lex;
if (
select_lex->sql_cache == SELECT_LEX::SQL_CACHE &&
(spider->share->query_cache_sync & 1)
) {
if (str->reserve(SPIDER_SQL_SQL_CACHE_LEN))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
str->q_append(SPIDER_SQL_SQL_CACHE_STR, SPIDER_SQL_SQL_CACHE_LEN);
} else if (
select_lex->sql_cache == SELECT_LEX::SQL_NO_CACHE &&
(spider->share->query_cache_sync & 2)
) {
if (str->reserve(SPIDER_SQL_SQL_NO_CACHE_LEN))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
str->q_append(SPIDER_SQL_SQL_NO_CACHE_STR,
SPIDER_SQL_SQL_NO_CACHE_LEN);
} else if (spider->share->query_cache == 1)
{
if (str->reserve(SPIDER_SQL_SQL_CACHE_LEN))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
@ -6154,7 +6373,9 @@ int spider_mysql_handler::append_minimum_select(
{
if (minimum_select_bit_is_set((*field)->field_index))
{
/*
spider_set_bit(minimum_select_bitmap, (*field)->field_index);
*/
field_length =
mysql_share->column_name_str[(*field)->field_index].length();
if (str->reserve(field_length +
@ -6241,7 +6462,9 @@ int spider_mysql_handler::append_minimum_select_with_alias(
{
if (minimum_select_bit_is_set((*field)->field_index))
{
/*
spider_set_bit(minimum_select_bitmap, (*field)->field_index);
*/
field_length =
mysql_share->column_name_str[(*field)->field_index].length();
if (str->reserve(alias_length + field_length +
@ -9839,6 +10062,7 @@ int spider_mysql_handler::show_table_status(
SPIDER_DB_RESULT *res;
SPIDER_SHARE *share = spider->share;
uint pos = (2 * spider->conn_link_idx[link_idx]);
ulonglong auto_increment_value = 0;
DBUG_ENTER("spider_mysql_handler::show_table_status");
DBUG_PRINT("info",("spider sts_mode=%d", sts_mode));
if (sts_mode == 1)
@ -9945,7 +10169,7 @@ int spider_mysql_handler::show_table_status(
share->data_file_length,
share->max_data_file_length,
share->index_file_length,
share->auto_increment_value,
auto_increment_value,
share->create_time,
share->update_time,
share->check_time
@ -10072,7 +10296,7 @@ int spider_mysql_handler::show_table_status(
share->data_file_length,
share->max_data_file_length,
share->index_file_length,
share->auto_increment_value,
auto_increment_value,
share->create_time,
share->update_time,
share->check_time
@ -10103,6 +10327,12 @@ int spider_mysql_handler::show_table_status(
DBUG_RETURN(error_num);
}
}
if (auto_increment_value > share->lgtm_tblhnd_share->auto_increment_value)
{
share->lgtm_tblhnd_share->auto_increment_value = auto_increment_value;
DBUG_PRINT("info",("spider auto_increment_value=%llu",
share->lgtm_tblhnd_share->auto_increment_value));
}
DBUG_RETURN(0);
}

View file

@ -214,6 +214,11 @@ public:
spider_string *str,
CHARSET_INFO *access_charset
);
int fetch_table_for_discover_table_structure(
spider_string *str,
SPIDER_SHARE *spider_share,
CHARSET_INFO *access_charset
);
#endif
};

View file

@ -1075,6 +1075,16 @@ int spider_db_oracle_result::fetch_index_for_discover_table_structure(
DBUG_PRINT("info",("spider this=%p", this));
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
}
int spider_db_oracle_result::fetch_table_for_discover_table_structure(
spider_string *str,
SPIDER_SHARE *spider_share,
CHARSET_INFO *access_charset
) {
DBUG_ENTER("spider_db_oracle_result::fetch_table_for_discover_table_structure");
DBUG_PRINT("info",("spider this=%p", this));
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
}
#endif
spider_db_oracle::spider_db_oracle(
@ -6022,7 +6032,9 @@ int spider_oracle_handler::append_minimum_select(
{
if (minimum_select_bit_is_set((*field)->field_index))
{
/*
spider_set_bit(minimum_select_bitmap, (*field)->field_index);
*/
field_length =
oracle_share->column_name_str[(*field)->field_index].length();
if (str->reserve(field_length +
@ -6109,7 +6121,9 @@ int spider_oracle_handler::append_minimum_select_with_alias(
{
if (minimum_select_bit_is_set((*field)->field_index))
{
/*
spider_set_bit(minimum_select_bitmap, (*field)->field_index);
*/
field_length =
oracle_share->column_name_str[(*field)->field_index].length();
if (str->reserve(alias_length + field_length +
@ -10193,6 +10207,7 @@ int spider_oracle_handler::show_table_status(
SPIDER_DB_RESULT *res;
SPIDER_SHARE *share = spider->share;
uint pos = (2 * spider->conn_link_idx[link_idx]);
ulonglong auto_increment_value = 0;
DBUG_ENTER("spider_oracle_handler::show_table_status");
DBUG_PRINT("info",("spider sts_mode=%d", sts_mode));
if (
@ -10301,7 +10316,7 @@ int spider_oracle_handler::show_table_status(
share->data_file_length,
share->max_data_file_length,
share->index_file_length,
share->auto_increment_value,
auto_increment_value,
share->create_time,
share->update_time,
share->check_time
@ -10317,9 +10332,6 @@ int spider_oracle_handler::show_table_status(
share->data_file_length = 65535;
share->max_data_file_length = 65535;
share->index_file_length = 65535;
/*
share->auto_increment_value = 0;
*/
share->create_time = (time_t) 0;
share->update_time = (time_t) 0;
share->check_time = (time_t) 0;
@ -10412,7 +10424,7 @@ int spider_oracle_handler::show_table_status(
share->data_file_length,
share->max_data_file_length,
share->index_file_length,
share->auto_increment_value,
auto_increment_value,
share->create_time,
share->update_time,
share->check_time
@ -10422,6 +10434,12 @@ int spider_oracle_handler::show_table_status(
if (error_num)
DBUG_RETURN(error_num);
}
if (auto_increment_value > share->lgtm_tblhnd_share->auto_increment_value)
{
share->lgtm_tblhnd_share->auto_increment_value = auto_increment_value;
DBUG_PRINT("info",("spider auto_increment_value=%llu",
share->lgtm_tblhnd_share->auto_increment_value));
}
DBUG_RETURN(0);
}
@ -10914,9 +10932,13 @@ int spider_oracle_handler::show_autoinc(
DBUG_PRINT("info", ("spider error_num=%d 7", error_num));
DBUG_RETURN(error_num);
}
if (auto_increment_value >= share->auto_increment_value)
if (auto_increment_value >=
share->lgtm_tblhnd_share->auto_increment_value)
{
share->auto_increment_value = auto_increment_value + 1;
share->lgtm_tblhnd_share->auto_increment_value =
auto_increment_value + 1;
DBUG_PRINT("info",("spider auto_increment_value=%llu",
share->lgtm_tblhnd_share->auto_increment_value));
}
DBUG_RETURN(0);
}

View file

@ -248,6 +248,11 @@ public:
spider_string *str,
CHARSET_INFO *access_charset
);
int fetch_table_for_discover_table_structure(
spider_string *str,
SPIDER_SHARE *spider_share,
CHARSET_INFO *access_charset
);
#endif
/* for oracle */
int set_column_info();

View file

@ -13,7 +13,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#define SPIDER_DETAIL_VERSION "3.2.0"
#define SPIDER_DETAIL_VERSION "3.2.4"
#define SPIDER_HEX_VERSION 0x0302
#if MYSQL_VERSION_ID < 50500
@ -47,6 +47,10 @@
#undef pthread_cond_wait
#endif
#define pthread_cond_wait mysql_cond_wait
#ifdef pthread_cond_timedwait
#undef pthread_cond_timedwait
#endif
#define pthread_cond_timedwait mysql_cond_timedwait
#ifdef pthread_cond_signal
#undef pthread_cond_signal
#endif
@ -75,6 +79,7 @@
#define SPIDER_ALTER_REBUILD_PARTITION Alter_info::ALTER_REBUILD_PARTITION
#define SPIDER_WARN_LEVEL_WARN Sql_condition::WARN_LEVEL_WARN
#define SPIDER_WARN_LEVEL_NOTE Sql_condition::WARN_LEVEL_NOTE
#define SPIDER_THD_KILL_CONNECTION KILL_CONNECTION
#else
#if MYSQL_VERSION_ID < 50500
#define spider_stmt_da_message(A) (A)->main_da.message()
@ -97,6 +102,7 @@
#define SPIDER_ALTER_REBUILD_PARTITION ALTER_REBUILD_PARTITION
#define SPIDER_WARN_LEVEL_WARN MYSQL_ERROR::WARN_LEVEL_WARN
#define SPIDER_WARN_LEVEL_NOTE MYSQL_ERROR::WARN_LEVEL_NOTE
#define SPIDER_THD_KILL_CONNECTION THD::KILL_CONNECTION
#endif
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100009
@ -132,7 +138,7 @@
#define SPIDER_TMP_SHARE_LONG_COUNT 15
#define SPIDER_TMP_SHARE_LONGLONG_COUNT 3
#define SPIDER_MEM_CALC_LIST_NUM 244
#define SPIDER_MEM_CALC_LIST_NUM 246
#define SPIDER_BACKUP_DASTATUS \
bool da_status; if (thd) da_status = thd->is_error(); else da_status = FALSE;
@ -426,6 +432,19 @@ typedef struct st_spider_conn
#endif
} SPIDER_CONN;
typedef struct st_spider_lgtm_tblhnd_share
{
char *table_name;
uint table_name_length;
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
my_hash_value_type table_path_hash_value;
#endif
pthread_mutex_t auto_increment_mutex;
volatile bool auto_increment_init;
volatile ulonglong auto_increment_lclval;
ulonglong auto_increment_value;
} SPIDER_LGTM_TBLHND_SHARE;
#ifdef WITH_PARTITION_STORAGE_ENGINE
typedef struct st_spider_patition_handler_share
{
@ -614,9 +633,12 @@ typedef struct st_spider_share
pthread_mutex_t mutex;
pthread_mutex_t sts_mutex;
pthread_mutex_t crd_mutex;
/*
pthread_mutex_t auto_increment_mutex;
*/
THR_LOCK lock;
TABLE_SHARE *table_share;
SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share;
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
my_hash_value_type table_name_hash_value;
#ifdef WITH_PARTITION_STORAGE_ENGINE
@ -669,13 +691,18 @@ typedef struct st_spider_share
pthread_t *bg_mon_threads;
pthread_mutex_t *bg_mon_mutexes;
pthread_cond_t *bg_mon_conds;
pthread_cond_t *bg_mon_sleep_conds;
#endif
/*
volatile bool auto_increment_init;
volatile ulonglong auto_increment_lclval;
*/
ulonglong data_file_length;
ulonglong max_data_file_length;
ulonglong index_file_length;
/*
ulonglong auto_increment_value;
*/
ha_rows records;
ulong mean_rec_length;
time_t check_time;
@ -721,6 +748,7 @@ typedef struct st_spider_share
int semi_table_lock_conn;
int selupd_lock_mode;
int query_cache;
int query_cache_sync;
int internal_delayed;
int bulk_size;
int bulk_update_mode;

View file

@ -1221,7 +1221,6 @@ bool spider_string::append(
DBUG_RETURN(res);
}
#ifdef SPIDER_HAS_APPEND_FOR_SINGLE_QUOTE
bool spider_string::append_for_single_quote(
const char *st,
uint len
@ -1231,11 +1230,50 @@ bool spider_string::append_for_single_quote(
DBUG_ASSERT(mem_calc_inited);
DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) ||
current_alloc_mem == str.alloced_length());
#ifdef SPIDER_HAS_APPEND_FOR_SINGLE_QUOTE
bool res = str.append_for_single_quote(st, len);
#else
String ststr(st, len, str.charset());
bool res = append_escaped(&str, &ststr);
#endif
SPIDER_STRING_CALC_MEM;
DBUG_RETURN(res);
}
bool spider_string::append_for_single_quote(
const String *s
) {
DBUG_ENTER("spider_string::append_for_single_quote");
DBUG_PRINT("info",("spider this=%p", this));
DBUG_ASSERT(mem_calc_inited);
DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) ||
current_alloc_mem == str.alloced_length());
#ifdef SPIDER_HAS_APPEND_FOR_SINGLE_QUOTE
bool res = str.append_for_single_quote(s);
#else
bool res = append_escaped(&str, s);
#endif
SPIDER_STRING_CALC_MEM;
DBUG_RETURN(res);
}
bool spider_string::append_for_single_quote(
const char *st
) {
DBUG_ENTER("spider_string::append_for_single_quote");
DBUG_PRINT("info",("spider this=%p", this));
DBUG_ASSERT(mem_calc_inited);
DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) ||
current_alloc_mem == str.alloced_length());
#ifdef SPIDER_HAS_APPEND_FOR_SINGLE_QUOTE
bool res = str.append_for_single_quote(st);
#else
String ststr(st, str.charset());
bool res = append_escaped(&str, &ststr);
#endif
SPIDER_STRING_CALC_MEM;
DBUG_RETURN(res);
}
void spider_string::swap(
spider_string &s

View file

@ -1273,6 +1273,16 @@ int spider_ping_table_mon_from_table(
ER_SPIDER_MON_AT_ALTER_TABLE_STR, MYF(0));
DBUG_RETURN(ER_SPIDER_MON_AT_ALTER_TABLE_NUM);
}
DBUG_PRINT("info",("spider thd->killed=%s",
thd ? (thd->killed ? "TRUE" : "FALSE") : "NULL"));
DBUG_PRINT("info",("spider abort_loop=%s",
abort_loop ? "TRUE" : "FALSE"));
if (
(thd && thd->killed) ||
abort_loop
) {
DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
}
link_idx_str_length = my_sprintf(link_idx_str, (link_idx_str, "%010d",
link_idx));
@ -1325,126 +1335,158 @@ int spider_ping_table_mon_from_table(
current_mon_count = 1;
while (TRUE)
{
if (!table_mon)
table_mon = table_mon_list->first;
DBUG_PRINT("info",("spider thd->killed=%s",
thd ? (thd->killed ? "TRUE" : "FALSE") : "NULL"));
DBUG_PRINT("info",("spider abort_loop=%s",
abort_loop ? "TRUE" : "FALSE"));
if (
current_mon_count > table_mon_list->list_size ||
(current_mon_count > 1 && table_mon->server_id == first_sid)
(thd && thd->killed) ||
abort_loop
) {
table_mon_list->last_caller_result = SPIDER_LINK_MON_DRAW_FEW_MON;
mon_table_result.result_status = SPIDER_LINK_MON_DRAW_FEW_MON;
DBUG_PRINT("info",(
"spider mon_table_result->result_status=SPIDER_LINK_MON_DRAW_FEW_MON 1"));
error_num = ER_SPIDER_LINK_MON_DRAW_FEW_MON_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_DRAW_FEW_MON_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
table_mon_list->share->tgt_table_names[0]);
error_num = ER_SPIDER_COND_SKIP_NUM;
break;
}
thd->clear_error();
if ((mon_conn = spider_get_ping_table_tgt_conn(trx,
table_mon->share, &error_num))
) {
if (!spider_db_udf_ping_table_mon_next(
thd, table_mon, mon_conn, &mon_table_result, conv_name,
conv_name_length, link_idx,
where_clause, where_clause_length, -1, table_mon_list->list_size,
0, 0, 0, flags, monitoring_limit))
} else {
if (!table_mon)
table_mon = table_mon_list->first;
if (
current_mon_count > table_mon_list->list_size ||
(current_mon_count > 1 && table_mon->server_id == first_sid)
) {
table_mon_list->last_caller_result = SPIDER_LINK_MON_DRAW_FEW_MON;
mon_table_result.result_status = SPIDER_LINK_MON_DRAW_FEW_MON;
DBUG_PRINT("info",(
"spider mon_table_result->result_status=SPIDER_LINK_MON_DRAW_FEW_MON 1"));
error_num = ER_SPIDER_LINK_MON_DRAW_FEW_MON_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_DRAW_FEW_MON_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
table_mon_list->share->tgt_table_names[0]);
break;
}
int prev_error = 0;
char prev_error_msg[MYSQL_ERRMSG_SIZE];
if (thd->is_error())
{
if (
mon_table_result.result_status == SPIDER_LINK_MON_NG &&
table_mon_list->mon_status != SPIDER_LINK_MON_NG
) {
pthread_mutex_lock(&table_mon_list->update_status_mutex);
if (table_mon_list->mon_status != SPIDER_LINK_MON_NG)
{
table_mon_list->mon_status = SPIDER_LINK_MON_NG;
table_mon_list->share->link_statuses[0] = SPIDER_LINK_STATUS_NG;
DBUG_PRINT("info", (
"spider share->link_statuses[%d]=SPIDER_LINK_STATUS_NG",
link_idx));
share->link_statuses[link_idx] = SPIDER_LINK_STATUS_NG;
spider_sys_update_tables_link_status(thd, conv_name,
conv_name_length, link_idx, SPIDER_LINK_STATUS_NG, need_lock);
spider_sys_log_tables_link_failed(thd, conv_name,
conv_name_length, link_idx, need_lock);
prev_error = spider_stmt_da_sql_errno(thd);
strmov(prev_error_msg, spider_stmt_da_message(thd));
thd->clear_error();
}
if ((mon_conn = spider_get_ping_table_tgt_conn(trx,
table_mon->share, &error_num))
) {
if (!spider_db_udf_ping_table_mon_next(
thd, table_mon, mon_conn, &mon_table_result, conv_name,
conv_name_length, link_idx,
where_clause, where_clause_length, -1, table_mon_list->list_size,
0, 0, 0, flags, monitoring_limit))
{
if (
mon_table_result.result_status == SPIDER_LINK_MON_NG &&
table_mon_list->mon_status != SPIDER_LINK_MON_NG
) {
pthread_mutex_lock(&table_mon_list->update_status_mutex);
if (table_mon_list->mon_status != SPIDER_LINK_MON_NG)
{
table_mon_list->mon_status = SPIDER_LINK_MON_NG;
table_mon_list->share->link_statuses[0] = SPIDER_LINK_STATUS_NG;
DBUG_PRINT("info", (
"spider share->link_statuses[%d]=SPIDER_LINK_STATUS_NG",
link_idx));
share->link_statuses[link_idx] = SPIDER_LINK_STATUS_NG;
spider_sys_update_tables_link_status(thd, conv_name,
conv_name_length, link_idx, SPIDER_LINK_STATUS_NG, need_lock);
spider_sys_log_tables_link_failed(thd, conv_name,
conv_name_length, link_idx, need_lock);
}
pthread_mutex_unlock(&table_mon_list->update_status_mutex);
}
pthread_mutex_unlock(&table_mon_list->update_status_mutex);
}
table_mon_list->last_caller_result = mon_table_result.result_status;
if (mon_table_result.result_status == SPIDER_LINK_MON_OK)
{
error_num = ER_SPIDER_LINK_MON_OK_NUM;
table_mon_list->last_caller_result = mon_table_result.result_status;
if (mon_table_result.result_status == SPIDER_LINK_MON_OK)
{
if (prev_error)
my_message(prev_error, prev_error_msg, MYF(0));
error_num = ER_SPIDER_LINK_MON_OK_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_OK_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
table_mon_list->share->tgt_table_names[0]);
break;
}
if (mon_table_result.result_status == SPIDER_LINK_MON_NG)
{
error_num = ER_SPIDER_LINK_MON_NG_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_NG_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
table_mon_list->share->tgt_table_names[0]);
break;
}
if (mon_table_result.result_status ==
SPIDER_LINK_MON_DRAW_FEW_MON)
{
error_num = ER_SPIDER_LINK_MON_DRAW_FEW_MON_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_DRAW_FEW_MON_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
table_mon_list->share->tgt_table_names[0]);
break;
}
error_num = ER_SPIDER_LINK_MON_DRAW_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_OK_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
table_mon_list->share->tgt_table_names[0]);
break;
}
if (mon_table_result.result_status == SPIDER_LINK_MON_NG)
{
error_num = ER_SPIDER_LINK_MON_NG_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_NG_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
table_mon_list->share->tgt_table_names[0]);
break;
}
if (mon_table_result.result_status ==
SPIDER_LINK_MON_DRAW_FEW_MON)
{
error_num = ER_SPIDER_LINK_MON_DRAW_FEW_MON_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_DRAW_FEW_MON_STR, MYF(0),
ER_SPIDER_LINK_MON_DRAW_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
table_mon_list->share->tgt_table_names[0]);
break;
}
}
table_mon = table_mon->next;
current_mon_count++;
}
}
pthread_mutex_unlock(&table_mon_list->caller_mutex);
} else {
pthread_mutex_lock(&table_mon_list->caller_mutex);
DBUG_PRINT("info",("spider thd->killed=%s",
thd ? (thd->killed ? "TRUE" : "FALSE") : "NULL"));
DBUG_PRINT("info",("spider abort_loop=%s",
abort_loop ? "TRUE" : "FALSE"));
if (
(thd && thd->killed) ||
abort_loop
) {
error_num = ER_SPIDER_COND_SKIP_NUM;
} else {
switch (table_mon_list->last_caller_result)
{
case SPIDER_LINK_MON_OK:
error_num = ER_SPIDER_LINK_MON_OK_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_OK_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
table_mon_list->share->tgt_table_names[0]);
break;
case SPIDER_LINK_MON_NG:
error_num = ER_SPIDER_LINK_MON_NG_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_NG_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
table_mon_list->share->tgt_table_names[0]);
break;
case SPIDER_LINK_MON_DRAW_FEW_MON:
error_num = ER_SPIDER_LINK_MON_DRAW_FEW_MON_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_DRAW_FEW_MON_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
table_mon_list->share->tgt_table_names[0]);
break;
default:
error_num = ER_SPIDER_LINK_MON_DRAW_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_DRAW_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
table_mon_list->share->tgt_table_names[0]);
break;
}
}
table_mon = table_mon->next;
current_mon_count++;
}
pthread_mutex_unlock(&table_mon_list->caller_mutex);
} else {
pthread_mutex_lock(&table_mon_list->caller_mutex);
switch (table_mon_list->last_caller_result)
{
case SPIDER_LINK_MON_OK:
error_num = ER_SPIDER_LINK_MON_OK_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_OK_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
table_mon_list->share->tgt_table_names[0]);
break;
case SPIDER_LINK_MON_NG:
error_num = ER_SPIDER_LINK_MON_NG_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_NG_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
table_mon_list->share->tgt_table_names[0]);
break;
case SPIDER_LINK_MON_DRAW_FEW_MON:
error_num = ER_SPIDER_LINK_MON_DRAW_FEW_MON_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_DRAW_FEW_MON_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
table_mon_list->share->tgt_table_names[0]);
break;
default:
error_num = ER_SPIDER_LINK_MON_DRAW_NUM;
my_printf_error(error_num,
ER_SPIDER_LINK_MON_DRAW_STR, MYF(0),
table_mon_list->share->tgt_dbs[0],
table_mon_list->share->tgt_table_names[0]);
break;
}
pthread_mutex_unlock(&table_mon_list->caller_mutex);
}

View file

@ -68,6 +68,7 @@ PSI_mutex_key spd_key_mutex_init_error_tbl;
#ifdef WITH_PARTITION_STORAGE_ENGINE
PSI_mutex_key spd_key_mutex_pt_share;
#endif
PSI_mutex_key spd_key_mutex_lgtm_tblhnd_share;
PSI_mutex_key spd_key_mutex_conn;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
PSI_mutex_key spd_key_mutex_hs_r_conn;
@ -114,6 +115,7 @@ static PSI_mutex_info all_spider_mutexes[]=
#ifdef WITH_PARTITION_STORAGE_ENGINE
{ &spd_key_mutex_pt_share, "pt_share", PSI_FLAG_GLOBAL},
#endif
{ &spd_key_mutex_lgtm_tblhnd_share, "lgtm_tblhnd_share", PSI_FLAG_GLOBAL},
{ &spd_key_mutex_conn, "conn", PSI_FLAG_GLOBAL},
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
{ &spd_key_mutex_hs_r_conn, "hs_r_conn", PSI_FLAG_GLOBAL},
@ -162,6 +164,7 @@ PSI_cond_key spd_key_cond_bg_sts_sync;
PSI_cond_key spd_key_cond_bg_crd;
PSI_cond_key spd_key_cond_bg_crd_sync;
PSI_cond_key spd_key_cond_bg_mon;
PSI_cond_key spd_key_cond_bg_mon_sleep;
PSI_cond_key spd_key_cond_bg_direct_sql;
#endif
PSI_cond_key spd_key_cond_udf_table_mon;
@ -175,6 +178,7 @@ static PSI_cond_info all_spider_conds[] = {
{&spd_key_cond_bg_crd, "bg_crd", 0},
{&spd_key_cond_bg_crd_sync, "bg_crd_sync", 0},
{&spd_key_cond_bg_mon, "bg_mon", 0},
{&spd_key_cond_bg_mon_sleep, "bg_mon_sleep", 0},
{&spd_key_cond_bg_direct_sql, "bg_direct_sql", 0},
#endif
{&spd_key_cond_udf_table_mon, "udf_table_mon", 0},
@ -257,6 +261,13 @@ ulong spider_open_pt_share_line_no;
pthread_mutex_t spider_pt_share_mutex;
#endif
HASH spider_lgtm_tblhnd_share_hash;
uint spider_lgtm_tblhnd_share_hash_id;
const char *spider_lgtm_tblhnd_share_hash_func_name;
const char *spider_lgtm_tblhnd_share_hash_file_name;
ulong spider_lgtm_tblhnd_share_hash_line_no;
pthread_mutex_t spider_lgtm_tblhnd_share_mutex;
HASH spider_allocated_thds;
uint spider_allocated_thds_id;
const char *spider_allocated_thds_func_name;
@ -317,6 +328,16 @@ uchar *spider_pt_handler_share_get_key(
}
#endif
uchar *spider_lgtm_tblhnd_share_hash_get_key(
SPIDER_LGTM_TBLHND_SHARE *share,
size_t *length,
my_bool not_used __attribute__ ((unused))
) {
DBUG_ENTER("spider_lgtm_tblhnd_share_hash_get_key");
*length = share->table_name_length;
DBUG_RETURN((uchar*) share->table_name);
}
uchar *spider_link_get_key(
SPIDER_LINK_FOR_HASH *link_for_hash,
size_t *length,
@ -1748,6 +1769,7 @@ int spider_parse_connect_info(
share->semi_table_lock_conn = -1;
share->selupd_lock_mode = -1;
share->query_cache = -1;
share->query_cache_sync = -1;
share->internal_delayed = -1;
share->bulk_size = -1;
share->bulk_update_mode = -1;
@ -1983,6 +2005,7 @@ int spider_parse_connect_info(
SPIDER_PARAM_STR_LIST("pkn", tgt_pk_names);
SPIDER_PARAM_LONGLONG("prt", priority, 0);
SPIDER_PARAM_INT_WITH_MAX("qch", query_cache, 0, 2);
SPIDER_PARAM_INT_WITH_MAX("qcs", query_cache_sync, 0, 3);
SPIDER_PARAM_INT_WITH_MAX("qmd", quick_mode, 0, 3);
SPIDER_PARAM_LONGLONG("qps", quick_page_size, 0);
SPIDER_PARAM_INT_WITH_MAX("rom", read_only_mode, 0, 1);
@ -2015,7 +2038,7 @@ int spider_parse_connect_info(
SPIDER_PARAM_INT_WITH_MAX("stl", semi_table_lock, 0, 1);
SPIDER_PARAM_LONG_LIST_WITH_MAX("svc", tgt_ssl_vscs, 0, 1);
SPIDER_PARAM_STR_LIST("tbl", tgt_table_names);
SPIDER_PARAM_INT_WITH_MAX("tcm", table_count_mode, 0, 1);
SPIDER_PARAM_INT_WITH_MAX("tcm", table_count_mode, 0, 3);
SPIDER_PARAM_LONG_LIST_WITH_MAX("uhd", use_handlers, 0, 3);
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
SPIDER_PARAM_LONG_LIST_WITH_MAX(
@ -2191,7 +2214,7 @@ int spider_parse_connect_info(
SPIDER_PARAM_INT_WITH_MAX(
"internal_delayed", internal_delayed, 0, 1);
SPIDER_PARAM_INT_WITH_MAX(
"table_count_mode", table_count_mode, 0, 1);
"table_count_mode", table_count_mode, 0, 3);
SPIDER_PARAM_INT_WITH_MAX(
"use_pushdown_udf", use_pushdown_udf, 0, 1);
SPIDER_PARAM_LONGLONG_LIST_WITH_MAX(
@ -2211,6 +2234,8 @@ int spider_parse_connect_info(
SPIDER_PARAM_INT_WITH_MAX(
"bulk_access_free", bulk_access_free, 0, 1);
#endif
SPIDER_PARAM_INT_WITH_MAX(
"query_cache_sync", query_cache_sync, 0, 3);
error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
MYF(0), tmp_ptr);
@ -3367,6 +3392,8 @@ int spider_set_connect_info_default(
share->selupd_lock_mode = 1;
if (share->query_cache == -1)
share->query_cache = 0;
if (share->query_cache_sync == -1)
share->query_cache_sync = 0;
if (share->internal_delayed == -1)
share->internal_delayed = 0;
if (share->bulk_size == -1)
@ -3991,7 +4018,7 @@ SPIDER_SHARE *spider_create_share(
use_table_charset = spider_param_use_table_charset(
share->use_table_charset);
if (use_table_charset)
if (table_share->table_charset && use_table_charset)
share->access_charset = table_share->table_charset;
else
share->access_charset = system_charset_info;
@ -3999,8 +4026,10 @@ SPIDER_SHARE *spider_create_share(
if ((*error_num = spider_create_conn_keys(share)))
goto error_create_conn_keys;
if (share->table_count_mode)
if (share->table_count_mode & 1)
share->additional_table_flags |= HA_STATS_RECORDS_IS_EXACT;
if (share->table_count_mode & 2)
share->additional_table_flags |= HA_HAS_RECORDS;
#if MYSQL_VERSION_ID < 50500
if (pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST))
@ -4035,19 +4064,20 @@ SPIDER_SHARE *spider_create_share(
goto error_init_crd_mutex;
}
#if MYSQL_VERSION_ID < 50500
if (pthread_mutex_init(&share->auto_increment_mutex, MY_MUTEX_INIT_FAST))
thr_lock_init(&share->lock);
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
if (!(share->lgtm_tblhnd_share =
spider_get_lgtm_tblhnd_share(tmp_name, length, hash_value, FALSE, TRUE,
error_num)))
#else
if (mysql_mutex_init(spd_key_mutex_share_auto_increment,
&share->auto_increment_mutex, MY_MUTEX_INIT_FAST))
if (!(share->lgtm_tblhnd_share =
spider_get_lgtm_tblhnd_share(tmp_name, length, FALSE, TRUE, error_num)))
#endif
{
*error_num = HA_ERR_OUT_OF_MEM;
goto error_init_auto_increment_mutex;
goto error_get_lgtm_tblhnd_share;
}
thr_lock_init(&share->lock);
#ifdef WITH_PARTITION_STORAGE_ENGINE
if (!(share->partition_share =
spider_get_pt_share(share, table_share, error_num)))
@ -4085,11 +4115,11 @@ error_init_dbton:
}
}
#ifdef WITH_PARTITION_STORAGE_ENGINE
spider_free_pt_share(share->partition_share);
error_get_pt_share:
#endif
error_get_lgtm_tblhnd_share:
thr_lock_delete(&share->lock);
pthread_mutex_destroy(&share->auto_increment_mutex);
error_init_auto_increment_mutex:
pthread_mutex_destroy(&share->crd_mutex);
error_init_crd_mutex:
pthread_mutex_destroy(&share->sts_mutex);
@ -5104,7 +5134,6 @@ void spider_free_share_resource_only(
DBUG_ENTER("spider_free_share_resource_only");
spider_free_share_alloc(share);
thr_lock_delete(&share->lock);
pthread_mutex_destroy(&share->auto_increment_mutex);
pthread_mutex_destroy(&share->crd_mutex);
pthread_mutex_destroy(&share->sts_mutex);
pthread_mutex_destroy(&share->mutex);
@ -5132,7 +5161,6 @@ int spider_free_share(
my_hash_delete(&spider_open_tables, (uchar*) share);
#endif
thr_lock_delete(&share->lock);
pthread_mutex_destroy(&share->auto_increment_mutex);
pthread_mutex_destroy(&share->crd_mutex);
pthread_mutex_destroy(&share->sts_mutex);
pthread_mutex_destroy(&share->mutex);
@ -5142,6 +5170,129 @@ int spider_free_share(
DBUG_RETURN(0);
}
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
SPIDER_LGTM_TBLHND_SHARE *spider_get_lgtm_tblhnd_share(
const char *table_name,
uint table_name_length,
my_hash_value_type hash_value,
bool locked,
bool need_to_create,
int *error_num
)
#else
SPIDER_LGTM_TBLHND_SHARE *spider_get_lgtm_tblhnd_share(
const char *table_name,
uint table_name_length,
bool locked,
bool need_to_create,
int *error_num
)
#endif
{
SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share;
char *tmp_name;
DBUG_ENTER("spider_get_lgtm_tblhnd_share");
if (!locked)
pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex);
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
if (!(lgtm_tblhnd_share = (SPIDER_LGTM_TBLHND_SHARE*)
my_hash_search_using_hash_value(
&spider_lgtm_tblhnd_share_hash, hash_value,
(uchar*) table_name, table_name_length)))
#else
if (!(lgtm_tblhnd_share = (SPIDER_LGTM_TBLHND_SHARE*) my_hash_search(
&spider_lgtm_tblhnd_share_hash,
(uchar*) table_name, table_name_length)))
#endif
{
DBUG_PRINT("info",("spider create new lgtm tblhnd share"));
if (!(lgtm_tblhnd_share = (SPIDER_LGTM_TBLHND_SHARE *)
spider_bulk_malloc(spider_current_trx, 244, MYF(MY_WME | MY_ZEROFILL),
&lgtm_tblhnd_share, sizeof(*lgtm_tblhnd_share),
&tmp_name, table_name_length + 1,
NullS))
) {
*error_num = HA_ERR_OUT_OF_MEM;
goto error_alloc_share;
}
lgtm_tblhnd_share->table_name_length = table_name_length;
lgtm_tblhnd_share->table_name = tmp_name;
memcpy(lgtm_tblhnd_share->table_name, table_name,
lgtm_tblhnd_share->table_name_length);
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
lgtm_tblhnd_share->table_path_hash_value = hash_value;
#endif
#if MYSQL_VERSION_ID < 50500
if (pthread_mutex_init(&lgtm_tblhnd_share->auto_increment_mutex,
MY_MUTEX_INIT_FAST))
#else
if (mysql_mutex_init(spd_key_mutex_share_auto_increment,
&lgtm_tblhnd_share->auto_increment_mutex, MY_MUTEX_INIT_FAST))
#endif
{
*error_num = HA_ERR_OUT_OF_MEM;
goto error_init_auto_increment_mutex;
}
uint old_elements = spider_lgtm_tblhnd_share_hash.array.max_element;
#ifdef HASH_UPDATE_WITH_HASH_VALUE
if (my_hash_insert_with_hash_value(&spider_lgtm_tblhnd_share_hash,
hash_value, (uchar*) lgtm_tblhnd_share))
#else
if (my_hash_insert(&spider_lgtm_tblhnd_share_hash,
(uchar*) lgtm_tblhnd_share))
#endif
{
*error_num = HA_ERR_OUT_OF_MEM;
goto error_hash_insert;
}
if (spider_lgtm_tblhnd_share_hash.array.max_element > old_elements)
{
spider_alloc_calc_mem(spider_current_trx,
spider_lgtm_tblhnd_share_hash,
(spider_lgtm_tblhnd_share_hash.array.max_element - old_elements) *
spider_lgtm_tblhnd_share_hash.array.size_of_element);
}
}
if (!locked)
pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex);
DBUG_PRINT("info",("spider lgtm_tblhnd_share=%p", lgtm_tblhnd_share));
DBUG_RETURN(lgtm_tblhnd_share);
error_hash_insert:
pthread_mutex_destroy(&lgtm_tblhnd_share->auto_increment_mutex);
error_init_auto_increment_mutex:
spider_free(spider_current_trx, lgtm_tblhnd_share, MYF(0));
error_alloc_share:
if (!locked)
pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex);
DBUG_RETURN(NULL);
}
void spider_free_lgtm_tblhnd_share_alloc(
SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share,
bool locked
) {
DBUG_ENTER("spider_free_lgtm_tblhnd_share");
if (!locked)
pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex);
#ifdef HASH_UPDATE_WITH_HASH_VALUE
my_hash_delete_with_hash_value(&spider_lgtm_tblhnd_share_hash,
lgtm_tblhnd_share->table_path_hash_value, (uchar*) lgtm_tblhnd_share);
#else
my_hash_delete(&spider_lgtm_tblhnd_share_hash, (uchar*) lgtm_tblhnd_share);
#endif
pthread_mutex_destroy(&lgtm_tblhnd_share->auto_increment_mutex);
spider_free(spider_current_trx, lgtm_tblhnd_share, MYF(0));
if (!locked)
pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex);
DBUG_VOID_RETURN;
}
#ifdef WITH_PARTITION_STORAGE_ENGINE
SPIDER_PARTITION_SHARE *spider_get_pt_share(
SPIDER_SHARE *share,
@ -5321,7 +5472,8 @@ void spider_copy_sts_to_pt_share(
partition_share->data_file_length = share->data_file_length;
partition_share->max_data_file_length = share->max_data_file_length;
partition_share->index_file_length = share->index_file_length;
partition_share->auto_increment_value = share->auto_increment_value;
partition_share->auto_increment_value =
share->lgtm_tblhnd_share->auto_increment_value;
partition_share->records = share->records;
partition_share->mean_rec_length = share->mean_rec_length;
partition_share->check_time = share->check_time;
@ -5343,7 +5495,10 @@ void spider_copy_sts_to_share(
share->data_file_length = partition_share->data_file_length;
share->max_data_file_length = partition_share->max_data_file_length;
share->index_file_length = partition_share->index_file_length;
share->auto_increment_value = partition_share->auto_increment_value;
share->lgtm_tblhnd_share->auto_increment_value =
partition_share->auto_increment_value;
DBUG_PRINT("info",("spider auto_increment_value=%llu",
share->lgtm_tblhnd_share->auto_increment_value));
share->records = partition_share->records;
share->mean_rec_length = partition_share->mean_rec_length;
share->check_time = partition_share->check_time;
@ -5758,6 +5913,7 @@ int spider_db_done(
SPIDER_CONN *conn;
SPIDER_INIT_ERROR_TABLE *spider_init_error_table;
SPIDER_TABLE_MON_LIST *table_mon_list;
SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share;
DBUG_ENTER("spider_db_done");
#ifndef WITHOUT_SPIDER_BG_SEARCH
@ -5855,6 +6011,13 @@ int spider_db_done(
spider_free_conn(conn);
}
pthread_mutex_unlock(&spider_conn_mutex);
pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex);
while ((lgtm_tblhnd_share = (SPIDER_LGTM_TBLHND_SHARE*) my_hash_element(
&spider_lgtm_tblhnd_share_hash, 0)))
{
spider_free_lgtm_tblhnd_share_alloc(lgtm_tblhnd_share, TRUE);
}
pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex);
spider_free_mem_calc(spider_current_trx,
spider_mon_table_cache_id,
spider_mon_table_cache.max_element *
@ -5882,6 +6045,11 @@ int spider_db_done(
spider_open_connections.array.max_element *
spider_open_connections.array.size_of_element);
my_hash_free(&spider_open_connections);
spider_free_mem_calc(spider_current_trx,
spider_lgtm_tblhnd_share_hash_id,
spider_lgtm_tblhnd_share_hash.array.max_element *
spider_lgtm_tblhnd_share_hash.array.size_of_element);
my_hash_free(&spider_lgtm_tblhnd_share_hash);
#ifdef WITH_PARTITION_STORAGE_ENGINE
spider_free_mem_calc(spider_current_trx,
spider_open_pt_share_id,
@ -5926,6 +6094,7 @@ int spider_db_done(
pthread_mutex_destroy(&spider_hs_r_conn_mutex);
#endif
pthread_mutex_destroy(&spider_conn_mutex);
pthread_mutex_destroy(&spider_lgtm_tblhnd_share_mutex);
#ifdef WITH_PARTITION_STORAGE_ENGINE
pthread_mutex_destroy(&spider_pt_share_mutex);
#endif
@ -6132,6 +6301,16 @@ int spider_db_init(
goto error_pt_share_mutex_init;
}
#endif
#if MYSQL_VERSION_ID < 50500
if (pthread_mutex_init(&spider_lgtm_tblhnd_share_mutex, MY_MUTEX_INIT_FAST))
#else
if (mysql_mutex_init(spd_key_mutex_lgtm_tblhnd_share,
&spider_lgtm_tblhnd_share_mutex, MY_MUTEX_INIT_FAST))
#endif
{
error_num = HA_ERR_OUT_OF_MEM;
goto error_lgtm_tblhnd_share_mutex_init;
}
#if MYSQL_VERSION_ID < 50500
if (pthread_mutex_init(&spider_conn_mutex, MY_MUTEX_INIT_FAST))
#else
@ -6256,6 +6435,19 @@ int spider_db_init(
spider_open_pt_share.array.max_element *
spider_open_pt_share.array.size_of_element);
#endif
if(
my_hash_init(&spider_lgtm_tblhnd_share_hash, spd_charset_utf8_bin,
32, 0, 0,
(my_hash_get_key) spider_lgtm_tblhnd_share_hash_get_key, 0, 0)
) {
error_num = HA_ERR_OUT_OF_MEM;
goto error_lgtm_tblhnd_share_hash_init;
}
spider_alloc_calc_mem_init(spider_lgtm_tblhnd_share_hash, 245);
spider_alloc_calc_mem(NULL,
spider_lgtm_tblhnd_share_hash,
spider_lgtm_tblhnd_share_hash.array.max_element *
spider_lgtm_tblhnd_share_hash.array.size_of_element);
if(
my_hash_init(&spider_open_connections, spd_charset_utf8_bin, 32, 0, 0,
(my_hash_get_key) spider_conn_get_key, 0, 0)
@ -6476,6 +6668,12 @@ error_hs_r_conn_hash_init:
spider_open_connections.array.size_of_element);
my_hash_free(&spider_open_connections);
error_open_connections_hash_init:
spider_free_mem_calc(NULL,
spider_lgtm_tblhnd_share_hash_id,
spider_lgtm_tblhnd_share_hash.array.max_element *
spider_lgtm_tblhnd_share_hash.array.size_of_element);
my_hash_free(&spider_lgtm_tblhnd_share_hash);
error_lgtm_tblhnd_share_hash_init:
#ifdef WITH_PARTITION_STORAGE_ENGINE
spider_free_mem_calc(NULL,
spider_open_pt_share_id,
@ -6516,6 +6714,8 @@ error_global_trx_mutex_init:
#endif
pthread_mutex_destroy(&spider_conn_mutex);
error_conn_mutex_init:
pthread_mutex_destroy(&spider_lgtm_tblhnd_share_mutex);
error_lgtm_tblhnd_share_mutex_init:
#ifdef WITH_PARTITION_STORAGE_ENGINE
pthread_mutex_destroy(&spider_pt_share_mutex);
error_pt_share_mutex_init:
@ -7634,6 +7834,8 @@ bool spider_check_direct_order_limit(
DBUG_ENTER("spider_check_direct_order_limit");
DBUG_PRINT("info",("spider SQLCOM_HA_READ=%s",
(spider->sql_command == SQLCOM_HA_READ) ? "TRUE" : "FALSE"));
DBUG_PRINT("info",("spider sql_kinds with SPIDER_SQL_KIND_HANDLER=%s",
(spider->sql_kinds & SPIDER_SQL_KIND_HANDLER) ? "TRUE" : "FALSE"));
DBUG_PRINT("info",("spider has_clone_for_merge=%s",
spider->has_clone_for_merge ? "TRUE" : "FALSE"));
DBUG_PRINT("info",("spider is_clone=%s",
@ -7653,6 +7855,11 @@ bool spider_check_direct_order_limit(
) {
spider_get_select_limit(spider, &select_lex, &select_limit, &offset_limit);
bool first_check = TRUE;
DBUG_PRINT("info",("spider select_lex=%p", select_lex));
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
DBUG_PRINT("info",("spider leaf_tables.elements=%u",
select_lex->leaf_tables.elements));
#endif
#ifdef HANDLER_HAS_DIRECT_AGGREGATE
spider->result_list.direct_aggregate = TRUE;
#endif
@ -7666,6 +7873,9 @@ bool spider_check_direct_order_limit(
OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) ||
#endif
!select_lex ||
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
select_lex->leaf_tables.elements != 1 ||
#endif
select_lex->table_list.elements != 1
) {
DBUG_PRINT("info",("spider first_check is FALSE"));
@ -7685,6 +7895,10 @@ bool spider_check_direct_order_limit(
) {
DBUG_PRINT("info",("spider this SQL is not aggregate SQL"));
spider->result_list.direct_aggregate = FALSE;
} else if (spider->sql_kinds & SPIDER_SQL_KIND_HANDLER)
{
DBUG_PRINT("info",("spider sql_kinds with SPIDER_SQL_KIND_HANDLER"));
spider->result_list.direct_aggregate = FALSE;
} else {
ORDER *group;
for (group = (ORDER *) select_lex->group_list.first; group;
@ -7846,8 +8060,8 @@ int spider_discover_table_structure_internal(
SPIDER_SHARE *spider_share,
spider_string *str
) {
int error_num, roop_count;
DBUG_ENTER("spider_discover_table_structure");
int error_num = 0, roop_count;
DBUG_ENTER("spider_discover_table_structure_internal");
for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; roop_count++)
{
if (spider_bit_is_set(spider_share->dbton_bitmap, roop_count))
@ -7855,11 +8069,12 @@ int spider_discover_table_structure_internal(
if ((error_num = spider_share->dbton_share[roop_count]->
discover_table_structure(trx, spider_share, str)))
{
DBUG_RETURN(error_num);
continue;
}
break;
}
}
DBUG_RETURN(0);
DBUG_RETURN(error_num);
}
int spider_discover_table_structure(
@ -7929,6 +8144,22 @@ int spider_discover_table_structure(
error_num = spider_discover_table_structure_internal(trx, spider_share, &str);
if (!error_num)
{
Open_tables_backup open_tables_backup;
TABLE *table_tables;
if (
(table_tables = spider_open_sys_table(
thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, FALSE,
&error_num))
) {
error_num = spider_insert_tables(table_tables, spider_share);
spider_close_sys_table(thd, table_tables,
&open_tables_backup, FALSE);
}
}
spider_free_share_resource_only(spider_share);
#ifdef WITH_PARTITION_STORAGE_ENGINE
} else {
@ -7998,8 +8229,15 @@ int spider_discover_table_structure(
DBUG_RETURN(error_num);
str.length(str.length() - SPIDER_SQL_COMMA_LEN);
uint csnamelen = strlen(share->table_charset->csname);
uint collatelen = strlen(share->table_charset->name);
CHARSET_INFO *table_charset;
if (share->table_charset)
{
table_charset = share->table_charset;
} else {
table_charset = system_charset_info;
}
uint csnamelen = strlen(table_charset->csname);
uint collatelen = strlen(table_charset->name);
if (str.reserve(SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_DEFAULT_CHARSET_LEN +
csnamelen + SPIDER_SQL_COLLATE_LEN + collatelen +
SPIDER_SQL_CONNECTION_LEN + SPIDER_SQL_VALUE_QUOTE_LEN
@ -8008,9 +8246,9 @@ int spider_discover_table_structure(
}
str.q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN);
str.q_append(SPIDER_SQL_DEFAULT_CHARSET_STR, SPIDER_SQL_DEFAULT_CHARSET_LEN);
str.q_append(share->table_charset->csname, csnamelen);
str.q_append(table_charset->csname, csnamelen);
str.q_append(SPIDER_SQL_COLLATE_STR, SPIDER_SQL_COLLATE_LEN);
str.q_append(share->table_charset->name, collatelen);
str.q_append(table_charset->name, collatelen);
str.q_append(SPIDER_SQL_COMMENT_STR, SPIDER_SQL_COMMENT_LEN);
str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
if (str.append_for_single_quote(share->comment.str, share->comment.length))

View file

@ -152,6 +152,30 @@ int spider_create_conn_keys(
SPIDER_SHARE *share
);
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
SPIDER_LGTM_TBLHND_SHARE *spider_get_lgtm_tblhnd_share(
const char *table_name,
uint table_name_length,
my_hash_value_type hash_value,
bool locked,
bool need_to_create,
int *error_num
);
#else
SPIDER_LGTM_TBLHND_SHARE *spider_get_lgtm_tblhnd_share(
const char *table_name,
uint table_name_length,
bool locked,
bool need_to_create,
int *error_num
);
#endif
void spider_free_lgtm_tblhnd_share_alloc(
SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share,
bool locked
);
SPIDER_SHARE *spider_create_share(
const char *table_name,
TABLE_SHARE *table_share,