satellite/metabase: add Prefix status for non-recursive listing

Currently it's awkward to use any of the existing statuses for the
objects in non-recursive listing. Hence, let's add a new one.

Change-Id: I8485e0f858e69998b097e757091991538ca697fa
This commit is contained in:
Egon Elbre 2023-10-25 18:10:28 +03:00 committed by Storj Robot
parent 8b6c60f26b
commit c8e4f0099c
5 changed files with 64 additions and 72 deletions

View File

@ -414,8 +414,10 @@ const (
CommittedVersioned = ObjectStatus(4)
// DeleteMarkerUnversioned is inserted when an unversioned object is deleted in a versioning suspended bucket.
DeleteMarkerUnversioned = ObjectStatus(5)
// DeleteMarkerVersioned is inserted when an object is deleted in a versioning enabled bucket.
// DeleteMarkerVersioned is inserted when an object is deleted in a versioning enabled bucket.
DeleteMarkerVersioned = ObjectStatus(6)
// Prefix is an ephemeral status used during non-recursive listing.
Prefix = ObjectStatus(7)
// Constants that can be used while constructing SQL queries.
statusPending = "1"

View File

@ -162,12 +162,7 @@ func (it *objectsIterator) Next(ctx context.Context, item *ObjectEntry) bool {
*item = ObjectEntry{
IsPrefix: true,
ObjectKey: item.ObjectKey[:p+1],
}
// TODO(ver): should we return something else here?
if it.pending {
item.Status = Pending
} else {
item.Status = CommittedUnversioned
Status: Prefix,
}
}

View File

@ -448,9 +448,9 @@ func TestIterateObjectsWithStatus(t *testing.T) {
},
Result: []metabase.ObjectEntry{
objects["a"],
prefixEntry("b/", metabase.CommittedUnversioned),
prefixEntry("b/"),
objects["c"],
prefixEntry("c/", metabase.CommittedUnversioned),
prefixEntry("c/"),
objects["g"],
},
}.Check(ctx, t, db)
@ -466,9 +466,9 @@ func TestIterateObjectsWithStatus(t *testing.T) {
Cursor: metabase.IterateCursor{Key: "a", Version: objects["a"].Version + 1},
},
Result: []metabase.ObjectEntry{
prefixEntry("b/", metabase.CommittedUnversioned),
prefixEntry("b/"),
objects["c"],
prefixEntry("c/", metabase.CommittedUnversioned),
prefixEntry("c/"),
objects["g"],
},
}.Check(ctx, t, db)
@ -484,9 +484,9 @@ func TestIterateObjectsWithStatus(t *testing.T) {
Cursor: metabase.IterateCursor{Key: "b", Version: 0},
},
Result: []metabase.ObjectEntry{
prefixEntry("b/", metabase.CommittedUnversioned),
prefixEntry("b/"),
objects["c"],
prefixEntry("c/", metabase.CommittedUnversioned),
prefixEntry("c/"),
objects["g"],
},
}.Check(ctx, t, db)
@ -570,7 +570,7 @@ func TestIterateObjectsWithStatus(t *testing.T) {
},
Result: withoutPrefix("c/",
objects["c/"],
prefixEntry("c//", metabase.CommittedUnversioned),
prefixEntry("c//"),
objects["c/1"],
),
}.Check(ctx, t, db)
@ -1003,8 +1003,8 @@ func TestIterateObjectsSkipCursor(t *testing.T) {
IncludeSystemMetadata: true,
},
Result: []metabase.ObjectEntry{
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("09/")),
prefixEntry(metabase.ObjectKey("10/")),
},
}.Check(ctx, t, db)
@ -1022,9 +1022,9 @@ func TestIterateObjectsSkipCursor(t *testing.T) {
IncludeSystemMetadata: true,
},
Result: []metabase.ObjectEntry{
prefixEntry(metabase.ObjectKey("08/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("08/")),
prefixEntry(metabase.ObjectKey("09/")),
prefixEntry(metabase.ObjectKey("10/")),
},
}.Check(ctx, t, db)
@ -1042,8 +1042,8 @@ func TestIterateObjectsSkipCursor(t *testing.T) {
IncludeSystemMetadata: true,
},
Result: []metabase.ObjectEntry{
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("09/")),
prefixEntry(metabase.ObjectKey("10/")),
},
}.Check(ctx, t, db)
})
@ -1071,9 +1071,9 @@ func TestIterateObjectsSkipCursor(t *testing.T) {
IncludeSystemMetadata: true,
},
Result: []metabase.ObjectEntry{
prefixEntry(metabase.ObjectKey("08/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("08/")),
prefixEntry(metabase.ObjectKey("09/")),
prefixEntry(metabase.ObjectKey("10/")),
},
}.Check(ctx, t, db)
@ -1091,8 +1091,8 @@ func TestIterateObjectsSkipCursor(t *testing.T) {
IncludeSystemMetadata: true,
},
Result: []metabase.ObjectEntry{
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("09/")),
prefixEntry(metabase.ObjectKey("10/")),
},
}.Check(ctx, t, db)
@ -1110,8 +1110,8 @@ func TestIterateObjectsSkipCursor(t *testing.T) {
IncludeSystemMetadata: true,
},
Result: []metabase.ObjectEntry{
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("09/")),
prefixEntry(metabase.ObjectKey("10/")),
},
}.Check(ctx, t, db)
})
@ -1157,10 +1157,10 @@ func TestIterateObjectsSkipCursor(t *testing.T) {
IncludeSystemMetadata: true,
},
Result: []metabase.ObjectEntry{
prefixEntry(metabase.ObjectKey("08/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("08/")),
withoutPrefix1("2017/05/", objects["2017/05/08"+afterDelimiter]),
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("09/")),
prefixEntry(metabase.ObjectKey("10/")),
},
}.Check(ctx, t, db)
@ -1181,8 +1181,8 @@ func TestIterateObjectsSkipCursor(t *testing.T) {
},
Result: []metabase.ObjectEntry{
withoutPrefix1("2017/05/", objects["2017/05/08"+afterDelimiter]),
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("09/")),
prefixEntry(metabase.ObjectKey("10/")),
},
}.Check(ctx, t, db)
@ -1202,8 +1202,8 @@ func TestIterateObjectsSkipCursor(t *testing.T) {
},
Result: []metabase.ObjectEntry{
withoutPrefix1("2017/05/", objects["2017/05/08"+afterDelimiter]),
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("09/")),
prefixEntry(metabase.ObjectKey("10/")),
},
}.Check(ctx, t, db)
})
@ -1520,11 +1520,11 @@ func withoutPrefix1(prefix metabase.ObjectKey, entry metabase.ObjectEntry) metab
return entry
}
func prefixEntry(key metabase.ObjectKey, status metabase.ObjectStatus) metabase.ObjectEntry {
func prefixEntry(key metabase.ObjectKey) metabase.ObjectEntry {
return metabase.ObjectEntry{
IsPrefix: true,
ObjectKey: key,
Status: status,
Status: metabase.Prefix,
}
}

View File

@ -266,12 +266,7 @@ func scanListObjectsResult(rows tagsql.Rows, opts ListObjects) (entries []Object
item = ObjectEntry{
IsPrefix: true,
ObjectKey: item.ObjectKey,
}
// TODO(ver): should we use `0` for prefixes instead?
if opts.Pending {
item.Status = Pending
} else {
item.Status = CommittedUnversioned
Status: Prefix,
}
}

View File

@ -90,7 +90,7 @@ func TestListObjects(t *testing.T) {
expected[i] = metabase.ObjectEntry{
IsPrefix: true,
ObjectKey: obj.ObjectKey[:delimiterIndex+1],
Status: 3,
Status: metabase.Prefix,
}
} else {
expected[i] = objectEntryFromRaw(obj)
@ -388,9 +388,9 @@ func TestListObjects(t *testing.T) {
Result: metabase.ListObjectsResult{
Objects: []metabase.ObjectEntry{
objects["a"],
prefixEntry("b/", metabase.CommittedUnversioned),
prefixEntry("b/"),
objects["c"],
prefixEntry("c/", metabase.CommittedUnversioned),
prefixEntry("c/"),
objects["g"],
}},
}.Check(ctx, t, db)
@ -407,9 +407,9 @@ func TestListObjects(t *testing.T) {
},
Result: metabase.ListObjectsResult{
Objects: []metabase.ObjectEntry{
prefixEntry("b/", metabase.CommittedUnversioned),
prefixEntry("b/"),
objects["c"],
prefixEntry("c/", metabase.CommittedUnversioned),
prefixEntry("c/"),
objects["g"],
}},
}.Check(ctx, t, db)
@ -426,9 +426,9 @@ func TestListObjects(t *testing.T) {
},
Result: metabase.ListObjectsResult{
Objects: []metabase.ObjectEntry{
prefixEntry("b/", metabase.CommittedUnversioned),
prefixEntry("b/"),
objects["c"],
prefixEntry("c/", metabase.CommittedUnversioned),
prefixEntry("c/"),
objects["g"],
}},
}.Check(ctx, t, db)
@ -516,7 +516,7 @@ func TestListObjects(t *testing.T) {
Result: metabase.ListObjectsResult{
Objects: withoutPrefix("c/",
objects["c/"],
prefixEntry("c//", metabase.CommittedUnversioned),
prefixEntry("c//"),
objects["c/1"],
)},
}.Check(ctx, t, db)
@ -570,8 +570,8 @@ func TestListObjectsSkipCursor(t *testing.T) {
},
Result: metabase.ListObjectsResult{
Objects: []metabase.ObjectEntry{
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("09/")),
prefixEntry(metabase.ObjectKey("10/")),
}},
}.Check(ctx, t, db)
@ -590,9 +590,9 @@ func TestListObjectsSkipCursor(t *testing.T) {
},
Result: metabase.ListObjectsResult{
Objects: []metabase.ObjectEntry{
prefixEntry(metabase.ObjectKey("08/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("08/")),
prefixEntry(metabase.ObjectKey("09/")),
prefixEntry(metabase.ObjectKey("10/")),
}},
}.Check(ctx, t, db)
@ -611,8 +611,8 @@ func TestListObjectsSkipCursor(t *testing.T) {
},
Result: metabase.ListObjectsResult{
Objects: []metabase.ObjectEntry{
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("09/")),
prefixEntry(metabase.ObjectKey("10/")),
}},
}.Check(ctx, t, db)
})
@ -641,9 +641,9 @@ func TestListObjectsSkipCursor(t *testing.T) {
},
Result: metabase.ListObjectsResult{
Objects: []metabase.ObjectEntry{
prefixEntry(metabase.ObjectKey("08/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("08/")),
prefixEntry(metabase.ObjectKey("09/")),
prefixEntry(metabase.ObjectKey("10/")),
}},
}.Check(ctx, t, db)
@ -662,8 +662,8 @@ func TestListObjectsSkipCursor(t *testing.T) {
},
Result: metabase.ListObjectsResult{
Objects: []metabase.ObjectEntry{
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("09/")),
prefixEntry(metabase.ObjectKey("10/")),
}},
}.Check(ctx, t, db)
@ -682,8 +682,8 @@ func TestListObjectsSkipCursor(t *testing.T) {
},
Result: metabase.ListObjectsResult{
Objects: []metabase.ObjectEntry{
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("09/")),
prefixEntry(metabase.ObjectKey("10/")),
}},
}.Check(ctx, t, db)
})
@ -729,10 +729,10 @@ func TestListObjectsSkipCursor(t *testing.T) {
},
Result: metabase.ListObjectsResult{
Objects: []metabase.ObjectEntry{
prefixEntry(metabase.ObjectKey("08/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("08/")),
withoutPrefix1("2017/05/", objects["2017/05/08"+afterDelimiter]),
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("09/")),
prefixEntry(metabase.ObjectKey("10/")),
}},
}.Check(ctx, t, db)
@ -754,8 +754,8 @@ func TestListObjectsSkipCursor(t *testing.T) {
Result: metabase.ListObjectsResult{
Objects: []metabase.ObjectEntry{
withoutPrefix1("2017/05/", objects["2017/05/08"+afterDelimiter]),
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("09/")),
prefixEntry(metabase.ObjectKey("10/")),
}},
}.Check(ctx, t, db)
@ -776,8 +776,8 @@ func TestListObjectsSkipCursor(t *testing.T) {
Result: metabase.ListObjectsResult{
Objects: []metabase.ObjectEntry{
withoutPrefix1("2017/05/", objects["2017/05/08"+afterDelimiter]),
prefixEntry(metabase.ObjectKey("09/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("10/"), metabase.CommittedUnversioned),
prefixEntry(metabase.ObjectKey("09/")),
prefixEntry(metabase.ObjectKey("10/")),
}},
}.Check(ctx, t, db)
})