[#248] Correct object versions response markers

Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
Denis Kirillov 2023-12-21 10:53:50 +03:00
parent a17ff66975
commit 43cae9ee04
2 changed files with 11 additions and 7 deletions

View file

@ -232,12 +232,16 @@ func TestMintVersioningListObjectVersionsVersionIDContinuation(t *testing.T) {
checkVersionsNames(t, page1, objects) checkVersionsNames(t, page1, objects)
require.Equal(t, page1.Version[maxKeys-1].VersionID, page1.NextVersionIDMarker) require.Equal(t, page1.Version[maxKeys-1].VersionID, page1.NextVersionIDMarker)
require.True(t, page1.IsTruncated) require.True(t, page1.IsTruncated)
require.Empty(t, page1.KeyMarker)
require.Empty(t, page1.VersionIDMarker)
page2 := listObjectsVersions(hc, bktName, "", "", page1.NextKeyMarker, page1.NextVersionIDMarker, maxKeys) page2 := listObjectsVersions(hc, bktName, "", "", page1.NextKeyMarker, page1.NextVersionIDMarker, maxKeys)
require.Len(t, page2.Version, maxKeys) require.Len(t, page2.Version, maxKeys)
checkVersionsNames(t, page1, objects) checkVersionsNames(t, page1, objects)
require.Empty(t, page2.NextVersionIDMarker) require.Empty(t, page2.NextVersionIDMarker)
require.False(t, page2.IsTruncated) require.False(t, page2.IsTruncated)
require.Equal(t, page1.NextKeyMarker, page2.KeyMarker)
require.Equal(t, page1.NextVersionIDMarker, page2.VersionIDMarker)
} }
func checkVersionsNames(t *testing.T, versions *ListObjectsVersionsResponse, names []string) { func checkVersionsNames(t *testing.T, versions *ListObjectsVersionsResponse, names []string) {

View file

@ -9,11 +9,6 @@ import (
) )
func (n *layer) ListObjectVersions(ctx context.Context, p *ListObjectVersionsParams) (*ListObjectVersionsInfo, error) { func (n *layer) ListObjectVersions(ctx context.Context, p *ListObjectVersionsParams) (*ListObjectVersionsInfo, error) {
var (
allObjects = make([]*data.ExtendedObjectInfo, 0, p.MaxKeys)
res = &ListObjectVersionsInfo{}
)
versions, err := n.getAllObjectsVersions(ctx, p.BktInfo, p.Prefix, p.Delimiter) versions, err := n.getAllObjectsVersions(ctx, p.BktInfo, p.Prefix, p.Delimiter)
if err != nil { if err != nil {
return nil, err return nil, err
@ -25,6 +20,8 @@ func (n *layer) ListObjectVersions(ctx context.Context, p *ListObjectVersionsPar
} }
sort.Strings(sortedNames) sort.Strings(sortedNames)
allObjects := make([]*data.ExtendedObjectInfo, 0, p.MaxKeys)
for _, name := range sortedNames { for _, name := range sortedNames {
sortedVersions := versions[name] sortedVersions := versions[name]
sort.Slice(sortedVersions, func(i, j int) bool { sort.Slice(sortedVersions, func(i, j int) bool {
@ -41,6 +38,11 @@ func (n *layer) ListObjectVersions(ctx context.Context, p *ListObjectVersionsPar
return nil, err return nil, err
} }
res := &ListObjectVersionsInfo{
KeyMarker: p.KeyMarker,
VersionIDMarker: p.VersionIDMarker,
}
res.CommonPrefixes, allObjects = triageExtendedObjects(allObjects) res.CommonPrefixes, allObjects = triageExtendedObjects(allObjects)
if len(allObjects) > p.MaxKeys { if len(allObjects) > p.MaxKeys {
@ -49,8 +51,6 @@ func (n *layer) ListObjectVersions(ctx context.Context, p *ListObjectVersionsPar
res.NextVersionIDMarker = allObjects[p.MaxKeys-1].ObjectInfo.VersionID() res.NextVersionIDMarker = allObjects[p.MaxKeys-1].ObjectInfo.VersionID()
allObjects = allObjects[:p.MaxKeys] allObjects = allObjects[:p.MaxKeys]
res.KeyMarker = p.KeyMarker
res.VersionIDMarker = p.VersionIDMarker
} }
res.Version, res.DeleteMarker = triageVersions(allObjects) res.Version, res.DeleteMarker = triageVersions(allObjects)