pkg/storj: move non-common types

Change-Id: I2dd15c95cd334660f29a528dfb3dec9c30b29cab
This commit is contained in:
Egon Elbre 2019-12-18 15:51:05 +02:00
parent 71d6eef0d7
commit 1eaf9e9ed7
7 changed files with 55 additions and 58 deletions

View File

@ -160,7 +160,7 @@ func (b *Bucket) NewWriter(ctx context.Context, path storj.Path, opts *UploadOpt
if opts.Volatile.EncryptionParameters.BlockSize == 0 {
opts.Volatile.EncryptionParameters.BlockSize = b.EncryptionParameters.BlockSize
}
createInfo := storj.CreateObject{
createInfo := kvmetainfo.CreateObject{
ContentType: opts.ContentType,
Metadata: opts.Metadata,
Expires: opts.Expires,

View File

@ -244,7 +244,7 @@ func TestGetObjectInfo(t *testing.T) {
assert.Equal(t, minio.ObjectNotFound{Bucket: TestBucket, Object: TestFile}, err)
// Create the object using the Metainfo API
createInfo := storj.CreateObject{
createInfo := kvmetainfo.CreateObject{
ContentType: "text/plain",
Metadata: map[string]string{"key1": "value1", "key2": "value2"},
}
@ -289,7 +289,7 @@ func TestGetObject(t *testing.T) {
assert.Equal(t, minio.ObjectNotFound{Bucket: TestBucket, Object: TestFile}, err)
// Create the object using the Metainfo API
createInfo := storj.CreateObject{
createInfo := kvmetainfo.CreateObject{
ContentType: "text/plain",
Metadata: map[string]string{"key1": "value1", "key2": "value2"},
}
@ -348,7 +348,7 @@ func TestCopyObject(t *testing.T) {
assert.Equal(t, minio.ObjectNameInvalid{Bucket: TestBucket}, err)
// Create the source object using the Metainfo API
createInfo := storj.CreateObject{
createInfo := kvmetainfo.CreateObject{
ContentType: "text/plain",
Metadata: map[string]string{"key1": "value1", "key2": "value2"},
}
@ -480,7 +480,7 @@ func testListObjects(t *testing.T, listObjects func(context.Context, minio.Objec
}
files := make(map[string]storj.Object, len(filePaths))
createInfo := storj.CreateObject{
createInfo := kvmetainfo.CreateObject{
ContentType: "text/plain",
Metadata: map[string]string{"key1": "value1", "key2": "value2"},
}
@ -766,7 +766,7 @@ func initEnv(ctx context.Context, t *testing.T, planet *testplanet.Planet) (mini
return layer, kvm, strms, err
}
func createFile(ctx context.Context, m *kvmetainfo.DB, strms streams.Store, bucket storj.Bucket, path storj.Path, createInfo *storj.CreateObject, data []byte) (storj.Object, error) {
func createFile(ctx context.Context, m *kvmetainfo.DB, strms streams.Store, bucket storj.Bucket, path storj.Path, createInfo *kvmetainfo.CreateObject, data []byte) (storj.Object, error) {
mutableObject, err := m.CreateObject(ctx, bucket, path, createInfo)
if err != nil {
return storj.Object{}, err

View File

@ -3,40 +3,6 @@
package storj
import (
"time"
)
// CreateObject has optional parameters that can be set
type CreateObject struct {
Metadata map[string]string
ContentType string
Expires time.Time
RedundancyScheme
EncryptionParameters
}
// Object converts the CreateObject to an object with unitialized values
func (create CreateObject) Object(bucket Bucket, path Path) Object {
return Object{
Bucket: bucket,
Path: path,
Metadata: create.Metadata,
ContentType: create.ContentType,
Expires: create.Expires,
Stream: Stream{
Size: -1, // unknown
Checksum: nil, // unknown
SegmentCount: -1, // unknown
FixedSegmentSize: -1, // unknown
RedundancyScheme: create.RedundancyScheme,
EncryptionParameters: create.EncryptionParameters,
},
}
}
// ListDirection specifies listing direction
type ListDirection int8
@ -111,14 +77,3 @@ func (opts BucketListOptions) NextPage(list BucketList) BucketListOptions {
Limit: opts.Limit,
}
}
// MetainfoLimits lists limits specified for the Metainfo database
type MetainfoLimits struct {
// ListLimit specifies the maximum amount of items that can be listed at a time.
ListLimit int64
// MinimumRemoteSegmentSize specifies the minimum remote segment that is allowed to be stored.
MinimumRemoteSegmentSize int64
// MaximumInlineSegmentSize specifies the maximum inline segment that is allowed to be stored.
MaximumInlineSegmentSize int64
}

View File

@ -5,10 +5,41 @@ package kvmetainfo
import (
"context"
"time"
"storj.io/storj/pkg/storj"
)
// CreateObject has optional parameters that can be set
type CreateObject struct {
Metadata map[string]string
ContentType string
Expires time.Time
storj.RedundancyScheme
storj.EncryptionParameters
}
// Object converts the CreateObject to an object with unitialized values
func (create CreateObject) Object(bucket storj.Bucket, path storj.Path) storj.Object {
return storj.Object{
Bucket: bucket,
Path: path,
Metadata: create.Metadata,
ContentType: create.ContentType,
Expires: create.Expires,
Stream: storj.Stream{
Size: -1, // unknown
Checksum: nil, // unknown
SegmentCount: -1, // unknown
FixedSegmentSize: -1, // unknown
RedundancyScheme: create.RedundancyScheme,
EncryptionParameters: create.EncryptionParameters,
},
}
}
// ReadOnlyStream is an interface for reading segment information
type ReadOnlyStream interface {
Info() storj.Object

View File

@ -49,15 +49,26 @@ func New(project *Project, metainfo *metainfo.Client, streams streams.Store, seg
const defaultLookupLimit = 1000
// Limits returns limits for this metainfo database
func (db *DB) Limits() (storj.MetainfoLimits, error) {
func (db *DB) Limits() (MetainfoLimits, error) {
// TODO: fetch this information from satellite
return storj.MetainfoLimits{
return MetainfoLimits{
ListLimit: defaultLookupLimit,
MinimumRemoteSegmentSize: memory.KiB.Int64(), // TODO: is this needed here?
MaximumInlineSegmentSize: memory.MiB.Int64(),
}, nil
}
// MetainfoLimits lists limits specified for the Metainfo database
type MetainfoLimits struct {
// ListLimit specifies the maximum amount of items that can be listed at a time.
ListLimit int64
// MinimumRemoteSegmentSize specifies the minimum remote segment that is allowed to be stored.
MinimumRemoteSegmentSize int64
// MaximumInlineSegmentSize specifies the maximum inline segment that is allowed to be stored.
MaximumInlineSegmentSize int64
}
// 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)

View File

@ -66,7 +66,7 @@ func (db *DB) GetObjectStream(ctx context.Context, bucket storj.Bucket, object s
}
// CreateObject creates an uploading object and returns an interface for uploading Object information
func (db *DB) CreateObject(ctx context.Context, bucket storj.Bucket, path storj.Path, createInfo *storj.CreateObject) (object MutableObject, err error) {
func (db *DB) CreateObject(ctx context.Context, bucket storj.Bucket, path storj.Path, createInfo *CreateObject) (object MutableObject, err error) {
defer mon.Task()(&ctx)(&err)
if bucket.Name == "" {

View File

@ -44,7 +44,7 @@ func TestCreateObject(t *testing.T) {
require.NoError(t, err)
for i, tt := range []struct {
create *storj.CreateObject
create *kvmetainfo.CreateObject
expectedRS storj.RedundancyScheme
expectedEP storj.EncryptionParameters
}{
@ -54,17 +54,17 @@ func TestCreateObject(t *testing.T) {
expectedEP: kvmetainfo.DefaultES,
},
{
create: &storj.CreateObject{RedundancyScheme: customRS, EncryptionParameters: customEP},
create: &kvmetainfo.CreateObject{RedundancyScheme: customRS, EncryptionParameters: customEP},
expectedRS: customRS,
expectedEP: customEP,
},
{
create: &storj.CreateObject{RedundancyScheme: customRS},
create: &kvmetainfo.CreateObject{RedundancyScheme: customRS},
expectedRS: customRS,
expectedEP: storj.EncryptionParameters{CipherSuite: kvmetainfo.DefaultES.CipherSuite, BlockSize: kvmetainfo.DefaultES.BlockSize},
},
{
create: &storj.CreateObject{EncryptionParameters: customEP},
create: &kvmetainfo.CreateObject{EncryptionParameters: customEP},
expectedRS: kvmetainfo.DefaultRS,
expectedEP: storj.EncryptionParameters{CipherSuite: customEP.CipherSuite, BlockSize: kvmetainfo.DefaultES.BlockSize},
},