Skip to content

Commit 160f329

Browse files
committed
Achieve capacity limits
1 parent b287c34 commit 160f329

File tree

13 files changed

+478
-145
lines changed

13 files changed

+478
-145
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ goofys
33
goofys.test
44
xout
55
s3proxy.jar
6+
.vscode

api/common/config.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
type PartSizeConfig struct {
30-
PartSize uint64
30+
PartSize uint64
3131
PartCount uint64
3232
}
3333

@@ -45,8 +45,12 @@ type FlagStorage struct {
4545

4646
// Common Backend Config
4747
UseContentType bool
48-
Endpoint string
49-
Backend interface{}
48+
49+
Provider string
50+
Capacity uint64
51+
DiskUsageInterval uint64
52+
Endpoint string
53+
Backend interface{}
5054

5155
// Tuning
5256
MemoryLimit uint64

go.mod

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,21 @@ require (
1616
github.com/aws/aws-sdk-go v1.38.7
1717
github.com/google/btree v1.0.0
1818
github.com/google/uuid v1.1.2
19-
github.com/gopherjs/gopherjs v0.0.0-20210202160940-bed99a852dfe // indirect
2019
github.com/jacobsa/fuse v0.0.0-20210818065549-10d864429bf7
21-
github.com/jtolds/gls v4.2.0+incompatible // indirect
2220
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
2321
github.com/kr/pretty v0.1.1-0.20190720101428-71e7e4993750 // indirect
2422
github.com/mattn/go-ieproxy v0.0.0-20190805055040-f9202b1cfdeb // indirect
23+
github.com/minio/madmin-go v1.4.6
2524
github.com/mitchellh/go-homedir v1.1.0
2625
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b
2726
github.com/sevlyar/go-daemon v0.1.5
2827
github.com/shirou/gopsutil v0.0.0-20190731134726-d80c43f9c984
2928
github.com/sirupsen/logrus v1.8.1
30-
github.com/smartystreets/assertions v0.0.0-20160201214316-443d812296a8 // indirect
31-
github.com/smartystreets/goconvey v1.6.1-0.20160119221636-995f5b2e021c // indirect
3229
github.com/urfave/cli v1.21.1-0.20190807111034-521735b7608a
3330
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a
3431
google.golang.org/api v0.49.0
3532
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127
36-
gopkg.in/ini.v1 v1.46.0
33+
gopkg.in/ini.v1 v1.62.0
3734
)
3835

3936
replace github.com/aws/aws-sdk-go => ./s3ext

go.sum

Lines changed: 163 additions & 0 deletions
Large diffs are not rendered by default.

internal/backend.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
type Capabilities struct {
30-
MaxMultipartSize uint64
30+
MaxMultipartSize uint64
3131
// indicates that the blob store has native support for directories
3232
DirBlob bool
3333
Name string
@@ -44,7 +44,7 @@ type BlobItemOutput struct {
4444
Size uint64
4545
StorageClass *string
4646
// may be nil in list responses for backends that don't return metadata in listings
47-
Metadata map[string]*string
47+
Metadata map[string]*string
4848
}
4949

5050
type HeadBlobOutput struct {
@@ -179,7 +179,7 @@ type MultipartBlobAddInput struct {
179179

180180
type MultipartBlobAddOutput struct {
181181
RequestId string
182-
PartId *string
182+
PartId *string
183183
}
184184

185185
type MultipartBlobCopyInput struct {
@@ -192,7 +192,7 @@ type MultipartBlobCopyInput struct {
192192

193193
type MultipartBlobCopyOutput struct {
194194
RequestId string
195-
PartId *string
195+
PartId *string
196196
}
197197

198198
type MultipartBlobCommitOutput struct {
@@ -228,6 +228,14 @@ type MakeBucketOutput struct {
228228
RequestId string
229229
}
230230

231+
type GetBucketUsageInput struct {
232+
}
233+
234+
type GetBucketUsageOutput struct {
235+
Size uint64
236+
RequestId string
237+
}
238+
231239
/// Implementations of all the functions here are expected to be
232240
/// concurrency-safe, except for
233241
///
@@ -256,6 +264,7 @@ type StorageBackend interface {
256264
MultipartExpire(param *MultipartExpireInput) (*MultipartExpireOutput, error)
257265
RemoveBucket(param *RemoveBucketInput) (*RemoveBucketOutput, error)
258266
MakeBucket(param *MakeBucketInput) (*MakeBucketOutput, error)
267+
GetBucketUsage(param *GetBucketUsageInput) (*GetBucketUsageOutput, error)
259268
Delegate() interface{}
260269
}
261270

@@ -424,6 +433,11 @@ func (s *StorageBackendInitWrapper) MakeBucket(param *MakeBucketInput) (*MakeBuc
424433
return s.StorageBackend.MakeBucket(param)
425434
}
426435

436+
func (s *StorageBackendInitWrapper) GetBucketUsage(param *GetBucketUsageInput) (*GetBucketUsageOutput, error) {
437+
s.Init("")
438+
return s.StorageBackend.GetBucketUsage(param)
439+
}
440+
427441
type StorageBackendInitError struct {
428442
error
429443
cap Capabilities
@@ -547,3 +561,7 @@ func (e StorageBackendInitError) RemoveBucket(param *RemoveBucketInput) (*Remove
547561
func (e StorageBackendInitError) MakeBucket(param *MakeBucketInput) (*MakeBucketOutput, error) {
548562
return nil, e
549563
}
564+
565+
func (e StorageBackendInitError) GetBucketUsage(param *GetBucketUsageInput) (*GetBucketUsageOutput, error) {
566+
return nil, e
567+
}

internal/backend_adlv1.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ func NewADLv1(bucket string, flags *FlagStorage, config *ADLv1Config) (*ADLv1, e
152152
bucket: bucket,
153153
cap: Capabilities{
154154
//NoParallelMultipart: true,
155-
DirBlob: true,
156-
Name: "adl",
155+
DirBlob: true,
156+
Name: "adl",
157157
// ADLv1 fails with 404 if we upload data
158158
// larger than 30000000 bytes (28.6MB) (28MB
159159
// also failed in at one point, but as of
@@ -701,3 +701,7 @@ func (b *ADLv1) mkdir(dir string) error {
701701
}
702702
return nil
703703
}
704+
705+
func (b *ADLv1) GetBucketUsage(param *GetBucketUsageInput) (*GetBucketUsageOutput, error) {
706+
return &GetBucketUsageOutput{Size: 0}, nil
707+
}

internal/backend_adlv2.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ func (b *ADLv2) Capabilities() *Capabilities {
207207
return &b.cap
208208
}
209209

210+
func (b *ADLv2) GetBucketUsage(param *GetBucketUsageInput) (*GetBucketUsageOutput, error) {
211+
return &GetBucketUsageOutput{Size: 0}, nil
212+
}
213+
210214
type ADL2Error struct {
211215
adl2.DataLakeStorageError
212216
}

internal/backend_azblob.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func (b *AZBlob) refreshToken() (*azblob.ContainerURL, error) {
222222
// our token totally expired, renew inline before using it
223223
b.mu.Unlock()
224224
b.tokenRenewGate <- 1
225-
defer func() { <- b.tokenRenewGate } ()
225+
defer func() { <-b.tokenRenewGate }()
226226

227227
b.mu.Lock()
228228
// check again, because in the mean time maybe it's renewed
@@ -248,7 +248,7 @@ func (b *AZBlob) refreshToken() (*azblob.ContainerURL, error) {
248248
if err != nil {
249249
azbLog.Errorf("Unable to refresh token: %v", err)
250250
}
251-
<- b.tokenRenewGate
251+
<-b.tokenRenewGate
252252
}()
253253

254254
// if we cannot renew token, treat it as a
@@ -665,7 +665,7 @@ func (b *AZBlob) DeleteBlobs(param *DeleteBlobsInput) (ret *DeleteBlobsOutput, d
665665

666666
go func(key string) {
667667
defer func() {
668-
<- SmallActionsGate
668+
<-SmallActionsGate
669669
wg.Done()
670670
}()
671671

@@ -947,3 +947,7 @@ func (b *AZBlob) MakeBucket(param *MakeBucketInput) (*MakeBucketOutput, error) {
947947
}
948948
return &MakeBucketOutput{}, nil
949949
}
950+
951+
func (b *AZBlob) GetBucketUsage(param *GetBucketUsageInput) (*GetBucketUsageOutput, error) {
952+
return &GetBucketUsageOutput{Size: 0}, nil
953+
}

internal/backend_gcs3.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ import (
2323
"sync"
2424
"syscall"
2525

26-
"github.com/jacobsa/fuse"
2726
"cloud.google.com/go/storage"
27+
"github.com/jacobsa/fuse"
2828
"google.golang.org/api/iterator"
2929
)
3030

3131
// GCS variant of S3
3232
type GCS3 struct {
3333
*S3Backend
34-
gcs *storage.Client
34+
gcs *storage.Client
3535
jsonCredFile string
3636
}
3737

@@ -103,12 +103,12 @@ func (s *GCS3) ListBlobs(param *ListBlobsInput) (*ListBlobsOutput, error) {
103103
})
104104
} else {
105105
items = append(items, BlobItemOutput{
106-
Key: &attrs.Name,
107-
ETag: &attrs.Etag,
106+
Key: &attrs.Name,
107+
ETag: &attrs.Etag,
108108
LastModified: &attrs.Updated,
109-
Size: uint64(attrs.Size),
109+
Size: uint64(attrs.Size),
110110
StorageClass: &attrs.StorageClass,
111-
Metadata: PMetadata(attrs.Metadata),
111+
Metadata: PMetadata(attrs.Metadata),
112112
})
113113
}
114114
n++
@@ -156,3 +156,7 @@ func (s *GCS3) DeleteBlobs(param *DeleteBlobsInput) (*DeleteBlobsOutput, error)
156156
func (s *GCS3) MultipartBlobCopy(param *MultipartBlobCopyInput) (*MultipartBlobCopyOutput, error) {
157157
return nil, syscall.ENOSYS
158158
}
159+
160+
func (s *GCS3) GetBucketUsage(param *GetBucketUsageInput) (*GetBucketUsageOutput, error) {
161+
return &GetBucketUsageOutput{Size: 0}, nil
162+
}

internal/backend_minio.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright 2019 Ka-Hing Cheung
2+
// Copyright 2021 Yandex LLC
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
package internal
17+
18+
import (
19+
"context"
20+
"encoding/json"
21+
"io/ioutil"
22+
"net/url"
23+
24+
"github.com/minio/madmin-go"
25+
. "github.com/yandex-cloud/geesefs/api/common"
26+
)
27+
28+
type BucketsUsage struct {
29+
BucketsSizes map[string]uint64
30+
}
31+
32+
type MinioBackend struct {
33+
*S3Backend
34+
}
35+
36+
func NewMinio(bucket string, flags *FlagStorage, config *S3Config) (*MinioBackend, error) {
37+
s3Backend, err := NewS3(bucket, flags, config)
38+
if err != nil {
39+
return nil, err
40+
}
41+
s3Backend.Capabilities().Name = "minio"
42+
s := &MinioBackend{S3Backend: s3Backend}
43+
return s, nil
44+
}
45+
46+
func (s *MinioBackend) GetBucketUsage(param *GetBucketUsageInput) (*GetBucketUsageOutput, error) {
47+
value, err := s.Config.Credentials.Get()
48+
if err != nil {
49+
return nil, err
50+
}
51+
52+
endpointURL, _ := url.Parse(s.Endpoint)
53+
madminClient, err := madmin.New(endpointURL.Host, value.AccessKeyID, value.SecretAccessKey, endpointURL.Scheme == "https")
54+
if err != nil {
55+
return nil, err
56+
}
57+
resp, err := madminClient.ExecuteMethod(context.Background(), "GET", madmin.RequestData{RelPath: "/v3/datausageinfo"})
58+
if err != nil {
59+
return nil, err
60+
}
61+
response, err := ioutil.ReadAll(resp.Body)
62+
if err != nil {
63+
return nil, err
64+
}
65+
var result BucketsUsage
66+
json.Unmarshal(response, &result)
67+
return &GetBucketUsageOutput{Size: result.BucketsSizes[s.Bucket()]}, nil
68+
}

0 commit comments

Comments
 (0)