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

cloudstorage(ticdc): write meta file if not found and add ut for 10137 (#10283) #10286

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pkg/sink/cloudstorage/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,19 @@ func (f *FilePathGenerator) CheckOrWriteSchema(
}

// Case 2: the table meta path is not empty.
if schemaFileCnt != 0 {
if lastVersion == 0 {
log.Warn("no table schema file found in an non-empty meta path",
zap.Any("versionedTableName", table),
zap.Uint32("checksum", checksum))
}
if schemaFileCnt != 0 && lastVersion != 0 {
f.versionMap[table] = lastVersion
return nil
}

// Case 3: the table meta path is empty, which happens when:
// a. the table is existed before changefeed started. We need to write schema file to external storage.
// b. the schema file is deleted by the consumer. We write schema file to external storage too.
if schemaFileCnt != 0 && lastVersion == 0 {
log.Warn("no table schema file found in an non-empty meta path",
zap.Any("versionedTableName", table),
zap.Uint32("checksum", checksum))
}
encodedDetail, err := def.MarshalWithQuery()
if err != nil {
return err
Expand Down
21 changes: 19 additions & 2 deletions pkg/sink/cloudstorage/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"testing"
"time"

"github.com/google/uuid"
timodel "github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/parser/types"
Expand Down Expand Up @@ -325,9 +326,25 @@ func TestCheckOrWriteSchema(t *testing.T) {
require.Equal(t, tableInfo.Version, f.versionMap[table])

dir = filepath.Join(dir, "test/table1/meta")
cnt, err := os.ReadDir(dir)
files, err := os.ReadDir(dir)
require.NoError(t, err)
require.Equal(t, 1, len(cnt))
require.Equal(t, 1, len(files))

// test schema file is invalid
err = os.WriteFile(filepath.Join(dir,
fmt.Sprintf("%s.tmp.%s", files[0].Name(), uuid.NewString())),
[]byte("invalid"), 0o644)
require.NoError(t, err)
err = os.Remove(filepath.Join(dir, files[0].Name()))
require.NoError(t, err)
delete(f.versionMap, table)
err = f.CheckOrWriteSchema(ctx, table, tableInfo)
require.NoError(t, err)
require.Equal(t, table.TableInfoVersion, f.versionMap[table])

files, err = os.ReadDir(dir)
require.NoError(t, err)
require.Equal(t, 2, len(files))
}

func TestRemoveExpiredFilesWithoutPartition(t *testing.T) {
Expand Down
Loading