如何解决myshard中找不到表[no_hash] 和table [tbl_test]的问题
admin
2023-05-19 02:41:34
0次

在创建表的时候

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开发看看为什么不能重启了

相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...