Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lightning cannot ignore broken symlink #49423

Closed
kennytm opened this issue Dec 13, 2023 · 1 comment · Fixed by #51170
Closed

Lightning cannot ignore broken symlink #49423

kennytm opened this issue Dec 13, 2023 · 1 comment · Fixed by #51170
Labels
affects-6.5 affects-7.1 affects-7.5 component/lightning This issue is related to Lightning of TiDB. found/gs found by gs severity/major type/bug The issue is confirmed as a bug.

Comments

@kennytm
Copy link
Contributor

kennytm commented Dec 13, 2023

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

mkdir dsd
cd dsd
ln -s non-existing-file.png file-that-should-be-ignored.png
cd ..
./tidb-lightning -d ./dsd --backend tidb --tidb-port 4000

2. What did you expect to see? (Required)

tidb lightning exit successfully

(nothing should be imported because the directory is effectively empty, the file name of the broken symlink does not match the pattern db.tbl.123.csv for instance)

3. What did you see instead (Required)

tidb lightning encountered error: [Lightning:Storage:ErrStorageUnknown]unknown storage error: stat ./dsd/file-that-should-be-ignored.png: no such file or directory

4. What is your TiDB version? (Required)

Release Version: v7.5.0
Git Commit Hash: 069631e2ecfedc000ffb92c67207bea81380f020
Git Branch: heads/refs/tags/v7.5.0
Go Version: go1.21.3
UTC Build Time: 2023-11-24 08:46:08
Race Enabled: false

Also affects v6.5.4.

@kennytm kennytm added type/bug The issue is confirmed as a bug. component/lightning This issue is related to Lightning of TiDB. affects-6.5 affects-7.5 found/gs found by gs labels Dec 13, 2023
@kennytm
Copy link
Contributor Author

kennytm commented Dec 13, 2023

The issue is caused by trying to obtain the "real size" of a symlink. The error is thrown from line 133.

size := f.Size()
// if not a regular file, we need to use os.stat to get the real file size
if !f.Mode().IsRegular() {
stat, err := os.Stat(filepath.Join(l.base, path))
if err != nil {
return errors.Trace(err)
}
size = stat.Size()
}

The fix should also consider the following scenarios:

  1. The broken symlink do have the name pattern db.tbl.123.csv, but the table db.tbl got filtered out by -f
  2. As above, but the table db.tbl is included.

There should still be no errors in scenario 1 as the file db.tbl.123.csv won't be read anyway. For scenario 2 I think we should not skip the broken file.

So IMO the proper fix is

  1. Turn line 133 into a WARNING log.
  2. Return a dummy size (0 or 1) for such files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-6.5 affects-7.1 affects-7.5 component/lightning This issue is related to Lightning of TiDB. found/gs found by gs severity/major type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants