uplink/storage: remove bucket store (#3376)
This commit is contained in:
parent
4f281ef348
commit
56f8b2d626
@ -11,6 +11,7 @@ import (
|
||||
"storj.io/storj/pkg/encryption"
|
||||
"storj.io/storj/pkg/storj"
|
||||
"storj.io/storj/storage"
|
||||
"storj.io/storj/uplink/metainfo"
|
||||
)
|
||||
|
||||
// CreateBucket creates a new bucket
|
||||
@ -60,7 +61,17 @@ func (db *Project) CreateBucket(ctx context.Context, bucketName string, info *st
|
||||
}
|
||||
|
||||
info.Name = bucketName
|
||||
newBucket, err := db.buckets.Create(ctx, *info)
|
||||
|
||||
// uuid MarshalJSON implementation always returns err == nil
|
||||
partnerID, _ := info.PartnerID.MarshalJSON()
|
||||
newBucket, err := db.metainfo.CreateBucket(ctx, metainfo.CreateBucketParams{
|
||||
Name: []byte(info.Name),
|
||||
PathCipher: info.PathCipher,
|
||||
PartnerID: partnerID,
|
||||
DefaultSegmentsSize: info.DefaultSegmentsSize,
|
||||
DefaultRedundancyScheme: info.DefaultRedundancyScheme,
|
||||
DefaultEncryptionParameters: info.DefaultEncryptionParameters,
|
||||
})
|
||||
if err != nil {
|
||||
return storj.Bucket{}, storj.ErrBucket.Wrap(err)
|
||||
}
|
||||
@ -91,8 +102,9 @@ func (db *Project) DeleteBucket(ctx context.Context, bucketName string) (err err
|
||||
if bucketName == "" {
|
||||
return storj.ErrNoBucket.New("")
|
||||
}
|
||||
|
||||
err = db.buckets.Delete(ctx, bucketName)
|
||||
err = db.metainfo.DeleteBucket(ctx, metainfo.DeleteBucketParams{
|
||||
Name: []byte(bucketName),
|
||||
})
|
||||
if err != nil {
|
||||
if storage.ErrKeyNotFound.Has(err) {
|
||||
err = storj.ErrBucketNotFound.Wrap(err)
|
||||
@ -111,7 +123,9 @@ func (db *Project) GetBucket(ctx context.Context, bucketName string) (_ storj.Bu
|
||||
return storj.Bucket{}, storj.ErrNoBucket.New("")
|
||||
}
|
||||
|
||||
bucket, err := db.buckets.Get(ctx, bucketName)
|
||||
bucket, err := db.metainfo.GetBucket(ctx, metainfo.GetBucketParams{
|
||||
Name: []byte(bucketName),
|
||||
})
|
||||
if err != nil {
|
||||
return storj.Bucket{}, storj.ErrBucket.Wrap(err)
|
||||
}
|
||||
@ -122,7 +136,10 @@ func (db *Project) GetBucket(ctx context.Context, bucketName string) (_ storj.Bu
|
||||
// ListBuckets lists buckets
|
||||
func (db *Project) ListBuckets(ctx context.Context, listOpts storj.BucketListOptions) (_ storj.BucketList, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
bucketList, err := db.buckets.List(ctx, listOpts)
|
||||
|
||||
bucketList, err := db.metainfo.ListBuckets(ctx, metainfo.ListBucketsParams{
|
||||
ListOpts: listOpts,
|
||||
})
|
||||
if err != nil {
|
||||
return storj.BucketList{}, storj.ErrBucket.Wrap(err)
|
||||
}
|
||||
|
@ -6,13 +6,12 @@ package kvmetainfo
|
||||
import (
|
||||
"storj.io/storj/uplink/eestream"
|
||||
"storj.io/storj/uplink/metainfo"
|
||||
"storj.io/storj/uplink/storage/buckets"
|
||||
"storj.io/storj/uplink/storage/streams"
|
||||
)
|
||||
|
||||
// Project implements project management operations
|
||||
type Project struct {
|
||||
buckets buckets.Store
|
||||
metainfo metainfo.Client
|
||||
streams streams.Store
|
||||
encryptedBlockSize int32
|
||||
redundancy eestream.RedundancyStrategy
|
||||
@ -20,9 +19,9 @@ type Project struct {
|
||||
}
|
||||
|
||||
// NewProject constructs a *Project
|
||||
func NewProject(streams streams.Store, encryptedBlockSize int32, redundancy eestream.RedundancyStrategy, segmentsSize int64, metainfoClient metainfo.Client) *Project {
|
||||
func NewProject(streams streams.Store, encryptedBlockSize int32, redundancy eestream.RedundancyStrategy, segmentsSize int64, metainfo metainfo.Client) *Project {
|
||||
return &Project{
|
||||
buckets: buckets.NewStore(metainfoClient),
|
||||
metainfo: metainfo,
|
||||
streams: streams,
|
||||
encryptedBlockSize: encryptedBlockSize,
|
||||
redundancy: redundancy,
|
||||
|
@ -1,76 +0,0 @@
|
||||
// Copyright (C) 2019 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package buckets
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gopkg.in/spacemonkeygo/monkit.v2"
|
||||
|
||||
"storj.io/storj/pkg/storj"
|
||||
"storj.io/storj/uplink/metainfo"
|
||||
)
|
||||
|
||||
var mon = monkit.Package()
|
||||
|
||||
// Store for buckets
|
||||
type Store interface {
|
||||
Create(ctx context.Context, bucket storj.Bucket) (_ storj.Bucket, err error)
|
||||
Get(ctx context.Context, bucketName string) (_ storj.Bucket, err error)
|
||||
Delete(ctx context.Context, bucketName string) (err error)
|
||||
List(ctx context.Context, listOpts storj.BucketListOptions) (_ storj.BucketList, err error)
|
||||
}
|
||||
|
||||
// BucketStore is an object to interact with buckets
|
||||
// via the metainfo client
|
||||
type BucketStore struct {
|
||||
metainfoClient metainfo.Client
|
||||
}
|
||||
|
||||
// NewStore creates a new bucket store
|
||||
func NewStore(metainfoClient metainfo.Client) *BucketStore {
|
||||
return &BucketStore{
|
||||
metainfoClient: metainfoClient,
|
||||
}
|
||||
}
|
||||
|
||||
// Create creates a bucket
|
||||
func (store *BucketStore) Create(ctx context.Context, bucket storj.Bucket) (_ storj.Bucket, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
// uuid MarshalJSON implementation always returns err == nil
|
||||
partnerID, _ := bucket.PartnerID.MarshalJSON()
|
||||
return store.metainfoClient.CreateBucket(ctx, metainfo.CreateBucketParams{
|
||||
Name: []byte(bucket.Name),
|
||||
PathCipher: bucket.PathCipher,
|
||||
PartnerID: partnerID,
|
||||
DefaultSegmentsSize: bucket.DefaultSegmentsSize,
|
||||
DefaultRedundancyScheme: bucket.DefaultRedundancyScheme,
|
||||
DefaultEncryptionParameters: bucket.DefaultEncryptionParameters,
|
||||
})
|
||||
}
|
||||
|
||||
// Get returns a bucket
|
||||
func (store *BucketStore) Get(ctx context.Context, bucketName string) (_ storj.Bucket, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
return store.metainfoClient.GetBucket(ctx, metainfo.GetBucketParams{
|
||||
Name: []byte(bucketName),
|
||||
})
|
||||
}
|
||||
|
||||
// Delete deletes a bucket
|
||||
func (store *BucketStore) Delete(ctx context.Context, bucketName string) (err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
return store.metainfoClient.DeleteBucket(ctx, metainfo.DeleteBucketParams{
|
||||
Name: []byte(bucketName),
|
||||
})
|
||||
}
|
||||
|
||||
// List returns a list of buckets
|
||||
func (store *BucketStore) List(ctx context.Context, listOpts storj.BucketListOptions) (_ storj.BucketList, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
return store.metainfoClient.ListBuckets(ctx, metainfo.ListBucketsParams{
|
||||
ListOpts: listOpts,
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user