You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2021/06/10 00:29:48 UTC

[GitHub] [kafka] satishd commented on a change in pull request #10848: MINOR Updated transaction index as optional in LogSegmentData.

satishd commented on a change in pull request #10848:
URL: https://github.com/apache/kafka/pull/10848#discussion_r648768897



##########
File path: storage/api/src/main/java/org/apache/kafka/server/log/remote/storage/LogSegmentData.java
##########
@@ -33,31 +34,32 @@
     private final Path logSegment;
     private final Path offsetIndex;
     private final Path timeIndex;
-    private final Path txnIndex;
+    private final Optional<Path> transactionIndex;
     private final Path producerSnapshotIndex;
     private final ByteBuffer leaderEpochIndex;
 
     /**
      * Creates a LogSegmentData instance with data and indexes.
-     *  @param logSegment            actual log segment file
+     *
+     * @param logSegment            actual log segment file
      * @param offsetIndex           offset index file
      * @param timeIndex             time index file
-     * @param txnIndex              transaction index file
+     * @param transactionIndex      transaction index file, which can be null
      * @param producerSnapshotIndex producer snapshot until this segment
      * @param leaderEpochIndex      leader-epoch-index until this segment
      */
     public LogSegmentData(Path logSegment,
                           Path offsetIndex,
                           Path timeIndex,
-                          Path txnIndex,
+                          Path transactionIndex,

Review comment:
       Passing `Optional` as arguments is not considered as a good practice. We still need to do null check for that Optional instance. 
   [SO answer from Brian Goetz](https://stackoverflow.com/questions/26327957/should-java-8-getters-return-optional-type/26328555#26328555) mentioned the right usage of `Optional`. I have also update PR not to use it as a field.
   
   ```
   You should almost never use it as a field of something or a method parameter.
   ```
   
   [Javadoc of Optional ](https://docs.oracle.com/javase/10/docs/api/java/util/Optional.html)suggests returning as an argument mentioned below.
   ```
   API Note:
   Optional is primarily intended for use as a method return type where there is a clear need to represent "no result," and where using null is likely to cause errors. A variable whose type is Optional should never itself be null; it should always point to an Optional instance.
   ```
   
   I do not have strong opinions on this, I am fine with the conventions that we are following in this project if we have any on `Optional` usage. 




-- 
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:
users@infra.apache.org