Implement a metadata file and correct sizing
As the controller does not mount/create the fs we have to store the capacity somewhere so the node knows about it.
This commit is contained in:
parent
db0fbf77dd
commit
1caf469966
9 changed files with 150 additions and 73 deletions
pkg/s3
|
@ -1,7 +1,10 @@
|
|||
package s3
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
@ -9,7 +12,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
metadataName = ".meta"
|
||||
metadataName = ".metadata.json"
|
||||
)
|
||||
|
||||
type s3Client struct {
|
||||
|
@ -17,6 +20,11 @@ type s3Client struct {
|
|||
minio *minio.Client
|
||||
}
|
||||
|
||||
type bucket struct {
|
||||
Name string
|
||||
CapacityBytes int64
|
||||
}
|
||||
|
||||
func newS3Client(cfg *Config) (*s3Client, error) {
|
||||
var client = &s3Client{}
|
||||
|
||||
|
@ -91,3 +99,32 @@ func (client *s3Client) emptyBucket(bucketName string) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (client *s3Client) setBucket(bucket *bucket) error {
|
||||
b := new(bytes.Buffer)
|
||||
json.NewEncoder(b).Encode(bucket)
|
||||
opts := minio.PutObjectOptions{ContentType: "application/json"}
|
||||
_, err := client.minio.PutObject(bucket.Name, metadataName, b, int64(b.Len()), opts)
|
||||
return err
|
||||
}
|
||||
|
||||
func (client *s3Client) getBucket(bucketName string) (*bucket, error) {
|
||||
opts := minio.GetObjectOptions{}
|
||||
obj, err := client.minio.GetObject(bucketName, metadataName, opts)
|
||||
if err != nil {
|
||||
return &bucket{}, err
|
||||
}
|
||||
objInfo, err := obj.Stat()
|
||||
if err != nil {
|
||||
return &bucket{}, err
|
||||
}
|
||||
b := make([]byte, objInfo.Size)
|
||||
_, err = obj.Read(b)
|
||||
|
||||
if err != nil && err != io.EOF {
|
||||
return &bucket{}, err
|
||||
}
|
||||
var meta bucket
|
||||
err = json.Unmarshal(b, &meta)
|
||||
return &meta, err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue