DonalEvans commented on a change in pull request #6701:
URL: https://github.com/apache/geode/pull/6701#discussion_r674408022
##########
File path:
geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/data/RedisHash.java
##########
@@ -237,15 +238,21 @@ public int hstrlen(byte[] field) {
return new ArrayList<>(hash.keySet());
}
- public ImmutablePair<Integer, List<byte[]>> hscan(Pattern matchPattern,
- int count,
- int cursor) {
-
- ArrayList<byte[]> resultList = new ArrayList<>(count + 2);
+ public ImmutablePair<Integer, List<byte[]>> hscan(Pattern matchPattern, int
count, int cursor) {
+ // No need to allocate more space than it's possible to use given the size
of the hash. We need
+ // to add 1 to hash.size() to ensure that if count > hash.size(), we
return a cursor of 0
+ long maximumCapacity = 2L * Math.min(count, hlen() + 1);
+ if (maximumCapacity > Integer.MAX_VALUE) {
+ LogService.getLogger().error(
+ "The size of the data to be returned by hscan, {}, exceeds the
maximum capacity of an array",
+ maximumCapacity);
+ throw new OutOfMemoryError("Requested array size exceeds VM limit");
Review comment:
Currently, the exception thrown here will ultimately get handled in
`ExecutionHandlerContext.getExceptionResponse()` where it will result in an
error message returned to the client with the message "The server had an
internal error please try again". This definitely doesn't seem correct, since
trying again will just result in the same error, but none of the currently
existing error responses we have seem right either, and I'm having a hard time
find a list of existing Redis error messages to see if any of them would be a
better fit. It's also not practical to test what Redis actually does in this
situation, given that would require a Redis hash with over a billion entries.
I'll have a look at the Redis source and see if I can figure out what the
behaviour would be in this situation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]