Skip to content

Commit

Permalink
Fix continuation token being invalidated by delete.
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Babenko committed Oct 28, 2018
1 parent 4d5c8c5 commit e2935e2
Showing 1 changed file with 14 additions and 7 deletions.
Expand Up @@ -346,6 +346,14 @@ public ListBucketResultV2 listObjectsInsideBucketV2(@PathVariable final String b
final List<BucketContents> contents = getBucketContents(bucketName, prefix);
List<BucketContents> filteredContents = getFilteredBucketContents(contents, startAfter);

Collections.sort(filteredContents, new Comparator<BucketContents>() {
@Override
public int compare(BucketContents lhs, BucketContents rhs) {
// -1 - less than, 1 - greater than, 0 - equal, all inversed for descending
return String.CASE_INSENSITIVE_ORDER.compare(lhs.getKey(),rhs.getKey());
}
});

final Set<String> commonPrefixes = new HashSet<>();
if (delimiter != null) {
collapseCommonPrefixes(prefix, delimiter, filteredContents, commonPrefixes);
Expand All @@ -354,13 +362,12 @@ public ListBucketResultV2 listObjectsInsideBucketV2(@PathVariable final String b
String nextContinuationToken = null;
boolean isTruncated = false;

int itemsToSkipForThisRequest = 0;

if (continuationToken != null) {
itemsToSkipForThisRequest = Integer.parseInt(
fileStorePagingStateCache.get(continuationToken).get().toString());
filteredContents = filteredContents.subList(itemsToSkipForThisRequest,
filteredContents.size());
String continuationKey = fileStorePagingStateCache.get(continuationToken).get().toString();
filteredContents = filteredContents
.stream()
.filter(p -> p.getKey().compareTo(continuationKey) > 0)
.collect(Collectors.toList());
fileStorePagingStateCache.evict(continuationToken);
}

Expand All @@ -369,7 +376,7 @@ public ListBucketResultV2 listObjectsInsideBucketV2(@PathVariable final String b
isTruncated = true;
nextContinuationToken = UUID.randomUUID().toString();
fileStorePagingStateCache.put(nextContinuationToken,
String.valueOf(itemsToSkipForThisRequest + maxKeys));
filteredContents.get(maxKeys - 1).getKey());
filteredContents = filteredContents.subList(0, maxKeys);
}

Expand Down

0 comments on commit e2935e2

Please sign in to comment.