Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from real-logic:master #2209

Merged
merged 3 commits into from
Dec 13, 2024
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
30 changes: 15 additions & 15 deletions aeron-client/src/main/java/io/aeron/ChannelUriStringBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,35 +51,35 @@ public final class ChannelUriStringBuilder
private String alias;
private String cc;
private String fc;
private String mediaReceiveTimestampOffset;
private String channelReceiveTimestampOffset;
private String channelSendTimestampOffset;
private String responseEndpoint;
private Boolean reliable;
private Integer ttl;
private Integer mtu;
private Integer termLength;
private Integer initialTermId;
private Integer termId;
private Integer termOffset;
private Long sessionId;
private Long groupTag;
private Long linger;
private Boolean sparse;
private Boolean eos;
private Boolean tether;
private Boolean group;
private Boolean rejoin;
private Boolean ssc;
private boolean isSessionIdTagged;
private Integer ttl;
private Integer mtu;
private Integer termLength;
private Integer initialTermId;
private Integer termId;
private Integer termOffset;
private Integer socketSndbufLength;
private Integer socketRcvbufLength;
private Integer receiverWindowLength;
private String mediaReceiveTimestampOffset;
private String channelReceiveTimestampOffset;
private String channelSendTimestampOffset;
private String responseEndpoint;
private Integer maxResend;
private Long sessionId;
private Long groupTag;
private Long linger;
private Long responseCorrelationId;
private Long nakDelay;
private Long untetheredWindowLimitTimeoutNs;
private Long untetheredRestingTimeoutNs;
private Integer maxResend;
private boolean isSessionIdTagged;

/**
* Default constructor.
Expand Down
14 changes: 14 additions & 0 deletions aeron-client/src/main/java/io/aeron/CommonContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,20 @@ public static InferableBoolean parse(final String value)
*/
public static final String MAX_RESEND_PARAM_NAME = "max-resend";

/**
* Parameter name to set the stream id for the channel.
*
* @since 1.47.0
*/
public static final String STREAM_ID_PARAM_NAME = "stream-id";

/**
* Parameter name for the publication window length, i.e. how far ahead can publication accept offers.
*
* @since 1.47.0
*/
public static final String PUBLICATION_WINDOW_LENGTH_PARAM_NAME = "pub-wnd";

/**
* Property name to use to set the secure random algorithm to be used by the Aeron component.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ public ControlProtocolException(final ErrorCode code, final Exception rootCause)
this.code = code;
}

/**
* Construct an exception to indicate an invalid command has been sent to the media driver.
*
* @param code for the type of error.
* @param msg providing more detail.
* @param rootCause of the error.
*/
public ControlProtocolException(final ErrorCode code, final String msg, final Exception rootCause)
{
super(msg, rootCause);
this.code = code;
}

/**
* The {@link ErrorCode} indicating more specific issue experienced by the media driver.
*
Expand Down
113 changes: 50 additions & 63 deletions aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,11 @@ void onAddNetworkPublication(
{
final UdpChannel udpChannel = asyncResult.get();
final ChannelUri channelUri = udpChannel.channelUri();
final PublicationParams params = getPublicationParams(channelUri, ctx, this, false);
final PublicationParams params =
getPublicationParams(channelUri, ctx, this, streamId, udpChannel.canonicalForm());
validateExperimentalFeatures(ctx.enableExperimentalFeatures(), udpChannel);
validateEndpointForPublication(udpChannel);
validateControlForPublication(udpChannel);
validateMtuForMaxMessage(params, channel);
validateResponseSubscription(params);

final SendChannelEndpoint channelEndpoint =
Expand All @@ -550,14 +550,9 @@ void onAddNetworkPublication(
boolean isNewPublication = false;
if (null == publication)
{
if (params.hasSessionId)
{
checkForSessionClash(params.sessionId, streamId, udpChannel.canonicalForm(), channel);
}

checkForSessionClash(params.sessionId, streamId, udpChannel.canonicalForm(), channel);
publication = newNetworkPublication(
correlationId, clientId, streamId, channel, udpChannel, channelEndpoint, params, isExclusive);

isNewPublication = true;
}
else
Expand Down Expand Up @@ -877,7 +872,7 @@ void onAddIpcPublication(
{
IpcPublication publication = null;
final ChannelUri channelUri = parseUri(channel);
final PublicationParams params = getPublicationParams(channelUri, ctx, this, true);
final PublicationParams params = getPublicationParams(channelUri, ctx, this, streamId, IPC_MEDIA);

if (!isExclusive)
{
Expand All @@ -887,12 +882,7 @@ void onAddIpcPublication(
boolean isNewPublication = false;
if (null == publication)
{
if (params.hasSessionId)
{
checkForSessionClash(params.sessionId, streamId, IPC_MEDIA, channel);
}

validateMtuForMaxMessage(params, channel);
checkForSessionClash(params.sessionId, streamId, IPC_MEDIA, channel);
publication = addIpcPublication(correlationId, clientId, streamId, channel, isExclusive, params);
isNewPublication = true;
}
Expand Down Expand Up @@ -1517,6 +1507,29 @@ void onRejectImage(
clientProxy.operationSucceeded(correlationId);
}

int nextAvailableSessionId(final int streamId, final String channel)
{
final SessionKey sessionKey = new SessionKey(streamId, channel);

while (true)
{
int sessionId = nextSessionId++;

if (ctx.publicationReservedSessionIdLow() <= sessionId &&
sessionId <= ctx.publicationReservedSessionIdHigh())
{
nextSessionId = ctx.publicationReservedSessionIdHigh() + 1;
sessionId = nextSessionId++;
}

sessionKey.sessionId = sessionId;
if (!activeSessionSet.contains(sessionKey))
{
return sessionId;
}
}
}

private void heartbeatAndCheckTimers(final long nowNs)
{
final long nowMs = cachedEpochClock.time();
Expand Down Expand Up @@ -1685,8 +1698,6 @@ private NetworkPublication newNetworkPublication(
final boolean isExclusive)
{
final String canonicalForm = udpChannel.canonicalForm();
final int sessionId = params.hasSessionId ? params.sessionId : nextAvailableSessionId(streamId, canonicalForm);
final int initialTermId = params.hasPosition ? params.initialTermId : BitUtil.generateRandomisedId();

final FlowControl flowControl = udpChannel.isMulticast() || udpChannel.isMultiDestination() ?
ctx.multicastFlowControlSupplier().newInstance(udpChannel, streamId, registrationId) :
Expand All @@ -1696,12 +1707,13 @@ private NetworkPublication newNetworkPublication(
countersManager,
udpChannel,
streamId,
sessionId,
params.sessionId,
registrationId,
initialTermId,
params.initialTermId,
params.termLength);

final RawLog rawLog = newNetworkPublicationLog(sessionId, streamId, initialTermId, registrationId, params);
final RawLog rawLog =
newNetworkPublicationLog(params.sessionId, streamId, params.initialTermId, registrationId, params);
UnsafeBufferPosition publisherPos = null;
UnsafeBufferPosition publisherLmt = null;
UnsafeBufferPosition senderPos = null;
Expand All @@ -1710,23 +1722,23 @@ private NetworkPublication newNetworkPublication(
try
{
publisherPos = PublisherPos.allocate(
tempBuffer, countersManager, registrationId, sessionId, streamId, channel);
tempBuffer, countersManager, registrationId, params.sessionId, streamId, channel);
publisherLmt = PublisherLimit.allocate(
tempBuffer, countersManager, registrationId, sessionId, streamId, channel);
tempBuffer, countersManager, registrationId, params.sessionId, streamId, channel);
senderPos = SenderPos.allocate(
tempBuffer, countersManager, registrationId, sessionId, streamId, channel);
tempBuffer, countersManager, registrationId, params.sessionId, streamId, channel);
senderLmt = SenderLimit.allocate(
tempBuffer, countersManager, registrationId, sessionId, streamId, channel);
tempBuffer, countersManager, registrationId, params.sessionId, streamId, channel);
senderBpe = SenderBpe.allocate(
tempBuffer, countersManager, registrationId, sessionId, streamId, channel);
tempBuffer, countersManager, registrationId, params.sessionId, streamId, channel);

countersManager.setCounterOwnerId(publisherLmt.id(), clientId);
final AtomicCounter retransmitOverflowCounter = ctx.systemCounters().get(RETRANSMIT_OVERFLOW);

if (params.hasPosition)
{
final int bits = LogBufferDescriptor.positionBitsToShift(params.termLength);
final long position = computePosition(params.termId, params.termOffset, bits, initialTermId);
final long position = computePosition(params.termId, params.termOffset, bits, params.initialTermId);
publisherPos.setOrdered(position);
publisherLmt.setOrdered(position);
senderPos.setOrdered(position);
Expand All @@ -1739,7 +1751,7 @@ private NetworkPublication newNetworkPublication(
ctx.retransmitUnicastDelayGenerator(),
ctx.retransmitUnicastLingerGenerator(),
udpChannel.hasGroupSemantics(),
params.hasMaxResend ? params.maxResend : ctx.maxResend(),
params.maxResend,
retransmitOverflowCounter);

final NetworkPublication publication = new NetworkPublication(
Expand All @@ -1748,15 +1760,15 @@ private NetworkPublication newNetworkPublication(
params,
channelEndpoint,
rawLog,
Configuration.producerWindowLength(params.termLength, ctx.publicationTermWindowLength()),
params.publicationWindowLength,
publisherPos,
publisherLmt,
senderPos,
senderLmt,
senderBpe,
sessionId,
params.sessionId,
streamId,
initialTermId,
params.initialTermId,
flowControl,
retransmitHandler,
networkPublicationThreadLocals,
Expand All @@ -1765,7 +1777,7 @@ private NetworkPublication newNetworkPublication(
channelEndpoint.incRef();
networkPublications.add(publication);
senderProxy.newNetworkPublication(publication);
activeSessionSet.add(new SessionKey(sessionId, streamId, canonicalForm));
activeSessionSet.add(new SessionKey(params.sessionId, streamId, canonicalForm));

return publication;
}
Expand Down Expand Up @@ -2249,26 +2261,25 @@ private IpcPublication addIpcPublication(
final boolean isExclusive,
final PublicationParams params)
{
final int sessionId = params.hasSessionId ? params.sessionId : nextAvailableSessionId(streamId, IPC_MEDIA);
final int initialTermId = params.hasPosition ? params.initialTermId : BitUtil.generateRandomisedId();
final RawLog rawLog = newIpcPublicationLog(sessionId, streamId, initialTermId, registrationId, params);
final RawLog rawLog =
newIpcPublicationLog(params.sessionId, streamId, params.initialTermId, registrationId, params);

UnsafeBufferPosition publisherPosition = null;
UnsafeBufferPosition publisherLimit = null;
try
{
publisherPosition = PublisherPos.allocate(
tempBuffer, countersManager, registrationId, sessionId, streamId, channel);
tempBuffer, countersManager, registrationId, params.sessionId, streamId, channel);
publisherLimit = PublisherLimit.allocate(
tempBuffer, countersManager, registrationId, sessionId, streamId, channel);
tempBuffer, countersManager, registrationId, params.sessionId, streamId, channel);

countersManager.setCounterOwnerId(publisherLimit.id(), clientId);

if (params.hasPosition)
{
final int positionBitsToShift = positionBitsToShift(params.termLength);
final long position = computePosition(
params.termId, params.termOffset, positionBitsToShift, initialTermId);
params.termId, params.termOffset, positionBitsToShift, params.initialTermId);
publisherPosition.setOrdered(position);
publisherLimit.setOrdered(position);
}
Expand All @@ -2278,17 +2289,16 @@ private IpcPublication addIpcPublication(
channel,
ctx,
params.entityTag,
sessionId,
params.sessionId,
streamId,
publisherPosition,
publisherLimit,
rawLog,
Configuration.producerWindowLength(params.termLength, ctx.ipcPublicationTermWindowLength()),
isExclusive,
params);

ipcPublications.add(publication);
activeSessionSet.add(new SessionKey(sessionId, streamId, IPC_MEDIA));
activeSessionSet.add(new SessionKey(params.sessionId, streamId, IPC_MEDIA));

return publication;
}
Expand Down Expand Up @@ -2383,29 +2393,6 @@ private void checkForSessionClash(
}
}

private int nextAvailableSessionId(final int streamId, final String channel)
{
final SessionKey sessionKey = new SessionKey(streamId, channel);

while (true)
{
int sessionId = nextSessionId++;

if (ctx.publicationReservedSessionIdLow() <= sessionId &&
sessionId <= ctx.publicationReservedSessionIdHigh())
{
nextSessionId = ctx.publicationReservedSessionIdHigh() + 1;
sessionId = nextSessionId++;
}

sessionKey.sessionId = sessionId;
if (!activeSessionSet.contains(sessionKey))
{
return sessionId;
}
}
}

private <T extends DriverManagedResource> void checkManagedResources(
final ArrayList<T> list, final long nowNs, final long nowMs)
{
Expand Down
Loading
Loading