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

Compacted log: tiny fix or enhancement #59195

Merged
merged 2 commits into from
Jan 27, 2025
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
8 changes: 5 additions & 3 deletions br/cmd/br/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ func newListMigrationsCommand() *cobra.Command {

func newMigrateToCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "migrate-to",
Short: "migrate to a specific version",
Args: cobra.NoArgs,
Use: "unsafe-migrate-to",
Short: "migrate to a specific version, use truncate will auto migrate to correct version, " +
"you should never use this command unless you know what you are doing",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
cfg := operator.MigrateToConfig{}
if err := cfg.ParseFromFlags(cmd.Flags()); err != nil {
Expand All @@ -109,6 +110,7 @@ func newMigrateToCommand() *cobra.Command {
},
}
operator.DefineFlagsForMigrateToConfig(cmd.Flags())
cmd.Hidden = true
return cmd
}

Expand Down
10 changes: 6 additions & 4 deletions br/pkg/restore/utils/rewrite_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,13 @@ func (r *RewriteRules) SetTimeRangeFilter(cfName string) error {
var ignoreBeforeTs uint64
switch {
case strings.Contains(cfName, DefaultCFName):
// for default cf, we need to check if shift start ts is greater than start ts
if r.ShiftStartTs > r.StartTs {
return errors.Errorf("shift start ts %d is greater than start ts %d", r.ShiftStartTs, r.StartTs)
}
ignoreBeforeTs = r.ShiftStartTs
if ignoreBeforeTs > r.StartTs {
// for default cf, shift start ts could less than start ts
// this could happen when large kv txn happen after small kv txn.
// use the start ts to filter out irrelevant data for default cf is more safe
ignoreBeforeTs = r.StartTs
}
case strings.Contains(cfName, WriteCFName):
ignoreBeforeTs = r.StartTs
default:
Expand Down
10 changes: 6 additions & 4 deletions br/pkg/restore/utils/rewrite_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ func TestSetTimeRangeFilter(t *testing.T) {
RestoredTs: 200,
},
cfName: "default",
expectError: true,
expectError: false,
},
{
name: "write cf valid shift start ts (greater than start ts)",
Expand Down Expand Up @@ -610,7 +610,6 @@ func TestSetTimeRangeFilter(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := tc.rules.SetTimeRangeFilter(tc.cfName)

if tc.expectError {
require.Error(t, err)
return
Expand All @@ -631,8 +630,11 @@ func TestSetTimeRangeFilter(t *testing.T) {
require.Equal(t, tc.rules.RestoredTs, rule.IgnoreAfterTimestamp)

if strings.Contains(tc.cfName, "default") {
require.Equal(t, tc.rules.ShiftStartTs, rule.IgnoreBeforeTimestamp)
require.Less(t, tc.rules.ShiftStartTs, tc.rules.StartTs)
if tc.rules.ShiftStartTs < tc.rules.StartTs {
require.Equal(t, tc.rules.ShiftStartTs, rule.IgnoreBeforeTimestamp)
} else {
require.Equal(t, tc.rules.StartTs, rule.IgnoreBeforeTimestamp)
}
} else if strings.Contains(tc.cfName, "write") {
require.Equal(t, tc.rules.StartTs, rule.IgnoreBeforeTimestamp)
}
Expand Down
Loading