satellite/metabase: use constant for pending version

Currently it wasn't quite clear what was a stub version and an actual
version. Use a PendingVersion constant to make this distinction clear.

Also use PendingVersion = NextVersion = 0, that way it's clearer that
the version hasn't been yet determined. DefaultVersion = 1 might imply
that the object will get that version once commited, however that will
entirely depend on whether use-pending-objects is used or versioning is
enabled or not.

Change-Id: I21398141f97035c48c778f23b542266b834c44f1
This commit is contained in:
Egon Elbre 2023-09-11 16:58:30 +03:00 committed by Storj Robot
parent 4f8697568d
commit d91ee440ba
9 changed files with 50 additions and 46 deletions

View File

@ -99,7 +99,7 @@ func (db *DB) BeginObjectNextVersion(ctx context.Context, opts BeginObjectNextVe
if opts.UsePendingObjectsTable {
object.Status = Pending
object.Version = DefaultVersion
object.Version = PendingVersion
if err := db.db.QueryRowContext(ctx, `
INSERT INTO pending_objects (
@ -683,6 +683,7 @@ func (db *DB) CommitObject(ctx context.Context, opts CommitObject) (object Objec
totalEncryptedSize += int64(seg.EncryptedSize)
}
const versionArgIndex = 3
args := []interface{}{
opts.ProjectID, []byte(opts.BucketName), opts.ObjectKey, opts.Version, opts.StreamID,
len(segments),
@ -746,7 +747,8 @@ func (db *DB) CommitObject(ctx context.Context, opts CommitObject) (object Objec
}
}
opts.Version = 1
opts.Version = DefaultVersion
args[versionArgIndex] = opts.Version
args = append(args,
opts.EncryptedMetadataNonce,

View File

@ -365,7 +365,7 @@ func TestBeginObjectNextVersion_PendingObjects(t *testing.T) {
UsePendingObjectsTable: true,
},
Version: metabase.DefaultVersion,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
metabasetest.BeginObjectNextVersion{
@ -376,7 +376,7 @@ func TestBeginObjectNextVersion_PendingObjects(t *testing.T) {
UsePendingObjectsTable: true,
},
Version: metabase.DefaultVersion,
Version: metabase.PendingVersion,
ErrClass: &metabase.ErrObjectAlreadyExists,
}.Check(ctx, t, db)
@ -415,7 +415,7 @@ func TestBeginObjectNextVersion_PendingObjects(t *testing.T) {
UsePendingObjectsTable: true,
},
Version: metabase.DefaultVersion,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
now2 := time.Now()
@ -430,7 +430,7 @@ func TestBeginObjectNextVersion_PendingObjects(t *testing.T) {
UsePendingObjectsTable: true,
},
Version: metabase.DefaultVersion,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
metabasetest.Verify{
@ -487,7 +487,7 @@ func TestBeginObjectNextVersion_PendingObjects(t *testing.T) {
UsePendingObjectsTable: true,
},
Version: metabase.DefaultVersion,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
metabasetest.Verify{
@ -1214,7 +1214,7 @@ func TestBeginSegment(t *testing.T) {
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
metabasetest.BeginSegment{
@ -1256,7 +1256,7 @@ func TestBeginSegment(t *testing.T) {
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
for i := 0; i < 5; i++ {
@ -1968,7 +1968,7 @@ func TestCommitSegment(t *testing.T) {
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
rootPieceID := testrand.PieceID()
@ -2065,7 +2065,7 @@ func TestCommitSegment(t *testing.T) {
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
rootPieceID1 := testrand.PieceID()
@ -2171,7 +2171,7 @@ func TestCommitSegment(t *testing.T) {
ExpiresAt: &expectedExpiresAt,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
metabasetest.CommitSegment{
@ -2242,7 +2242,7 @@ func TestCommitSegment(t *testing.T) {
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
metabasetest.CommitSegment{
@ -2799,7 +2799,7 @@ func TestCommitInlineSegment(t *testing.T) {
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
encryptedKey := testrand.Bytes(32)
@ -2878,7 +2878,7 @@ func TestCommitInlineSegment(t *testing.T) {
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
encryptedKey := testrand.Bytes(32)
@ -2961,7 +2961,7 @@ func TestCommitInlineSegment(t *testing.T) {
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
metabasetest.CommitInlineSegment{
@ -3023,7 +3023,7 @@ func TestCommitInlineSegment(t *testing.T) {
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
metabasetest.CommitInlineSegment{
@ -3087,7 +3087,7 @@ func TestCommitInlineSegment(t *testing.T) {
ExpiresAt: &expectedExpiresAt,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
metabasetest.CommitInlineSegment{
@ -3776,7 +3776,7 @@ func TestCommitObject(t *testing.T) {
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
now := time.Now()
@ -3849,7 +3849,7 @@ func TestCommitObject(t *testing.T) {
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
obj.Version++
now := time.Now()
@ -3968,7 +3968,7 @@ func TestCommitObject(t *testing.T) {
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
obj.Version++
now := time.Now()
@ -4082,7 +4082,7 @@ func TestCommitObject(t *testing.T) {
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
obj.Version++
now := time.Now()
@ -4133,7 +4133,7 @@ func TestCommitObject(t *testing.T) {
EncryptedMetadataNonce: expectedMetadataNonce,
UsePendingObjectsTable: true,
},
Version: metabase.DefaultVersion,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
obj.Version++
@ -4182,7 +4182,7 @@ func TestCommitObject(t *testing.T) {
EncryptedMetadataNonce: testrand.Nonce().Bytes(),
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
obj.Version++
@ -4232,7 +4232,7 @@ func TestCommitObject(t *testing.T) {
EncryptedMetadataNonce: testrand.Nonce().Bytes(),
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
obj.Version++
@ -4281,7 +4281,7 @@ func TestCommitObject(t *testing.T) {
EncryptedMetadataNonce: testrand.Nonce().Bytes(),
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
obj.Version++

View File

@ -342,6 +342,9 @@ const NextVersion = Version(0)
// DefaultVersion represents default version 1.
const DefaultVersion = Version(1)
// PendingVersion represents version that is used for pending objects (with UsePendingObjects).
const PendingVersion = Version(0)
// MaxVersion represents maximum version.
// Version in DB is represented as INT4.
const MaxVersion = Version(math.MaxInt32)

View File

@ -252,7 +252,7 @@ func TestDeleteBucketObjects(t *testing.T) {
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
metabasetest.DeleteBucketObjects{
@ -272,7 +272,7 @@ func TestDeleteBucketObjects(t *testing.T) {
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
metabasetest.DeleteBucketObjects{

View File

@ -526,7 +526,7 @@ func TestDeleteInactivePendingObjects(t *testing.T) {
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
// zombie object with deadline time in the past
@ -537,7 +537,7 @@ func TestDeleteInactivePendingObjects(t *testing.T) {
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
// pending object with expiration time in the future
@ -548,7 +548,7 @@ func TestDeleteInactivePendingObjects(t *testing.T) {
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
metabasetest.DeleteInactivePendingObjects{
@ -588,7 +588,7 @@ func TestDeleteInactivePendingObjects(t *testing.T) {
ZombieDeletionDeadline: &now,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
metabasetest.BeginSegment{
Opts: metabase.BeginSegment{
@ -680,7 +680,7 @@ func TestDeleteInactivePendingObjects(t *testing.T) {
// use default 24h zombie deletion deadline
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
for i := byte(0); i < 3; i++ {

View File

@ -412,7 +412,7 @@ func TestDeletePendingObjectNew(t *testing.T) {
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
object := metabase.RawObject{
@ -444,7 +444,7 @@ func TestDeletePendingObjectNew(t *testing.T) {
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
metabasetest.CommitSegment{
@ -498,7 +498,7 @@ func TestDeletePendingObjectNew(t *testing.T) {
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
metabasetest.CommitInlineSegment{

View File

@ -94,9 +94,8 @@ func CreatePendingObjectNew(ctx *testcontext.Context, t *testing.T, db *metabase
Encryption: DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
obj.Version = 1
for i := byte(0); i < numberOfSegments; i++ {
BeginSegment{

View File

@ -94,7 +94,7 @@ func TestIteratePendingObjects(t *testing.T) {
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
encryptedMetadata := testrand.Bytes(1024)
@ -107,7 +107,7 @@ func TestIteratePendingObjects(t *testing.T) {
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
committed.Version++
@ -644,7 +644,7 @@ func TestIteratePendingObjects(t *testing.T) {
EncryptedMetadataNonce: []byte{5},
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
// include custom metadata
@ -700,7 +700,7 @@ func TestIteratePendingObjects(t *testing.T) {
EncryptedMetadataNonce: []byte{5},
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
var collector metabasetest.PendingObjectsCollector
@ -816,7 +816,7 @@ func TestIteratePendingObjects(t *testing.T) {
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
}
for _, batchSize := range []int{1, 2, 3} {
@ -897,7 +897,7 @@ func TestIteratePendingObjects(t *testing.T) {
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
objs = append(objs, metabase.PendingObjectEntry{
@ -937,7 +937,7 @@ func createPendingObjects(ctx *testcontext.Context, t *testing.T, db *metabase.D
Encryption: metabasetest.DefaultEncryption,
UsePendingObjectsTable: true,
},
Version: 1,
Version: metabase.PendingVersion,
}.Check(ctx, t, db)
obj.Version++

View File

@ -1717,7 +1717,7 @@ func (endpoint *Endpoint) pendingObjectEntryToProtoListItem(ctx context.Context,
satStreamID, err := endpoint.packStreamID(ctx, &internalpb.StreamID{
Bucket: bucket,
EncryptedObjectKey: append([]byte(prefixToPrependInSatStreamID), []byte(entry.ObjectKey)...),
Version: 1,
Version: int64(metabase.PendingVersion),
CreationDate: entry.CreatedAt,
ExpirationDate: expiresAt,
StreamId: entry.StreamID[:],