diff options
author | Kentoku SHIBA <kentokushiba@gmail.com> | 2020-09-04 22:10:57 +0900 |
---|---|---|
committer | Kentoku SHIBA <kentokushiba@gmail.com> | 2020-09-07 10:18:43 +0900 |
commit | 9dedba16ab12976487377208afe4721ea7b322ce (patch) | |
tree | f039cf8572116cd0d6cec0bd0ffe34c04cf76de4 | |
parent | c029d4562322d8c792f96717e0fb7f18d2379b2f (diff) | |
download | mariadb-git-9dedba16ab12976487377208afe4721ea7b322ce.tar.gz |
MDEV-7098 spider/bg.spider_fixes failed in buildbot with safe_mutex: Trying to unlock mutex conn->mta_conn_mutex that wasn't locked at storage/spider/spd_db_conn.cc, line 671
-rw-r--r-- | storage/spider/ha_spider.cc | 179 | ||||
-rw-r--r-- | storage/spider/spd_conn.cc | 22 | ||||
-rw-r--r-- | storage/spider/spd_db_conn.cc | 772 | ||||
-rw-r--r-- | storage/spider/spd_db_mysql.cc | 597 | ||||
-rw-r--r-- | storage/spider/spd_db_oracle.cc | 492 | ||||
-rw-r--r-- | storage/spider/spd_include.h | 4 | ||||
-rw-r--r-- | storage/spider/spd_table.cc | 7 |
7 files changed, 1534 insertions, 539 deletions
diff --git a/storage/spider/ha_spider.cc b/storage/spider/ha_spider.cc index fb453ddc637..5e7b5a1e8ce 100644 --- a/storage/spider/ha_spider.cc +++ b/storage/spider/ha_spider.cc @@ -2258,6 +2258,7 @@ int ha_spider::index_read_map_internal( } #endif spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -2265,6 +2266,11 @@ int ha_spider::index_read_map_internal( } if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) @@ -2286,11 +2292,15 @@ int ha_spider::index_read_map_internal( } else { #endif conn->need_mon = &need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(this, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -2325,6 +2335,8 @@ int ha_spider::index_read_map_internal( result_list.quick_mode, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -2351,6 +2363,8 @@ int ha_spider::index_read_map_internal( DBUG_RETURN(check_error_mode_eof(error_num)); } connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -2750,6 +2764,7 @@ int ha_spider::index_read_last_map_internal( } #endif spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -2757,6 +2772,11 @@ int ha_spider::index_read_last_map_internal( } if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) @@ -2775,11 +2795,15 @@ int ha_spider::index_read_last_map_internal( } else { #endif conn->need_mon = &need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(this, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -2814,6 +2838,8 @@ int ha_spider::index_read_last_map_internal( result_list.quick_mode, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -2840,6 +2866,8 @@ int ha_spider::index_read_last_map_internal( DBUG_RETURN(check_error_mode_eof(error_num)); } connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -3216,6 +3244,7 @@ int ha_spider::index_first_internal( } #endif spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -3224,6 +3253,11 @@ int ha_spider::index_first_internal( if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) @@ -3242,11 +3276,15 @@ int ha_spider::index_first_internal( } else { #endif conn->need_mon = &need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(this, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -3281,6 +3319,8 @@ int ha_spider::index_first_internal( result_list.quick_mode, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -3307,6 +3347,8 @@ int ha_spider::index_first_internal( DBUG_RETURN(check_error_mode_eof(error_num)); } connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -3600,6 +3642,7 @@ int ha_spider::index_last_internal( } #endif spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -3608,6 +3651,11 @@ int ha_spider::index_last_internal( if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) @@ -3626,11 +3674,15 @@ int ha_spider::index_last_internal( } else { #endif conn->need_mon = &need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(this, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -3665,6 +3717,8 @@ int ha_spider::index_last_internal( result_list.quick_mode, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -3691,6 +3745,8 @@ int ha_spider::index_last_internal( DBUG_RETURN(check_error_mode_eof(error_num)); } connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -4044,6 +4100,7 @@ int ha_spider::read_range_first_internal( } #endif spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -4051,6 +4108,11 @@ int ha_spider::read_range_first_internal( } if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) @@ -4069,11 +4131,15 @@ int ha_spider::read_range_first_internal( } else { #endif conn->need_mon = &need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(this, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -4108,6 +4174,8 @@ int ha_spider::read_range_first_internal( result_list.quick_mode, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -4134,6 +4202,8 @@ int ha_spider::read_range_first_internal( DBUG_RETURN(check_error_mode_eof(error_num)); } connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -4670,6 +4740,7 @@ int ha_spider::read_multi_range_first_internal( } #endif spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -4678,6 +4749,11 @@ int ha_spider::read_multi_range_first_internal( if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) @@ -4702,11 +4778,15 @@ int ha_spider::read_multi_range_first_internal( } else { #endif conn->need_mon = &need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(this, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -4742,6 +4822,8 @@ int ha_spider::read_multi_range_first_internal( result_list.quick_mode, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -4770,6 +4852,8 @@ int ha_spider::read_multi_range_first_internal( if (!error_num) { connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -5463,6 +5547,7 @@ int ha_spider::read_multi_range_first_internal( } #endif spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -5471,6 +5556,11 @@ int ha_spider::read_multi_range_first_internal( if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) @@ -5496,11 +5586,15 @@ int ha_spider::read_multi_range_first_internal( } else { #endif conn->need_mon = &need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(this, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5542,6 +5636,8 @@ int ha_spider::read_multi_range_first_internal( -1, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -5577,6 +5673,8 @@ int ha_spider::read_multi_range_first_internal( result_list.quick_mode, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -5603,6 +5701,8 @@ int ha_spider::read_multi_range_first_internal( break; } connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -6110,6 +6210,7 @@ int ha_spider::read_multi_range_next( } #endif spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -6118,6 +6219,11 @@ int ha_spider::read_multi_range_next( if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) @@ -6142,11 +6248,15 @@ int ha_spider::read_multi_range_next( } else { #endif conn->need_mon = &need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(this, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -6182,6 +6292,8 @@ int ha_spider::read_multi_range_next( result_list.quick_mode, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -6210,6 +6322,8 @@ int ha_spider::read_multi_range_next( if (!error_num) { connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -6907,6 +7021,7 @@ int ha_spider::read_multi_range_next( } #endif spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -6915,6 +7030,11 @@ int ha_spider::read_multi_range_next( if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) @@ -6940,11 +7060,15 @@ int ha_spider::read_multi_range_next( } else { #endif conn->need_mon = &need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(this, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -6986,6 +7110,8 @@ int ha_spider::read_multi_range_next( -1, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -7021,6 +7147,8 @@ int ha_spider::read_multi_range_next( result_list.quick_mode, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -7047,6 +7175,8 @@ int ha_spider::read_multi_range_next( break; } connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -7524,6 +7654,7 @@ int ha_spider::rnd_next_internal( sql_type = SPIDER_SQL_TYPE_HANDLER; } spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -7532,6 +7663,11 @@ int ha_spider::rnd_next_internal( if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) @@ -7541,11 +7677,15 @@ int ha_spider::rnd_next_internal( } DBUG_PRINT("info",("spider sql_type=%lu", sql_type)); conn->need_mon = &need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(this, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -7580,6 +7720,8 @@ int ha_spider::rnd_next_internal( result_list.quick_mode, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -7606,6 +7748,8 @@ int ha_spider::rnd_next_internal( DBUG_RETURN(check_error_mode_eof(error_num)); } connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -8116,6 +8260,7 @@ int ha_spider::ft_read_internal( uint dbton_id = share->use_sql_dbton_ids[roop_count]; spider_db_handler *dbton_hdl = dbton_handler[dbton_id]; SPIDER_CONN *conn = conns[roop_count]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec( SPIDER_SQL_TYPE_SELECT_SQL)) { @@ -8125,6 +8270,12 @@ int ha_spider::ft_read_internal( if ((error_num = dbton_hdl->set_sql_for_exec( SPIDER_SQL_TYPE_SELECT_SQL, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_SELECT_SQL)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec( @@ -8134,10 +8285,14 @@ int ha_spider::ft_read_internal( SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); } conn->need_mon = &need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(this, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -8171,6 +8326,8 @@ int ha_spider::ft_read_internal( result_list.quick_mode, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -8197,6 +8354,8 @@ int ha_spider::ft_read_internal( DBUG_RETURN(check_error_mode_eof(error_num)); } connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -10455,9 +10614,12 @@ void ha_spider::bulk_req_exec() if (conn->bulk_access_requests) { spider_bg_conn_wait(conn); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; /* currently only used for HS */ @@ -10475,6 +10637,8 @@ void ha_spider::bulk_req_exec() conn->bulk_access_sended += conn->bulk_access_requests; */ conn->bulk_access_requests = 0; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -12217,6 +12381,7 @@ int ha_spider::drop_tmp_tables() uint dbton_id = share->use_sql_dbton_ids[roop_count]; spider_db_handler *dbton_hdl = dbton_handler[dbton_id]; SPIDER_CONN *conn = conns[roop_count]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec( SPIDER_SQL_TYPE_TMP_SQL)) { @@ -12226,6 +12391,12 @@ int ha_spider::drop_tmp_tables() if ((error_num = dbton_hdl->set_sql_for_exec( SPIDER_SQL_TYPE_TMP_SQL, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_TMP_SQL)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec( @@ -12235,10 +12406,14 @@ int ha_spider::drop_tmp_tables() SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); } conn->need_mon = &need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((tmp_error_num = spider_db_set_names(this, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -12275,6 +12450,8 @@ int ha_spider::drop_tmp_tables() -1, &need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; tmp_error_num = spider_db_errorno(conn); @@ -12300,6 +12477,8 @@ int ha_spider::drop_tmp_tables() } error_num = tmp_error_num; } else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); diff --git a/storage/spider/spd_conn.cc b/storage/spider/spd_conn.cc index c1c2ce07476..30296215952 100644 --- a/storage/spider/spd_conn.cc +++ b/storage/spider/spd_conn.cc @@ -2385,6 +2385,7 @@ void *spider_bg_conn_action( sql_type = SPIDER_SQL_TYPE_SELECT_HS; } #endif + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -2414,6 +2415,8 @@ void *spider_bg_conn_action( if (!result_list->bgs_error) { conn->need_mon = &spider->need_mons[conn->link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; #ifdef HA_CAN_BULK_ACCESS @@ -2491,6 +2494,8 @@ void *spider_bg_conn_action( #ifdef HA_CAN_BULK_ACCESS } #endif + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -2501,11 +2506,14 @@ void *spider_bg_conn_action( } } else { spider->connection_ids[conn->link_idx] = conn->connection_id; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_unlock_later = TRUE; result_list->bgs_error = spider_db_store_result(spider, conn->link_idx, result_list->table); if ((result_list->bgs_error_with_message = thd->is_error())) strmov(result_list->bgs_error_msg, spider_stmt_da_message(thd)); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_unlock_later = FALSE; } conn->bg_search = FALSE; @@ -2569,12 +2577,26 @@ void *spider_bg_conn_action( { DBUG_PRINT("info",("spider bg exec sql start")); spider = (ha_spider*) conn->bg_target; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[conn->link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; *conn->bg_error_num = spider_db_query_with_set_names( conn->bg_sql_type, spider, conn, conn->link_idx ); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); conn->bg_exec_sql = FALSE; continue; } diff --git a/storage/spider/spd_db_conn.cc b/storage/spider/spd_db_conn.cc index 13ff6c568de..f77603d0d3a 100644 --- a/storage/spider/spd_db_conn.cc +++ b/storage/spider/spd_db_conn.cc @@ -208,23 +208,14 @@ int spider_db_ping( DBUG_PRINT("info", ("spider thd->query_id is %lld", spider->trx->thd->query_id)); #endif - if (!conn->mta_conn_mutex_lock_already) - { - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - conn->need_mon = &spider->need_mons[link_idx]; - } + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); if (conn->server_lost || conn->queued_connect) { if ((error_num = spider_db_connect(spider->share, conn, spider->conn_link_idx[link_idx]))) { - if (!conn->mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_RETURN(error_num); } conn->server_lost = FALSE; @@ -238,11 +229,7 @@ int spider_db_ping( { DBUG_PRINT("info", ("spider conn=%p SERVER_LOST", conn)); conn->server_lost = TRUE; - if (!conn->mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_RETURN(error_num); } if((error_num = conn->db_conn->ping())) @@ -250,20 +237,12 @@ int spider_db_ping( spider_db_disconnect(conn); DBUG_PRINT("info", ("spider conn=%p SERVER_LOST", conn)); conn->server_lost = TRUE; - if (!conn->mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_RETURN(error_num); } } conn->ping_time = (time_t) time((time_t*) 0); - if (!conn->mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_RETURN(0); } @@ -303,6 +282,7 @@ int spider_db_conn_queue_action( conn->queued_connect = FALSE; } + pthread_mutex_assert_owner(&conn->mta_conn_mutex); #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) if (conn->conn_kind == SPIDER_CONN_KIND_MYSQL) { @@ -551,7 +531,6 @@ int spider_db_before_query( int *need_mon ) { int error_num; - bool tmp_mta_conn_mutex_lock_already; DBUG_ENTER("spider_db_before_query"); DBUG_ASSERT(need_mon); #ifndef WITHOUT_SPIDER_BG_SEARCH @@ -559,25 +538,18 @@ int spider_db_before_query( spider_bg_conn_break(conn, NULL); #endif conn->in_before_query = TRUE; - if (!conn->mta_conn_mutex_lock_already) - { - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - conn->need_mon = need_mon; - } + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); - tmp_mta_conn_mutex_lock_already = conn->mta_conn_mutex_lock_already; - conn->mta_conn_mutex_lock_already = TRUE; if ((error_num = spider_db_conn_queue_action(conn))) { conn->in_before_query = FALSE; - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_RETURN(error_num); } - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; if (conn->server_lost) { conn->in_before_query = FALSE; + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_RETURN(CR_SERVER_GONE_ERROR); } DBUG_PRINT("info", ("spider conn[%p]->quick_target=%p", @@ -604,6 +576,7 @@ int spider_db_before_query( ) { conn->mta_conn_mutex_unlock_later = tmp_mta_conn_mutex_unlock_later; conn->in_before_query = FALSE; + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_RETURN(error_num); } } @@ -619,6 +592,7 @@ int spider_db_before_query( } } conn->in_before_query = FALSE; + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_RETURN(0); } @@ -631,6 +605,7 @@ int spider_db_query( ) { int error_num; DBUG_ENTER("spider_db_query"); + pthread_mutex_assert_owner(&conn->mta_conn_mutex); #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) if (conn->conn_kind == SPIDER_CONN_KIND_MYSQL) { @@ -673,6 +648,7 @@ int spider_db_errorno( int error_num; DBUG_ENTER("spider_db_errorno"); DBUG_ASSERT(conn->need_mon); + pthread_mutex_assert_owner(&conn->mta_conn_mutex); #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) if (conn->conn_kind == SPIDER_CONN_KIND_MYSQL) { @@ -687,6 +663,7 @@ int spider_db_errorno( } if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -708,6 +685,7 @@ int spider_db_errorno( } if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -720,6 +698,7 @@ int spider_db_errorno( conn->error_length = strlen(conn->error_str); if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -745,6 +724,7 @@ int spider_db_errorno( } if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -766,6 +746,7 @@ int spider_db_errorno( } if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -782,6 +763,7 @@ int spider_db_errorno( conn->server_lost = TRUE; if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -791,6 +773,7 @@ int spider_db_errorno( *conn->need_mon = 0; if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -813,6 +796,7 @@ int spider_db_errorno( *conn->need_mon = ER_SPIDER_HS_NUM; if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -821,6 +805,7 @@ int spider_db_errorno( #endif if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -843,33 +828,25 @@ int spider_db_set_names_internal( int all_link_idx, int *need_mon ) { - bool tmp_mta_conn_mutex_lock_already; DBUG_ENTER("spider_db_set_names_internal"); #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) if (conn->conn_kind == SPIDER_CONN_KIND_MYSQL) { #endif - if (!conn->mta_conn_mutex_lock_already) - { - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - conn->need_mon = need_mon; - } + pthread_mutex_assert_owner(&conn->mta_conn_mutex); DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); if ( !conn->access_charset || share->access_charset->cset != conn->access_charset->cset ) { - tmp_mta_conn_mutex_lock_already = conn->mta_conn_mutex_lock_already; - conn->mta_conn_mutex_lock_already = TRUE; if ( spider_db_before_query(conn, need_mon) || conn->db_conn->set_character_set(share->access_charset->csname) ) { - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; DBUG_RETURN(spider_db_errorno(conn)); } - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; conn->access_charset = share->access_charset; } if ( @@ -884,13 +861,10 @@ int spider_db_set_names_internal( ) { DBUG_PRINT("info",("spider all_link_idx=%d db=%s", all_link_idx, share->tgt_dbs[all_link_idx])); - tmp_mta_conn_mutex_lock_already = conn->mta_conn_mutex_lock_already; - conn->mta_conn_mutex_lock_already = TRUE; if ( spider_db_before_query(conn, need_mon) || conn->db_conn->select_db(share->tgt_dbs[all_link_idx]) ) { - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; DBUG_RETURN(spider_db_errorno(conn)); } conn->default_database.length(0); @@ -900,12 +874,6 @@ int spider_db_set_names_internal( conn->default_database.q_append(share->tgt_dbs[all_link_idx], share->tgt_dbs_lengths[all_link_idx] + 1); conn->default_database.length(share->tgt_dbs_lengths[all_link_idx]); - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; - } - if (!conn->mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); } #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) } @@ -934,19 +902,11 @@ int spider_db_query_with_set_names( spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; DBUG_ENTER("spider_db_query_with_set_names"); -/* - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); -*/ - conn->need_mon = &spider->need_mons[link_idx]; - conn->mta_conn_mutex_lock_already = TRUE; - conn->mta_conn_mutex_unlock_later = TRUE; + pthread_mutex_assert_owner(&conn->mta_conn_mutex); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); if ((error_num = spider_db_set_names(spider, conn, link_idx))) { - 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); if ( share->monitoring_kind[link_idx] && spider->need_mons[link_idx] @@ -977,8 +937,6 @@ int spider_db_query_with_set_names( -1, &spider->need_mons[link_idx]) ) { - conn->mta_conn_mutex_lock_already = FALSE; - conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); if ( share->monitoring_kind[link_idx] && @@ -1002,10 +960,6 @@ int spider_db_query_with_set_names( } DBUG_RETURN(error_num); } - 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); DBUG_RETURN(0); } @@ -1019,15 +973,16 @@ int spider_db_query_for_bulk_update( SPIDER_SHARE *share = spider->share; DBUG_ENTER("spider_db_query_for_bulk_update"); -/* - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); -*/ + pthread_mutex_assert_owner(&conn->mta_conn_mutex); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -1063,6 +1018,8 @@ int spider_db_query_for_bulk_update( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -1109,6 +1066,8 @@ int spider_db_query_for_bulk_update( } if (error_num > 0 && !conn->db_conn->is_dup_entry_error(error_num)) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -1135,6 +1094,8 @@ int spider_db_query_for_bulk_update( } DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -3644,6 +3605,7 @@ int spider_db_store_result( ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -3660,6 +3622,7 @@ int spider_db_store_result( ) { if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -3691,6 +3654,7 @@ int spider_db_store_result( ) { if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -3734,6 +3698,7 @@ int spider_db_store_result( ) { if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -3773,6 +3738,7 @@ int spider_db_store_result( { if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -3801,6 +3767,7 @@ int spider_db_store_result( #endif if (!conn->mta_conn_mutex_unlock_later && !call_db_errorno) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -3808,6 +3775,7 @@ int spider_db_store_result( } else { if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -3851,6 +3819,7 @@ int spider_db_store_result( result_list->limit_num -= current->prev->record_num; if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -3874,6 +3843,7 @@ int spider_db_store_result( } else { if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -3885,6 +3855,7 @@ int spider_db_store_result( spider->quick_targets[link_idx] = spider; if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -4043,6 +4014,7 @@ int spider_db_store_result( ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -4068,6 +4040,7 @@ int spider_db_store_result( } else { if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -4078,6 +4051,7 @@ int spider_db_store_result( result_list->hs_has_result = TRUE; if (!conn->mta_conn_mutex_unlock_later) { + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&conn->mta_conn_mutex); } @@ -4163,15 +4137,15 @@ int spider_db_bulk_store_result( error_num = spider_db_bulk_open_handler(spider, conn, link_idx); if (!discard_result) { - bool tmp_mta_conn_mutex_unlock_later; - tmp_mta_conn_mutex_unlock_later = conn->mta_conn_mutex_unlock_later; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_unlock_later = TRUE; if ((tmp_error_num = spider_db_store_result(spider, link_idx, spider->get_table()))) { error_num = tmp_error_num; } - conn->mta_conn_mutex_unlock_later = tmp_mta_conn_mutex_unlock_later; + conn->mta_conn_mutex_unlock_later = FALSE; } else { if (spider->connection_ids[link_idx] == conn->connection_id) spider_db_discard_result(spider, link_idx, conn); @@ -4381,10 +4355,14 @@ int spider_db_seek_next( SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); } conn->need_mon = &spider->need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -4420,6 +4398,8 @@ int spider_db_seek_next( result_list->quick_mode, &spider->need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -4447,6 +4427,8 @@ int spider_db_seek_next( DBUG_RETURN(error_num); } spider->connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -4487,6 +4469,8 @@ int spider_db_seek_next( } } else { spider->connection_ids[link_idx] = conn->connection_id; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_store_result(spider, link_idx, table))) { @@ -4613,6 +4597,7 @@ int spider_db_seek_last( } conn = spider->conns[roop_count]; spider_db_handler *dbton_handler = spider->dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -4620,6 +4605,11 @@ int spider_db_seek_last( } if ((error_num = dbton_handler->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) @@ -4629,10 +4619,14 @@ int spider_db_seek_last( } DBUG_PRINT("info",("spider sql_type=%lu", sql_type)); conn->need_mon = &spider->need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -4667,6 +4661,8 @@ int spider_db_seek_last( result_list->quick_mode, &spider->need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -4693,6 +4689,8 @@ int spider_db_seek_last( DBUG_RETURN(error_num); } spider->connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -4813,6 +4811,7 @@ int spider_db_seek_last( } conn = spider->conns[roop_count]; spider_db_handler *dbton_handler = spider->dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -4820,6 +4819,11 @@ int spider_db_seek_last( } if ((error_num = dbton_handler->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) @@ -4829,10 +4833,14 @@ int spider_db_seek_last( } DBUG_PRINT("info",("spider sql_type=%lu", sql_type)); conn->need_mon = &spider->need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -4867,6 +4875,8 @@ int spider_db_seek_last( result_list->quick_mode, &spider->need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -4893,6 +4903,8 @@ int spider_db_seek_last( DBUG_RETURN(error_num); } spider->connection_ids[roop_count] = conn->connection_id; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (roop_count == link_ok) @@ -5561,8 +5573,6 @@ int spider_db_bulk_insert( #endif SPIDER_SHARE *share = spider->share; THD *thd = spider->trx->thd; - bool mta_conn_mutex_lock_already_backup; - bool mta_conn_mutex_unlock_later_backup; DBUG_ENTER("spider_db_bulk_insert"); if (!bulk_end) @@ -5617,61 +5627,50 @@ int spider_db_bulk_insert( sql_type = SPIDER_SQL_TYPE_INSERT_SQL; conn = spider->conns[roop_count2]; dbton_handler = spider->dbton_handler[conn->dbton_id]; - mta_conn_mutex_lock_already_backup = - conn->mta_conn_mutex_lock_already; - mta_conn_mutex_unlock_later_backup = - conn->mta_conn_mutex_unlock_later; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) { - if (!mta_conn_mutex_lock_already_backup) - { - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - } + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); } if ((error_num = dbton_handler->set_sql_for_exec(sql_type, roop_count2))) { + if (dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) { - if (!mta_conn_mutex_lock_already_backup) - { - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - } + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); } #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) } else { sql_type = SPIDER_SQL_TYPE_INSERT_HS; conn = spider->hs_w_conns[roop_count2]; dbton_handler = spider->dbton_handler[conn->dbton_id]; - mta_conn_mutex_lock_already_backup = - conn->mta_conn_mutex_lock_already; - mta_conn_mutex_unlock_later_backup = - conn->mta_conn_mutex_unlock_later; - if (!mta_conn_mutex_lock_already_backup) - { - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); } #endif conn->need_mon = &spider->need_mons[roop_count2]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, roop_count2))) { - conn->mta_conn_mutex_lock_already = - mta_conn_mutex_lock_already_backup; - conn->mta_conn_mutex_unlock_later = - mta_conn_mutex_unlock_later_backup; - if (!mta_conn_mutex_unlock_later_backup) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); if ( share->monitoring_kind[roop_count2] && spider->need_mons[roop_count2] @@ -5709,15 +5708,12 @@ int spider_db_bulk_insert( { conn->db_conn->set_dup_key_idx(spider, roop_count2); } - conn->mta_conn_mutex_lock_already = - mta_conn_mutex_lock_already_backup; - conn->mta_conn_mutex_unlock_later = - mta_conn_mutex_unlock_later_backup; - if (!mta_conn_mutex_unlock_later_backup) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); if ( error_num != ER_DUP_ENTRY && error_num != ER_DUP_KEY && @@ -5743,8 +5739,10 @@ int spider_db_bulk_insert( } DBUG_RETURN(error_num); } - conn->mta_conn_mutex_lock_already = mta_conn_mutex_lock_already_backup; - conn->mta_conn_mutex_unlock_later = mta_conn_mutex_unlock_later_backup; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) if (conn->conn_kind != SPIDER_CONN_KIND_MYSQL) { @@ -5780,11 +5778,8 @@ int spider_db_bulk_insert( } } #endif - if (!mta_conn_mutex_unlock_later_backup) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); if (first_insert_link_idx == -1) { first_insert_link_idx = roop_count2; @@ -5793,14 +5788,12 @@ int spider_db_bulk_insert( } conn = first_insert_conn; - mta_conn_mutex_lock_already_backup = conn->mta_conn_mutex_lock_already; - mta_conn_mutex_unlock_later_backup = conn->mta_conn_mutex_unlock_later; - if (!mta_conn_mutex_lock_already_backup) - { - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[first_insert_link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if (spider->sql_kinds & SPIDER_SQL_KIND_SQL) @@ -5822,15 +5815,12 @@ int spider_db_bulk_insert( else if ((error_num = dbton_handler-> show_last_insert_id(first_insert_link_idx, last_insert_id))) { - conn->mta_conn_mutex_lock_already = - mta_conn_mutex_lock_already_backup; - conn->mta_conn_mutex_unlock_later = - mta_conn_mutex_unlock_later_backup; - if (!mta_conn_mutex_unlock_later_backup) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); DBUG_RETURN(error_num); } table->next_number_field->set_notnull(); @@ -5840,25 +5830,21 @@ int spider_db_bulk_insert( (error_num = table->next_number_field->store( last_insert_id, TRUE)) ) { - conn->mta_conn_mutex_lock_already = - mta_conn_mutex_lock_already_backup; - conn->mta_conn_mutex_unlock_later = - mta_conn_mutex_unlock_later_backup; - if (!mta_conn_mutex_unlock_later_backup) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); DBUG_RETURN(error_num); } } - conn->mta_conn_mutex_lock_already = mta_conn_mutex_lock_already_backup; - conn->mta_conn_mutex_unlock_later = mta_conn_mutex_unlock_later_backup; - if (!mta_conn_mutex_unlock_later_backup) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); spider->store_last_insert_id = 0; #ifdef HA_CAN_BULK_ACCESS } @@ -5902,8 +5888,11 @@ int spider_db_bulk_bulk_insert( conn = spider->hs_w_conns[roop_count2]; } #endif + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((tmp_error_num = spider_db_bulk_open_handler(spider, conn, @@ -5911,6 +5900,8 @@ int spider_db_bulk_bulk_insert( { error_num = tmp_error_num; } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) @@ -5959,9 +5950,12 @@ int spider_db_bulk_bulk_insert( } conn = first_insert_conn; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[first_insert_link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if (table->next_number_field && @@ -5988,6 +5982,8 @@ int spider_db_bulk_bulk_insert( error_num = tmp_error_num; } } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -6115,6 +6111,7 @@ int spider_db_bulk_update_size_limit( ) { conn = spider->conns[roop_count]; spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec( SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) { @@ -6124,6 +6121,12 @@ int spider_db_bulk_update_size_limit( if ((error_num = dbton_hdl->set_sql_for_exec( SPIDER_SQL_TYPE_BULK_UPDATE_SQL, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec( @@ -6134,7 +6137,11 @@ int spider_db_bulk_update_size_limit( } if ((error_num = spider_db_query_for_bulk_update( spider, conn, roop_count, &dup_key_found))) + { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); DBUG_RETURN(error_num); + } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); } spider->reset_sql_sql(SPIDER_SQL_TYPE_BULK_UPDATE_SQL); } else { @@ -6200,6 +6207,7 @@ int spider_db_bulk_update_end( ) { conn = spider->conns[roop_count]; spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec( SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) { @@ -6209,14 +6217,14 @@ int spider_db_bulk_update_end( if ((error_num = dbton_hdl->set_sql_for_exec( SPIDER_SQL_TYPE_BULK_UPDATE_SQL, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } if (error_num == ER_SPIDER_COND_SKIP_NUM) { - if (dbton_hdl->need_lock_before_set_sql_for_exec( - SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } continue; } DBUG_RETURN(error_num); @@ -6229,7 +6237,11 @@ int spider_db_bulk_update_end( } if ((error_num = spider_db_query_for_bulk_update( spider, conn, roop_count, dup_key_found))) + { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); goto error_query; + } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); } } if (error_num != HA_ERR_END_OF_FILE) @@ -6254,6 +6266,7 @@ int spider_db_bulk_update_end( ) { conn = spider->conns[roop_count]; spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec( SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) { @@ -6263,6 +6276,12 @@ int spider_db_bulk_update_end( if ((error_num = dbton_hdl->set_sql_for_exec( SPIDER_SQL_TYPE_BULK_UPDATE_SQL, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_BULK_UPDATE_SQL)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec( @@ -6273,7 +6292,11 @@ int spider_db_bulk_update_end( } if ((error_num = spider_db_query_for_bulk_update( spider, conn, roop_count, dup_key_found))) + { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); goto error_last_query; + } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); } } } @@ -6341,6 +6364,7 @@ int spider_db_update( #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 conn->ignore_dup_key = spider->ignore_dup_key; #endif + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec( SPIDER_SQL_TYPE_UPDATE_SQL)) { @@ -6350,6 +6374,12 @@ int spider_db_update( if ((error_num = dbton_hdl->set_sql_for_exec( SPIDER_SQL_TYPE_UPDATE_SQL, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_UPDATE_SQL)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec( @@ -6359,10 +6389,14 @@ int spider_db_update( SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); } conn->need_mon = &spider->need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -6397,6 +6431,8 @@ int spider_db_update( -1, &spider->need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -6435,6 +6471,8 @@ int spider_db_update( if ((error_num = dbton_hdl->append_insert_for_recovery( SPIDER_SQL_TYPE_INSERT_SQL, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -6449,6 +6487,8 @@ int spider_db_update( -1, &spider->need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -6478,6 +6518,8 @@ int spider_db_update( DBUG_RETURN(error_num); } } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -6666,6 +6708,7 @@ int spider_db_direct_update( } #endif spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -6673,6 +6716,11 @@ int spider_db_direct_update( } if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) @@ -6688,10 +6736,14 @@ int spider_db_direct_update( } else { #endif conn->need_mon = &spider->need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -6729,6 +6781,8 @@ int spider_db_direct_update( ) && (error_num != HA_ERR_FOUND_DUPP_KEY || !spider->ignore_dup_key) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -6795,6 +6849,8 @@ int spider_db_direct_update( { error_num = spider_db_errorno(conn); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -6803,11 +6859,13 @@ int spider_db_direct_update( } } #endif + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; #ifdef HA_CAN_BULK_ACCESS } #endif - 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); } @@ -6852,8 +6910,11 @@ int spider_db_bulk_direct_update( conn = spider->hs_w_conns[roop_count]; } #endif + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((tmp_error_num = spider_db_bulk_open_handler(spider, conn, @@ -6899,6 +6960,8 @@ int spider_db_bulk_direct_update( { error_num = spider_db_errorno(conn); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -6907,6 +6970,8 @@ int spider_db_bulk_direct_update( } } #endif + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -6963,6 +7028,7 @@ int spider_db_delete( ) { conn = spider->conns[roop_count]; spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec( SPIDER_SQL_TYPE_DELETE_SQL)) { @@ -6972,6 +7038,12 @@ int spider_db_delete( if ((error_num = dbton_hdl->set_sql_for_exec( SPIDER_SQL_TYPE_DELETE_SQL, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_DELETE_SQL)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec( @@ -6980,9 +7052,27 @@ int spider_db_delete( pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); } + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_query_with_set_names( SPIDER_SQL_TYPE_DELETE_SQL, spider, conn, roop_count))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); DBUG_RETURN(error_num); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); result_list->update_sqls[roop_count].length(0); } if ((error_num = spider->reset_sql_sql(SPIDER_SQL_TYPE_DELETE_SQL))) @@ -7094,6 +7184,7 @@ int spider_db_direct_delete( } #endif spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) { pthread_mutex_lock(&conn->mta_conn_mutex); @@ -7101,6 +7192,11 @@ int spider_db_direct_delete( } if ((error_num = dbton_hdl->set_sql_for_exec(sql_type, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec(sql_type)) @@ -7116,10 +7212,14 @@ int spider_db_direct_delete( } else { #endif conn->need_mon = &spider->need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -7154,6 +7254,8 @@ int spider_db_direct_delete( -1, &spider->need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -7179,6 +7281,8 @@ int spider_db_direct_delete( } DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) @@ -7271,6 +7375,7 @@ int spider_db_delete_all_rows( uint dbton_id = share->use_sql_dbton_ids[roop_count]; spider_db_handler *dbton_hdl = spider->dbton_handler[dbton_id]; conn = spider->conns[roop_count]; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); if (dbton_hdl->need_lock_before_set_sql_for_exec( SPIDER_SQL_TYPE_DELETE_SQL)) { @@ -7280,6 +7385,12 @@ int spider_db_delete_all_rows( if ((error_num = dbton_hdl->set_sql_for_exec( SPIDER_SQL_TYPE_DELETE_SQL, roop_count))) { + if (dbton_hdl->need_lock_before_set_sql_for_exec( + SPIDER_SQL_TYPE_DELETE_SQL)) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(error_num); } if (!dbton_hdl->need_lock_before_set_sql_for_exec( @@ -7289,6 +7400,8 @@ int spider_db_delete_all_rows( SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); } conn->need_mon = &spider->need_mons[roop_count]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(conn, roop_count, spider->trx->thd, @@ -7311,6 +7424,8 @@ int spider_db_delete_all_rows( /* retry */ if ((error_num = spider_db_ping(spider, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -7339,6 +7454,8 @@ int spider_db_delete_all_rows( } if ((error_num = spider_db_set_names(spider, conn, roop_count))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -7373,6 +7490,8 @@ int spider_db_delete_all_rows( -1, &spider->need_mons[roop_count]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -7399,6 +7518,8 @@ int spider_db_delete_all_rows( DBUG_RETURN(error_num); } } else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -7426,6 +7547,8 @@ int spider_db_delete_all_rows( DBUG_RETURN(error_num); } } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -8807,7 +8930,14 @@ int spider_db_udf_direct_sql( c_thd->lex->sql_command = SQLCOM_INSERT; #endif + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if ( !(error_num = spider_db_udf_direct_sql_set_names(direct_sql, trx, conn)) && !(error_num = spider_db_udf_direct_sql_select_db(direct_sql, conn)) @@ -8830,9 +8960,6 @@ int spider_db_udf_direct_sql( #endif DBUG_RETURN(error_num); } - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); } #endif spider_conn_set_timeout_from_direct_sql(conn, thd, direct_sql); @@ -8851,8 +8978,6 @@ int spider_db_udf_direct_sql( DBUG_PRINT("info",("spider conn=%p", conn)); if (!direct_sql->table_count) roop_count = -1; - conn->mta_conn_mutex_lock_already = TRUE; - conn->mta_conn_mutex_unlock_later = TRUE; do { if (roop_count == direct_sql->table_count) { @@ -9064,12 +9189,14 @@ int spider_db_udf_direct_sql( if (roop_count >= 0) roop_count++; } while (status == 0); - 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); } } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); if (need_trx_end && insert_start) { if (error_num) @@ -9099,19 +9226,13 @@ int spider_db_udf_direct_sql_select_db( SPIDER_CONN *conn ) { int error_num, need_mon = 0; - bool tmp_mta_conn_mutex_lock_already; SPIDER_DB_CONN *db_conn = conn->db_conn; DBUG_ENTER("spider_db_udf_direct_sql_select_db"); + pthread_mutex_assert_owner(&conn->mta_conn_mutex); #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) if (direct_sql->access_mode == 0) { #endif - if (!conn->mta_conn_mutex_lock_already) - { - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - conn->need_mon = &need_mon; - } DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); if ( !conn->default_database.length() || @@ -9120,8 +9241,6 @@ int spider_db_udf_direct_sql_select_db( memcmp(direct_sql->tgt_default_db_name, conn->default_database.ptr(), direct_sql->tgt_default_db_name_length) ) { - tmp_mta_conn_mutex_lock_already = conn->mta_conn_mutex_lock_already; - conn->mta_conn_mutex_lock_already = TRUE; if ( ( spider_db_before_query(conn, &need_mon) || @@ -9135,7 +9254,6 @@ int spider_db_udf_direct_sql_select_db( ) my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM, ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; DBUG_RETURN(error_num); } conn->default_database.length(0); @@ -9145,12 +9263,6 @@ int spider_db_udf_direct_sql_select_db( conn->default_database.q_append(direct_sql->tgt_default_db_name, direct_sql->tgt_default_db_name_length + 1); conn->default_database.length(direct_sql->tgt_default_db_name_length); - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; - } - if (!conn->mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); } #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) } @@ -9164,25 +9276,17 @@ int spider_db_udf_direct_sql_set_names( SPIDER_CONN *conn ) { int error_num, need_mon = 0; - bool tmp_mta_conn_mutex_lock_already; DBUG_ENTER("spider_db_udf_direct_sql_set_names"); + pthread_mutex_assert_owner(&conn->mta_conn_mutex); #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) if (direct_sql->access_mode == 0) { #endif - if (!conn->mta_conn_mutex_lock_already) - { - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - conn->need_mon = &need_mon; - } DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); if ( !conn->access_charset || trx->udf_access_charset->cset != conn->access_charset->cset ) { - tmp_mta_conn_mutex_lock_already = conn->mta_conn_mutex_lock_already; - conn->mta_conn_mutex_lock_already = TRUE; if ( ( spider_db_before_query(conn, &need_mon) || @@ -9197,17 +9301,10 @@ int spider_db_udf_direct_sql_set_names( my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM, ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); } - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; DBUG_RETURN(error_num); } - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; conn->access_charset = trx->udf_access_charset; } - if (!conn->mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) } #endif @@ -9271,13 +9368,18 @@ int spider_db_udf_ping_table( spider.conn_link_idx = &tmp_conn_link_idx; spider.db_request_phase = &db_request_phase; spider.db_request_id = &db_request_id; + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_ping(&spider, conn, 0))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -9293,6 +9395,8 @@ int spider_db_udf_ping_table( share->server_names[0]); DBUG_RETURN(ER_CONNECT_TO_FOREIGN_DATA_SOURCE); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -9336,13 +9440,18 @@ int spider_db_udf_ping_table( my_error(error_num, MYF(0)); DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(&spider, conn, 0))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -9360,6 +9469,8 @@ int spider_db_udf_ping_table( -1, &need_mon) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); @@ -9368,6 +9479,8 @@ int spider_db_udf_ping_table( DBUG_PRINT("info",("spider error_num=%d", error_num)); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; spider_db_discard_result(&spider, 0, conn); @@ -9553,13 +9666,18 @@ int spider_db_udf_ping_table_mon_next( DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_ping(&spider, conn, 0))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -9570,6 +9688,8 @@ int spider_db_udf_ping_table_mon_next( } if ((error_num = spider_db_set_names(&spider, conn, 0))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -9584,6 +9704,8 @@ int spider_db_udf_ping_table_mon_next( -1, &need_mon) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); @@ -9596,13 +9718,25 @@ int spider_db_udf_ping_table_mon_next( request_key.next = NULL; if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; - if (error_num || (error_num = spider_db_errorno(conn))) + if (error_num) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + else if ((error_num = spider_db_errorno(conn))) + { DBUG_RETURN(error_num); + } my_error(HA_ERR_OUT_OF_MEM, MYF(0)); DBUG_RETURN(HA_ERR_OUT_OF_MEM); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -9683,8 +9817,22 @@ int spider_db_udf_copy_tables( spider_conn_clear_queue_at_commit(tmp_conn); if (!tmp_conn->trx_start) { + pthread_mutex_assert_not_owner(&tmp_conn->mta_conn_mutex); + pthread_mutex_lock(&tmp_conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + tmp_conn->need_mon = &tmp_spider->need_mons[0]; + DBUG_ASSERT(!tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = TRUE; + tmp_conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_ping(tmp_spider, tmp_conn, 0)) { + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), tmp_spider->share->server_names[0]); error_num = ER_CONNECT_TO_FOREIGN_DATA_SOURCE; @@ -9694,8 +9842,21 @@ int spider_db_udf_copy_tables( (error_num = spider_db_set_names(tmp_spider, tmp_conn, 0)) || (error_num = spider_db_start_transaction(tmp_conn, tmp_spider->need_mons)) - ) + ) { + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); goto error_start_transaction; + } + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); } } } else { @@ -9715,8 +9876,22 @@ int spider_db_udf_copy_tables( { tmp_spider = &spider[roop_count]; tmp_conn = tmp_spider->conns[0]; + pthread_mutex_assert_not_owner(&tmp_conn->mta_conn_mutex); + pthread_mutex_lock(&tmp_conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + tmp_conn->need_mon = &tmp_spider->need_mons[0]; + DBUG_ASSERT(!tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = TRUE; + tmp_conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_ping(tmp_spider, tmp_conn, 0)) { + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), tmp_spider->share->server_names[0]); error_num = ER_CONNECT_TO_FOREIGN_DATA_SOURCE; @@ -9729,11 +9904,23 @@ int spider_db_udf_copy_tables( (error_num = spider_db_lock_tables(tmp_spider, 0)) ) ) { + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); tmp_conn->table_lock = 0; if (error_num == HA_ERR_OUT_OF_MEM) my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); goto error_lock_tables; } + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); tmp_conn->table_lock = 1; } } @@ -9741,11 +9928,23 @@ int spider_db_udf_copy_tables( tmp_conn = src_tbl_conn->conn; spider_conn_set_timeout_from_share(tmp_conn, 0, copy_tables->trx->thd, src_tbl_conn->share); + pthread_mutex_assert_not_owner(&tmp_conn->mta_conn_mutex); + pthread_mutex_lock(&tmp_conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + tmp_conn->need_mon = &src_tbl_conn->need_mon; + DBUG_ASSERT(!tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = TRUE; + tmp_conn->mta_conn_mutex_unlock_later = TRUE; if (select_ct->exec_query( tmp_conn, -1, &src_tbl_conn->need_mon) ) { + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(tmp_conn); if (error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM) my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM, @@ -9774,6 +9973,10 @@ int spider_db_udf_copy_tables( my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); result->free_result(); delete result; + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); goto error_db_query; @@ -9789,6 +9992,10 @@ int spider_db_udf_copy_tables( my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); result->free_result(); delete result; + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); goto error_db_query; @@ -9815,6 +10022,10 @@ int spider_db_udf_copy_tables( my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); result->free_result(); delete result; + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); goto error_db_query; @@ -9832,6 +10043,10 @@ int spider_db_udf_copy_tables( my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); result->free_result(); delete result; + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); error_num = ER_OUT_OF_RESOURCES; @@ -9844,12 +10059,20 @@ int spider_db_udf_copy_tables( my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); result->free_result(); delete result; + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); goto error_db_query; } result->free_result(); delete result; + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); for (dst_tbl_conn = copy_tables->table_conn[1]; dst_tbl_conn; @@ -9870,6 +10093,12 @@ int spider_db_udf_copy_tables( } if (error_num) { + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; + SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); if (error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM) my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM, ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); @@ -9877,6 +10106,10 @@ int spider_db_udf_copy_tables( } error_num = HA_ERR_END_OF_FILE; end_of_file = TRUE; + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); + tmp_conn->mta_conn_mutex_lock_already = FALSE; + tmp_conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); pthread_mutex_unlock(&tmp_conn->mta_conn_mutex); } @@ -9919,9 +10152,12 @@ int spider_db_udf_copy_tables( { tmp_conn = dst_tbl_conn->conn; insert_ct = dst_tbl_conn->copy_table; + pthread_mutex_assert_not_owner(&tmp_conn->mta_conn_mutex); pthread_mutex_lock(&tmp_conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); tmp_conn->need_mon = &dst_tbl_conn->need_mon; + DBUG_ASSERT(!tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!tmp_conn->mta_conn_mutex_unlock_later); tmp_conn->mta_conn_mutex_lock_already = TRUE; tmp_conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(tmp_conn, 0, @@ -9931,6 +10167,8 @@ int spider_db_udf_copy_tables( -1, &dst_tbl_conn->need_mon) ) { + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); tmp_conn->mta_conn_mutex_lock_already = FALSE; tmp_conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(tmp_conn); @@ -9939,6 +10177,8 @@ int spider_db_udf_copy_tables( ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0)); goto error_db_query; } else { + DBUG_ASSERT(tmp_conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(tmp_conn->mta_conn_mutex_unlock_later); tmp_conn->mta_conn_mutex_lock_already = FALSE; tmp_conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&tmp_conn->mta_conn_mutex_file_pos); @@ -10079,8 +10319,6 @@ int spider_db_open_handler( int link_idx ) { int error_num; - bool tmp_mta_conn_mutex_lock_already; - bool tmp_mta_conn_mutex_unlock_later; SPIDER_SHARE *share = spider->share; uint *handler_id_ptr = #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) @@ -10095,16 +10333,14 @@ int spider_db_open_handler( ; spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; DBUG_ENTER("spider_db_open_handler"); - if (!conn->mta_conn_mutex_lock_already) - { - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - conn->need_mon = &spider->need_mons[link_idx]; - } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); - tmp_mta_conn_mutex_lock_already = conn->mta_conn_mutex_lock_already; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; - tmp_mta_conn_mutex_unlock_later = conn->mta_conn_mutex_unlock_later; conn->mta_conn_mutex_unlock_later = TRUE; if (!spider->handler_opened(link_idx, conn->conn_kind)) *handler_id_ptr = conn->opened_handlers; @@ -10153,11 +10389,6 @@ int spider_db_open_handler( { my_printf_error(ER_SPIDER_HS_NUM, ER_SPIDER_HS_STR, MYF(0), conn->db_conn->get_errno(), conn->db_conn->get_error()); - if (!conn->mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } spider->need_mons[link_idx] = ER_SPIDER_HS_NUM; error_num = ER_SPIDER_HS_NUM; goto error; @@ -10293,23 +10524,21 @@ int spider_db_open_handler( } DBUG_PRINT("info",("spider conn=%p", conn)); DBUG_PRINT("info",("spider opened_handlers=%u", conn->opened_handlers)); - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; - conn->mta_conn_mutex_unlock_later = tmp_mta_conn_mutex_unlock_later; - if (!tmp_mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); DBUG_RETURN(0); error: - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; - conn->mta_conn_mutex_unlock_later = tmp_mta_conn_mutex_unlock_later; - if (!tmp_mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); DBUG_RETURN(error_num); } @@ -10359,6 +10588,7 @@ int spider_db_bulk_open_handler( } bool tmp_mta_conn_mutex_unlock_later; + pthread_mutex_assert_owner(&conn->mta_conn_mutex); tmp_mta_conn_mutex_unlock_later = conn->mta_conn_mutex_unlock_later; conn->mta_conn_mutex_unlock_later = TRUE; SPIDER_DB_RESULT *result; @@ -10397,24 +10627,19 @@ int spider_db_close_handler( uint tgt_conn_kind ) { int error_num; - bool tmp_mta_conn_mutex_lock_already; - bool tmp_mta_conn_mutex_unlock_later; spider_db_handler *dbton_hdl = spider->dbton_handler[conn->dbton_id]; DBUG_ENTER("spider_db_close_handler"); DBUG_PRINT("info",("spider conn=%p", conn)); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider->handler_opened(link_idx, tgt_conn_kind)) { - if (!conn->mta_conn_mutex_lock_already) - { - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - conn->need_mon = &spider->need_mons[link_idx]; - } - DBUG_ASSERT(conn->mta_conn_mutex_file_pos.file_name); - tmp_mta_conn_mutex_lock_already = conn->mta_conn_mutex_lock_already; - conn->mta_conn_mutex_lock_already = TRUE; - tmp_mta_conn_mutex_unlock_later = conn->mta_conn_mutex_unlock_later; - conn->mta_conn_mutex_unlock_later = TRUE; #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) if (conn->conn_kind == SPIDER_CONN_KIND_MYSQL) { @@ -10422,7 +10647,15 @@ int spider_db_close_handler( dbton_hdl->reset_sql(SPIDER_SQL_TYPE_HANDLER); if ((error_num = dbton_hdl->append_close_handler_part( SPIDER_SQL_TYPE_HANDLER, link_idx))) + { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); DBUG_RETURN(error_num); + } spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, spider->share); @@ -10448,24 +10681,22 @@ int spider_db_close_handler( goto error; conn->opened_handlers--; DBUG_PRINT("info",("spider opened_handlers=%u", conn->opened_handlers)); - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; - conn->mta_conn_mutex_unlock_later = tmp_mta_conn_mutex_unlock_later; - if (!tmp_mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); DBUG_RETURN(0); error: - conn->mta_conn_mutex_lock_already = tmp_mta_conn_mutex_lock_already; - conn->mta_conn_mutex_unlock_later = tmp_mta_conn_mutex_unlock_later; - if (!tmp_mta_conn_mutex_unlock_later) - { - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); - } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); DBUG_RETURN(error_num); } @@ -10502,3 +10733,4 @@ bool spider_db_conn_is_network_error( } DBUG_RETURN(FALSE); } + diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index 2be4c810c06..9ed29d015b3 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -1844,10 +1844,6 @@ void spider_db_mysql::print_warnings( if (!(db_conn->server_status & SERVER_MORE_RESULTS_EXISTS)) #endif { -/* - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); -*/ if ( spider_param_dry_access() || !mysql_real_query(db_conn, SPIDER_SQL_SHOW_WARNINGS_STR, @@ -1865,18 +1861,10 @@ void spider_db_mysql::print_warnings( { if (res) mysql_free_result(res); -/* - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); -*/ DBUG_VOID_RETURN; } /* no record is ok */ } -/* - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); -*/ num_fields = mysql_num_fields(res); if (num_fields != 3) { @@ -1895,11 +1883,6 @@ void spider_db_mysql::print_warnings( } if (res) mysql_free_result(res); - } else { -/* - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); -*/ } } } @@ -2039,14 +2022,31 @@ int spider_db_mysql::consistent_snapshot( ) { DBUG_ENTER("spider_db_mysql::consistent_snapshot"); DBUG_PRINT("info",("spider this=%p", this)); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_START_CONSISTENT_SNAPSHOT_STR, SPIDER_SQL_START_CONSISTENT_SNAPSHOT_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); DBUG_RETURN(0); @@ -2064,16 +2064,18 @@ int spider_db_mysql::start_transaction( ) { DBUG_ENTER("spider_db_mysql::start_transaction"); DBUG_PRINT("info",("spider this=%p", this)); + pthread_mutex_assert_owner(&conn->mta_conn_mutex); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); if (spider_db_query( conn, SPIDER_SQL_START_TRANSACTION_STR, SPIDER_SQL_START_TRANSACTION_LEN, -1, need_mon) - ) + ) { DBUG_RETURN(spider_db_errorno(conn)); - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(0); } @@ -2082,14 +2084,31 @@ int spider_db_mysql::commit( ) { DBUG_ENTER("spider_db_mysql::commit"); DBUG_PRINT("info",("spider this=%p", this)); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_COMMIT_STR, SPIDER_SQL_COMMIT_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); DBUG_RETURN(0); @@ -2102,6 +2121,13 @@ int spider_db_mysql::rollback( int error_num; DBUG_ENTER("spider_db_mysql::rollback"); DBUG_PRINT("info",("spider this=%p", this)); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, @@ -2118,12 +2144,18 @@ int spider_db_mysql::rollback( ) conn->thd->clear_error(); else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); DBUG_RETURN(error_num); } } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); @@ -2160,14 +2192,31 @@ int spider_db_mysql::xa_end( sql_str.length(0); sql_str.q_append(SPIDER_SQL_XA_END_STR, SPIDER_SQL_XA_END_LEN); spider_db_append_xid_str(&sql_str, xid); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, sql_str.ptr(), sql_str.length(), -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); DBUG_RETURN(0); @@ -2186,14 +2235,31 @@ int spider_db_mysql::xa_prepare( sql_str.length(0); sql_str.q_append(SPIDER_SQL_XA_PREPARE_STR, SPIDER_SQL_XA_PREPARE_LEN); spider_db_append_xid_str(&sql_str, xid); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, sql_str.ptr(), sql_str.length(), -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); DBUG_RETURN(0); @@ -2212,14 +2278,31 @@ int spider_db_mysql::xa_commit( sql_str.length(0); sql_str.q_append(SPIDER_SQL_XA_COMMIT_STR, SPIDER_SQL_XA_COMMIT_LEN); spider_db_append_xid_str(&sql_str, xid); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, sql_str.ptr(), sql_str.length(), -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); DBUG_RETURN(0); @@ -2238,14 +2321,31 @@ int spider_db_mysql::xa_rollback( sql_str.length(0); sql_str.q_append(SPIDER_SQL_XA_ROLLBACK_STR, SPIDER_SQL_XA_ROLLBACK_LEN); spider_db_append_xid_str(&sql_str, xid); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, sql_str.ptr(), sql_str.length(), -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); DBUG_RETURN(0); @@ -2267,50 +2367,118 @@ int spider_db_mysql::set_trx_isolation( switch (trx_isolation) { case ISO_READ_UNCOMMITTED: + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_ISO_READ_UNCOMMITTED_STR, SPIDER_SQL_ISO_READ_UNCOMMITTED_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); break; case ISO_READ_COMMITTED: + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_ISO_READ_COMMITTED_STR, SPIDER_SQL_ISO_READ_COMMITTED_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); break; case ISO_REPEATABLE_READ: + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_ISO_REPEATABLE_READ_STR, SPIDER_SQL_ISO_REPEATABLE_READ_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); break; case ISO_SERIALIZABLE: + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_ISO_SERIALIZABLE_STR, SPIDER_SQL_ISO_SERIALIZABLE_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); break; @@ -2335,25 +2503,59 @@ int spider_db_mysql::set_autocommit( DBUG_PRINT("info",("spider this=%p", this)); if (autocommit) { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_AUTOCOMMIT_ON_STR, SPIDER_SQL_AUTOCOMMIT_ON_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); } else { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_AUTOCOMMIT_OFF_STR, SPIDER_SQL_AUTOCOMMIT_OFF_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); } @@ -2375,25 +2577,59 @@ int spider_db_mysql::set_sql_log_off( DBUG_PRINT("info",("spider this=%p", this)); if (sql_log_off) { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_SQL_LOG_ON_STR, SPIDER_SQL_SQL_LOG_ON_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); } else { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_SQL_LOG_OFF_STR, SPIDER_SQL_SQL_LOG_OFF_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); } @@ -2424,14 +2660,31 @@ int spider_db_mysql::set_time_zone( sql_str.q_append(SPIDER_SQL_TIME_ZONE_STR, SPIDER_SQL_TIME_ZONE_LEN); sql_str.q_append(tz_str->ptr(), tz_str->length()); sql_str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, sql_str.ptr(), sql_str.length(), -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); DBUG_RETURN(0); @@ -4973,6 +5226,14 @@ int spider_mysql_share::discover_table_structure( ) { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (!conn->disable_reconnect) { ha_spider tmp_spider; @@ -4985,14 +5246,15 @@ int spider_mysql_share::discover_table_structure( if ((error_num = spider_db_ping(&tmp_spider, conn, 0))) { DBUG_PRINT("info",("spider spider_db_ping error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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; } } - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - conn->need_mon = &need_mon; - conn->mta_conn_mutex_lock_already = TRUE; - conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(conn, roop_count, trx->thd, spider_share); if ( @@ -5009,6 +5271,8 @@ int spider_mysql_share::discover_table_structure( ) ) { DBUG_PRINT("info",("spider spider_get_trx error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5028,6 +5292,8 @@ int spider_mysql_share::discover_table_structure( if (error_num || (error_num = spider_db_errorno(conn))) { DBUG_PRINT("info",("spider column store error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5036,6 +5302,8 @@ int spider_mysql_share::discover_table_structure( } /* no record */ DBUG_PRINT("info",("spider column no record error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5048,6 +5316,8 @@ int spider_mysql_share::discover_table_structure( DBUG_PRINT("info",("spider column fetch error")); res->free_result(); delete res; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5064,6 +5334,8 @@ int spider_mysql_share::discover_table_structure( if (conn->db_conn->next_result()) { DBUG_PRINT("info",("spider single result error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5076,6 +5348,8 @@ int spider_mysql_share::discover_table_structure( if (error_num || (error_num = spider_db_errorno(conn))) { DBUG_PRINT("info",("spider index store error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5084,6 +5358,8 @@ int spider_mysql_share::discover_table_structure( } /* no record */ DBUG_PRINT("info",("spider index no record error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5096,6 +5372,8 @@ int spider_mysql_share::discover_table_structure( DBUG_PRINT("info",("spider index fetch error")); res->free_result(); delete res; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5107,6 +5385,8 @@ int spider_mysql_share::discover_table_structure( if (conn->db_conn->next_result()) { DBUG_PRINT("info",("spider dual result error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5119,6 +5399,8 @@ int spider_mysql_share::discover_table_structure( if (error_num || (error_num = spider_db_errorno(conn))) { DBUG_PRINT("info",("spider table store error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5127,6 +5409,8 @@ int spider_mysql_share::discover_table_structure( } /* no record */ DBUG_PRINT("info",("spider table no record error")); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5139,6 +5423,8 @@ int spider_mysql_share::discover_table_structure( DBUG_PRINT("info",("spider table fetch error")); res->free_result(); delete res; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5147,6 +5433,8 @@ int spider_mysql_share::discover_table_structure( } res->free_result(); delete res; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10347,9 +10635,12 @@ int spider_mysql_handler::show_table_status( if (sts_mode == 1) { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; conn->disable_connect_retry = TRUE; @@ -10375,6 +10666,8 @@ int spider_mysql_handler::show_table_status( if ((error_num = spider_db_ping(spider, conn, link_idx))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10384,6 +10677,8 @@ int spider_mysql_handler::show_table_status( if ((error_num = spider_db_set_names(spider, conn, link_idx))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10400,12 +10695,16 @@ int spider_mysql_handler::show_table_status( &spider->need_mons[link_idx]) ) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); } } else { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10422,6 +10721,8 @@ int spider_mysql_handler::show_table_status( if (spider_param_dry_access()) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10431,9 +10732,17 @@ int spider_mysql_handler::show_table_status( if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; - if (error_num || (error_num = spider_db_errorno(conn))) + if (error_num) + { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); + DBUG_RETURN(error_num); + } + else if ((error_num = spider_db_errorno(conn))) DBUG_RETURN(error_num); else { @@ -10446,6 +10755,8 @@ int spider_mysql_handler::show_table_status( } } conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10488,9 +10799,12 @@ int spider_mysql_handler::show_table_status( DBUG_RETURN(error_num); } } else { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; conn->disable_connect_retry = TRUE; @@ -10516,6 +10830,8 @@ int spider_mysql_handler::show_table_status( if ((error_num = spider_db_ping(spider, conn, link_idx))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10525,6 +10841,8 @@ int spider_mysql_handler::show_table_status( if ((error_num = spider_db_set_names(spider, conn, link_idx))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10541,12 +10859,16 @@ int spider_mysql_handler::show_table_status( &spider->need_mons[link_idx]) ) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); } } else { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10563,6 +10885,8 @@ int spider_mysql_handler::show_table_status( if (spider_param_dry_access()) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10572,6 +10896,8 @@ int spider_mysql_handler::show_table_status( if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) { conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (error_num || (error_num = spider_db_errorno(conn))) @@ -10580,6 +10906,8 @@ int spider_mysql_handler::show_table_status( DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); } conn->disable_connect_retry = FALSE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10664,9 +10992,12 @@ int spider_mysql_handler::show_index( DBUG_PRINT("info",("spider crd_mode=%d", crd_mode)); if (crd_mode == 1) { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, @@ -10690,6 +11021,8 @@ int spider_mysql_handler::show_index( /* retry */ if ((error_num = spider_db_ping(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10698,6 +11031,8 @@ int spider_mysql_handler::show_index( } if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10713,11 +11048,15 @@ int spider_mysql_handler::show_index( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); } } else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10735,6 +11074,8 @@ int spider_mysql_handler::show_index( { if (error_num || (error_num = spider_db_errorno(conn))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10743,6 +11084,8 @@ int spider_mysql_handler::show_index( } /* no record is ok */ } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10797,9 +11140,12 @@ int spider_mysql_handler::show_index( DBUG_RETURN(error_num); } } else { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, @@ -10823,6 +11169,8 @@ int spider_mysql_handler::show_index( /* retry */ if ((error_num = spider_db_ping(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10831,6 +11179,8 @@ int spider_mysql_handler::show_index( } if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10846,11 +11196,15 @@ int spider_mysql_handler::show_index( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); } } else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10868,6 +11222,8 @@ int spider_mysql_handler::show_index( { if (error_num || (error_num = spider_db_errorno(conn))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10876,6 +11232,8 @@ int spider_mysql_handler::show_index( } /* no record is ok */ } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10942,9 +11300,12 @@ int spider_mysql_handler::show_records( SPIDER_SHARE *share = spider->share; uint pos = spider->conn_link_idx[link_idx]; DBUG_ENTER("spider_mysql_handler::show_records"); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, @@ -10968,6 +11329,8 @@ int spider_mysql_handler::show_records( /* retry */ if ((error_num = spider_db_ping(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10977,6 +11340,8 @@ int spider_mysql_handler::show_records( } if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10993,12 +11358,16 @@ int spider_mysql_handler::show_records( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; DBUG_PRINT("info", ("spider error_num=%d 3", error_num)); DBUG_RETURN(spider_db_errorno(conn)); } } else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11015,18 +11384,29 @@ int spider_mysql_handler::show_records( request_key.next = NULL; if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; - if (error_num || (error_num = spider_db_errorno(conn))) + if (error_num) { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_PRINT("info", ("spider error_num=%d 5", error_num)); DBUG_RETURN(error_num); + } + else if ((error_num = spider_db_errorno(conn))) + { + DBUG_PRINT("info", ("spider error_num=%d 6", error_num)); + DBUG_RETURN(error_num); } else { - DBUG_PRINT("info", ("spider error_num=%d 6", + DBUG_PRINT("info", ("spider error_num=%d 7", ER_QUERY_ON_FOREIGN_DATA_SOURCE)); DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); } } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11076,9 +11456,12 @@ ha_rows spider_mysql_handler::explain_select( DBUG_RETURN(HA_POS_ERROR); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, @@ -11104,6 +11487,8 @@ ha_rows spider_mysql_handler::explain_select( { if (spider->check_error_mode(error_num)) my_errno = error_num; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11114,6 +11499,8 @@ ha_rows spider_mysql_handler::explain_select( { if (spider->check_error_mode(error_num)) my_errno = error_num; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11132,6 +11519,8 @@ ha_rows spider_mysql_handler::explain_select( error_num = spider_db_errorno(conn); if (spider->check_error_mode(error_num)) my_errno = error_num; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11141,6 +11530,8 @@ ha_rows spider_mysql_handler::explain_select( } else { if (spider->check_error_mode(error_num)) my_errno = error_num; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11160,6 +11551,8 @@ ha_rows spider_mysql_handler::explain_select( { if (spider->check_error_mode(error_num)) my_errno = error_num; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11167,6 +11560,8 @@ ha_rows spider_mysql_handler::explain_select( DBUG_RETURN(HA_POS_ERROR); } else { my_errno = ER_QUERY_ON_FOREIGN_DATA_SOURCE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11174,6 +11569,8 @@ ha_rows spider_mysql_handler::explain_select( DBUG_RETURN(HA_POS_ERROR); } } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11206,13 +11603,18 @@ int spider_mysql_handler::lock_tables( } if (str->length()) { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11228,10 +11630,14 @@ int spider_mysql_handler::lock_tables( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11266,14 +11672,31 @@ int spider_mysql_handler::unlock_tables( { spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, spider->share); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, str->ptr(), str->length(), -1, &spider->need_mons[link_idx]) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); } @@ -11296,13 +11719,18 @@ int spider_mysql_handler::disable_keys( { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11318,11 +11746,15 @@ int spider_mysql_handler::disable_keys( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11345,13 +11777,18 @@ int spider_mysql_handler::enable_keys( { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11367,11 +11804,15 @@ int spider_mysql_handler::enable_keys( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11395,13 +11836,18 @@ int spider_mysql_handler::check_table( { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11417,11 +11863,15 @@ int spider_mysql_handler::check_table( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11445,13 +11895,18 @@ int spider_mysql_handler::repair_table( { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11467,11 +11922,15 @@ int spider_mysql_handler::repair_table( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11494,13 +11953,18 @@ int spider_mysql_handler::analyze_table( { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11516,11 +11980,15 @@ int spider_mysql_handler::analyze_table( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11543,13 +12011,18 @@ int spider_mysql_handler::optimize_table( { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11565,11 +12038,15 @@ int spider_mysql_handler::optimize_table( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11595,6 +12072,14 @@ int spider_mysql_handler::flush_tables( } spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, share); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, str->ptr(), @@ -11602,9 +12087,17 @@ int spider_mysql_handler::flush_tables( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); DBUG_RETURN(0); @@ -11620,6 +12113,14 @@ int spider_mysql_handler::flush_logs( DBUG_PRINT("info",("spider this=%p", this)); spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, share); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_FLUSH_LOGS_STR, @@ -11627,9 +12128,17 @@ int spider_mysql_handler::flush_logs( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); DBUG_RETURN(0); diff --git a/storage/spider/spd_db_oracle.cc b/storage/spider/spd_db_oracle.cc index 281e3188067..d5d41f4a994 100644 --- a/storage/spider/spd_db_oracle.cc +++ b/storage/spider/spd_db_oracle.cc @@ -1780,16 +1780,18 @@ int spider_db_oracle::start_transaction( } DBUG_RETURN(set_trx_isolation(conn->trx_isolation, need_mon)); } + pthread_mutex_assert_owner(&conn->mta_conn_mutex); + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); if (spider_db_query( conn, SPIDER_SQL_START_TRANSACTION_STR, SPIDER_SQL_START_TRANSACTION_LEN, -1, need_mon) - ) + ) { DBUG_RETURN(spider_db_errorno(conn)); - SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); - pthread_mutex_unlock(&conn->mta_conn_mutex); + } DBUG_RETURN(0); } @@ -1978,14 +1980,31 @@ int spider_db_oracle::set_trx_isolation( DBUG_RETURN(exec_query(SPIDER_SQL_ISO_READ_COMMITTED_STR, SPIDER_SQL_ISO_READ_COMMITTED_LEN, -1)); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_ISO_READ_COMMITTED_STR, SPIDER_SQL_ISO_READ_COMMITTED_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); break; @@ -1996,14 +2015,31 @@ int spider_db_oracle::set_trx_isolation( DBUG_RETURN(exec_query(SPIDER_SQL_ISO_SERIALIZABLE_STR, SPIDER_SQL_ISO_SERIALIZABLE_LEN, -1)); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_ISO_SERIALIZABLE_STR, SPIDER_SQL_ISO_SERIALIZABLE_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); break; @@ -2033,14 +2069,31 @@ int spider_db_oracle::set_autocommit( DBUG_RETURN(exec_query(SPIDER_SQL_AUTOCOMMIT_ON_STR, SPIDER_SQL_AUTOCOMMIT_ON_LEN, -1)); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_AUTOCOMMIT_ON_STR, SPIDER_SQL_AUTOCOMMIT_ON_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); } else { @@ -2049,14 +2102,31 @@ int spider_db_oracle::set_autocommit( DBUG_RETURN(exec_query(SPIDER_SQL_AUTOCOMMIT_OFF_STR, SPIDER_SQL_AUTOCOMMIT_OFF_LEN, -1)); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = need_mon; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_AUTOCOMMIT_OFF_STR, SPIDER_SQL_AUTOCOMMIT_OFF_LEN, -1, need_mon) - ) + ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); + } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); } @@ -10449,112 +10519,6 @@ int spider_oracle_handler::show_table_status( if (sts_mode == 1) { -/* - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - conn->need_mon = &spider->need_mons[link_idx]; - conn->mta_conn_mutex_lock_already = TRUE; - conn->mta_conn_mutex_unlock_later = TRUE; - spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, - share); - if ( - (error_num = spider_db_set_names(spider, conn, link_idx)) || - ( - spider_db_query( - conn, - oracle_share->show_table_status[0 + pos].ptr(), - oracle_share->show_table_status[0 + pos].length(), - -1, - &spider->need_mons[link_idx]) && - (error_num = spider_db_errorno(conn)) - ) - ) { - if ( - error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && - !conn->disable_reconnect - ) { -*/ - /* retry */ -/* - if ((error_num = spider_db_ping(spider, conn, link_idx))) - { - 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); - DBUG_RETURN(error_num); - } - if ((error_num = spider_db_set_names(spider, conn, link_idx))) - { - 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); - DBUG_RETURN(error_num); - } - spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, - share); - if (spider_db_query( - conn, - oracle_share->show_table_status[0 + pos].ptr(), - oracle_share->show_table_status[0 + pos].length(), - -1, - &spider->need_mons[link_idx]) - ) { - conn->mta_conn_mutex_lock_already = FALSE; - conn->mta_conn_mutex_unlock_later = FALSE; - DBUG_RETURN(spider_db_errorno(conn)); - } - } else { - 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); - DBUG_RETURN(error_num); - } - } - st_spider_db_request_key request_key; - request_key.spider_thread_id = spider->trx->spider_thread_id; - request_key.query_id = spider->trx->thd->query_id; - request_key.handler = spider; - request_key.request_id = 1; - request_key.next = NULL; - if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) - { - conn->mta_conn_mutex_lock_already = FALSE; - conn->mta_conn_mutex_unlock_later = FALSE; - if (error_num || (error_num = spider_db_errorno(conn))) - DBUG_RETURN(error_num); - else { - my_printf_error(ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM, - ER_SPIDER_REMOTE_TABLE_NOT_FOUND_STR, MYF(0), - oracle_share->db_names_str[spider->conn_link_idx[link_idx]].ptr(), - oracle_share->table_names_str[spider->conn_link_idx[ - link_idx]].ptr()); - DBUG_RETURN(ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM); - } - } - 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); - error_num = res->fetch_table_status( - sts_mode, - share->records, - share->mean_rec_length, - share->data_file_length, - share->max_data_file_length, - share->index_file_length, - auto_increment_value, - share->create_time, - share->update_time, - share->check_time - ); - res->free_result(); - delete res; - if (error_num) - DBUG_RETURN(error_num); -*/ if (!share->records) share->records = 10000; share->mean_rec_length = 65535; @@ -10565,9 +10529,12 @@ int spider_oracle_handler::show_table_status( share->update_time = (time_t) 0; share->check_time = (time_t) 0; } else { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, @@ -10591,6 +10558,8 @@ int spider_oracle_handler::show_table_status( /* retry */ if ((error_num = spider_db_ping(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10599,6 +10568,8 @@ int spider_oracle_handler::show_table_status( } if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10614,11 +10585,15 @@ int spider_oracle_handler::show_table_status( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); } } else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10634,6 +10609,8 @@ int spider_oracle_handler::show_table_status( request_key.next = NULL; if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; if (error_num || (error_num = spider_db_errorno(conn))) @@ -10641,6 +10618,8 @@ int spider_oracle_handler::show_table_status( else DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10695,105 +10674,6 @@ int spider_oracle_handler::show_index( DBUG_PRINT("info",("spider crd_mode=%d", crd_mode)); if (crd_mode == 1) { -/* - pthread_mutex_lock(&conn->mta_conn_mutex); - SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); - conn->need_mon = &spider->need_mons[link_idx]; - conn->mta_conn_mutex_lock_already = TRUE; - conn->mta_conn_mutex_unlock_later = TRUE; - spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, - share); - if ( - (error_num = spider_db_set_names(spider, conn, link_idx)) || - ( - spider_db_query( - conn, - oracle_share->show_index[0 + pos].ptr(), - oracle_share->show_index[0 + pos].length(), - -1, - &spider->need_mons[link_idx]) && - (error_num = spider_db_errorno(conn)) - ) - ) { - if ( - error_num == ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM && - !conn->disable_reconnect - ) { -*/ - /* retry */ -/* - if ((error_num = spider_db_ping(spider, conn, link_idx))) - { - 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); - DBUG_RETURN(error_num); - } - if ((error_num = spider_db_set_names(spider, conn, link_idx))) - { - 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); - DBUG_RETURN(error_num); - } - spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, - share); - if (spider_db_query( - conn, - oracle_share->show_index[0 + pos].ptr(), - oracle_share->show_index[0 + pos].length(), - -1, - &spider->need_mons[link_idx]) - ) { - conn->mta_conn_mutex_lock_already = FALSE; - conn->mta_conn_mutex_unlock_later = FALSE; - DBUG_RETURN(spider_db_errorno(conn)); - } - } else { - 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); - DBUG_RETURN(error_num); - } - } - st_spider_db_request_key request_key; - request_key.spider_thread_id = spider->trx->spider_thread_id; - request_key.query_id = spider->trx->thd->query_id; - request_key.handler = spider; - request_key.request_id = 1; - request_key.next = NULL; - if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) - { - if (error_num || (error_num = spider_db_errorno(conn))) - { - 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); - DBUG_RETURN(error_num); - } -*/ - /* no record is ok */ -/* - } - 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); - if (res) - { - error_num = res->fetch_table_cardinality( - crd_mode, - table, - share->cardinality, - share->cardinality_upd, - share->bitmap_size - ); - } -*/ for (roop_count = 0, tmp_cardinality = share->cardinality; roop_count < (int) table->s->fields; roop_count++, tmp_cardinality++) @@ -10805,19 +10685,13 @@ int spider_oracle_handler::show_index( *tmp_cardinality = 1; } } -/* - if (res) - { - res->free_result(); - delete res; - } - if (error_num) - DBUG_RETURN(error_num); -*/ } else { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, @@ -10841,6 +10715,8 @@ int spider_oracle_handler::show_index( /* retry */ if ((error_num = spider_db_ping(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10849,6 +10725,8 @@ int spider_oracle_handler::show_index( } if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10864,11 +10742,15 @@ int spider_oracle_handler::show_index( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); } } else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10886,6 +10768,8 @@ int spider_oracle_handler::show_index( { if (error_num || (error_num = spider_db_errorno(conn))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10894,6 +10778,8 @@ int spider_oracle_handler::show_index( } /* no record is ok */ } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10939,9 +10825,12 @@ int spider_oracle_handler::show_records( SPIDER_SHARE *share = spider->share; uint pos = spider->conn_link_idx[link_idx]; DBUG_ENTER("spider_oracle_handler::show_records"); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, @@ -10965,6 +10854,8 @@ int spider_oracle_handler::show_records( /* retry */ if ((error_num = spider_db_ping(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10974,6 +10865,8 @@ int spider_oracle_handler::show_records( } if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -10990,12 +10883,16 @@ int spider_oracle_handler::show_records( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; DBUG_PRINT("info", ("spider error_num=%d 3", error_num)); DBUG_RETURN(spider_db_errorno(conn)); } } else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11012,18 +10909,29 @@ int spider_oracle_handler::show_records( request_key.next = NULL; if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; - if (error_num || (error_num = spider_db_errorno(conn))) + if (error_num) { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_PRINT("info", ("spider error_num=%d 5", error_num)); DBUG_RETURN(error_num); + } + else if (error_num || (error_num = spider_db_errorno(conn))) + { + DBUG_PRINT("info", ("spider error_num=%d 6", error_num)); + DBUG_RETURN(error_num); } else { - DBUG_PRINT("info", ("spider error_num=%d 6", + DBUG_PRINT("info", ("spider error_num=%d 7", ER_QUERY_ON_FOREIGN_DATA_SOURCE)); DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); } } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11056,9 +10964,12 @@ int spider_oracle_handler::show_autoinc( if (!oracle_share->show_autoinc) DBUG_RETURN(0); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, @@ -11082,6 +10993,8 @@ int spider_oracle_handler::show_autoinc( /* retry */ if ((error_num = spider_db_ping(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11091,6 +11004,8 @@ int spider_oracle_handler::show_autoinc( } if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11107,12 +11022,16 @@ int spider_oracle_handler::show_autoinc( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; DBUG_PRINT("info", ("spider error_num=%d 3", error_num)); DBUG_RETURN(spider_db_errorno(conn)); } } else { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11129,18 +11048,29 @@ int spider_oracle_handler::show_autoinc( request_key.next = NULL; if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; - if (error_num || (error_num = spider_db_errorno(conn))) + if (error_num) { + SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); + pthread_mutex_unlock(&conn->mta_conn_mutex); DBUG_PRINT("info", ("spider error_num=%d 5", error_num)); DBUG_RETURN(error_num); + } + else if ((error_num = spider_db_errorno(conn))) + { + DBUG_PRINT("info", ("spider error_num=%d 6", error_num)); + DBUG_RETURN(error_num); } else { - DBUG_PRINT("info", ("spider error_num=%d 6", + DBUG_PRINT("info", ("spider error_num=%d 7", ER_QUERY_ON_FOREIGN_DATA_SOURCE)); DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); } } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11250,9 +11180,12 @@ ha_rows spider_oracle_handler::explain_select( DBUG_RETURN(HA_POS_ERROR); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, @@ -11278,6 +11211,8 @@ ha_rows spider_oracle_handler::explain_select( { if (spider->check_error_mode(error_num)) my_errno = error_num; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11288,6 +11223,8 @@ ha_rows spider_oracle_handler::explain_select( { if (spider->check_error_mode(error_num)) my_errno = error_num; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11306,6 +11243,8 @@ ha_rows spider_oracle_handler::explain_select( error_num = spider_db_errorno(conn); if (spider->check_error_mode(error_num)) my_errno = error_num; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11315,6 +11254,8 @@ ha_rows spider_oracle_handler::explain_select( } else { if (spider->check_error_mode(error_num)) my_errno = error_num; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11334,6 +11275,8 @@ ha_rows spider_oracle_handler::explain_select( { if (spider->check_error_mode(error_num)) my_errno = error_num; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11341,6 +11284,8 @@ ha_rows spider_oracle_handler::explain_select( DBUG_RETURN(HA_POS_ERROR); } else { my_errno = ER_QUERY_ON_FOREIGN_DATA_SOURCE; + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11348,6 +11293,8 @@ ha_rows spider_oracle_handler::explain_select( DBUG_RETURN(HA_POS_ERROR); } } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11381,13 +11328,18 @@ int spider_oracle_handler::lock_tables( } if (str->length()) { + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11403,10 +11355,14 @@ int spider_oracle_handler::lock_tables( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; DBUG_RETURN(spider_db_errorno(conn)); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11452,13 +11408,18 @@ int spider_oracle_handler::disable_keys( { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11474,11 +11435,15 @@ int spider_oracle_handler::disable_keys( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11501,13 +11466,18 @@ int spider_oracle_handler::enable_keys( { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11523,11 +11493,15 @@ int spider_oracle_handler::enable_keys( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11551,13 +11525,18 @@ int spider_oracle_handler::check_table( { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11573,11 +11552,15 @@ int spider_oracle_handler::check_table( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11601,13 +11584,18 @@ int spider_oracle_handler::repair_table( { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11623,11 +11611,15 @@ int spider_oracle_handler::repair_table( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11650,13 +11642,18 @@ int spider_oracle_handler::analyze_table( { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11672,11 +11669,15 @@ int spider_oracle_handler::analyze_table( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11699,13 +11700,18 @@ int spider_oracle_handler::optimize_table( { DBUG_RETURN(error_num); } + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, link_idx))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11721,11 +11727,15 @@ int spider_oracle_handler::optimize_table( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -11751,6 +11761,14 @@ int spider_oracle_handler::flush_tables( } spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, share); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, str->ptr(), @@ -11758,9 +11776,17 @@ int spider_oracle_handler::flush_tables( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); DBUG_RETURN(0); @@ -11776,6 +11802,14 @@ int spider_oracle_handler::flush_logs( DBUG_PRINT("info",("spider this=%p", this)); spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd, share); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); + pthread_mutex_lock(&conn->mta_conn_mutex); + SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); + conn->need_mon = &spider->need_mons[link_idx]; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = TRUE; + conn->mta_conn_mutex_unlock_later = TRUE; if (spider_db_query( conn, SPIDER_SQL_FLUSH_LOGS_STR, @@ -11783,9 +11817,17 @@ int spider_oracle_handler::flush_logs( -1, &spider->need_mons[link_idx]) ) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + conn->mta_conn_mutex_lock_already = FALSE; + conn->mta_conn_mutex_unlock_later = FALSE; error_num = spider_db_errorno(conn); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); + 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); DBUG_RETURN(0); diff --git a/storage/spider/spd_include.h b/storage/spider/spd_include.h index a6ce2efe774..a871e186d96 100644 --- a/storage/spider/spd_include.h +++ b/storage/spider/spd_include.h @@ -17,6 +17,8 @@ #define SPIDER_HEX_VERSION 0x0302 #if MYSQL_VERSION_ID < 50500 +#define pthread_mutex_assert_owner(A) +#define pthread_mutex_assert_not_owner(A) #else #define my_free(A,B) my_free(A) #ifdef pthread_mutex_t @@ -39,6 +41,8 @@ #undef pthread_mutex_destroy #endif #define pthread_mutex_destroy mysql_mutex_destroy +#define pthread_mutex_assert_owner(A) mysql_mutex_assert_owner(A) +#define pthread_mutex_assert_not_owner(A) mysql_mutex_assert_not_owner(A) #ifdef pthread_cond_t #undef pthread_cond_t #endif diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc index 7c591cf691d..39f51fa1b59 100644 --- a/storage/spider/spd_table.cc +++ b/storage/spider/spd_table.cc @@ -5815,13 +5815,18 @@ int spider_open_all_tables( } conn->error_mode &= spider_param_error_read_mode(thd, 0); conn->error_mode &= spider_param_error_write_mode(thd, 0); + pthread_mutex_assert_not_owner(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex); SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); conn->need_mon = &mon_val; + DBUG_ASSERT(!conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_before_query(conn, &mon_val))) { + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -5834,6 +5839,8 @@ int spider_open_all_tables( free_root(&mem_root, MYF(0)); DBUG_RETURN(error_num); } + DBUG_ASSERT(conn->mta_conn_mutex_lock_already); + DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_unlock_later = FALSE; SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |