Skip to content

Commit

Permalink
br: add test for pingcap#54421 (pingcap#55571)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leavrth authored Aug 27, 2024
1 parent 3d42e34 commit 290dc46
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
3 changes: 2 additions & 1 deletion br/pkg/restore/log_client/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ go_test(
],
embed = [":log_client"],
flaky = True,
shard_count = 39,
shard_count = 40,
deps = [
"//br/pkg/errors",
"//br/pkg/gluetidb",
Expand All @@ -95,6 +95,7 @@ go_test(
"//br/pkg/utils",
"//br/pkg/utils/iter",
"//br/pkg/utiltest",
"//pkg/domain",
"//pkg/kv",
"//pkg/store/pdtypes",
"//pkg/tablecodec",
Expand Down
47 changes: 47 additions & 0 deletions br/pkg/restore/log_client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ import (
"testing"
"time"

"github.com/pingcap/errors"
backuppb "github.com/pingcap/kvproto/pkg/brpb"
"github.com/pingcap/kvproto/pkg/import_sstpb"
"github.com/pingcap/tidb/br/pkg/gluetidb"
"github.com/pingcap/tidb/br/pkg/mock"
logclient "github.com/pingcap/tidb/br/pkg/restore/log_client"
"github.com/pingcap/tidb/br/pkg/restore/utils"
"github.com/pingcap/tidb/br/pkg/storage"
"github.com/pingcap/tidb/br/pkg/stream"
"github.com/pingcap/tidb/br/pkg/utils/iter"
"github.com/pingcap/tidb/br/pkg/utiltest"
"github.com/pingcap/tidb/pkg/domain"
"github.com/pingcap/tidb/pkg/tablecodec"
filter "github.com/pingcap/tidb/pkg/util/table-filter"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -1337,3 +1340,47 @@ func TestLogFilesIterWithSplitHelper(t *testing.T) {
require.Equal(t, []byte(fmt.Sprintf("a%d", next)), r.Item.StartKey)
}
}

type fakeStorage struct {
storage.ExternalStorage
}

func (fs fakeStorage) FileExists(ctx context.Context, name string) (bool, error) {
return false, errors.Errorf("name: %s", name)
}

type fakeStorageOK struct {
storage.ExternalStorage
}

func (fs fakeStorageOK) FileExists(ctx context.Context, name string) (bool, error) {
return false, nil
}

func TestInitSchemasReplaceForDDL(t *testing.T) {
ctx := context.Background()

{
client := logclient.TEST_NewLogClient(123, 1, 2, fakeStorage{}, domain.NewMockDomain())
cfg := &logclient.InitSchemaConfig{IsNewTask: false}
_, err := client.InitSchemasReplaceForDDL(ctx, cfg)
require.Error(t, err)
require.Contains(t, err.Error(), "failed to check filename:pitr_id_maps/pitr_id_map.cluster_id:123.restored_ts:2")
}

{
client := logclient.TEST_NewLogClient(123, 1, 2, fakeStorage{}, domain.NewMockDomain())
cfg := &logclient.InitSchemaConfig{IsNewTask: true}
_, err := client.InitSchemasReplaceForDDL(ctx, cfg)
require.Error(t, err)
require.Contains(t, err.Error(), "failed to check filename:pitr_id_maps/pitr_id_map.cluster_id:123.restored_ts:1")
}

{
client := logclient.TEST_NewLogClient(123, 1, 2, fakeStorageOK{}, domain.NewMockDomain())
cfg := &logclient.InitSchemaConfig{IsNewTask: true}
_, err := client.InitSchemasReplaceForDDL(ctx, cfg)
require.Error(t, err)
require.Contains(t, err.Error(), "miss upstream table information at `start-ts`(1) but the full backup path is not specified")
}
}
13 changes: 13 additions & 0 deletions br/pkg/restore/log_client/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
backuppb "github.com/pingcap/kvproto/pkg/brpb"
"github.com/pingcap/tidb/br/pkg/storage"
"github.com/pingcap/tidb/br/pkg/utils/iter"
"github.com/pingcap/tidb/pkg/domain"
)

var FilterFilesByRegion = filterFilesByRegion
Expand All @@ -38,6 +39,18 @@ func (rc *LogFileManager) ReadStreamMeta(ctx context.Context) ([]Meta, error) {
return r.Item, nil
}

func TEST_NewLogClient(clusterID, startTS, restoreTS uint64, storage storage.ExternalStorage, dom *domain.Domain) *LogClient {
return &LogClient{
dom: dom,
LogFileManager: &LogFileManager{
startTS: startTS,
restoreTS: restoreTS,
},
clusterID: clusterID,
storage: storage,
}
}

func TEST_NewLogFileManager(startTS, restoreTS, shiftStartTS uint64, helper streamMetadataHelper) *LogFileManager {
return &LogFileManager{
startTS: startTS,
Expand Down
9 changes: 9 additions & 0 deletions br/tests/br_pitr/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ check_result() {
echo "restart a services"
restart_services

# non-compliant operation
echo "non compliant operation"
restore_fail=0
run_br --pd $PD_ADDR restore point -s "local://$TEST_DIR/$PREFIX/log" --start-ts $current_ts || restore_fail=1
if [ $restore_fail -ne 1 ]; then
echo 'pitr success'
exit 1
fi

# PITR restore
echo "run pitr"
run_br --pd $PD_ADDR restore point -s "local://$TEST_DIR/$PREFIX/log" --full-backup-storage "local://$TEST_DIR/$PREFIX/full" > $res_file 2>&1
Expand Down

0 comments on commit 290dc46

Please sign in to comment.