szetszwo commented on code in PR #1062:
URL: https://github.com/apache/ratis/pull/1062#discussion_r1546672731
##########
ratis-server-api/src/main/java/org/apache/ratis/server/raftlog/RaftLog.java:
##########
@@ -188,17 +188,41 @@ default long getNextIndex() {
interface EntryWithData {
/** @return the index of this entry. */
default long getIndex() {
+ ReferenceCountedObject<LogEntryProto> ref = null;
try {
- return getEntry(TimeDuration.ONE_MINUTE).getIndex();
+ ref = getEntryWithRetainedData(TimeDuration.ONE_MINUTE);
+ return ref.get().getIndex();
} catch (Exception e) {
throw new IllegalStateException("Failed to getIndex", e);
+ } finally {
+ if (ref != null) {
+ ref.release();
+ }
}
}
/** @return the serialized size including both log entry and state machine
data. */
int getSerializedSize();
- /** @return the {@link LogEntryProto} containing both the log entry and
the state machine data. */
- LogEntryProto getEntry(TimeDuration timeout) throws RaftLogIOException,
TimeoutException;
+ /**
+ * @return the {@link LogEntryProto} containing both the log entry and the
state machine data.
+ * @deprecated
+ */
+ default LogEntryProto getEntry(TimeDuration timeout) throws
RaftLogIOException, TimeoutException {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @return a {@link ReferenceCountedObject} wrapping {@link LogEntryProto}
containing both the log entry
+ * and the state machine data.
+ * The state machine data are retained (by the state machine) and this is
represented by the wrapping
+ * {@link ReferenceCountedObject}. The caller must call {@link
ReferenceCountedObject#release()}} after use.
+ */
+ default ReferenceCountedObject<LogEntryProto>
getEntryWithRetainedData(TimeDuration timeout)
Review Comment:
This method may make things complicated since there will be two
`ReferenceCountedObject`s. Since we have the state machine data future and the
log ref when creating an `EntryWithData` object. Let's wrap everything to a
single `ReferenceCountedObject`.
--
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]