Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ private void testArchiveLogging(final String enabledEvents, final EnumSet<Archiv
.archiveDir(new File(testDir, "archive"))
.deleteArchiveOnStart(true)
.recordingEventsEnabled(false)
.replicationChannel("aeron:udp?endpoint=localhost:0")
.controlChannel(aeronArchiveContext.controlRequestChannel())
.controlStreamId(aeronArchiveContext.controlRequestStreamId())
.localControlStreamId(aeronArchiveContext.controlRequestStreamId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.aeron.driver.ThreadingMode;
import io.aeron.test.InterruptAfter;
import io.aeron.test.InterruptingTestCallback;
import io.aeron.test.TestContexts;
import io.aeron.test.Tests;
import io.aeron.test.cluster.ClusterTests;
import org.agrona.CloseHelper;
Expand Down Expand Up @@ -120,7 +121,7 @@ private void testClusterEventsLogging(
.controlResponseStreamId(AeronArchive.Configuration.localControlStreamId() + 1)
.controlResponseStreamId(101);

final Archive.Context archiveCtx = new Archive.Context()
final Archive.Context archiveCtx = TestContexts.localhostArchive()
.errorHandler(Tests::onError)
.archiveDir(new File(testDir, "archive"))
.deleteArchiveOnStart(true)
Expand Down
60 changes: 46 additions & 14 deletions aeron-archive/src/main/java/io/aeron/archive/Archive.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.function.Supplier;

import static io.aeron.CommonContext.ENDPOINT_PARAM_NAME;
import static io.aeron.archive.ArchiveThreadingMode.DEDICATED;
import static io.aeron.logbuffer.LogBufferDescriptor.TERM_MAX_LENGTH;
import static io.aeron.logbuffer.LogBufferDescriptor.TERM_MIN_LENGTH;
Expand Down Expand Up @@ -430,13 +431,6 @@ public static final class Configuration
*/
public static final String REPLICATION_CHANNEL_PROP_NAME = "aeron.archive.replication.channel";

/**
* Channel for receiving replication streams replayed from another archive.
*
* @see #REPLICATION_CHANNEL_PROP_NAME
*/
public static final String REPLICATION_CHANNEL_DEFAULT = "aeron:udp?endpoint=localhost:0";

/**
* Name of the system property for specifying a supplier of {@link Authenticator} for the archive.
*/
Expand Down Expand Up @@ -737,15 +731,13 @@ public static boolean deleteArchiveOnStart()
}

/**
* The value {@link #REPLICATION_CHANNEL_DEFAULT} or system property
* {@link #REPLICATION_CHANNEL_PROP_NAME} if set.
* The system property {@link #REPLICATION_CHANNEL_PROP_NAME} if set, null otherwise.
*
* @return {@link #REPLICATION_CHANNEL_DEFAULT} or system property
* {@link #REPLICATION_CHANNEL_PROP_NAME} if set.
* @return system property {@link #REPLICATION_CHANNEL_PROP_NAME} if set.
*/
public static String replicationChannel()
{
return System.getProperty(REPLICATION_CHANNEL_PROP_NAME, REPLICATION_CHANNEL_DEFAULT);
return System.getProperty(REPLICATION_CHANNEL_PROP_NAME);
}

/**
Expand Down Expand Up @@ -960,16 +952,34 @@ public void conclude()
throw new ConfigurationException("invalid fileIoMaxLength=" + fileIoMaxLength);
}

if (null == controlChannel)
{
throw new ConfigurationException("Archive.Context.controlChannel must be set");
}

if (!controlChannel.startsWith(CommonContext.UDP_CHANNEL))
{
throw new ConfigurationException("remote control channel must be UDP media: uri=" + controlChannel);
throw new ConfigurationException(
"Archive.Context.controlChannel must be UDP media: uri=" + controlChannel);
}

if (!localControlChannel.startsWith(CommonContext.IPC_CHANNEL))
{
throw new ConfigurationException("local control channel must be IPC media: uri=" + localControlChannel);
}

if (null == replicationChannel)
{
throw new ConfigurationException("Archive.Context.replicationChannel must be set");
}

if (recordingEventsEnabled() && null == recordingEventsChannel())
{
throw new ConfigurationException(
"Archive.Context.recordingEventsChannel must be set if " +
"Archive.Context.recordingEventsEnabled is true");
}

if (null == archiveDir)
{
archiveDir = new File(archiveDirectoryName);
Expand Down Expand Up @@ -1183,6 +1193,28 @@ else if (segmentFileLength < TERM_MIN_LENGTH || segmentFileLength > TERM_MAX_LEN
archiveClientContext = new AeronArchive.Context();
}

if (null == archiveClientContext.controlResponseChannel())
{
final ChannelUri controlChannelUri = ChannelUri.parse(controlChannel);
final String endpoint = controlChannelUri.get(ENDPOINT_PARAM_NAME);
int separatorIndex = -1;
if (null == endpoint || -1 == (separatorIndex = endpoint.lastIndexOf(':')))
{
throw new ConfigurationException(
"Unable to derive Archive.Context.archiveClientContext.controlResponseChannel as " +
"Archive.Context.controlChannel.endpoint=" + endpoint +
" and is not in the <host>:<port> format");

}
final String responseEndpoint = endpoint.substring(0, separatorIndex) + ":0";
final String responseChannel = new ChannelUriStringBuilder()
.media("udp")
.endpoint(responseEndpoint)
.build();

archiveClientContext.controlResponseChannel(responseChannel);
}

archiveClientContext.aeron(aeron).lock(NoOpLock.INSTANCE).errorHandler(errorHandler);

if (null == controlSessionsCounter)
Expand Down Expand Up @@ -1493,7 +1525,7 @@ public Context localControlStreamId(final int controlStreamId)
}

/**
* Get the channel URI on which the recording events publication will publish.
* Get the channel URI on which the recording events publication will publish. Will be null if not configured.
*
* @return the channel URI on which the recording events publication will publish.
* @see io.aeron.archive.client.AeronArchive.Configuration#RECORDING_EVENTS_CHANNEL_PROP_NAME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ private static int alignedTotalFileLength(final Archive.Context ctx)
(4 * VarAsciiEncodingEncoder.lengthEncodingLength()) +
ctx.controlChannel().length() +
ctx.localControlChannel().length() +
ctx.recordingEventsChannel().length() +
(null != ctx.recordingEventsChannel() ? ctx.recordingEventsChannel().length() : 0) +
ctx.aeronDirectoryName().length();

if (headerLength > HEADER_LENGTH)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
package io.aeron.archive.client;

import io.aeron.*;
import io.aeron.archive.codecs.*;
import io.aeron.archive.codecs.ControlResponseCode;
import io.aeron.archive.codecs.RecordingSignal;
import io.aeron.archive.codecs.RecordingSignalEventDecoder;
import io.aeron.archive.codecs.SourceLocation;
import io.aeron.exceptions.AeronException;
import io.aeron.exceptions.ConcurrentConcludeException;
import io.aeron.exceptions.ConfigurationException;
import io.aeron.exceptions.TimeoutException;
import io.aeron.security.CredentialsSupplier;
import io.aeron.security.NullCredentialsSupplier;
Expand Down Expand Up @@ -2529,11 +2533,6 @@ public static final class Configuration
*/
public static final String CONTROL_CHANNEL_PROP_NAME = "aeron.archive.control.channel";

/**
* Channel for sending control messages to an archive.
*/
public static final String CONTROL_CHANNEL_DEFAULT = "aeron:udp?endpoint=localhost:8010";

/**
* Stream id within a channel for sending control messages to an archive.
*/
Expand Down Expand Up @@ -2581,11 +2580,6 @@ public static final class Configuration
*/
public static final String CONTROL_RESPONSE_CHANNEL_PROP_NAME = "aeron.archive.control.response.channel";

/**
* Default channel for receiving control response messages from an archive.
*/
public static final String CONTROL_RESPONSE_CHANNEL_DEFAULT = "aeron:udp?endpoint=localhost:0";

/**
* Stream id within a channel for receiving control messages from an archive.
*/
Expand Down Expand Up @@ -2627,7 +2621,7 @@ public static final class Configuration
/**
* Channel enabled for recording progress events of recordings from an archive which defaults to true.
*/
public static final boolean RECORDING_EVENTS_ENABLED_DEFAULT = true;
public static final boolean RECORDING_EVENTS_ENABLED_DEFAULT = false;

/**
* Sparse term buffer indicator for control streams.
Expand Down Expand Up @@ -2712,15 +2706,13 @@ public static int controlMtuLength()
}

/**
* The value {@link #CONTROL_CHANNEL_DEFAULT} or system property
* {@link #CONTROL_CHANNEL_PROP_NAME} if set.
* The value of system property {@link #CONTROL_CHANNEL_PROP_NAME} if set, null otherwise
*
* @return {@link #CONTROL_CHANNEL_DEFAULT} or system property
* {@link #CONTROL_CHANNEL_PROP_NAME} if set.
* @return system property {@link #CONTROL_CHANNEL_PROP_NAME} if set.
*/
public static String controlChannel()
{
return System.getProperty(CONTROL_CHANNEL_PROP_NAME, CONTROL_CHANNEL_DEFAULT);
return System.getProperty(CONTROL_CHANNEL_PROP_NAME);
}

/**
Expand Down Expand Up @@ -2760,15 +2752,13 @@ public static int localControlStreamId()
}

/**
* The value {@link #CONTROL_RESPONSE_CHANNEL_DEFAULT} or system property
* {@link #CONTROL_RESPONSE_CHANNEL_PROP_NAME} if set.
* The value of system property {@link #CONTROL_RESPONSE_CHANNEL_PROP_NAME} if set, null otherwise.
*
* @return {@link #CONTROL_RESPONSE_CHANNEL_DEFAULT} or system property
* {@link #CONTROL_RESPONSE_CHANNEL_PROP_NAME} if set.
* @return of system property {@link #CONTROL_RESPONSE_CHANNEL_PROP_NAME} if set.
*/
public static String controlResponseChannel()
{
return System.getProperty(CONTROL_RESPONSE_CHANNEL_PROP_NAME, CONTROL_RESPONSE_CHANNEL_DEFAULT);
return System.getProperty(CONTROL_RESPONSE_CHANNEL_PROP_NAME);
}

/**
Expand All @@ -2784,15 +2774,13 @@ public static int controlResponseStreamId()
}

/**
* The value {@link #RECORDING_EVENTS_CHANNEL_DEFAULT} or system property
* {@link #RECORDING_EVENTS_CHANNEL_PROP_NAME} if set.
* The value of system property {@link #RECORDING_EVENTS_CHANNEL_PROP_NAME} if set, null otherwise.
*
* @return {@link #RECORDING_EVENTS_CHANNEL_DEFAULT} or system property
* {@link #RECORDING_EVENTS_CHANNEL_PROP_NAME} if set.
* @return system property {@link #RECORDING_EVENTS_CHANNEL_PROP_NAME} if set.
*/
public static String recordingEventsChannel()
{
return System.getProperty(RECORDING_EVENTS_CHANNEL_PROP_NAME, RECORDING_EVENTS_CHANNEL_DEFAULT);
return System.getProperty(RECORDING_EVENTS_CHANNEL_PROP_NAME);
}

/**
Expand All @@ -2816,7 +2804,7 @@ public static int recordingEventsStreamId()
public static boolean recordingEventsEnabled()
{
final String propValue = System.getProperty(RECORDING_EVENTS_ENABLED_PROP_NAME);
return null != propValue ? "true".equals(propValue) : RECORDING_EVENTS_ENABLED_DEFAULT;
return null != propValue ? Boolean.parseBoolean(propValue) : RECORDING_EVENTS_ENABLED_DEFAULT;
}
}

Expand Down Expand Up @@ -2882,6 +2870,16 @@ public void conclude()
throw new ConcurrentConcludeException();
}

if (null == controlRequestChannel)
{
throw new ConfigurationException("AeronArchive.Context.controlRequestChannel must be set");
}

if (null == controlResponseChannel)
{
throw new ConfigurationException("AeronArchive.Context.controlResponseChannel must be set");
}

if (null == aeron)
{
aeron = Aeron.connect(
Expand Down
4 changes: 4 additions & 0 deletions aeron-archive/src/test/cpp/AeronArchiveTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ class AeronArchiveTestBase
"-Daeron.archive.recording.events.enabled=false",
"-Daeron.driver.termination.validator=io.aeron.driver.DefaultAllowTerminationValidator",
"-Daeron.archive.authenticator.supplier=io.aeron.samples.archive.SampleAuthenticatorSupplier",
"-Daeron.archive.authenticator.supplier=io.aeron.samples.archive.SampleAuthenticatorSupplier",
"-Daeron.archive.control.channel=aeron:udp?endpoint=localhost:8010",
"-Daeron.archive.replication.channel=aeron:udp?endpoint=localhost:0",
"-Daeron.archive.control.response.channel=aeron:udp?endpoint=localhost:0",
archiveDirArg.c_str(),
aeronDirArg.c_str(),
"-cp",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

import io.aeron.Aeron;
import io.aeron.RethrowingErrorHandler;
import io.aeron.exceptions.ConfigurationException;
import io.aeron.security.AuthorisationService;
import io.aeron.security.AuthorisationServiceSupplier;
import io.aeron.test.TestContexts;
import org.agrona.concurrent.status.AtomicCounter;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -33,9 +35,9 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class ArchiveContextTests
class ArchiveContextTest
{
private final Archive.Context context = new Archive.Context();
private final Archive.Context context = TestContexts.localhostArchive();

@BeforeEach
void beforeEach(final @TempDir Path tempDir)
Expand Down Expand Up @@ -128,6 +130,35 @@ void shouldUseProvidedAuthorisationServiceSupplierInstance()
}
}

@Test
void shouldThrowIfReplicationChannelIsNotSet()
{
context.replicationChannel(null);
assertThrows(ConfigurationException.class, context::conclude);
}

@Test
void shouldDeriveArchiveClientContextResponseChannelFromArchiveControlChannel()
{
context.controlChannel("aeron:udp?endpoint=127.0.0.2:23005");
context.conclude();
assertEquals("aeron:udp?endpoint=127.0.0.2:0", context.archiveClientContext().controlResponseChannel());
}

@Test
void shouldThrowConfigurationExceptionIfUnableToDeriveArchiveClientContextResponseChannelDueToEndpointFormat()
{
context.controlChannel("aeron:udp?endpoint=some_logical_name");
assertThrows(ConfigurationException.class, context::conclude);
}

@Test
void shouldThrowConfigurationExceptionIfUnableToDeriveArchiveClientContextResponseChannelDueToEndpointNull()
{
context.controlChannel("aeron:udp?control-mode=dynamic|control=192.168.0.1:12345");
assertThrows(ConfigurationException.class, context::conclude);
}

public static class TestAuthorisationSupplier implements AuthorisationServiceSupplier
{
public AuthorisationService get()
Expand Down
Loading