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

fix: fix bgsave bug #3021

Merged
merged 1 commit into from
Feb 20, 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
4 changes: 2 additions & 2 deletions .github/workflows/pika.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
rm -rf ./deps
rm -rf ./buildtrees

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_PIKA_NAME }}
path: ${{ github.workspace }}/build/pika
Expand Down Expand Up @@ -221,7 +221,7 @@ jobs:
with:
images: pikadb/pika

- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_PIKA_NAME }}
path: artifact/
Expand Down
84 changes: 0 additions & 84 deletions tests/integration/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"strconv"
"strings"
"time"
"os"
"path/filepath"
. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"
"github.com/redis/go-redis/v9"
Expand Down Expand Up @@ -177,88 +175,6 @@ var _ = Describe("Server", func() {
Expect(err).NotTo(HaveOccurred())
Expect(val).To(ContainSubstring("Background append only file rewriting"))
})

It("should BgSave", func() {
res := client.Set(ctx, "bgsava_key1", "bgsava_value1", 0)
Expect(res.Err()).NotTo(HaveOccurred())
_ = client.Set(ctx, "bgsava_key2", "bgsava_value2", 0)
Expect(res.Err()).NotTo(HaveOccurred())

lastSaveBefore, err := client.LastSave(ctx).Result()
Expect(err).NotTo(HaveOccurred())

currentDir, err := os.Getwd()
Expect(err).NotTo(HaveOccurred())

var pikaDir string
for currentDir != "/" {
if filepath.Base(currentDir) == "pika" {
pikaDir = currentDir
break
}
currentDir = filepath.Dir(currentDir)
}
Expect(pikaDir).NotTo(BeEmpty(), "Could not find 'pika' directory")

var dumpDirs []string
err = filepath.WalkDir(pikaDir, func(path string, info os.DirEntry, err error) error {
if err != nil {
return err
}
if info.IsDir() && info.Name() == "dump" {
absPath, err := filepath.Abs(path)
if err != nil {
return err
}
dumpDirs = append(dumpDirs, absPath)
}
return nil
})
Expect(err).NotTo(HaveOccurred(), "Error while searching for 'dump' directories")
Expect(len(dumpDirs)).To(BeNumerically(">", 0), "No 'dump' directories found in 'pika'")

shortestDumpDir := dumpDirs[0]
for _, dir := range dumpDirs {
if len(dir) < len(shortestDumpDir) {
shortestDumpDir = dir
}
}

dumpConfig := client.ConfigGet(ctx, "dump-path")
Expect(dumpConfig.Err()).NotTo(HaveOccurred())
originalDumpPath, ok := dumpConfig.Val()["dump-path"]
Expect(ok).To(BeTrue())

dumpPath := filepath.Join(filepath.Dir(shortestDumpDir), originalDumpPath)

res2, err2 := client.BgSave(ctx).Result()
Expect(err2).NotTo(HaveOccurred())
Expect(res.Err()).NotTo(HaveOccurred())
Expect(res2).To(ContainSubstring("Background saving started"))

startTime := time.Now()
maxWaitTime := 10 * time.Second

for {
lastSaveAfter, err := client.LastSave(ctx).Result()
Expect(err).NotTo(HaveOccurred())

if lastSaveAfter > lastSaveBefore {
break
}

if time.Since(startTime) > maxWaitTime {
Fail("BGSAVE did not complete within the expected time")
}

time.Sleep(500 * time.Millisecond)
}


files, err := os.ReadDir(dumpPath)
Expect(err).NotTo(HaveOccurred(), "Failed to read dump_path")
Expect(len(files)).To(BeNumerically(">", 0), "dump_tmp directory is empty, BGSAVE failed to create a file")
})

It("should FlushDb", func() {
res := client.Do(ctx, "flushdb")
Expand Down
Loading