You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ratis.apache.org by "duongkame (via GitHub)" <gi...@apache.org> on 2024/04/01 21:41:04 UTC
Re: [PR] RATIS-1979. Allow StateMachine.read to return a ReferentCountedObject [ratis]
duongkame commented on code in PR #1062:
URL: https://github.com/apache/ratis/pull/1062#discussion_r1546878670
##########
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:
Agree, I was concerned about the same thing but couldn't find a good way to wrap the ref of the LogEntry and the one in the future.
--
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: issues-unsubscribe@ratis.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org