diff --git a/cmd/format.go b/cmd/format.go index 948a9189c4b3..182f7406968e 100644 --- a/cmd/format.go +++ b/cmd/format.go @@ -142,6 +142,10 @@ Details: https://juicefs.com/docs/community/quick_start_guide`, Value: 1, Usage: "number of days after which removed files will be permanently deleted", }, + &cli.BoolFlag{ + Name: "hash-prefix", + Usage: "give each object a hashed prefix", + }, &cli.BoolFlag{ Name: "force", Usage: "overwrite existing format", @@ -320,6 +324,7 @@ func format(c *cli.Context) error { SecretKey: c.String("secret-key"), EncryptKey: loadEncrypt(c.String("encrypt-rsa-key")), Shards: c.Int("shards"), + HashPrefix: c.Bool("hash-prefix"), Capacity: c.Uint64("capacity") << 30, Inodes: c.Uint64("inodes"), BlockSize: fixObjectSize(c.Int("block-size")), @@ -361,6 +366,8 @@ func format(c *cli.Context) error { format.Compression = c.String(flag) case "shards": format.Shards = c.Int(flag) + case "hash-prefix": + format.HashPrefix = c.Bool(flag) case "storage": format.Storage = c.String(flag) case "encrypt-rsa-key": diff --git a/cmd/mount.go b/cmd/mount.go index eb5c6a3bcead..558c98fc5be0 100644 --- a/cmd/mount.go +++ b/cmd/mount.go @@ -278,8 +278,9 @@ func newStore(format *meta.Format, chunkConf *chunk.Config, registerer prometheu func getChunkConf(c *cli.Context, format *meta.Format) *chunk.Config { chunkConf := &chunk.Config{ - BlockSize: format.BlockSize * 1024, - Compress: format.Compression, + BlockSize: format.BlockSize * 1024, + Compress: format.Compression, + HashPrefix: format.HashPrefix, GetTimeout: time.Second * time.Duration(c.Int("get-timeout")), PutTimeout: time.Second * time.Duration(c.Int("put-timeout")), diff --git a/pkg/chunk/cached_store.go b/pkg/chunk/cached_store.go index 07fce3b3ae59..b82cb4abe620 100644 --- a/pkg/chunk/cached_store.go +++ b/pkg/chunk/cached_store.go @@ -134,7 +134,7 @@ func (c *rChunk) blockSize(indx int) int { } func (c *rChunk) key(indx int) string { - if c.store.conf.Partitions > 1 { + if c.store.conf.HashPrefix { return fmt.Sprintf("chunks/%02X/%v/%v_%v_%v", c.id%256, c.id/1000/1000, c.id, indx, c.blockSize(indx)) } return fmt.Sprintf("chunks/%v/%v/%v_%v_%v", c.id/1000/1000, c.id/1000, c.id, indx, c.blockSize(indx)) @@ -623,7 +623,7 @@ type Config struct { DownloadLimit int64 // bytes per second Writeback bool UploadDelay time.Duration - Partitions int + HashPrefix bool BlockSize int GetTimeout time.Duration PutTimeout time.Duration diff --git a/pkg/chunk/cached_store_test.go b/pkg/chunk/cached_store_test.go index 01fc9685adbd..e46a60ef017d 100644 --- a/pkg/chunk/cached_store_test.go +++ b/pkg/chunk/cached_store_test.go @@ -205,7 +205,7 @@ func TestStoreDelayed(t *testing.T) { func TestStoreMultiBuckets(t *testing.T) { mem, _ := object.CreateStorage("mem", "", "", "") conf := defaultConf - conf.Partitions = 3 + conf.HashPrefix = true store := NewCachedStore(mem, conf, nil) testStore(t, store) } diff --git a/pkg/meta/config.go b/pkg/meta/config.go index 9b185fdda0cf..2cd7deafad3b 100644 --- a/pkg/meta/config.go +++ b/pkg/meta/config.go @@ -52,7 +52,7 @@ type Format struct { BlockSize int Compression string Shards int - Partitions int + HashPrefix bool Capacity uint64 Inodes uint64 EncryptKey string `json:",omitempty"` diff --git a/pkg/meta/metadata-sub.sample b/pkg/meta/metadata-sub.sample index 676801defe8a..043f06bffa71 100644 --- a/pkg/meta/metadata-sub.sample +++ b/pkg/meta/metadata-sub.sample @@ -9,7 +9,7 @@ "BlockSize": 4096, "Compression": "none", "Shards": 0, - "Partitions": 0, + "HashPrefix": false, "Capacity": 0, "Inodes": 0, "EncryptKey": "AQSttslKOSE/hQT/gmaMniCsdPF8JdPRfoYK6zFkdUOnifYwBA==", diff --git a/pkg/meta/metadata.sample b/pkg/meta/metadata.sample index d6136200c655..0149a8b0e7a9 100644 --- a/pkg/meta/metadata.sample +++ b/pkg/meta/metadata.sample @@ -9,7 +9,7 @@ "BlockSize": 4096, "Compression": "none", "Shards": 0, - "Partitions": 0, + "HashPrefix": false, "Capacity": 0, "Inodes": 0, "EncryptKey": "AQSttslKOSE/hQT/gmaMniCsdPF8JdPRfoYK6zFkdUOnifYwBA==", diff --git a/sdk/java/libjfs/main.go b/sdk/java/libjfs/main.go index ee73f64c883c..72a6c238a116 100644 --- a/sdk/java/libjfs/main.go +++ b/sdk/java/libjfs/main.go @@ -464,7 +464,7 @@ func jfs_init(cname, jsonConf, user, group, superuser, supergroup *C.char) uintp DownloadLimit: int64(jConf.DownloadLimit) * 1e6 / 8, Prefetch: jConf.Prefetch, Writeback: jConf.Writeback, - Partitions: format.Partitions, + HashPrefix: format.HashPrefix, GetTimeout: time.Second * time.Duration(jConf.GetTimeout), PutTimeout: time.Second * time.Duration(jConf.PutTimeout), BufferSize: jConf.MemorySize << 20,