DonalEvans commented on a change in pull request #6699:
URL: https://github.com/apache/geode/pull/6699#discussion_r670883384
##########
File path:
geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/data/RedisSortedSet.java
##########
@@ -171,20 +170,24 @@ public int getDSFID() {
}
protected synchronized byte[] memberAdd(byte[] memberToAdd, byte[]
scoreToAdd) {
- byte[] oldScore = null;
-
OrderedSetEntry newEntry = new OrderedSetEntry(memberToAdd, scoreToAdd);
- OrderedSetEntry orderedSetEntry = members.put(memberToAdd, newEntry);
- if (orderedSetEntry == null) {
+ OrderedSetEntry existingEntry = members.put(memberToAdd, newEntry);
+ if (existingEntry == null) {
scoreSet.add(newEntry);
- sizeInBytes += calculateSizeOfFieldValuePair(memberToAdd, scoreToAdd);
+ // Without this adjustment, we count the entry and member name array
twice, since references
+ // to them appear in both backing collections.
+ sizeInBytesAdjustment += newEntry.getSizeInBytes() +
calculateByteArraySize(memberToAdd);
+ return null;
} else {
- scoreSet.remove(orderedSetEntry);
+ scoreSet.remove(existingEntry);
scoreSet.add(newEntry);
- oldScore = orderedSetEntry.getScoreBytes();
- sizeInBytes += scoreToAdd.length - oldScore.length;
+ // When updating an entry, the references to the member name array in
the backing collections
Review comment:
Ah, I had tried to find a solution for that when I was writing this, but
I ran out of steam before I could figure one out. Yours works perfectly, thanks!
--
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]