diff --git a/aeron-archive/src/main/java/io/aeron/archive/Archive.java b/aeron-archive/src/main/java/io/aeron/archive/Archive.java index d4bd7d6f93..ccf97dfcbf 100644 --- a/aeron-archive/src/main/java/io/aeron/archive/Archive.java +++ b/aeron-archive/src/main/java/io/aeron/archive/Archive.java @@ -3717,6 +3717,7 @@ private void concludeArchiveId() if (NULL_VALUE == archiveId) { archiveId = aeron.clientId(); + markFile.encoder().archiveId(archiveId); } } diff --git a/aeron-archive/src/test/java/io/aeron/archive/ArchiveTest.java b/aeron-archive/src/test/java/io/aeron/archive/ArchiveTest.java index bdbe5333ad..3562fc48c6 100644 --- a/aeron-archive/src/test/java/io/aeron/archive/ArchiveTest.java +++ b/aeron-archive/src/test/java/io/aeron/archive/ArchiveTest.java @@ -962,6 +962,31 @@ void shouldTimeoutInactiveArchiveClients(final String controlRequestChannel, fin } } + @Test + void archiveMarkFileShouldContainArchiveIdSetOnContextConclude() + { + final MediaDriver.Context driverCtx = new MediaDriver.Context() + .errorHandler(Tests::onError) + .dirDeleteOnStart(true) + .threadingMode(ThreadingMode.SHARED); + final Archive.Context archiveCtx = TestContexts.localhostArchive().threadingMode(SHARED); + + assertEquals(Aeron.NULL_VALUE, archiveCtx.archiveId()); // <-- Should not have been set yet. + try (ArchivingMediaDriver ignored = ArchivingMediaDriver.launch(driverCtx, archiveCtx); + AeronArchive archiveClient = AeronArchive.connect(TestContexts.localhostAeronArchive())) + { + final long archiveId = archiveCtx.archiveId(); // <-- Should have been set now as the context is concluded. + assertNotEquals(Aeron.NULL_VALUE, archiveId); + assertEquals(archiveId, archiveClient.archiveId()); + assertEquals(archiveId, archiveCtx.archiveMarkFile().archiveId()); + } + finally + { + archiveCtx.deleteDirectory(); + driverCtx.deleteDirectory(); + } + } + private static Catalog openCatalog(final String archiveDirectoryName) { final IntConsumer intConsumer = (version) ->