nonbinaryprogrammer commented on a change in pull request #6296:
URL: https://github.com/apache/geode/pull/6296#discussion_r626952701
##########
File path:
geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/data/RedisSet.java
##########
@@ -35,27 +35,61 @@
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
+import org.apache.geode.DataSerializer;
import org.apache.geode.annotations.VisibleForTesting;
import org.apache.geode.cache.Region;
-import org.apache.geode.internal.InternalDataSerializer;
import org.apache.geode.internal.serialization.DeserializationContext;
import org.apache.geode.internal.serialization.KnownVersion;
import org.apache.geode.internal.serialization.SerializationContext;
+import org.apache.geode.internal.size.ReflectionObjectSizer;
import org.apache.geode.redis.internal.delta.AddsDeltaInfo;
import org.apache.geode.redis.internal.delta.DeltaInfo;
import org.apache.geode.redis.internal.delta.RemsDeltaInfo;
public class RedisSet extends AbstractRedisData {
-
private HashSet<ByteArrayWrapper> members;
+ private static int baseRedissetOverhead;
+ private static int perMemberOverhead;
+ private static int internalHashsetStorageOverhead;
+
+ private int myCalculatedSize;
+
@SuppressWarnings("unchecked")
RedisSet(Collection<ByteArrayWrapper> members) {
+ calibrate_memory_values();
+
if (members instanceof HashSet) {
this.members = (HashSet<ByteArrayWrapper>) members;
} else {
this.members = new HashSet<>(members);
}
+
+ for (ByteArrayWrapper value : this.members) {
+ myCalculatedSize += perMemberOverhead + value.length();
+ }
+ }
+
+ private void calibrate_memory_values() {
+ ReflectionObjectSizer reflectionObjectSizer =
ReflectionObjectSizer.getInstance();
+ baseRedissetOverhead = reflectionObjectSizer.sizeof(this) + 18;
+
+ HashSet<ByteArrayWrapper> temp_hashset = new HashSet<>();
+ int base_hashset_size = reflectionObjectSizer.sizeof(temp_hashset);
+ baseRedissetOverhead += base_hashset_size;
+
+ ByteArrayWrapper baw1 = new ByteArrayWrapper("a".getBytes());
+ ByteArrayWrapper baw2 = new ByteArrayWrapper("b".getBytes());
+ temp_hashset.add(baw1);
+ int one_entry_hashset_size = reflectionObjectSizer.sizeof(temp_hashset);
+ temp_hashset.add(baw2);
+ int two_entries_hashset_size = reflectionObjectSizer.sizeof(temp_hashset);
+
+ perMemberOverhead = two_entries_hashset_size - one_entry_hashset_size + 5;
+ internalHashsetStorageOverhead =
+ two_entries_hashset_size - (2 * perMemberOverhead) - base_hashset_size;
+
+ myCalculatedSize = baseRedissetOverhead;
Review comment:
switched to using constants and added tests
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]