diff --git a/lib/uplink/bucket.go b/lib/uplink/bucket.go index 381cbfbb0..8f3ac271e 100644 --- a/lib/uplink/bucket.go +++ b/lib/uplink/bucket.go @@ -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, diff --git a/pkg/miniogw/gateway_test.go b/pkg/miniogw/gateway_test.go index fab46d2b8..051ee34b2 100644 --- a/pkg/miniogw/gateway_test.go +++ b/pkg/miniogw/gateway_test.go @@ -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 diff --git a/pkg/storj/metainfo.go b/pkg/storj/metainfo.go index 4f084bf32..75d6fdec8 100644 --- a/pkg/storj/metainfo.go +++ b/pkg/storj/metainfo.go @@ -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 -} diff --git a/uplink/metainfo/kvmetainfo/interface.go b/uplink/metainfo/kvmetainfo/interface.go index cc821b010..b6c6bc380 100644 --- a/uplink/metainfo/kvmetainfo/interface.go +++ b/uplink/metainfo/kvmetainfo/interface.go @@ -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 diff --git a/uplink/metainfo/kvmetainfo/metainfo.go b/uplink/metainfo/kvmetainfo/metainfo.go index 33da66af1..7a86fa8c4 100644 --- a/uplink/metainfo/kvmetainfo/metainfo.go +++ b/uplink/metainfo/kvmetainfo/metainfo.go @@ -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) diff --git a/uplink/metainfo/kvmetainfo/objects.go b/uplink/metainfo/kvmetainfo/objects.go index b44bbd539..0005d90b6 100644 --- a/uplink/metainfo/kvmetainfo/objects.go +++ b/uplink/metainfo/kvmetainfo/objects.go @@ -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 == "" { diff --git a/uplink/metainfo/kvmetainfo/objects_test.go b/uplink/metainfo/kvmetainfo/objects_test.go index a3723adea..99ad32999 100644 --- a/uplink/metainfo/kvmetainfo/objects_test.go +++ b/uplink/metainfo/kvmetainfo/objects_test.go @@ -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}, },