问题现象
客户通过 OMS 进行数据迁移时,在 “结构迁移” 阶段遇到报错 Data too long for column。
INNER_ERROR
### Error updating database. Cause: java.sql.SQLSyntaxErrorException: (conn=283136) Data too long for column
### The error may exist in com/alipay/oms/common/dal/mapper/migrate/OmsStructMigrationRecordMapper.java (best guess)
### The error may involve com.alipay.oms.common.dal.mapper.migrate.OmsStructMigrationRecordMapper.updateById-Inline
### The error occurred while setting parameters
### SQL: UPDATE oms_struct_migration_record SET task_id=?, obj_type=?, obj_schema=?, dest_schema=?, obj_name=?, dest_obj_name=?, exec_order=?, serialization_id=?, sql_script_id=?, record_status=?, oms_indexes_dropped=?, oms_columns_dropped=?, post_script_executed=?, post_sql=?, extra_msg=?, gmt_create=?, gmt_modified=now() WHERE id=?
### Cause: java.sql.SQLSyntaxErrorException: (conn=283136) Data too long for column ; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: (conn=283136) Data too long for column

问题原因
OMS 结构迁移负责迁移源库中的数据对象定义(表、索引、约束、注释和视图等)至目标库中,会自动过滤临时表。当源端数据库非 OceanBase 数据库时,会依据目标 OceanBase 租户类型的语法定义标准进行数据类型和 SQL 语法的自动转换和拼装,然后复制至目标库中。因此,结构迁移仅涉及到业务数据库 Schema 的迁移,并未涉及到业务数据的迁移。 从上面截图中的报错信息及相关的表名可知相关报错的表为 OMS 内部使用的元信息表 oms_struct_migration_record,在结构迁移阶段维护该元信息表时遇到了 Data too long for column 的报错。通过查询 MetaDB 的系统 gv$sql_audit 视图,排查后得知在更新 oms_struct_migration_record 表的 post_sql 列时,插入的数据长度超限了。
MySQL [oceanbase]> select usec_to_time(request_time), * from gv$sql_audit where query_sql like '%UPDATE oms_struct_migration_record%' and ret_code !=0\G

确定该问题为 OMS 低版本上元数据设计的一个缺陷,修复在 OMS V4.1.0 及公有云/多云 202303 迭代。
问题的风险及影响
OMS 结构迁移失败,迁移流程卡住。
影响租户
影响 OceanBase 数据库中的 SYS 租户和 Oracle 租户以及 MySQL 租户。
适用版本
专有云 OMS V4.1.0(不含)之前的版本,或者从 OMS V4.1.0 及更低版本一路升级上来的 OMS 高版本。
公有云及多云 202303 迭代(不含)之前的版本。
解决方法
方法一)使用全新部署的 OMS V4.1.0 或 OMS 公有云/多云 202303 迭代。
方法二)使用管理员用户连接到 OMS 的元数据库,手工调大相关字段类型,示例如下。
首先查询到当前 oms_struct_migration_record 表的实际定义 DDL:
$ mysql -hxxx.xxx.xxx.xxx -uroot@oms_meta#metadb_cluster -P2883 -pxxx -A -c
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 1060347
Server version: 5.6.25 OceanBase 2.2.77 (r116010032023022813-4f4fbb6de5d75b4db00ee05d44d56d8c1500c21c) (Built Feb 28 2023 13:48:43)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| oceanbase |
| information_schema |
| mysql |
| test |
| oms_cm |
| oms_rm |
| oms_cm_heartbeat |
+--------------------+
7 rows in set (0.01 sec)
MySQL [(none)]> use oms_rm;
Database changed
MySQL [oms_rm]> desc oms_struct_migration_record;
+-----------------------+--------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------+--------------+------+-----+-------------------+-----------------------------+
| id | varchar(32) | NO | PRI | NULL | |
| task_id | varchar(32) | NO | MUL | NULL | |
| obj_type | varchar(64) | NO | | NULL | |
| obj_schema | varchar(128) | NO | | NULL | |
| dest_schema | varchar(128) | YES | | NULL | |
| obj_name | varchar(128) | NO | | NULL | |
| exec_order | int(11) | NO | | 0 | |
| serialization_id | varchar(32) | YES | | NULL | |
| sql_script_id | varchar(32) | YES | | NULL | |
| record_status | varchar(32) | NO | | INIT | |
| time_cost | varchar(32) | YES | | NULL | |
| extra_msg | longtext | YES | | NULL | |
| gmt_create | timestamp | YES | | CURRENT_TIMESTAMP | |
| gmt_modified | timestamp | YES | | CURRENT_TIMESTAMP | ON UPDATE CURRENT_TIMESTAMP |
| dest_obj_name | varchar(128) | NO | | NULL | |
| oms_indexes_dropped | tinyint(4) | NO | | 0 | |
| oms_columns_dropped | tinyint(4) | NO | | 0 | |
| post_script_executed | tinyint(4) | NO | | 0 | |
| post_sql | text | YES | | NULL | |
| start_time | timestamp(3) | YES | | NULL | |
| finish_time | timestamp(3) | YES | | NULL | |
| action_id | varchar(256) | YES | | NULL | |
| retry_count | int(11) | NO | | 0 | |
| degree | int(11) | NO | | 0 | |
| referenced_by_objects | mediumtext | YES | | NULL | |
| query_time_cost | int(11) | YES | | NULL | |
+-----------------------+--------------+------+-----+-------------------+-----------------------------+
26 rows in set (0.01 sec)
MySQL [oms_rm]> show create table oms_struct_migration_record;
+-----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| oms_struct_migration_record | CREATE TABLE `oms_struct_migration_record` (
`id` varchar(32) NOT NULL COMMENT '记录ID',
`task_id` varchar(32) NOT NULL COMMENT '结构迁移任务ID',
`obj_type` varchar(64) NOT NULL COMMENT '对象类型 tablevuewfunction等',
`obj_schema` varchar(128) NOT NULL COMMENT '对象所在库',
`dest_schema` varchar(128) DEFAULT NULL COMMENT '对象迁移目标库',
`obj_name` varchar(128) NOT NULL COMMENT '对象名',
`exec_order` int(11) NOT NULL DEFAULT '0' COMMENT '执行顺序',
`serialization_id` varchar(32) DEFAULT NULL COMMENT '对象序列化结果',
`sql_script_id` varchar(32) DEFAULT NULL COMMENT 'SQL',
`record_status` varchar(32) NOT NULL DEFAULT 'INIT' COMMENT '迁移状态',
`time_cost` varchar(32) DEFAULT NULL COMMENT '迁移记录耗时,单位毫秒',
`extra_msg` longtext DEFAULT NULL,
`gmt_create` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`gmt_modified` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`dest_obj_name` varchar(128) NOT NULL COMMENT '对象目标名',
`oms_indexes_dropped` tinyint(4) NOT NULL DEFAULT '0' COMMENT '对目标端唯一索引的操作状态,0 没执行,1 执行成功,2 执行失败',
`oms_columns_dropped` tinyint(4) NOT NULL DEFAULT '0' COMMENT '对目标端附属列操作的状态,0 没执行,1 执行成功,2 执行失败',
`post_script_executed` tinyint(4) NOT NULL DEFAULT '0' COMMENT '结构迁移中禁用的约束是否已在目标库恢复',
`post_sql` text DEFAULT NULL COMMENT '后置sql',
`start_time` timestamp(3) NULL DEFAULT NULL COMMENT '开始时间',
`finish_time` timestamp(3) NULL DEFAULT NULL COMMENT '结束时间',
`action_id` varchar(256) DEFAULT NULL COMMENT 'supervisor 执行某项任务时本地生成的任务 ID',
`retry_count` int(11) NOT NULL DEFAULT '0' COMMENT '重试次数',
`degree` int(11) NOT NULL DEFAULT '0' COMMENT '该对象依赖对象的个数(不包括间接依赖)',
`referenced_by_objects` mediumtext DEFAULT NULL COMMENT '依赖当前对象的其他对象名称集合',
`query_time_cost` int(11) DEFAULT NULL COMMENT '读取对象消耗时间,单位ms',
PRIMARY KEY (`id`),
KEY `idx_task_id_type_schema_name_order` (`task_id`, `obj_type`, `obj_schema`, `dest_schema`, `obj_name`, `record_status`, `exec_order`) BLOCK_SIZE 16384 GLOBAL,
KEY `idx_id_status_serialization_id` (`task_id`, `record_status`, `serialization_id`) BLOCK_SIZE 16384 GLOBAL,
KEY `idx_id_status_type_serialization_id` (`task_id`, `record_status`, `obj_type`, `serialization_id`, `obj_schema`, `obj_name`) BLOCK_SIZE 16384 GLOBAL,
KEY `idx_id_status_serialization_schema` (`task_id`, `record_status`, `serialization_id`, `obj_schema`) BLOCK_SIZE 16384 GLOBAL
) DEFAULT CHARSET = utf8mb4 ROW_FORMAT = DYNAMIC COMPRESSION = 'zstd_1.0' REPLICA_NUM = 1 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0 COMMENT = 'oms 结构迁移记录表' |
+-----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
然后拷贝当前 oms_struct_migration_record 的实际定义 DDL,将 post_sql 字段的类型修改为 longtext,其它均保持不变,创建出一张新的临时表 oms_struct_migration_record_new:
(注意:以下内容仅为示例,具体操作时以实际情况为准)
MySQL [oms_rm]> CREATE TABLE `oms_struct_migration_record_new` (
`id` varchar(32) NOT NULL COMMENT '记录ID',
`task_id` varchar(32) NOT NULL COMMENT '结构迁移任务ID',
`obj_type` varchar(64) NOT NULL COMMENT '对象类型 tablevuewfunction等',
`obj_schema` varchar(128) NOT NULL COMMENT '对象所在库',
`dest_schema` varchar(128) DEFAULT NULL COMMENT '对象迁移目标库',
`obj_name` varchar(128) NOT NULL COMMENT '对象名',
`exec_order` int(11) NOT NULL DEFAULT '0' COMMENT '执行顺序',
`serialization_id` varchar(32) DEFAULT NULL COMMENT '对象序列化结果',
`sql_script_id` varchar(32) DEFAULT NULL COMMENT 'SQL',
`record_status` varchar(32) NOT NULL DEFAULT 'INIT' COMMENT '迁移状态',
`time_cost` varchar(32) DEFAULT NULL COMMENT '迁移记录耗时,单位毫秒',
`extra_msg` longtext DEFAULT NULL,
`gmt_create` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`gmt_modified` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`dest_obj_name` varchar(128) NOT NULL COMMENT '对象目标名',
`oms_indexes_dropped` tinyint(4) NOT NULL DEFAULT '0' COMMENT '对目标端唯一索引的操作状态,0 没执行,1 执行成功,2 执行失败',
`oms_columns_dropped` tinyint(4) NOT NULL DEFAULT '0' COMMENT '对目标端附属列操作的状态,0 没执行,1 执行成功,2 执行失败',
`post_script_executed` tinyint(4) NOT NULL DEFAULT '0' COMMENT '结构迁移中禁用的约束是否已在目标库恢复',
`post_sql` longtext DEFAULT NULL COMMENT '后置sql',
`start_time` timestamp(3) NULL DEFAULT NULL COMMENT '开始时间',
`finish_time` timestamp(3) NULL DEFAULT NULL COMMENT '结束时间',
`action_id` varchar(256) DEFAULT NULL COMMENT 'supervisor 执行某项任务时本地生成的任务 ID',
`retry_count` int(11) NOT NULL DEFAULT '0' COMMENT '重试次数',
`degree` int(11) NOT NULL DEFAULT '0' COMMENT '该对象依赖对象的个数(不包括间接依赖)',
`referenced_by_objects` mediumtext DEFAULT NULL COMMENT '依赖当前对象的其他对象名称集合',
`query_time_cost` int(11) DEFAULT NULL COMMENT '读取对象消耗时间,单位ms',
PRIMARY KEY (`id`),
KEY `idx_task_id_type_schema_name_order` (`task_id`, `obj_type`, `obj_schema`, `dest_schema`, `obj_name`, `record_status`, `exec_order`) BLOCK_SIZE 16384 GLOBAL,
KEY `idx_id_status_serialization_id` (`task_id`, `record_status`, `serialization_id`) BLOCK_SIZE 16384 GLOBAL,
KEY `idx_id_status_type_serialization_id` (`task_id`, `record_status`, `obj_type`, `serialization_id`, `obj_schema`, `obj_name`) BLOCK_SIZE 16384 GLOBAL,
KEY `idx_id_status_serialization_schema` (`task_id`, `record_status`, `serialization_id`, `obj_schema`) BLOCK_SIZE 16384 GLOBAL
) DEFAULT CHARSET = utf8mb4 ROW_FORMAT = DYNAMIC COMPRESSION = 'zstd_1.0' REPLICA_NUM = 1 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0 COMMENT = 'oms 结构迁移记录表';
Query OK, 0 rows affected (0.332 sec)
最后将 oms_struct_migration_record 表的数据全部插入到新表中去,并对这两张表进行重命名:
MySQL [oms_rm]> insert into oms_struct_migration_record_new select * from oms_struct_migration_record;
Query OK, 30938 rows affected (0.006 sec)
Records: 30938 Duplicates: 0 Warnings: 0
MySQL [oms_rm]> commit;
Query OK, 0 rows affected (0.000 sec)
MySQL [oms_rm]> alter table oms_struct_migration_record rename to oms_struct_migration_record_old;
Query OK, 0 rows affected (0.063 sec)
MySQL [oms_rm]> alter table oms_struct_migration_record_new rename to oms_struct_migration_record;
Query OK, 0 rows affected (0.028 sec)
MySQL [oms_rm]> commit;
Query OK, 0 rows affected (0.000 sec)


备注:
- 如果 MetaDB 的版本为 V4.x,可以直接通过
alter table modify column语句原地修改post_sql字段的类型为longtext:MySQL [(none)]> use oms_rm; Database changed MySQL [oms_rm]> alter table oms_struct_migration_record modify post_sql longtext; -- OB 4.2.1.10上 Query OK, 0 rows affected (0.19 sec)
- 从 OMS V4.1.0 及更低版本一路升级上来的 OMS 高版本上也存在同样的问题。