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

WIP: fixing backup_pitr flaky tests #13761

Closed
Closed
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
30 changes: 24 additions & 6 deletions go/test/endtoend/backup/vtctlbackup/backup_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1089,10 +1089,18 @@ func vtctlBackupReplicaNoDestroyNoWrites(t *testing.T, replicaIndex int) (backup
return backups
}

func GetTabletPosition(t *testing.T, tablet *cluster.Vttablet) string {
pos, _ := cluster.GetPrimaryPosition(t, *tablet, hostname)
return pos
}

func GetReplicaPosition(t *testing.T, replicaIndex int) string {
replica := getReplica(t, replicaIndex)
pos, _ := cluster.GetPrimaryPosition(t, *replica, hostname)
return pos
return GetTabletPosition(t, replica)
}

func GetPrimaryPosition(t *testing.T) string {
return GetTabletPosition(t, primary)
}

func GetReplicaGtidPurged(t *testing.T, replicaIndex int) string {
Expand Down Expand Up @@ -1147,16 +1155,26 @@ func ReadRowsFromReplica(t *testing.T, replicaIndex int) (msgs []string) {
return ReadRowsFromTablet(t, getReplica(t, replicaIndex))
}

// FlushBinaryLogsOnReplica issues `FLUSH BINARY LOGS` <count> times
func FlushBinaryLogsOnReplica(t *testing.T, replicaIndex int, count int) {
replica := getReplica(t, replicaIndex)
// FlushBinaryLogsOnTablet issues `FLUSH BINARY LOGS` <count> times
func FlushBinaryLogsOnTablet(t *testing.T, tablet *cluster.Vttablet, count int) {
query := "flush binary logs"
for i := 0; i < count; i++ {
_, err := replica.VttabletProcess.QueryTablet(query, keyspaceName, true)
_, err := tablet.VttabletProcess.QueryTablet(query, keyspaceName, true)
require.NoError(t, err)
}
}

// FlushBinaryLogsOnReplica issues `FLUSH BINARY LOGS` <count> times
func FlushBinaryLogsOnReplica(t *testing.T, replicaIndex int, count int) {
replica := getReplica(t, replicaIndex)
FlushBinaryLogsOnTablet(t, replica, count)
}

// FlushBinaryLogsOnPrimary issues `FLUSH BINARY LOGS` <count> times
func FlushBinaryLogsOnPrimary(t *testing.T, count int) {
FlushBinaryLogsOnTablet(t, primary, count)
}

// FlushAndPurgeBinaryLogsOnReplica intentionally loses all existing binary logs. It flushes into a new binary log
// and immediately purges all previous logs.
// This is used to lose information.
Expand Down
11 changes: 5 additions & 6 deletions go/test/endtoend/backup/vtctlbackup/pitr_test_framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/stretchr/testify/require"

"vitess.io/vitess/go/mysql/replication"

"vitess.io/vitess/go/test/endtoend/cluster"
"vitess.io/vitess/go/vt/mysqlctl"
)
Expand Down Expand Up @@ -61,10 +60,10 @@ type testedBackupTimestampInfo struct {
func waitForReplica(t *testing.T, replicaIndex int) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
pMsgs := ReadRowsFromPrimary(t)
for {
rMsgs := ReadRowsFromReplica(t, replicaIndex)
if len(pMsgs) == len(rMsgs) {
primaryPos := GetPrimaryPosition(t)
replicaPos := GetReplicaPosition(t, replicaIndex)
if replicaPos == primaryPos {
// success
return
}
Expand Down Expand Up @@ -170,10 +169,10 @@ func ExecTestIncrementalBackupAndRestoreToPos(t *testing.T, tcase *PITRTestCase)
if tc.writeBeforeBackup {
InsertRowOnPrimary(t, "")
}
// we wait for 1 second because backups are written to a directory named after the current timestamp,
// we wait for >1 second because backups are written to a directory named after the current timestamp,
// in 1 second resolution. We want to avoid two backups that have the same pathname. Realistically this
// is only ever a problem in this end-to-end test, not in production.
// Also, we gie the replica a chance to catch up.
// Also, we give the replica a chance to catch up.
time.Sleep(postWriteSleepDuration)
// randomly flush binary logs 0, 1 or 2 times
FlushBinaryLogsOnReplica(t, 0, rand.Intn(3))
Expand Down