您好,登錄后才能下訂單哦!
本篇文章給大家分享的是有關如何解決myshard中找不到表[no_hash] 和table [tbl_test]的問題,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
在創建表的時候
mysql> CREATE TABLE `myshard`.`tbl_test` ( -> `col1` VARCHAR(32) DEFAULT NULL , -> `col2` VARCHAR(11) DEFAULT '0' , -> PRIMARY KEY (col1) -> ) COLLATE='utf8_bin' ENGINE=InnoDB DEFAULT CHARSET=utf8 PARTITION KEY col1 SHARDING_RULE no_hash; ERROR 65535 (HY000): Cannot find rule [no_hash] for table [tbl_test]
然而admin_show allconfig能看到有no_hash的分表規則
| allconfig#rule | rule_name|default_server|mode|expression | | allconfig#rule | no_hash|server1|5|
在打印日志時,重建這個表,看日志有什么報錯
tail -f shardadmin_short_video_oss_40_d/shardadmin_short_video_oss_40_d.log
會發現日志會對myshard_metadata做一些插入和查詢操作
May 17 09:46:44 debug shardadmin_short_video_oss_40_d[46650]: CMySQLQueryServer::handle_mysql: cmd_type[3], cmd_len:[220], cmd[CREATE TABLE `myshard`.`tbl_test` ( `col1` VARCHAR(32) DEFAULT NULL , `col2` VARCHAR(11) DEFAULT '0' , PRIMARY KEY (col1) ) COLLATE='utf8_bin' ENGINE=InnoDB DEFAULT CHARSET=utf8 PARTITION KEY col1 SHARDING_RULE no_hash] May 17 09:46:44 debug shardadmin_short_video_oss_40_d[46650]: entering CQueryProcessor::process. May 17 09:46:44 debug shardadmin_short_video_oss_40_d[46650]: Vincent: CQueryProcessor::process,, it should be 0: ptSQLStruct->m_SysOP=7. May 17 09:46:44 debug shardadmin_short_video_oss_40_d[46650]: Vincent: CQueryProcessor::process, obj found to process it. May 17 09:46:44 info shardadmin_short_video_oss_40_d[46650]: sqlPreView:[select default_timestamp_mode from myshard_table_rule where busi_name='short_video_oss' and machine_room_no=4 and rule_name='no_hash'] May 17 09:46:44 info shardadmin_short_video_oss_40_d[46650]: sqlPreView:[insert into myshard_table (busi_name,machine_room_no,table_name,rule_name,db_name,sharding_column,engine_type,charset_type,collation_type,partition2_key,partition2_range) values('short_video_oss',4,'tbl_test','no_hash','myshard','col1','InnoDB','utf8','utf8_bin', '', '')] May 17 09:46:44 info shardadmin_short_video_oss_40_d[46650]: sqlPreView:[insert into myshard_table_columns (busi_name,machine_room_no,TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION,COLUMN_DEFAULT,COLUMN_TYPE,DATA_TYPE) values('short_video_oss',4,'tbl_test','col1',1,'NULL','VARCHAR(32)', 'VARCHAR')] May 17 09:46:44 info shardadmin_short_video_oss_40_d[46650]: sqlPreView:[insert into myshard_table_columns (busi_name,machine_room_no,TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION,COLUMN_DEFAULT,COLUMN_TYPE,DATA_TYPE) values('short_video_oss',4,'tbl_test','col2',2,'0','VARCHAR(11)', 'VARCHAR')] May 17 09:46:44 info shardadmin_short_video_oss_40_d[46650]: sqlPreView:[update myshard_table_columns set COLUMN_KEY='PRI' where busi_name='short_video_oss' and machine_room_no=4 and table_name='tbl_test' and column_name='col1'] May 17 09:46:44 info shardadmin_short_video_oss_40_d[46650]: sqlPreView:[insert into myshard_table_statistics (busi_name,machine_room_no,TABLE_NAME,INDEX_NAME,COLUMN_NAME,SEQ_IN_INDEX) values('short_video_oss',4,'tbl_test','PRIMARY','col1',1)] May 17 09:46:44 info shardadmin_short_video_oss_40_d[46650]: sqlPreView:[select db_name, rule_name from myshard_table where busi_name='short_video_oss' and machine_room_no=4 and table_name = 'tbl_test'] May 17 09:46:44 info shardadmin_short_video_oss_40_d[46650]: sqlPreView:[select default_server,default_timestamp_mode from myshard_table_rule where busi_name='short_video_oss' and machine_room_no=4 and rule_name='no_hash'] May 17 09:46:44 info shardadmin_short_video_oss_40_d[46650]: sqlPreView:[select sharding_rule_name,server,table_rewrite from myshard_sharding_rule where busi_name='short_video_oss' and machine_room_no=4 and rule_name='no_hash'] May 17 09:46:44 info shardadmin_short_video_oss_40_d[46650]: sqlPreView:[select property, value from myshard_server_con_config where busi_name='short_video_oss' and machine_room_no=4 and server_name='server1'] May 17 09:46:44 info shardadmin_short_video_oss_40_d[46650]: Creating connection to schema=myshard, ipAddress=127.0.0.1, user=db_myshard_rw, password=DauK4Ju92x, port=6301 May 17 09:46:44 debug shardadmin_short_video_oss_40_d[46650]: CREATE TABLE myshard.tbl_test(col1 VARCHAR(32) DEFAULT NULL,col2 VARCHAR(11) DEFAULT '0' , __version BIGINT unsigned default 0 , __deleted TINYINT default 0,PRIMARY KEY (col1)) ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_bin#-1946151400 May 17 09:46:44 err shardadmin_short_video_oss_40_d[46650]: [CShardAdmin2::send_msg_to_proxy]shenglong, send_msg_to_proxy[proxy_4_0_0] failed: errcode:65535, errmsg:Cannot find rule [no_hash] for table [tbl_test], strSQL:CREATE TABLE `myshard`.`tbl_test` ( `col1` VARCHAR(32) DEFAULT NULL , `col2` VARCHAR(11) DEFAULT '0' , PRIMARY KEY (col1) ) COLLATE='utf8_bin' ENGINE=InnoDB DEFAULT CHARSET=utf8 PARTITION KEY col1 SHARDING_RULE no_hash May 17 09:46:44 err shardadmin_short_video_oss_40_d[46650]: send_msg_to_proxy sql [CREATE TABLE `myshard`.`tbl_test` ( `col1` VARCHAR(32) DEFAULT NULL , `col2` VARCHAR(11) DEFAULT '0' , PRIMARY KEY (col1) ) COLLATE='utf8_bin' ENGINE=InnoDB DEFAULT CHARSET=utf8 PARTITION KEY col1 SHARDING_RULE no_hash] to [proxy_4_0_0] get a error [65535][Cannot find rule [no_hash] for table [tbl_test]]
與分表規則相關的查詢有如下2個
select default_server,default_timestamp_mode from myshard_table_rule where busi_name='short_video_oss' and machine_room_no=4 and rule_name='no_hash'; select sharding_rule_name,server,table_rewrite from myshard_sharding_rule where busi_name='short_video_oss' and machine_room_no=4 and rule_name='no_hash';
如果myshard底下掛的MySQL的myshard_metadata的schema里,找不到這些數據就大概是報錯的原因,查詢第一句是有的,但是查詢第二個表myshard_sharding_rule是查詢不到的,查詢不到是正常的,因為no_hash就不存在分表規則sharding_rule
+----------------+------------------------+ | default_server | default_timestamp_mode | +----------------+------------------------+ | server1 | 5 | +----------------+------------------------+
不過也發現一個報錯,send_msg_to_proxy[proxy_4_0_0] failed: errcode:65535,這是一個proxy的錯誤,并不是shardadmin的錯誤,使用4455把表進行刪除時,實際上是刪除元數據關于表的信息,同樣有個send_msg_to_proxy的報錯
May 17 10:25:25 debug shardadmin_short_video_oss_40_d[46650]: drop table myshard.tbl_test#-1946110424 May 17 10:25:25 info shardadmin_short_video_oss_40_d[46650]: sqlPreView:[delete from myshard_table where busi_name='short_video_oss' and machine_room_no=4 and table_name='tbl_test'] May 17 10:25:25 info shardadmin_short_video_oss_40_d[46650]: sqlPreView:[delete from myshard_table_columns where busi_name='short_video_oss' and machine_room_no=4 and table_name='tbl_test'] May 17 10:25:25 info shardadmin_short_video_oss_40_d[46650]: sqlPreView:[delete from myshard_table_statistics where busi_name='short_video_oss' and machine_room_no=4 and table_name='tbl_test'] May 17 10:25:25 info shardadmin_short_video_oss_40_d[46650]: sqlPreView:[select index_name from myshard_index where busi_name='short_video_oss' and machine_room_no=4 and table_name = 'tbl_test'] May 17 10:25:25 info shardadmin_short_video_oss_40_d[46650]: sqlPreView:[delete from myshard_index where busi_name='short_video_oss' and machine_room_no=4 and table_name='tbl_test'] May 17 10:25:25 err shardadmin_short_video_oss_40_d[46650]: [CShardAdmin2::send_msg_to_proxy]shenglong, send_msg_to_proxy[proxy_4_0_0] failed: errcode:65535, errmsg:Table not existed!, strSQL:drop table tbl_test May 17 10:25:25 err shardadmin_short_video_oss_40_d[46650]: send_msg_to_proxy sql [drop table tbl_test] to [proxy_4_0_0] get a error [65535][Table not existed!] May 17 10:25:27 notice shardadmin_short_video_oss_40_d[58881]: request:0 proc:0 droped:0 active:0 May 17 10:25:27 notice shardadmin_short_video_oss_40_d[58881]: measure: 0| 0 = 9999442, 20, 499972, 500007
send_msg_to_proxy 這里有一個報錯,8821-8827其實是一個proxy,它不一定轉到127.0.0.1,也可以轉到其他地方。懷疑是8821到8827的端口程序有問題,于是重啟每次重啟,只打印少量的日志,創建端口8821 OK,于是更換了,rds程序。對于no_hash的分表規則,shardadmin在MySQL創建了規則,但是shard不知道,怎么讓shard知道,需要重啟shard,但這個shard重啟是有問題的
May 17 12:06:35 info shard_short_video_oss_210_d[130853]: create listen port 8826 success May 17 12:06:35 info shard_short_video_oss_210_d[130853]: server start May 17 12:07:07 info shard_short_video_oss_210_d[131498]: HAVE_EPOLL May 17 12:07:07 debug shard_short_video_oss_210_d[131498]: output queue ok May 17 12:07:07 debug shard_short_video_oss_210_d[131498]: output queue ok May 17 12:07:07 info shard_short_video_oss_210_d[131498]: create listen port 8826 success May 17 12:07:07 info shard_short_video_oss_210_d[131498]: server start May 17 12:07:14 info shard_short_video_oss_210_d[132027]: HAVE_EPOLL May 17 12:07:14 debug shard_short_video_oss_210_d[132027]: output queue ok May 17 12:07:14 debug shard_short_video_oss_210_d[132027]: output queue ok May 17 12:07:14 info shard_short_video_oss_210_d[132027]: create listen port 8826 success May 17 12:07:14 info shard_short_video_oss_210_d[132027]: server start
所以懷疑是rds程序有問題,于是更換別的rds程序,重啟shard端口,會進行大量的初始化,打大量的日志,如果沒有做這些初始化,比如剛才,說明shard沒有成功成功,以前也遇到過類似的問題,
May 17 10:56:48 info shard_short_video_oss_40b_d[62191]: HAVE_EPOLL May 17 10:56:48 debug shard_short_video_oss_40b_d[62191]: output queue ok May 17 10:56:48 debug shard_short_video_oss_40b_d[62191]: output queue ok May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1, cur: 1, min: 20, max: 20, idle: 0 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1, cur: 2, min: 20, max: 20, idle: 1 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1, cur: 3, min: 20, max: 20, idle: 2 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1, cur: 4, min: 20, max: 20, idle: 3 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1, cur: 5, min: 20, max: 20, idle: 4 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1, cur: 6, min: 20, max: 20, idle: 5 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1, cur: 7, min: 20, max: 20, idle: 6 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1, cur: 8, min: 20, max: 20, idle: 7 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1, cur: 9, min: 20, max: 20, idle: 8 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1, cur: 10, min: 20, max: 20, idle: 9 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1, cur: 11, min: 20, max: 20, idle: 10 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1, cur: 12, min: 20, max: 20, idle: 11 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1, cur: 13, min: 20, max: 20, idle: 12 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1, cur: 14, min: 20, max: 20, idle: 13 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1, cur: 15, min: 20, max: 20, idle: 14 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1, cur: 16, min: 20, max: 20, idle: 15 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1, cur: 17, min: 20, max: 20, idle: 16 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1, cur: 18, min: 20, max: 20, idle: 17 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1, cur: 19, min: 20, max: 20, idle: 18 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1, cur: 20, min: 20, max: 20, idle: 19 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1_nobinlog, cur: 1, min: 20, max: 20, idle: 0 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1_nobinlog, cur: 2, min: 20, max: 20, idle: 1 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1_nobinlog, cur: 3, min: 20, max: 20, idle: 2 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1_nobinlog, cur: 4, min: 20, max: 20, idle: 3 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1_nobinlog, cur: 5, min: 20, max: 20, idle: 4 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1_nobinlog, cur: 6, min: 20, max: 20, idle: 5 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1_nobinlog, cur: 7, min: 20, max: 20, idle: 6 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1_nobinlog, cur: 8, min: 20, max: 20, idle: 7 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1_nobinlog, cur: 9, min: 20, max: 20, idle: 8 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1_nobinlog, cur: 10, min: 20, max: 20, idle: 9 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1_nobinlog, cur: 11, min: 20, max: 20, idle: 10 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1_nobinlog, cur: 12, min: 20, max: 20, idle: 11 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1_nobinlog, cur: 13, min: 20, max: 20, idle: 12 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1_nobinlog, cur: 14, min: 20, max: 20, idle: 13 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1_nobinlog, cur: 15, min: 20, max: 20, idle: 14 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1_nobinlog, cur: 16, min: 20, max: 20, idle: 15 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1_nobinlog, cur: 17, min: 20, max: 20, idle: 16 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1_nobinlog, cur: 18, min: 20, max: 20, idle: 17 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1_nobinlog, cur: 19, min: 20, max: 20, idle: 18 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 notice shard_short_video_oss_40b_d[62191]: inc pool, type: MySQL, name: server1_nobinlog, cur: 20, min: 20, max: 20, idle: 19 [PartitionConnectionPool.cpp, #76] May 17 10:56:48 info shard_short_video_oss_40b_d[62191]: create listen port 8821 success May 17 10:56:48 info shard_short_video_oss_40b_d[62191]: server start, epoll_prt=0x28e9e20 May 17 10:56:58 notice shard_short_video_oss_40b_d[62191]: request:0 proc:0 droped:0 active:0
做的工作是初始化一個pool,最后以一個port8821創建監聽為標志,每次重啟都會打印這么的初始化信息,再次進入4455進行建表
mysql> CREATE TABLE `myshard`.`tbl_test` ( -> `col1` VARCHAR(32) DEFAULT NULL , -> `col2` VARCHAR(11) DEFAULT '0' , -> PRIMARY KEY (col1) -> ) COLLATE='utf8_bin' ENGINE=InnoDB DEFAULT CHARSET=utf8 PARTITION KEY col1 SHARDING_RULE no_hash; Query OK, 0 rows affected (0.00 sec)
沒有任何報錯,使用8821-8827也能正常查詢該表,問題的原因:RDS程序有問題,接下來要讓myshard開發看看為什么不能重啟了
以上就是如何解決myshard中找不到表[no_hash] 和table [tbl_test]的問題,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。