Skip to content

Commit 077372c

Browse files
PBM-1447. Unset LD_PRELOAD on physical restore to prevent PSMDB 8.0 from getting stuck (#1064)
1 parent 294173f commit 077372c

File tree

4 files changed

+48
-20
lines changed

4 files changed

+48
-20
lines changed

e2e-tests/cmd/pbm-test/run_physical.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"context"
55
"math/rand"
66

7-
"golang.org/x/mod/semver"
8-
97
"github.com/percona/percona-backup-mongodb/e2e-tests/pkg/tests/sharded"
108
"github.com/percona/percona-backup-mongodb/pbm/defs"
119
)
@@ -60,11 +58,8 @@ func runPhysical(t *sharded.Cluster, typ testTyp) {
6058
t.DistributedTrxPhysical)
6159
}
6260

63-
// Skip test for 8.0 until PBM-1447 is fixed
64-
if semver.Compare(cVersion, "v8.0") < 0 {
65-
runTest("Clock Skew Tests",
66-
func() { t.ClockSkew(defs.PhysicalBackup, cVersion) })
67-
}
61+
runTest("Clock Skew Tests",
62+
func() { t.ClockSkew(defs.PhysicalBackup, cVersion) })
6863

6964
flushStore(t)
7065
}

e2e-tests/pkg/pbm/clock_skew.go

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package pbm
33
import (
44
"context"
55
"log"
6+
"strings"
67

78
"github.com/docker/docker/api/types/container"
89
"github.com/docker/docker/api/types/filters"
@@ -13,7 +14,9 @@ import (
1314
)
1415

1516
func ClockSkew(rsName, ts, dockerHost string) error {
16-
log.Printf("== Skew the clock for %s on the replicaset %s ", ts, rsName)
17+
if ts != "0" {
18+
log.Printf("==Skew the clock for %s on the replicaset %s ", ts, rsName)
19+
}
1720

1821
cn, err := client.NewClientWithOpts(client.WithHost(dockerHost))
1922
if err != nil {
@@ -36,18 +39,41 @@ func ClockSkew(rsName, ts, dockerHost string) error {
3639
return errors.Wrapf(err, "ContainerInspect for %s", c.ID)
3740
}
3841

42+
envs := append([]string{}, containerOld.Config.Env...)
43+
if ts == "0" {
44+
ldPreloadDefined := false
45+
for _, env := range envs {
46+
if strings.HasPrefix(env, "LD_PRELOAD") {
47+
ldPreloadDefined = true
48+
break
49+
}
50+
}
51+
52+
if !ldPreloadDefined {
53+
log.Printf("Variable LD_PRELOAD isn't defined, skipping container restart for %s\n", containerOld.Name)
54+
continue
55+
}
56+
57+
var filteredEnvs []string
58+
for _, env := range envs {
59+
if !strings.HasPrefix(env, "LD_PRELOAD") {
60+
filteredEnvs = append(filteredEnvs, env)
61+
}
62+
}
63+
envs = filteredEnvs
64+
} else {
65+
envs = append(envs,
66+
`LD_PRELOAD=/lib64/faketime/libfaketime.so.1`,
67+
`FAKETIME=`+ts,
68+
)
69+
}
70+
3971
log.Printf("Removing container %s/%s\n", containerOld.ID, containerOld.Name)
4072
err = cn.ContainerRemove(context.Background(), c.ID, container.RemoveOptions{Force: true})
4173
if err != nil {
4274
return errors.Wrapf(err, "remove container %s", c.ID)
4375
}
4476

45-
envs := append([]string{}, containerOld.Config.Env...)
46-
envs = append(envs,
47-
`LD_PRELOAD=/lib64/faketime/libfaketime.so.1`,
48-
`FAKETIME=`+ts,
49-
)
50-
5177
log.Printf("Creating container %s/%s with the clock skew %s\n", containerOld.ID, containerOld.Name, ts)
5278
containerNew, err := cn.ContainerCreate(context.Background(), &container.Config{
5379
Image: containerOld.Image,

e2e-tests/pkg/tests/sharded/cluster.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ func (c *Cluster) PhysicalRestore(ctx context.Context, bcpName string) {
145145
}
146146

147147
func (c *Cluster) PhysicalRestoreWithParams(ctx context.Context, bcpName string, options []string) {
148+
stdlog.Println("reset ENV variables")
149+
for name := range c.shards {
150+
err := pbmt.ClockSkew(name, "0", c.cfg.DockerURI)
151+
if err != nil {
152+
stdlog.Fatalln("reset ENV variables:", err)
153+
}
154+
}
155+
148156
stdlog.Println("restoring the backup")
149157
name, err := c.pbm.Restore(bcpName, options)
150158
if err != nil {

e2e-tests/pkg/tests/sharded/test_clock_skew.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package sharded
22

33
import (
44
"log"
5+
"math/rand"
56

67
pbmt "github.com/percona/percona-backup-mongodb/e2e-tests/pkg/pbm"
78
"github.com/percona/percona-backup-mongodb/pbm/defs"
@@ -11,16 +12,14 @@ func (c *Cluster) ClockSkew(typ defs.BackupType, mongoVersion string) {
1112
timeShifts := []string{
1213
"+90m", "-195m", "+2d", "-7h", "+11m", "+42d", "-13h",
1314
}
14-
rsNames := []string{"cfg"}
15+
rsNames := []string{}
1516
for s := range c.shards {
1617
rsNames = append(rsNames, s)
1718
}
1819

19-
for k, rs := range rsNames {
20-
if k >= len(timeShifts) {
21-
k %= len(timeShifts)
22-
}
23-
shift := timeShifts[k]
20+
for _, rs := range rsNames {
21+
randomIndex := rand.Intn(len(timeShifts))
22+
shift := timeShifts[randomIndex]
2423

2524
err := pbmt.ClockSkew(rs, shift, c.cfg.DockerURI)
2625
if err != nil {

0 commit comments

Comments
 (0)