Skip to content

Commit

Permalink
gateway: skip init meta bucket when meta is read only (#4992)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhijian-pro authored Jul 19, 2024
1 parent 98741c4 commit 61a0099
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
12 changes: 8 additions & 4 deletions cmd/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,16 @@ func gateway(c *cli.Context) error {
if err != nil {
return err
}

if _, err := jfsGateway.GetBucketInfo(context.Background(), minio.MinioMetaBucket); errors.As(err, &minio.BucketNotFound{}) {
if err := jfsGateway.MakeBucketWithLocation(context.Background(), minio.MinioMetaBucket, minio.BucketOptions{}); err != nil {
logger.Fatalf("init MinioMetaBucket error %s: %s", minio.MinioMetaBucket, err)
if c.IsSet("read-only") {
os.Setenv("JUICEFS_META_READ_ONLY", "1")
} else {
if _, err := jfsGateway.GetBucketInfo(context.Background(), minio.MinioMetaBucket); errors.As(err, &minio.BucketNotFound{}) {
if err := jfsGateway.MakeBucketWithLocation(context.Background(), minio.MinioMetaBucket, minio.BucketOptions{}); err != nil {
logger.Fatalf("init MinioMetaBucket error %s: %s", minio.MinioMetaBucket, err)
}
}
}

args := []string{"server", "--address", listenAddr, "--anonymous"}
if c.Bool("no-banner") {
args = append(args, "--quiet")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ require (
xorm.io/builder v0.3.7 // indirect
)

replace github.com/minio/minio v0.0.0-20210206053228-97fe57bba92c => github.com/juicedata/minio v0.0.0-20240612084555-8a33dba0f571
replace github.com/minio/minio v0.0.0-20210206053228-97fe57bba92c => github.com/juicedata/minio v0.0.0-20240719032536-5d15c7c0135d

replace github.com/hanwen/go-fuse/v2 v2.1.1-0.20210611132105-24a1dfe6b4f8 => github.com/juicedata/go-fuse/v2 v2.1.1-0.20240425033113-7c40cb5eb3e9

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,8 @@ github.com/juicedata/gogfapi v0.0.0-20230626071140-fc28e5537825 h1:7KrwI4HPqvNLK
github.com/juicedata/gogfapi v0.0.0-20230626071140-fc28e5537825/go.mod h1:Ho5G4KgrgbMKW0buAJdOmYoJcOImkzznJQaLiATrsx4=
github.com/juicedata/huaweicloud-sdk-go-obs v3.22.12-0.20230228031208-386e87b5c091+incompatible h1:2/ttSmYoX+QMegpNyAJR0Y6aHcVk57F7RJit5xN2T/s=
github.com/juicedata/huaweicloud-sdk-go-obs v3.22.12-0.20230228031208-386e87b5c091+incompatible/go.mod h1:Ukwa8ffRQLV6QRwpqGioPjn2Wnf7TBDA4DbennDOqHE=
github.com/juicedata/minio v0.0.0-20240612084555-8a33dba0f571 h1:usZ1RJ9AssiJxSVRibh2mbQ5cI9FuSbkXJTiweL3hxk=
github.com/juicedata/minio v0.0.0-20240612084555-8a33dba0f571/go.mod h1:UOWyfa3ls1tnpJrNw2yzGqfrwM4nzsZq/qz+zd6H+/Q=
github.com/juicedata/minio v0.0.0-20240719032536-5d15c7c0135d h1:rDGD7VqSTs2gTr8HNFgnit1xrUPUWl6v+5HsgL2QrYM=
github.com/juicedata/minio v0.0.0-20240719032536-5d15c7c0135d/go.mod h1:UOWyfa3ls1tnpJrNw2yzGqfrwM4nzsZq/qz+zd6H+/Q=
github.com/juicedata/mpb/v7 v7.0.4-0.20231024073412-2b8d31be510b h1:0/6suPNZnrOlRlBaU/Bnitu8HiKkkLSzQhHbwQ9AysM=
github.com/juicedata/mpb/v7 v7.0.4-0.20231024073412-2b8d31be510b/go.mod h1:NXGsfPGx6G2JssqvEcULtDqUrxuuYs4llpv8W6ZUpzk=
github.com/juju/ratelimit v1.0.2 h1:sRxmtRiajbvrcLQT7S+JbqU0ntsb9W2yhSdNN8tWfaI=
Expand Down
18 changes: 13 additions & 5 deletions pkg/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,11 @@ func (n *jfsObjects) MakeBucketWithLocation(ctx context.Context, bucket string,
}
}
eno := n.fs.Mkdir(mctx, n.path(bucket), 0777, n.gConf.Umask)
metadata := minio.NewBucketMetadata(bucket)
if err := metadata.Save(ctx, n); err != nil {
return err
if eno == 0 {
metadata := minio.NewBucketMetadata(bucket)
if err := metadata.Save(ctx, n); err != nil {
return err
}
}
return jfsToObjectErr(ctx, eno, bucket)
}
Expand Down Expand Up @@ -1200,6 +1202,9 @@ func (j *jfsFLock) GetLock(ctx context.Context, timeout *minio.DynamicTimeout) (
}

func (j *jfsFLock) getFlockWithTimeOut(ctx context.Context, ltype uint32, timeout *minio.DynamicTimeout) (context.Context, error) {
if os.Getenv("JUICEFS_META_READ_ONLY") != "" {
return ctx, nil
}
if j.inode == 0 {
logger.Warnf("failed to get lock")
return ctx, nil
Expand Down Expand Up @@ -1254,7 +1259,7 @@ func (j *jfsFLock) getFlockWithTimeOut(ctx context.Context, ltype uint32, timeou
}

func (j *jfsFLock) Unlock() {
if j.inode == 0 {
if j.inode == 0 || os.Getenv("JUICEFS_META_READ_ONLY") != "" {
return
}
if errno := j.meta.Flock(mctx, j.inode, j.owner, meta.F_UNLCK, true); errno != 0 {
Expand All @@ -1268,7 +1273,7 @@ func (j *jfsFLock) GetRLock(ctx context.Context, timeout *minio.DynamicTimeout)
}

func (j *jfsFLock) RUnlock() {
if j.inode == 0 {
if j.inode == 0 || os.Getenv("JUICEFS_META_READ_ONLY") != "" {
return
}
if errno := j.meta.Flock(mctx, j.inode, j.owner, meta.F_UNLCK, true); errno != 0 {
Expand All @@ -1278,6 +1283,9 @@ func (j *jfsFLock) RUnlock() {
}

func (n *jfsObjects) NewNSLock(bucket string, objects ...string) minio.RWLocker {
if os.Getenv("JUICEFS_META_READ_ONLY") != "" {
return &jfsFLock{}
}
if len(objects) != 1 {
panic(fmt.Errorf("jfsObjects.NewNSLock: the length of the objects parameter must be 1, current %s", objects))
}
Expand Down

0 comments on commit 61a0099

Please sign in to comment.