szetszwo commented on PR #1045:
URL: https://github.com/apache/ratis/pull/1045#issuecomment-1983962784
Could we retain it before returns and ask the caller to release it?
```java
//RaftLog
/**
- * @return a ReferenceCountedObject to the log entry corresponding to
the given log index if it exists.
- * otherwise, null.
+ * @return a retained {@link ReferenceCountedObject} to the log entry
corresponding to the given index
+ * if it exists; otherwise, return null.
+ * Since the returned reference is retained,
+ * the caller must call {@link ReferenceCountedObject#release()}}
after use.
*/
- default ReferenceCountedObject<LogEntryProto> getWithRef(long index)
throws RaftLogIOException {
+ default ReferenceCountedObject<LogEntryProto> retainEntry(long index)
throws RaftLogIOException {
return ReferenceCountedObject.wrap(get(index));
}
```
```java
@@ -287,6 +287,7 @@ public final class SegmentedRaftLog extends RaftLogBase {
}
final ReferenceCountedObject<LogEntryProto> entry =
segment.getEntryFromCache(record.getTermIndex());
if (entry != null) {
+ entry.retain();
getRaftLogMetrics().onRaftLogCacheHit();
return entry;
}
```
--
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]