Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Commit

Permalink
fix: handle null table_info after importing from v1.0.x (#952)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Aug 28, 2020
1 parent a358aca commit a2e8c5f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
22 changes: 13 additions & 9 deletions syncer/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package syncer

import (
"bytes"
"database/sql"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -693,16 +694,19 @@ func (cp *RemoteCheckPoint) Load(tctx *tcontext.Context, schemaTracker *schema.T
}

var ti model.TableInfo
if err = json.Unmarshal(tiBytes, &ti); err != nil {
return terror.ErrSchemaTrackerInvalidJSON.Delegate(err, cpSchema, cpTable)
}

if schemaTracker != nil {
if err = schemaTracker.CreateSchemaIfNotExists(cpSchema); err != nil {
return terror.ErrSchemaTrackerCannotCreateSchema.Delegate(err, cpSchema)
if !bytes.Equal(tiBytes, []byte("null")) {
// only create table if `table_info` is not `null`.
if err = json.Unmarshal(tiBytes, &ti); err != nil {
return terror.ErrSchemaTrackerInvalidJSON.Delegate(err, cpSchema, cpTable)
}
if err = schemaTracker.CreateTableIfNotExists(cpSchema, cpTable, &ti); err != nil {
return terror.ErrSchemaTrackerCannotCreateTable.Delegate(err, cpSchema, cpTable)

if schemaTracker != nil {
if err = schemaTracker.CreateSchemaIfNotExists(cpSchema); err != nil {
return terror.ErrSchemaTrackerCannotCreateSchema.Delegate(err, cpSchema)
}
if err = schemaTracker.CreateTableIfNotExists(cpSchema, cpTable, &ti); err != nil {
return terror.ErrSchemaTrackerCannotCreateTable.Delegate(err, cpSchema, cpTable)
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion tests/import_v10x/data/v106_syncer_checkpoint.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ CREATE TABLE IF NOT EXISTS `dm_meta`.`test_syncer_checkpoint` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
INSERT INTO `dm_meta`.`test_syncer_checkpoint` VALUES
('mysql-replica-01','','','BINLOG_NAME1',BINLOG_POS1,1,'2020-07-31 18:10:40','2020-07-31 18:11:40'),
('mysql-replica-02','','','BINLOG_NAME2',BINLOG_POS2,1,'2020-07-31 18:10:40','2020-07-31 18:11:40');
('mysql-replica-01','import_v10x','t1','BINLOG_NAME1',BINLOG_POS1,0,'2020-07-31 18:10:40','2020-07-31 18:11:40'),
('mysql-replica-02','','','BINLOG_NAME2',BINLOG_POS2,1,'2020-07-31 18:10:40','2020-07-31 18:11:40'),
('mysql-replica-02','import_v10x','t2','BINLOG_NAME2',BINLOG_POS2,0,'2020-07-31 18:10:40','2020-07-31 18:11:40');

0 comments on commit a2e8c5f

Please sign in to comment.