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

Commit

Permalink
lightning: Return error for empty path (#1397)
Browse files Browse the repository at this point in the history
  • Loading branch information
dveeden authored Aug 2, 2021
1 parent 9412628 commit e8bd882
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
# for the web interface
web/node_modules/
web/dist/
.vscode/
2 changes: 2 additions & 0 deletions pkg/lightning/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,8 @@ func (worker *restoreSchemaWorker) makeJobs(
// we already has this table in TiDB.
// we should skip ddl job and let SchemaValid check.
continue
} else if tblMeta.SchemaFile.FileMeta.Path == "" {
return errors.Errorf("table `%s`.`%s` schema not found", dbMeta.Name, tblMeta.Name)
}
sql, err := tblMeta.GetSchema(worker.ctx, worker.store)
if sql != "" {
Expand Down
27 changes: 27 additions & 0 deletions pkg/lightning/restore/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,33 @@ func (s *restoreSchemaSuite) TestRestoreSchemaFailed(c *C) {
c.Assert(errors.ErrorEqual(err, injectErr), IsTrue)
}

// When restoring a CSV with `-no-schema` and the target table doesn't exist
// then we can't restore the schema as the `Path` is empty. This is to make
// sure this results in the correct error.
// https://github.com/pingcap/br/issues/1394
func (s *restoreSchemaSuite) TestNoSchemaPath(c *C) {
fakeTable := mydump.MDTableMeta{
DB: "fakedb",
Name: "fake1",
SchemaFile: mydump.FileInfo{
TableName: filter.Table{
Schema: "fakedb",
Name: "fake1",
},
FileMeta: mydump.SourceFileMeta{
Path: "",
},
},
DataFiles: []mydump.FileInfo{},
TotalSize: 0,
}
s.rc.dbMetas[0].Tables = append(s.rc.dbMetas[0].Tables, &fakeTable)
err := s.rc.restoreSchema(s.ctx)
c.Assert(err, NotNil)
c.Assert(err, ErrorMatches, `table .* schema not found`)
s.rc.dbMetas[0].Tables = s.rc.dbMetas[0].Tables[:len(s.rc.dbMetas[0].Tables)-1]
}

func (s *restoreSchemaSuite) TestRestoreSchemaContextCancel(c *C) {
childCtx, cancel := context.WithCancel(s.ctx)
mockSession := mock.NewMockSession(s.controller)
Expand Down

0 comments on commit e8bd882

Please sign in to comment.