From da1c8b6aee0704cb216894d1d630e0cb75936f07 Mon Sep 17 00:00:00 2001 From: Changxin Miao Date: Tue, 5 Nov 2024 09:43:12 +0800 Subject: [PATCH] Fix gc tool never compacts keys with hash-prefix (#5277) Signed-off-by: Changxin Miao --- cmd/fsck.go | 13 ++----------- cmd/gc.go | 11 ++--------- cmd/gc_test.go | 2 +- 3 files changed, 5 insertions(+), 21 deletions(-) diff --git a/cmd/fsck.go b/cmd/fsck.go index aed50d35e8a5..cdb900e7f6b3 100644 --- a/cmd/fsck.go +++ b/cmd/fsck.go @@ -20,9 +20,7 @@ import ( "fmt" "sort" "strings" - "time" - "github.com/juicedata/juicefs/pkg/chunk" "github.com/juicedata/juicefs/pkg/meta" "github.com/juicedata/juicefs/pkg/object" osync "github.com/juicedata/juicefs/pkg/sync" @@ -91,15 +89,8 @@ func fsck(ctx *cli.Context) error { return m.Check(c, p, ctx.Bool("repair"), ctx.Bool("recursive"), ctx.Bool("sync-dir-stat")) } - chunkConf := chunk.Config{ - BlockSize: format.BlockSize * 1024, - Compress: format.Compression, - GetTimeout: time.Second * 60, - PutTimeout: time.Second * 60, - MaxUpload: 20, - BufferSize: 300 << 20, - CacheDir: "memory", - } + chunkConf := *getDefaultChunkConf(format) + chunkConf.CacheDir = "memory" blob, err := createStorage(*format) if err != nil { diff --git a/cmd/gc.go b/cmd/gc.go index 30e7d9740f88..df7114dcec69 100644 --- a/cmd/gc.go +++ b/cmd/gc.go @@ -84,15 +84,8 @@ func gc(ctx *cli.Context) error { logger.Fatalf("load setting: %s", err) } - chunkConf := chunk.Config{ - BlockSize: format.BlockSize * 1024, - Compress: format.Compression, - GetTimeout: time.Second * 60, - PutTimeout: time.Second * 60, - MaxUpload: 20, - BufferSize: 300 << 20, - CacheDir: "memory", - } + chunkConf := *getDefaultChunkConf(format) + chunkConf.CacheDir = "memory" blob, err := createStorage(*format) if err != nil { diff --git a/cmd/gc_test.go b/cmd/gc_test.go index 83c2c7412a93..7c8990de9046 100644 --- a/cmd/gc_test.go +++ b/cmd/gc_test.go @@ -68,7 +68,7 @@ func getFileCount(dir string) int { func TestGc(t *testing.T) { var bucket string - mountTemp(t, &bucket, []string{"--trash-days=0"}, nil) + mountTemp(t, &bucket, []string{"--trash-days=0", "--hash-prefix"}, nil) defer umountTemp(t) if err := writeSmallBlocks(testMountPoint); err != nil {