duongkame commented on code in PR #1045:
URL: https://github.com/apache/ratis/pull/1045#discussion_r1515270971


##########
ratis-server-api/src/main/java/org/apache/ratis/server/raftlog/RaftLog.java:
##########
@@ -58,8 +59,21 @@ default boolean contains(TermIndex ti) {
   /**
    * @return null if the log entry is not found in this log;
    *         otherwise, return the log entry corresponding to the given index.
+   * @deprecated use {@link RaftLog#getWithRef(long)} instead.
    */
-  LogEntryProto get(long index) throws RaftLogIOException;
+  @Deprecated
+  default LogEntryProto get(long index) throws RaftLogIOException {
+    ReferenceCountedObject<LogEntryProto> ref = getWithRef(index);
+    return ref != null ? ref.get() : null;
+  }
+
+  /**
+   * @return a ReferenceCountedObject to the  log entry corresponding to the 
given log index if it exists.
+   * otherwise, null.
+   */
+  default ReferenceCountedObject<LogEntryProto> getWithRef(long index) throws 
RaftLogIOException {
+    return ReferenceCountedObject.wrap(get(index));
+  }

Review Comment:
   `TransactionContext.getLogEntryRef()` will be protected by a retain/release 
pair from the framework. So, the StateMachine code doesn't need to call 
retain/release unless extending the LogEntry usage outside the method scope. 
It's where the javadoc above from.
   
   ```
   // in StateMachineUpdater.
   final ReferenceCountedObject<LogEntryProto> next = 
raftLog.getWithRef(nextIndex);
   next.retain();
   try {
     server.applyLogToStateMachine(next);
   } finally {
     next.release();
   }
   ```



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