Copilot commented on code in PR #24278:
URL: https://github.com/apache/kafka/pull/24278#discussion_r4680982827


##########
streams/src/main/java/org/apache/kafka/streams/state/internals/LRUCacheEntry.java:
##########
@@ -93,13 +102,13 @@ public boolean equals(final Object o) {
             return false;
         }
         final LRUCacheEntry that = (LRUCacheEntry) o;
-        return sizeBytes == that.sizeBytes &&
+        return size() == that.size() &&
             isDirty() == that.isDirty() &&
             Objects.equals(record, that.record);

Review Comment:
   `equals`/`hashCode` now depend on `size()`, which can change after 
`freeRawRecord()` (and also depends on other mutable state like `isDirty`). If 
`LRUCacheEntry` is ever placed in hash-based collections, this can violate the 
hashCode/equals contract. Consider removing size-dependent (and more generally 
mutable) fields from `equals`/`hashCode`, or avoid overriding these methods if 
stable identity semantics aren't required.



##########
streams/src/test/java/org/apache/kafka/streams/state/internals/ThreadCacheTest.java:
##########
@@ -136,8 +136,12 @@ public void cacheOverheadsLargeValues() {
     }
 
 
-    static long memoryCacheEntrySize(final byte[] key, final byte[] value, 
final String topic) {
-        return key.length +
+    static long memoryCacheEntrySize(final byte[] key,
+                                     final byte[] value,
+                                     final String topic,
+                                     final int rawKeySize,
+                                     final int rawValueSize) {
+        return (long) rawKeySize + rawValueSize +
             value.length +

Review Comment:
   `memoryCacheEntrySize` previously included `key.length`, but the updated 
implementation no longer accounts for it. This will under-estimate entry sizes 
in tests and can make cache-budget/eviction assertions inaccurate. Include 
`key.length` in the returned size calculation (alongside `value.length` and raw 
sizes).



##########
streams/src/main/java/org/apache/kafka/streams/state/internals/LRUCacheEntry.java:
##########
@@ -93,13 +102,13 @@ public boolean equals(final Object o) {
             return false;
         }
         final LRUCacheEntry that = (LRUCacheEntry) o;
-        return sizeBytes == that.sizeBytes &&
+        return size() == that.size() &&
             isDirty() == that.isDirty() &&
             Objects.equals(record, that.record);
     }
 
     @Override
     public int hashCode() {
-        return Objects.hash(record, sizeBytes, isDirty());
+        return Objects.hash(record, size(), isDirty());

Review Comment:
   `equals`/`hashCode` now depend on `size()`, which can change after 
`freeRawRecord()` (and also depends on other mutable state like `isDirty`). If 
`LRUCacheEntry` is ever placed in hash-based collections, this can violate the 
hashCode/equals contract. Consider removing size-dependent (and more generally 
mutable) fields from `equals`/`hashCode`, or avoid overriding these methods if 
stable identity semantics aren't required.



-- 
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]

Reply via email to