tejaslodayadd commented on PR #3269:
URL: https://github.com/apache/kvrocks/pull/3269#issuecomment-3573397905

   After discussing this w/ @ltagliamonte-dd, there's a problem:
   
   Currently, `HLEN` returns the field count by reading `metadata.size` 
directly - an O(1) operation. However, with per-field expiration:
   
   - Expired fields remain in storage until compaction cleans them up
   - The `metadata.size` counter doesn't know when individual fields expire
   - Result: A hash with 5 fields where 1 has expired will still report `HLEN = 
5` instead of `4`
   
   Options:
   
   1. Accept approximate count:  Keep current O(1) behavior, document that 
`HLEN` returns approximate count when using field TTL, accurate after 
compaction (eventual consistenct)
   2. Scan-based count:  `HLEN` scans all fields and counts non-expired ones. 
Con: O(n) instead of O(1), expensive for large hashes
   3. Optimized scan with metadata tracking: Add a flag in `HashMetadata` to 
track if any field has expiration set. `HLEN` returns `metadata.size` directly 
if no fields have TTL -- O(1), and only scan when hash has fields with 
expiration -- O(n)
   
   Let us know which way you'd want us to move forward @PragmaTwice @torwig 
@aleksraiden 


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