Skip to content

Commit

Permalink
make the engine reuse its outbound recording consistently
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wojciech-adaptive committed Mar 14, 2024
1 parent 4d5f3d6 commit c254de8
Showing 1 changed file with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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{" +
Expand Down

0 comments on commit c254de8

Please sign in to comment.