You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "chanbinme (via GitHub)" <gi...@apache.org> on 2025/08/18 15:06:56 UTC

[PR] MINOR: Refactor snapshottableSize method for better readability and simplicity [kafka]

chanbinme opened a new pull request, #20368:
URL: https://github.com/apache/kafka/pull/20368

   ### Motivation
   The `snapshottableSize(long epoch)` method previously contained unnecessary nested conditions and multiple redundant `return baseSize();` statements. This refactor aims to simplify the method's control flow and improve code readability.
   
   ### Changes
   - Changed the condition from `epoch == LATEST_EPOCH` to `epoch != LATEST_EPOCH` to avoid unnecessary else block usage.
   - Consolidated the redundant `return baseSize();` statements into a single return at the end of the method.
   - Ensured the iterator logic executes only when necessary, resulting in clearer control flow.
   
   ### Before
   ```java
   int snapshottableSize(long epoch) {
       if (epoch == LATEST_EPOCH) {
           return baseSize();
       } else {
           Iterator<Snapshot> iterator = snapshotRegistry.iterator(epoch);
           while(iterator.hasNext()) {
               Snapshot snapshot = iterator.next();
               HashTier<T> tier = snapshot.getDelta(SnapshottableHashTable.this);
               if (tier != null) {
                   return tier.size;
               }
           }
           return baseSize();
       }
   }
   ```
   
   ### After
   ```java
   int snapshottableSize(long epoch) {
       if (epoch != LATEST_EPOCH) {
           Iterator<Snapshot> iterator = snapshotRegistry.iterator(epoch);
           while(iterator.hasNext()) {
               Snapshot snapshot = iterator.next();
               HashTier<T> tier = snapshot.getDelta(SnapshottableHashTable.this);
               if (tier != null) {
                   return tier.size;
               }
           }
       }
       return baseSize();
   }
   ```
   
   ---
   
   Please let me know if any further adjustments are needed.  
   Thank you for your review!


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINOR: Refactor snapshottableSize method for better readability and simplicity [kafka]

Posted by "chanbinme (via GitHub)" <gi...@apache.org>.
chanbinme closed pull request #20368: MINOR: Refactor snapshottableSize method for better readability and simplicity
URL: https://github.com/apache/kafka/pull/20368


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINOR: Refactor snapshottableSize method for better readability and simplicity [kafka]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #20368:
URL: https://github.com/apache/kafka/pull/20368#issuecomment-3222446291

   A label of 'needs-attention' was automatically added to this PR in order to raise the
   attention of the committers. Once this issue has been triaged, the `triage` label
   should be removed to prevent this automation from happening again.


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org