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

migration(ticdc): fix backup key issue #6232

Merged
merged 1 commit into from
Jul 8, 2022
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
3 changes: 3 additions & 0 deletions pkg/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ func GetEtcdKeyJob(clusterID string, changeFeedID model.ChangeFeedID) string {

// MigrateBackupKey is the key of backup data during a migration.
func MigrateBackupKey(version int, backupKey string) string {
if strings.HasPrefix(backupKey, "/") {
return fmt.Sprintf("%s/%d%s", migrateBackupPrefix, version, backupKey)
}
return fmt.Sprintf("%s/%d/%s", migrateBackupPrefix, version, backupKey)
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/etcd/etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,10 @@ func TestExtractKeySuffix(t *testing.T) {
}
}
}

func TestMigrateBackupKey(t *testing.T) {
key := MigrateBackupKey(1, "/tidb/cdc/capture/abcd")
require.Equal(t, "/tidb/cdc/__backup__/1/tidb/cdc/capture/abcd", key)
key = MigrateBackupKey(1, "abcdc")
require.Equal(t, "/tidb/cdc/__backup__/1/abcdc", key)
}
14 changes: 7 additions & 7 deletions pkg/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func createPDClient(ctx context.Context,
// 1. check and put metaVersion
// 2. campaign old owner
// 3. update keys
// 4. check meta data consistency
// 4. check metadata consistency
// 5. update metaVersion
func (m *migrator) migrate(ctx context.Context, etcdNoMetaVersion bool, oldVersion int) error {
pdClient, err := m.createPDClientFunc(ctx,
Expand Down Expand Up @@ -292,7 +292,7 @@ func cleanOldData(ctx context.Context, client *etcd.Client) {
if strings.HasPrefix(key, oldChangefeedPrefix) {
value = maskChangefeedInfo(kvPair.Value)
}
// 0 is the backup verion. For now, we only support verion 0
// 0 is the backup version. For now, we only support version 0
newKey := etcd.MigrateBackupKey(0, key)
log.Info("renaming old etcd data",
zap.String("key", key),
Expand All @@ -312,7 +312,7 @@ func cleanOldData(ctx context.Context, client *etcd.Client) {
}
}

// old key prefix that should be remove
// old key prefix that should be removed
var oldKeyPrefix = []string{
"/tidb/cdc/changefeed/info",
"/tidb/cdc/job",
Expand Down Expand Up @@ -469,7 +469,7 @@ func (m *migrator) Migrate(ctx context.Context) error {
return m.migrate(ctx, version == noMetaVersion, oldVersion)
}

// ShouldMigrate checks if we should migrate etcd meta data
// ShouldMigrate checks if we should migrate etcd metadata
func (m *migrator) ShouldMigrate(ctx context.Context) (bool, error) {
version, err := getMetaVersion(ctx, m.cli.Client, m.cli.ClusterID)
if err != nil {
Expand Down Expand Up @@ -568,17 +568,17 @@ func getMetaVersion(ctx context.Context, cli *etcd.Client, clusterID string) (in
type NoOpMigrator struct{}

// ShouldMigrate checks if we need to migrate metadata
func (f *NoOpMigrator) ShouldMigrate(ctx context.Context) (bool, error) {
func (f *NoOpMigrator) ShouldMigrate(_ context.Context) (bool, error) {
return false, nil
}

// Migrate migrates the cdc metadata
func (f *NoOpMigrator) Migrate(ctx context.Context) error {
func (f *NoOpMigrator) Migrate(_ context.Context) error {
return nil
}

// WaitMetaVersionMatched wait util migration is done
func (f *NoOpMigrator) WaitMetaVersionMatched(ctx context.Context) error {
func (f *NoOpMigrator) WaitMetaVersionMatched(_ context.Context) error {
return nil
}

Expand Down