From c254de868bc06a60dfb121aa1a1abfe01bf692ed Mon Sep 17 00:00:00 2001 From: Wojciech Lukowicz Date: Thu, 14 Mar 2024 10:15:48 +0000 Subject: [PATCH] make the engine reuse its outbound recording consistently Previously, outbound recordings would get reused in non-deterministic way after restart, meaning that a recording used by the engine could become used by the library and the other way round. This is OK, but it's confusing. Now the engine will reuse its old recording. If there's a single library, then it will reuse its old recording too. --- .../artio/engine/RecordingCoordinator.java | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/artio-core/src/main/java/uk/co/real_logic/artio/engine/RecordingCoordinator.java b/artio-core/src/main/java/uk/co/real_logic/artio/engine/RecordingCoordinator.java index b6deb9b7e8..07ce6ef2bd 100644 --- a/artio-core/src/main/java/uk/co/real_logic/artio/engine/RecordingCoordinator.java +++ b/artio-core/src/main/java/uk/co/real_logic/artio/engine/RecordingCoordinator.java @@ -288,7 +288,8 @@ public ExclusivePublication trackEngine(final String aeronChannel, final int str final boolean isInbound = streamId == configuration.inboundLibraryStream(); final RecordingIds recordingIds = isInbound ? inboundRecordingIds : outboundRecordingIds; final RecordingIdLookup lookup = isInbound ? framerOutboundLookup : framerInboundLookup; - final LibraryExtendPosition libraryExtendPosition = acquireRecording(streamId, recordingIds); + final LibraryExtendPosition libraryExtendPosition = + acquireRecording(streamId, recordingIds, ENGINE_LIBRARY_ID); final ExclusivePublication publication; if (libraryExtendPosition != null) { @@ -389,16 +390,13 @@ private void extendRecording( } private LibraryExtendPosition acquireRecording( - final int streamId, final RecordingIds recordingIds) + final int streamId, final RecordingIds recordingIds, final int libraryId) { libraryExtendPosition = null; - final Long2LongHashMap.ValueIterator it = recordingIds.free.values().iterator(); - if (it.hasNext()) + final long recordingId = recordingIds.acquire(libraryId); + if (recordingId != NULL_RECORDING_ID) { - final long recordingId = it.nextValue(); - it.remove(); - final int count = archive.listRecording(recordingId, this); if (count != 1 || null == libraryExtendPosition) { @@ -460,7 +458,7 @@ public LibraryExtendPosition trackLibrary(final int sessionId, final int library } } - extendPosition = acquireRecording(streamId, outboundRecordingIds); + extendPosition = acquireRecording(streamId, outboundRecordingIds, libraryId); if (extendPosition != null) { extendRecording(streamId, extendPosition, extendPosition.newSessionId); @@ -763,6 +761,23 @@ private void forEach(final Long2LongHashMap map, final LibraryAndRecordingIdCons } } + long acquire(final int libraryId) + { + long recordingId = free.remove(libraryId); + + if (recordingId == NULL_RECORDING_ID) + { + final Long2LongHashMap.ValueIterator it = free.values().iterator(); + if (it.hasNext()) + { + recordingId = it.nextValue(); + it.remove(); + } + } + + return recordingId; + } + public String toString() { return "RecordingIds{" +