Skip to content

Commit

Permalink
fix: marker logic
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh4723 committed Sep 4, 2024
1 parent f118be6 commit 24ad950
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
18 changes: 11 additions & 7 deletions cmd/bucket-listobjects-handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func limitMergeObjects(mergeObjects []ObjectInfo, mergePrefixes []string, maxKey
} else {
limitedObjs = append(limitedObjs, objPrefixMap[key])
}
if i >= maxKeys {
if i >= (maxKeys - 1) {
nextMarker = key
break
}
Expand Down Expand Up @@ -360,14 +360,16 @@ func (api objectAPIHandlers) ListObjectsV2Handler(w http.ResponseWriter, r *http
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL)
return
}
isTruncated := listObjectsV2Info.IsTruncated || listObjectsV2InfoCache.IsTruncated

mergeObjects := mergeListObjects(listObjectsV2Info.Objects, listObjectsV2InfoCache.Objects)
mergePrefixes := mergePrefixes(listObjectsV2Info.Prefixes, listObjectsV2InfoCache.Prefixes)
limitedObjects, limitedPrefix, nextMarker := limitMergeObjects(mergeObjects, mergePrefixes, maxKeys)
listObjectsV2Info.Objects = limitedObjects
listObjectsV2Info.Prefixes = limitedPrefix
listObjectsV2Info.NextContinuationToken = nextMarker
listObjectsV2Info.IsTruncated = isTruncated
if nextMarker != "" {
listObjectsV2Info.NextContinuationToken = nextMarker
listObjectsV2Info.IsTruncated = true
}

fmt.Printf("Final listObjectsV2InfoCache %+v\n", listObjectsV2InfoCache)
fmt.Printf("Final listObjectsV2Info %+v\n", listObjectsV2Info)
Expand Down Expand Up @@ -496,14 +498,16 @@ func (api objectAPIHandlers) ListObjectsV1Handler(w http.ResponseWriter, r *http
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL)
return
}
isTruncated := listObjectsInfo.IsTruncated || listObjectsInfoCache.IsTruncated
mergeObjects := mergeListObjects(listObjectsInfo.Objects, listObjectsInfoCache.Objects)
mergePrefixes := mergePrefixes(listObjectsInfo.Prefixes, listObjectsInfoCache.Prefixes)
limitedObjects, limitedPrefix, nextMarker := limitMergeObjects(mergeObjects, mergePrefixes, maxKeys)
listObjectsInfo.Objects = limitedObjects
listObjectsInfo.Prefixes = limitedPrefix
listObjectsInfo.NextMarker = nextMarker
listObjectsInfo.IsTruncated = isTruncated
if nextMarker != "" {
listObjectsInfo.NextMarker = nextMarker
listObjectsInfo.IsTruncated = true
}

concurrentDecryptETag(ctx, listObjectsInfo.Objects)

response := generateListObjectsV1Response(bucket, prefix, marker, delimiter, encodingType, maxKeys, listObjectsInfo)
Expand Down
6 changes: 4 additions & 2 deletions cmd/disk-cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,6 @@ func (c *cacheObjects) ListObjects(ctx context.Context, bucket, prefix, marker,
objectCount := 0
leafFilter := func(n art.Node) bool {
if n.Kind() == art.Leaf {
fmt.Println("value=", string(n.Key()), n.Value())
if strings.HasPrefix(string(n.Key()), rootprefix) {
if marker == "" || string(n.Key()) > rootMarker {
trimmed := strings.TrimPrefix(string(n.Key()), rootprefix)
Expand All @@ -539,7 +538,10 @@ func (c *cacheObjects) ListObjects(ctx context.Context, bucket, prefix, marker,
objInfos = append(objInfos, ob)
}
} else if delimiter != "" {
prefixes[prefix+parts[0]+delimiter] = true
dir := prefix + parts[0] + delimiter
if marker == "" || dir > marker {
prefixes[dir] = true
}
}
}
}
Expand Down

0 comments on commit 24ad950

Please sign in to comment.