Skip to content

Commit

Permalink
cloudstorage(ticdc): write meta file if not found and add ut for 101… (
Browse files Browse the repository at this point in the history
  • Loading branch information
sdojjy authored Dec 18, 2023
1 parent 6b082ea commit bfece83
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
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

0 comments on commit bfece83

Please sign in to comment.