Skip to content

Commit

Permalink
Compacted log: tiny fix or enhancement (#59195)
Browse files Browse the repository at this point in the history
ref #58238
  • Loading branch information
3pointer authored Jan 27, 2025
1 parent 8b2ef95 commit 0cede10
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
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

0 comments on commit 0cede10

Please sign in to comment.