2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-06 11:40:06 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package kvmetainfo
|
|
|
|
|
|
|
|
import (
|
2019-06-21 12:29:31 +01:00
|
|
|
"context"
|
|
|
|
|
2018-11-06 11:40:06 +00:00
|
|
|
"github.com/zeebo/errs"
|
2018-11-16 13:59:27 +00:00
|
|
|
monkit "gopkg.in/spacemonkeygo/monkit.v2"
|
2018-11-06 11:40:06 +00:00
|
|
|
|
|
|
|
"storj.io/storj/internal/memory"
|
2019-06-24 20:23:07 +01:00
|
|
|
"storj.io/storj/pkg/encryption"
|
2018-11-06 11:40:06 +00:00
|
|
|
"storj.io/storj/pkg/storj"
|
|
|
|
"storj.io/storj/storage"
|
2019-03-22 09:01:49 +00:00
|
|
|
"storj.io/storj/uplink/metainfo"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/uplink/storage/segments"
|
|
|
|
"storj.io/storj/uplink/storage/streams"
|
2018-11-06 11:40:06 +00:00
|
|
|
)
|
|
|
|
|
2018-11-16 13:59:27 +00:00
|
|
|
var mon = monkit.Package()
|
|
|
|
|
2018-11-06 11:40:06 +00:00
|
|
|
var errClass = errs.Class("kvmetainfo")
|
|
|
|
|
|
|
|
const defaultSegmentLimit = 8 // TODO
|
|
|
|
|
|
|
|
var _ storj.Metainfo = (*DB)(nil)
|
|
|
|
|
|
|
|
// DB implements metainfo database
|
|
|
|
type DB struct {
|
2019-06-21 12:29:31 +01:00
|
|
|
project *Project
|
2019-04-03 09:46:21 +01:00
|
|
|
|
2019-06-25 16:36:23 +01:00
|
|
|
metainfo *metainfo.Client
|
2019-04-03 09:46:21 +01:00
|
|
|
|
2018-11-14 09:26:18 +00:00
|
|
|
streams streams.Store
|
|
|
|
segments segments.Store
|
|
|
|
|
2019-06-24 20:23:07 +01:00
|
|
|
encStore *encryption.Store
|
2018-11-06 11:40:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// New creates a new metainfo database
|
2019-06-25 16:36:23 +01:00
|
|
|
func New(project *Project, metainfo *metainfo.Client, streams streams.Store, segments segments.Store, encStore *encryption.Store) *DB {
|
2018-11-06 11:40:06 +00:00
|
|
|
return &DB{
|
2019-06-24 03:06:14 +01:00
|
|
|
project: project,
|
2019-03-22 09:01:49 +00:00
|
|
|
metainfo: metainfo,
|
2018-11-14 09:26:18 +00:00
|
|
|
streams: streams,
|
|
|
|
segments: segments,
|
2019-06-24 20:23:07 +01:00
|
|
|
encStore: encStore,
|
2018-11-06 11:40:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Limits returns limits for this metainfo database
|
|
|
|
func (db *DB) Limits() (storj.MetainfoLimits, error) {
|
|
|
|
return storj.MetainfoLimits{
|
|
|
|
ListLimit: storage.LookupLimit,
|
2019-03-18 10:55:06 +00:00
|
|
|
MinimumRemoteSegmentSize: memory.KiB.Int64(), // TODO: is this needed here?
|
|
|
|
MaximumInlineSegmentSize: memory.MiB.Int64(),
|
2018-11-06 11:40:06 +00:00
|
|
|
}, nil
|
|
|
|
}
|
2019-06-21 12:29:31 +01:00
|
|
|
|
|
|
|
// CreateBucket creates a new bucket with the specified information
|
|
|
|
func (db *DB) CreateBucket(ctx context.Context, bucketName string, info *storj.Bucket) (bucketInfo storj.Bucket, err error) {
|
|
|
|
return db.project.CreateBucket(ctx, bucketName, info)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteBucket deletes bucket
|
|
|
|
func (db *DB) DeleteBucket(ctx context.Context, bucketName string) (err error) {
|
|
|
|
return db.project.DeleteBucket(ctx, bucketName)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBucket gets bucket information
|
|
|
|
func (db *DB) GetBucket(ctx context.Context, bucketName string) (bucketInfo storj.Bucket, err error) {
|
|
|
|
return db.project.GetBucket(ctx, bucketName)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListBuckets lists buckets
|
|
|
|
func (db *DB) ListBuckets(ctx context.Context, options storj.BucketListOptions) (list storj.BucketList, err error) {
|
|
|
|
return db.project.ListBuckets(ctx, options)
|
|
|
|
}
|