Skip to content

Commit

Permalink
object/searchv2: Fix cursor for ROOT and PHY filters
Browse files Browse the repository at this point in the history
650b801 defect. These filters are
transformed into `ROOT|PHY EQ 1` ones, so this should be reflected in
the cursor.

Refs #3116. Refs #3058.

Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
  • Loading branch information
cthulhu-rider committed Feb 18, 2025
1 parent 03497a5 commit 16bb277
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions pkg/local_object_storage/metabase/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,14 +865,23 @@ func convertFilterValue(f object.SearchFilter) (object.SearchMatchType, string)

// CalculateCursor calculates cursor for the given last search result item.
func CalculateCursor(fs object.SearchFilters, lastItem client.SearchResultItem) (SearchCursor, error) {
if len(lastItem.Attributes) == 0 || len(fs) == 0 || fs[0].Operation() == object.MatchNotPresent {
if len(fs) == 0 || fs[0].Operation() == object.MatchNotPresent {

Check warning on line 868 in pkg/local_object_storage/metabase/metadata.go

View check run for this annotation

Codecov / codecov/patch

pkg/local_object_storage/metabase/metadata.go#L868

Added line #L868 was not covered by tests
return SearchCursor{Key: lastItem.ID[:]}, nil
}
attr := fs[0].Header()
var lastItemVal string
if len(lastItem.Attributes) == 0 {
if attr != object.FilterRoot && attr != object.FilterPhysical {
return SearchCursor{Key: lastItem.ID[:]}, nil
}
lastItemVal = binPropMarker
} else {
lastItemVal = lastItem.Attributes[0]
}

Check warning on line 880 in pkg/local_object_storage/metabase/metadata.go

View check run for this annotation

Codecov / codecov/patch

pkg/local_object_storage/metabase/metadata.go#L872-L880

Added lines #L872 - L880 were not covered by tests
var val []byte
switch attr {
default:
if n, ok := new(big.Int).SetString(lastItem.Attributes[0], 10); ok {
if n, ok := new(big.Int).SetString(lastItemVal, 10); ok {

Check warning on line 884 in pkg/local_object_storage/metabase/metadata.go

View check run for this annotation

Codecov / codecov/patch

pkg/local_object_storage/metabase/metadata.go#L884

Added line #L884 was not covered by tests
var res SearchCursor
res.Key = make([]byte, len(attr)+utf8DelimiterLen+intValLen+oid.Size)
off := copy(res.Key, attr)
Expand All @@ -883,11 +892,11 @@ func CalculateCursor(fs object.SearchFilters, lastItem client.SearchResultItem)
}
case object.FilterOwnerID, object.FilterFirstSplitObject, object.FilterParentID:
var err error
if val, err = base58.Decode(lastItem.Attributes[0]); err != nil {
if val, err = base58.Decode(lastItemVal); err != nil {

Check warning on line 895 in pkg/local_object_storage/metabase/metadata.go

View check run for this annotation

Codecov / codecov/patch

pkg/local_object_storage/metabase/metadata.go#L895

Added line #L895 was not covered by tests
return SearchCursor{}, fmt.Errorf("decode %q attribute value from Base58: %w", attr, err)
}
case object.FilterPayloadChecksum, object.FilterPayloadHomomorphicHash:
ln := hex.DecodedLen(len(lastItem.Attributes[0]))
ln := hex.DecodedLen(len(lastItemVal))

Check warning on line 899 in pkg/local_object_storage/metabase/metadata.go

View check run for this annotation

Codecov / codecov/patch

pkg/local_object_storage/metabase/metadata.go#L899

Added line #L899 was not covered by tests
if attr == object.FilterPayloadChecksum && ln != sha256.Size || attr == object.FilterPayloadHomomorphicHash && ln != tz.Size {
return SearchCursor{}, fmt.Errorf("wrong %q attribute decoded len %d", attr, ln)
}
Expand All @@ -896,21 +905,21 @@ func CalculateCursor(fs object.SearchFilters, lastItem client.SearchResultItem)
off := copy(res.Key, attr)
res.ValIDOff = off + copy(res.Key[off:], utf8Delimiter)
var err error
if _, err = hex.Decode(res.Key[res.ValIDOff:], []byte(lastItem.Attributes[0])); err != nil {
if _, err = hex.Decode(res.Key[res.ValIDOff:], []byte(lastItemVal)); err != nil {

Check warning on line 908 in pkg/local_object_storage/metabase/metadata.go

View check run for this annotation

Codecov / codecov/patch

pkg/local_object_storage/metabase/metadata.go#L908

Added line #L908 was not covered by tests
return SearchCursor{}, fmt.Errorf("decode %q attribute from HEX: %w", attr, err)
}
copy(res.Key[res.ValIDOff+ln:], lastItem.ID[:])
return res, nil
case object.FilterSplitID:
uid, err := uuid.Parse(lastItem.Attributes[0])
uid, err := uuid.Parse(lastItemVal)

Check warning on line 914 in pkg/local_object_storage/metabase/metadata.go

View check run for this annotation

Codecov / codecov/patch

pkg/local_object_storage/metabase/metadata.go#L914

Added line #L914 was not covered by tests
if err != nil {
return SearchCursor{}, fmt.Errorf("decode %q attribute from HEX: %w", attr, err)
}
val = uid[:]
case object.FilterVersion, object.FilterType:
}
if val == nil {
val = []byte(lastItem.Attributes[0])
val = []byte(lastItemVal)

Check warning on line 922 in pkg/local_object_storage/metabase/metadata.go

View check run for this annotation

Codecov / codecov/patch

pkg/local_object_storage/metabase/metadata.go#L922

Added line #L922 was not covered by tests
}
var res SearchCursor
res.Key = make([]byte, len(attr)+utf8DelimiterLen+len(val)+oid.Size)
Expand Down

0 comments on commit 16bb277

Please sign in to comment.