From a378c8fdb3ab70cc39e124f95a6e6c93e4331ac4 Mon Sep 17 00:00:00 2001 From: Peter Veentjer Date: Fri, 20 Dec 2024 07:18:02 +0200 Subject: [PATCH 01/24] Initial checking extra properties logbuffer metadata --- .../aeron/logbuffer/LogBufferDescriptor.java | 242 +++++++++++++++++- .../java/io/aeron/driver/DriverConductor.java | 155 ++++++++++- .../src/main/java/io/aeron/driver/Main.java | 198 ++++++++++++++ 3 files changed, 588 insertions(+), 7 deletions(-) create mode 100644 aeron-driver/src/main/java/io/aeron/driver/Main.java diff --git a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java index ca4b20cf9c..68da90c393 100644 --- a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java +++ b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java @@ -135,11 +135,34 @@ public class LogBufferDescriptor */ public static final int LOG_DEFAULT_FRAME_HEADER_OFFSET; + + /** * Maximum length of a frame header. */ public static final int LOG_DEFAULT_FRAME_HEADER_MAX_LENGTH = CACHE_LINE_LENGTH * 2; + + // todo: Add documentation + public static final int LOG_ACTIVE_TERM_ID_OFFSET; + public static final int LOG_TERM_OFFSET_OFFSET; + public static final int LOG_SENDER_MTU_LENGTH_OFFSET; + public static final int LOG_IS_SPARSE_OFFSET; + public static final int LOG_IS_TETHER_OFFSET; + public static final int LOG_IS_REJOIN_OFFSET; + public static final int LOG_IS_RELIABLE_OFFSET; + public static final int LOG_SOCKET_RCVBUF_LENGTH_OFFSET; + public static final int LOG_SOCKET_SNDBUF_LENGTH_OFFSET; + public static final int LOG_RECEIVER_WINDOW_LENGTH_OFFSET; + public static final int LOG_PUBLICATION_WINDOW_LENGTH_OFFSET; + public static final int LOG_GROUP_OFFSET; + public static final int LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET; + public static final int LOG_UNTETHERED_RESTING_TIMEOUT_NS_OFFSET; + public static final int LOG_MAX_RESEND_OFFSET; + public static final int LOG_LINGER_TIMEOUT_NS_OFFSET; + public static final int LOG_SIGNAL_EOS_OFFSET; + public static final int LOG_SPIES_SIMULATE_CONNECTION_OFFSET; + /** * Total length of the log metadata buffer in bytes. *
@@ -217,7 +240,68 @@ public class LogBufferDescriptor
         offset += CACHE_LINE_LENGTH;
         LOG_DEFAULT_FRAME_HEADER_OFFSET = offset;
 
-        LOG_META_DATA_LENGTH = align(offset + LOG_DEFAULT_FRAME_HEADER_MAX_LENGTH, PAGE_MIN_SIZE);
+        // the new fields will be added with 1 cacheline of padding after the frame header.
+        offset+= LOG_DEFAULT_FRAME_HEADER_MAX_LENGTH+CACHE_LINE_LENGTH;
+
+        LOG_ACTIVE_TERM_ID_OFFSET = offset;
+        offset += SIZE_OF_INT;
+
+        LOG_TERM_OFFSET_OFFSET = offset;
+        offset += SIZE_OF_INT;
+
+        LOG_SENDER_MTU_LENGTH_OFFSET = offset;
+        offset += SIZE_OF_INT;
+
+        LOG_IS_SPARSE_OFFSET = offset;
+        offset += SIZE_OF_INT;
+
+        LOG_IS_TETHER_OFFSET = offset;
+        offset += SIZE_OF_INT;
+
+        LOG_IS_REJOIN_OFFSET = offset;
+        offset += SIZE_OF_INT;
+
+        LOG_IS_RELIABLE_OFFSET = offset;
+        offset += SIZE_OF_INT;
+
+
+        LOG_SOCKET_RCVBUF_LENGTH_OFFSET = offset;
+        offset += SIZE_OF_INT;
+
+        LOG_SOCKET_SNDBUF_LENGTH_OFFSET = offset;
+        offset += SIZE_OF_INT;
+
+        LOG_RECEIVER_WINDOW_LENGTH_OFFSET = offset;
+        offset += SIZE_OF_INT;
+
+        LOG_PUBLICATION_WINDOW_LENGTH_OFFSET = offset;
+        offset += SIZE_OF_INT;
+
+        LOG_GROUP_OFFSET = offset;
+        offset += SIZE_OF_INT;
+
+        LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET = offset;
+        offset += SIZE_OF_LONG;
+
+        LOG_UNTETHERED_RESTING_TIMEOUT_NS_OFFSET = offset;
+        offset += SIZE_OF_LONG;
+
+        LOG_LINGER_TIMEOUT_NS_OFFSET = offset;
+        offset += SIZE_OF_LONG;
+
+        LOG_MAX_RESEND_OFFSET = offset;
+        offset += SIZE_OF_INT;
+
+        LOG_SIGNAL_EOS_OFFSET = offset;
+        offset += SIZE_OF_INT;
+
+        LOG_SPIES_SIMULATE_CONNECTION_OFFSET = offset;
+        offset += SIZE_OF_INT;
+
+
+        LOG_META_DATA_LENGTH = align(offset, PAGE_MIN_SIZE);
+        System.out.println("Offset:"+offset);
+        System.out.println("LOG_META_DATA_LENGTH:"+LOG_META_DATA_LENGTH);
     }
 
     /**
@@ -878,4 +962,160 @@ public static int computeAssembledFrameLength(final int length, final int maxPay
 
         return HEADER_LENGTH + (numMaxPayloads * maxPayloadSize) + remainingPayload;
     }
+
+    // Active Term ID
+    public static int activeTermId(final UnsafeBuffer metadataBuffer) {
+        return metadataBuffer.getInt(LOG_ACTIVE_TERM_ID_OFFSET);
+    }
+
+    public static void activeTermId(final UnsafeBuffer metadataBuffer, final int value) {
+        metadataBuffer.putInt(LOG_ACTIVE_TERM_ID_OFFSET, value);
+    }
+
+    // Term Offset
+    public static int termOffset(final UnsafeBuffer metadataBuffer) {
+        return metadataBuffer.getInt(LOG_TERM_OFFSET_OFFSET);
+    }
+
+    public static void termOffset(final UnsafeBuffer metadataBuffer, final int value) {
+        metadataBuffer.putInt(LOG_TERM_OFFSET_OFFSET, value);
+    }
+
+    // Sender MTU Length
+    public static int senderMtuLength(final UnsafeBuffer metadataBuffer) {
+        return metadataBuffer.getInt(LOG_SENDER_MTU_LENGTH_OFFSET);
+    }
+
+    public static void senderMtuLength(final UnsafeBuffer metadataBuffer, final int value) {
+        metadataBuffer.putInt(LOG_SENDER_MTU_LENGTH_OFFSET, value);
+    }
+
+    // Is Sparse
+    public static boolean isSparse(final UnsafeBuffer metadataBuffer) {
+        return metadataBuffer.getInt(LOG_IS_SPARSE_OFFSET) == 1;
+    }
+
+    public static void isSparse(final UnsafeBuffer metadataBuffer, final boolean value) {
+        metadataBuffer.putInt(LOG_IS_SPARSE_OFFSET, value ? 1 : 0);
+    }
+
+    // Is Tether
+    public static boolean isTether(final UnsafeBuffer metadataBuffer) {
+        return metadataBuffer.getInt(LOG_IS_TETHER_OFFSET) == 1;
+    }
+
+    public static void isTether(final UnsafeBuffer metadataBuffer, final boolean value) {
+        metadataBuffer.putInt(LOG_IS_TETHER_OFFSET, value ? 1 : 0);
+    }
+
+    // Is Rejoin
+    public static boolean isRejoin(final UnsafeBuffer metadataBuffer) {
+        return metadataBuffer.getInt(LOG_IS_REJOIN_OFFSET) == 1;
+    }
+
+    public static void isRejoin(final UnsafeBuffer metadataBuffer, final boolean value) {
+        metadataBuffer.putInt(LOG_IS_REJOIN_OFFSET, value ? 1 : 0);
+    }
+
+    // Is Reliable
+    public static boolean isReliable(final UnsafeBuffer metadataBuffer) {
+        return metadataBuffer.getInt(LOG_IS_RELIABLE_OFFSET) == 1;
+    }
+
+    public static void isReliable(final UnsafeBuffer metadataBuffer, final boolean value) {
+        metadataBuffer.putInt(LOG_IS_RELIABLE_OFFSET, value ? 1 : 0);
+    }
+
+    // Socket Rcvbuf Length
+    public static int socketRcvbufLength(final UnsafeBuffer metadataBuffer) {
+        return metadataBuffer.getInt(LOG_SOCKET_RCVBUF_LENGTH_OFFSET);
+    }
+
+    public static void socketRcvbufLength(final UnsafeBuffer metadataBuffer, final int value) {
+        metadataBuffer.putInt(LOG_SOCKET_RCVBUF_LENGTH_OFFSET, value);
+    }
+
+    // Socket Sndbuf Length
+    public static int socketSndbufLength(final UnsafeBuffer metadataBuffer) {
+        return metadataBuffer.getInt(LOG_SOCKET_SNDBUF_LENGTH_OFFSET);
+    }
+
+    public static void socketSndbufLength(final UnsafeBuffer metadataBuffer, final int value) {
+        metadataBuffer.putInt(LOG_SOCKET_SNDBUF_LENGTH_OFFSET, value);
+    }
+
+    // Receiver Window Length
+    public static int receiverWindowLength(final UnsafeBuffer metadataBuffer) {
+        return metadataBuffer.getInt(LOG_RECEIVER_WINDOW_LENGTH_OFFSET);
+    }
+
+    public static void receiverWindowLength(final UnsafeBuffer metadataBuffer, final int value) {
+        metadataBuffer.putInt(LOG_RECEIVER_WINDOW_LENGTH_OFFSET, value);
+    }
+
+    public static int publicationWindowLength(final UnsafeBuffer metadataBuffer) {
+        return metadataBuffer.getInt(LOG_PUBLICATION_WINDOW_LENGTH_OFFSET);
+    }
+
+    public static void publicationWindowLength(final UnsafeBuffer metadataBuffer, final int value) {
+        metadataBuffer.putInt(LOG_PUBLICATION_WINDOW_LENGTH_OFFSET, value);
+    }
+
+    public static long untetheredWindowLimitTimeoutNs(final UnsafeBuffer metadataBuffer) {
+        return metadataBuffer.getLong(LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET);
+    }
+
+    public static void untetheredWindowLimitTimeoutNs(final UnsafeBuffer metadataBuffer, final long value) {
+        metadataBuffer.putLong(LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET, value);
+    }
+
+    // Untethered Resting Timeout (in nanoseconds)
+    public static long untetheredRestingTimeoutNs(final UnsafeBuffer metadataBuffer) {
+        return metadataBuffer.getLong(LOG_UNTETHERED_RESTING_TIMEOUT_NS_OFFSET);
+    }
+
+    public static void untetheredRestingTimeoutNs(final UnsafeBuffer metadataBuffer, final long value) {
+        metadataBuffer.putLong(LOG_UNTETHERED_RESTING_TIMEOUT_NS_OFFSET, value);
+    }
+
+    // Group
+    public static boolean group(final UnsafeBuffer metadataBuffer) {
+        return metadataBuffer.getInt(LOG_GROUP_OFFSET) == 1;
+    }
+
+    public static void group(final UnsafeBuffer metadataBuffer, final boolean value) {
+        metadataBuffer.putInt(LOG_GROUP_OFFSET, value ? 1 : 0);
+    }
+
+    public static int maxResend(final UnsafeBuffer metadataBuffer) {
+        return metadataBuffer.getInt(LOG_MAX_RESEND_OFFSET);
+    }
+
+    public static void maxResend(final UnsafeBuffer metadataBuffer, final int value) {
+        metadataBuffer.putInt(LOG_MAX_RESEND_OFFSET, value);
+    }
+
+    public static long lingerTimeoutNs(final UnsafeBuffer metadataBuffer) {
+        return metadataBuffer.getLong(LOG_LINGER_TIMEOUT_NS_OFFSET);
+    }
+
+    public static void lingerTimeoutNs(final UnsafeBuffer metadataBuffer, final long value) {
+        metadataBuffer.putLong(LOG_LINGER_TIMEOUT_NS_OFFSET, value);
+    }
+
+    public static boolean signalEos(final UnsafeBuffer metadataBuffer) {
+        return metadataBuffer.getInt(LOG_SIGNAL_EOS_OFFSET) == 1;
+    }
+
+    public static void signalEos(final UnsafeBuffer metadataBuffer, final boolean value) {
+        metadataBuffer.putInt(LOG_SIGNAL_EOS_OFFSET,value ? 1 : 0);
+    }
+
+    public static boolean spiesSimulateConnection(final UnsafeBuffer metadataBuffer) {
+        return metadataBuffer.getInt(LOG_SPIES_SIMULATE_CONNECTION_OFFSET) == 1;
+    }
+
+    public static void spiesSimulateConnection(final UnsafeBuffer metadataBuffer, final boolean value) {
+        metadataBuffer.putInt(LOG_SPIES_SIMULATE_CONNECTION_OFFSET, value ? 1 : 0);
+    }
 }
diff --git a/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java b/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java
index 8b0e8b7e3b..adb06a4cc5 100644
--- a/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java
+++ b/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java
@@ -309,6 +309,13 @@ void onCreatePublicationImage(
                     termBufferLength,
                     isOldestSubscriptionSparse(subscriberPositions),
                     senderMtuLength,
+                    subscriptionChannel.socketRcvbufLength(),
+                    subscriptionChannel.socketSndbufLength(),
+                    termOffset,
+                    subscriptionParams.receiverWindowLength,
+                    subscriptionParams.isTether,
+                    subscriptionParams.isRejoin,
+                    subscriptionParams.isReliable,
                     registrationId);
 
                 congestionControl = ctx.congestionControlSupplier().newInstance(
@@ -1724,8 +1731,10 @@ private NetworkPublication newNetworkPublication(
             params.initialTermId,
             params.termLength);
 
-        final RawLog rawLog =
-            newNetworkPublicationLog(params.sessionId, streamId, params.initialTermId, registrationId, params);
+        // todo:
+        final int termOffset = 0;
+        final RawLog rawLog = newNetworkPublicationLog(params.sessionId, streamId, params.initialTermId, registrationId,
+            udpChannel.socketRcvbufLength(), udpChannel.socketSndbufLength(), termOffset, params);
         UnsafeBufferPosition publisherPos = null;
         UnsafeBufferPosition publisherLmt = null;
         UnsafeBufferPosition senderPos = null;
@@ -1805,10 +1814,38 @@ private RawLog newNetworkPublicationLog(
         final int streamId,
         final int initialTermId,
         final long registrationId,
+        final int socketRcvBufLength,
+        final int socketSndBufLength,
+        final int termOffset,
         final PublicationParams params)
     {
         final RawLog rawLog = logFactory.newPublication(registrationId, params.termLength, params.isSparse);
-        initLogMetadata(sessionId, streamId, initialTermId, params.mtuLength, registrationId, rawLog);
+        final int receiverWindowLength = 0;
+        final boolean tether = false;
+        final boolean rejoin = false;
+        final boolean reliable = false;
+        initLogMetadata(
+            sessionId,
+            streamId,
+            initialTermId,
+            params.mtuLength,
+            registrationId,
+            socketRcvBufLength,
+            socketSndBufLength,
+            termOffset,
+            receiverWindowLength,
+            tether,
+            rejoin,
+            reliable,
+            params.isSparse,
+            params.publicationWindowLength,
+            params.untetheredWindowLimitTimeoutNs,
+            params.untetheredRestingTimeoutNs,
+            params.maxResend,
+            params.lingerTimeoutNs,
+            params.signalEos,
+            params.spiesSimulateConnection,
+            rawLog);
         initialisePositionCounters(initialTermId, params, rawLog.metaData());
 
         return rawLog;
@@ -1819,10 +1856,38 @@ private RawLog newIpcPublicationLog(
         final int streamId,
         final int initialTermId,
         final long registrationId,
+        final int termOffset,
         final PublicationParams params)
     {
         final RawLog rawLog = logFactory.newPublication(registrationId, params.termLength, params.isSparse);
-        initLogMetadata(sessionId, streamId, initialTermId, params.mtuLength, registrationId, rawLog);
+        final int socketRcvBufLength = 0;
+        final int socketSndBufLength = 0;
+        final int receiverWindowLength = 0;
+        final boolean tether = false;
+        final boolean rejoin = false;
+        final boolean reliable = false;
+        initLogMetadata(
+            sessionId,
+            streamId,
+            initialTermId,
+            params.mtuLength,
+            registrationId,
+            socketRcvBufLength,
+            socketSndBufLength,
+            termOffset,
+            receiverWindowLength,
+            tether,
+            rejoin,
+            reliable,
+            params.isSparse,
+            params.publicationWindowLength,
+            params.untetheredWindowLimitTimeoutNs,
+            params.untetheredRestingTimeoutNs,
+            params.maxResend,
+            params.lingerTimeoutNs,
+            params.signalEos,
+            params.spiesSimulateConnection,
+            rawLog);
         initialisePositionCounters(initialTermId, params, rawLog.metaData());
 
         return rawLog;
@@ -1834,8 +1899,25 @@ private void initLogMetadata(
         final int initialTermId,
         final int mtuLength,
         final long registrationId,
+        final int socketRcvBufLength,
+        final int socketSndbufLength,
+        final int termOffset,
+        final int receiverWindowLength,
+        final boolean tether,
+        final boolean rejoin,
+        final boolean reliable,
+        final boolean sparse,
+        final int publicationWindowLength,
+        final long untetheredWindowLimitTimeoutNs,
+        final long untetheredRestingTimeoutNs,
+        final int maxResend,
+        final long lingerTimeoutNs,
+        final boolean signalEos,
+        final boolean spiesSimulateConnection,
         final RawLog rawLog)
     {
+        // peter
+
         final UnsafeBuffer logMetaData = rawLog.metaData();
 
         defaultDataHeader.sessionId(sessionId).streamId(streamId).termId(initialTermId);
@@ -1846,9 +1928,32 @@ private void initLogMetadata(
         termLength(logMetaData, rawLog.termLength());
         pageSize(logMetaData, ctx.filePageSize());
         correlationId(logMetaData, registrationId);
+
+        // new
+        termOffset(logMetaData, termOffset);
+        socketRcvbufLength(logMetaData, socketRcvBufLength);
+        socketSndbufLength(logMetaData, socketSndbufLength);
+        receiverWindowLength(logMetaData, receiverWindowLength);
+        isTether(logMetaData, tether);
+        isRejoin(logMetaData, rejoin);
+        isReliable(logMetaData, reliable);
+        isSparse(logMetaData, sparse);
+        publicationWindowLength(logMetaData, publicationWindowLength);
+        untetheredWindowLimitTimeoutNs(logMetaData, untetheredWindowLimitTimeoutNs);
+        untetheredRestingTimeoutNs(logMetaData, untetheredRestingTimeoutNs);
+        maxResend(logMetaData, maxResend);
+        lingerTimeoutNs(logMetaData, lingerTimeoutNs);
+        signalEos(logMetaData, signalEos);
+        spiesSimulateConnection(logMetaData, spiesSimulateConnection);
+
+//        channelUriStringBuilder.termId(params.termId);
+//        channelUriStringBuilder.sessionId(params.sessionId);
+
+        // Acts like a release fence; so this should be the last statement here.
         endOfStreamPosition(logMetaData, Long.MAX_VALUE);
     }
 
+
     private static void initialisePositionCounters(
         final int initialTermId, final PublicationParams params, final UnsafeBuffer logMetaData)
     {
@@ -1886,10 +1991,45 @@ private RawLog newPublicationImageLog(
         final int termBufferLength,
         final boolean isSparse,
         final int senderMtuLength,
+        final int socketRcvBufLength,
+        final int socketSndBufLength,
+        final int termOffset,
+        final int receiverWindowLength,
+        final boolean tether,
+        final boolean rejoin,
+        final boolean reliable,
         final long correlationId)
     {
         final RawLog rawLog = logFactory.newImage(correlationId, termBufferLength, isSparse);
-        initLogMetadata(sessionId, streamId, initialTermId, senderMtuLength, correlationId, rawLog);
+        int publicationWindowLength = 0;
+        long untetheredWindowLimitTimeoutNs = 0;
+        long untetheredRestingTimeoutNs = 0;
+        int maxResend = 0;
+        long lingerTimeoutNs = 0;
+        boolean signalEos = false;
+        boolean spiesSimulateConnection = false;
+        initLogMetadata(
+            sessionId,
+            streamId,
+            initialTermId,
+            senderMtuLength,
+            correlationId,
+            socketRcvBufLength,
+            socketSndBufLength,
+            termOffset,
+            receiverWindowLength,
+            tether,
+            rejoin,
+            reliable,
+            isSparse,
+            publicationWindowLength,
+            untetheredWindowLimitTimeoutNs,
+            untetheredRestingTimeoutNs,
+            maxResend,
+            lingerTimeoutNs,
+            signalEos,
+            spiesSimulateConnection,
+            rawLog);
 
         return rawLog;
     }
@@ -2273,8 +2413,11 @@ private IpcPublication addIpcPublication(
         final boolean isExclusive,
         final PublicationParams params)
     {
+        // todo:
+        final int termOffset = 0;
+
         final RawLog rawLog =
-            newIpcPublicationLog(params.sessionId, streamId, params.initialTermId, registrationId, params);
+            newIpcPublicationLog(params.sessionId, streamId, params.initialTermId, registrationId, termOffset, params);
 
         UnsafeBufferPosition publisherPosition = null;
         UnsafeBufferPosition publisherLimit = null;
diff --git a/aeron-driver/src/main/java/io/aeron/driver/Main.java b/aeron-driver/src/main/java/io/aeron/driver/Main.java
new file mode 100644
index 0000000000..3fc0198994
--- /dev/null
+++ b/aeron-driver/src/main/java/io/aeron/driver/Main.java
@@ -0,0 +1,198 @@
+package io.aeron.driver;
+
+import io.aeron.Aeron;
+import io.aeron.ChannelUriStringBuilder;
+import io.aeron.Publication;
+import io.aeron.Subscription;
+import io.aeron.driver.media.ReceiveChannelEndpoint;
+import io.aeron.logbuffer.FragmentHandler;
+import org.agrona.concurrent.UnsafeBuffer;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+
+import static io.aeron.CommonContext.InferableBoolean.FORCE_TRUE;
+import static io.aeron.CommonContext.InferableBoolean.INFER;
+
+// todo: will be removed in final commit.
+public class Main
+{
+
+    private static final String CHANNEL = "aeron:udp?endpoint=localhost:40123";
+    private static final int STREAM_ID = 1001;
+
+    public static void main(String[] args)
+    {
+        // Start an embedded MediaDriver
+        MediaDriver mediaDriver = MediaDriver.launchEmbedded();
+
+        // Aeron context using the embedded driver's directory
+        Aeron.Context ctx = new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName());
+
+        // Start Aeron
+        Aeron aeron = Aeron.connect(ctx);
+
+        // Start the server in a separate thread
+        Thread serverThread = new Thread(() -> runServer(aeron));
+        serverThread.start();
+
+        // Start the client
+        runClient(aeron);
+
+        // Clean up
+        try
+        {
+            serverThread.join();
+        }
+        catch (InterruptedException e)
+        {
+            Thread.currentThread().interrupt();
+        }
+        finally
+        {
+            aeron.close();
+            mediaDriver.close();
+        }
+    }
+
+    private static void runServer(Aeron aeron)
+    {
+        try (Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID))
+        {
+            System.out.println("Server started. Listening on channel: " + CHANNEL + ", stream ID: " + STREAM_ID);
+
+            FragmentHandler fragmentHandler = (buffer, offset, length, header) ->
+            {
+                String message = buffer.getStringWithoutLengthUtf8(offset, length);
+                System.out.println("Server received message: " + message);
+            };
+
+            while (!Thread.currentThread().isInterrupted())
+            {
+                int fragmentsRead = subscription.poll(fragmentHandler, 10);
+                if (fragmentsRead == 0)
+                {
+                    Thread.onSpinWait();
+                }
+            }
+        }
+    }
+
+    private static void runClient(Aeron aeron)
+    {
+        try (Publication publication = aeron.addPublication(CHANNEL, STREAM_ID))
+        {
+            String message = "Hello from the client!";
+            byte[] messageBytes = message.getBytes(StandardCharsets.UTF_8);
+
+            // Wrap the byte array in an UnsafeBuffer
+            UnsafeBuffer buffer = new UnsafeBuffer(ByteBuffer.allocateDirect(messageBytes.length));
+            buffer.putBytes(0, messageBytes);
+
+            while (true)
+            {
+                long result = publication.offer(buffer, 0, messageBytes.length);
+                if (result > 0)
+                {
+                    System.out.println("Client sent message: " + message);
+                    break;
+                }
+                else if (result == Publication.BACK_PRESSURED)
+                {
+                    System.out.println("Client back pressured. Retrying...");
+                }
+                else if (result == Publication.NOT_CONNECTED)
+                {
+                    System.out.println("Client not connected to the subscription.");
+                }
+                else if (result == Publication.ADMIN_ACTION)
+                {
+                    System.out.println("Publication is being administratively managed. Retrying...");
+                }
+                else
+                {
+                    System.out.println("Unexpected offer result: " + result);
+                }
+
+                try
+                {
+                    Thread.sleep(100);
+                }
+                catch (InterruptedException e)
+                {
+                    throw new RuntimeException(e);
+                }
+            }
+        }
+    }
+
+
+    private static String enrichImagePublicationChannelUri(
+        final ReceiveChannelEndpoint receiveChannelEndpoint,
+           final SubscriptionParams params,
+        final CongestionControl congestionControl)
+    {
+        final ChannelUriStringBuilder channelUriStringBuilder = new ChannelUriStringBuilder(
+            receiveChannelEndpoint.udpChannel().channelUri());
+
+        final int streamId=0;
+        final int initialTermId=0;
+        final int activeTermId=0;
+        final int termBufferLength=0;
+        final int termOffset=0;
+        final int senderMtuLength=0;
+        final boolean isSparse=false;
+        boolean isTether = params.isTether;
+        boolean isRejoin = params.isRejoin;
+        boolean isReliable = params.isReliable;
+        String name = congestionControl.getClass().getName();
+        boolean hasSessionId = params.hasSessionId;
+        int sessionId = params.sessionId;
+        int socketRcvbufLength = receiveChannelEndpoint.socketRcvbufLength();
+        int receiverWindowLength = params.receiverWindowLength;
+        int socketSndbufLength = receiveChannelEndpoint.socketSndbufLength();
+        boolean group = FORCE_TRUE == params.group;
+
+
+        channelUriStringBuilder.sessionId(sessionId);
+
+        channelUriStringBuilder.streamId(streamId);
+
+        channelUriStringBuilder.termLength(termBufferLength);
+        channelUriStringBuilder.mtu(senderMtuLength);
+
+        channelUriStringBuilder.initialTermId(initialTermId);
+        channelUriStringBuilder.termId(activeTermId);
+
+        channelUriStringBuilder.termOffset(termOffset);
+
+        channelUriStringBuilder.tether(isTether);
+        channelUriStringBuilder.rejoin(isRejoin);
+        channelUriStringBuilder.reliable(isReliable);
+        if (INFER != params.group)
+        {
+            channelUriStringBuilder.group(group);
+        }
+        channelUriStringBuilder.sparse(isSparse);
+
+        channelUriStringBuilder.congestionControl(name);
+
+        if (hasSessionId)
+        {
+            channelUriStringBuilder.sessionId(sessionId);
+        }
+
+        channelUriStringBuilder.socketRcvbufLength(socketRcvbufLength);
+        channelUriStringBuilder.socketSndbufLength(socketSndbufLength);
+
+        channelUriStringBuilder.receiverWindowLength(receiverWindowLength);
+
+        //  channelUriStringBuilder.group(params.group);
+
+//        boolean hasJoinPosition = false;
+//        boolean isResponse = false;
+//        InferableBoolean group = InferableBoolean.INFER;
+//
+        return channelUriStringBuilder.toString();
+    }
+}

From 708407ee389f1cbea0c64e042a58ab2830e60f09 Mon Sep 17 00:00:00 2001
From: Peter Veentjer 
Date: Fri, 20 Dec 2024 07:24:40 +0200
Subject: [PATCH 02/24] WIP

---
 .../aeron/logbuffer/LogBufferDescriptor.java  | 70 +++++++++++--------
 1 file changed, 41 insertions(+), 29 deletions(-)

diff --git a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java
index 68da90c393..3ee34c8eb4 100644
--- a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java
+++ b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java
@@ -146,7 +146,6 @@ public class LogBufferDescriptor
     // todo: Add documentation
     public static final int LOG_ACTIVE_TERM_ID_OFFSET;
     public static final int LOG_TERM_OFFSET_OFFSET;
-    public static final int LOG_SENDER_MTU_LENGTH_OFFSET;
     public static final int LOG_IS_SPARSE_OFFSET;
     public static final int LOG_IS_TETHER_OFFSET;
     public static final int LOG_IS_REJOIN_OFFSET;
@@ -249,10 +248,7 @@ public class LogBufferDescriptor
         LOG_TERM_OFFSET_OFFSET = offset;
         offset += SIZE_OF_INT;
 
-        LOG_SENDER_MTU_LENGTH_OFFSET = offset;
-        offset += SIZE_OF_INT;
-
-        LOG_IS_SPARSE_OFFSET = offset;
+         LOG_IS_SPARSE_OFFSET = offset;
         offset += SIZE_OF_INT;
 
         LOG_IS_TETHER_OFFSET = offset;
@@ -264,7 +260,6 @@ public class LogBufferDescriptor
         LOG_IS_RELIABLE_OFFSET = offset;
         offset += SIZE_OF_INT;
 
-
         LOG_SOCKET_RCVBUF_LENGTH_OFFSET = offset;
         offset += SIZE_OF_INT;
 
@@ -280,7 +275,13 @@ public class LogBufferDescriptor
         LOG_GROUP_OFFSET = offset;
         offset += SIZE_OF_INT;
 
+        LOG_MAX_RESEND_OFFSET = offset;
+        offset += SIZE_OF_INT;
+
         LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET = offset;
+        if((LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET % SIZE_OF_LONG)!=0){
+            throw new Error();
+        }
         offset += SIZE_OF_LONG;
 
         LOG_UNTETHERED_RESTING_TIMEOUT_NS_OFFSET = offset;
@@ -289,9 +290,6 @@ public class LogBufferDescriptor
         LOG_LINGER_TIMEOUT_NS_OFFSET = offset;
         offset += SIZE_OF_LONG;
 
-        LOG_MAX_RESEND_OFFSET = offset;
-        offset += SIZE_OF_INT;
-
         LOG_SIGNAL_EOS_OFFSET = offset;
         offset += SIZE_OF_INT;
 
@@ -963,158 +961,172 @@ public static int computeAssembledFrameLength(final int length, final int maxPay
         return HEADER_LENGTH + (numMaxPayloads * maxPayloadSize) + remainingPayload;
     }
 
-    // Active Term ID
+    // todo: javadoc
     public static int activeTermId(final UnsafeBuffer metadataBuffer) {
         return metadataBuffer.getInt(LOG_ACTIVE_TERM_ID_OFFSET);
     }
 
+    // todo: javadoc
     public static void activeTermId(final UnsafeBuffer metadataBuffer, final int value) {
         metadataBuffer.putInt(LOG_ACTIVE_TERM_ID_OFFSET, value);
     }
 
-    // Term Offset
+    // todo: javadoc
     public static int termOffset(final UnsafeBuffer metadataBuffer) {
         return metadataBuffer.getInt(LOG_TERM_OFFSET_OFFSET);
     }
 
+    // todo: javadoc
     public static void termOffset(final UnsafeBuffer metadataBuffer, final int value) {
         metadataBuffer.putInt(LOG_TERM_OFFSET_OFFSET, value);
     }
 
-    // Sender MTU Length
-    public static int senderMtuLength(final UnsafeBuffer metadataBuffer) {
-        return metadataBuffer.getInt(LOG_SENDER_MTU_LENGTH_OFFSET);
-    }
-
-    public static void senderMtuLength(final UnsafeBuffer metadataBuffer, final int value) {
-        metadataBuffer.putInt(LOG_SENDER_MTU_LENGTH_OFFSET, value);
-    }
-
-    // Is Sparse
+    // todo: javadoc
     public static boolean isSparse(final UnsafeBuffer metadataBuffer) {
         return metadataBuffer.getInt(LOG_IS_SPARSE_OFFSET) == 1;
     }
 
+    // todo: javadoc
     public static void isSparse(final UnsafeBuffer metadataBuffer, final boolean value) {
         metadataBuffer.putInt(LOG_IS_SPARSE_OFFSET, value ? 1 : 0);
     }
 
-    // Is Tether
+    // todo: javadoc
     public static boolean isTether(final UnsafeBuffer metadataBuffer) {
         return metadataBuffer.getInt(LOG_IS_TETHER_OFFSET) == 1;
     }
 
+    // todo: javadoc
     public static void isTether(final UnsafeBuffer metadataBuffer, final boolean value) {
         metadataBuffer.putInt(LOG_IS_TETHER_OFFSET, value ? 1 : 0);
     }
 
-    // Is Rejoin
+    // todo: javadoc
     public static boolean isRejoin(final UnsafeBuffer metadataBuffer) {
         return metadataBuffer.getInt(LOG_IS_REJOIN_OFFSET) == 1;
     }
 
+    // todo: javadoc
     public static void isRejoin(final UnsafeBuffer metadataBuffer, final boolean value) {
         metadataBuffer.putInt(LOG_IS_REJOIN_OFFSET, value ? 1 : 0);
     }
 
-    // Is Reliable
+    // todo: javadoc
     public static boolean isReliable(final UnsafeBuffer metadataBuffer) {
         return metadataBuffer.getInt(LOG_IS_RELIABLE_OFFSET) == 1;
     }
 
+    // todo: javadoc
     public static void isReliable(final UnsafeBuffer metadataBuffer, final boolean value) {
         metadataBuffer.putInt(LOG_IS_RELIABLE_OFFSET, value ? 1 : 0);
     }
 
-    // Socket Rcvbuf Length
+    // todo: javadoc
     public static int socketRcvbufLength(final UnsafeBuffer metadataBuffer) {
         return metadataBuffer.getInt(LOG_SOCKET_RCVBUF_LENGTH_OFFSET);
     }
 
+    // todo: javadoc
     public static void socketRcvbufLength(final UnsafeBuffer metadataBuffer, final int value) {
         metadataBuffer.putInt(LOG_SOCKET_RCVBUF_LENGTH_OFFSET, value);
     }
 
-    // Socket Sndbuf Length
+    // todo: javadoc
     public static int socketSndbufLength(final UnsafeBuffer metadataBuffer) {
         return metadataBuffer.getInt(LOG_SOCKET_SNDBUF_LENGTH_OFFSET);
     }
 
+    // todo: javadoc
     public static void socketSndbufLength(final UnsafeBuffer metadataBuffer, final int value) {
         metadataBuffer.putInt(LOG_SOCKET_SNDBUF_LENGTH_OFFSET, value);
     }
 
-    // Receiver Window Length
+    // todo: javadoc
     public static int receiverWindowLength(final UnsafeBuffer metadataBuffer) {
         return metadataBuffer.getInt(LOG_RECEIVER_WINDOW_LENGTH_OFFSET);
     }
 
+    // todo: javadoc
     public static void receiverWindowLength(final UnsafeBuffer metadataBuffer, final int value) {
         metadataBuffer.putInt(LOG_RECEIVER_WINDOW_LENGTH_OFFSET, value);
     }
 
+    // todo: javadoc
     public static int publicationWindowLength(final UnsafeBuffer metadataBuffer) {
         return metadataBuffer.getInt(LOG_PUBLICATION_WINDOW_LENGTH_OFFSET);
     }
 
+    // todo: javadoc
     public static void publicationWindowLength(final UnsafeBuffer metadataBuffer, final int value) {
         metadataBuffer.putInt(LOG_PUBLICATION_WINDOW_LENGTH_OFFSET, value);
     }
 
+    // todo: javadoc
     public static long untetheredWindowLimitTimeoutNs(final UnsafeBuffer metadataBuffer) {
         return metadataBuffer.getLong(LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET);
     }
 
+    // todo: javadoc
     public static void untetheredWindowLimitTimeoutNs(final UnsafeBuffer metadataBuffer, final long value) {
         metadataBuffer.putLong(LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET, value);
     }
 
-    // Untethered Resting Timeout (in nanoseconds)
+    // todo: javadoc
     public static long untetheredRestingTimeoutNs(final UnsafeBuffer metadataBuffer) {
         return metadataBuffer.getLong(LOG_UNTETHERED_RESTING_TIMEOUT_NS_OFFSET);
     }
 
+    // todo: javadoc
     public static void untetheredRestingTimeoutNs(final UnsafeBuffer metadataBuffer, final long value) {
         metadataBuffer.putLong(LOG_UNTETHERED_RESTING_TIMEOUT_NS_OFFSET, value);
     }
 
-    // Group
+    // todo: javadoc
     public static boolean group(final UnsafeBuffer metadataBuffer) {
         return metadataBuffer.getInt(LOG_GROUP_OFFSET) == 1;
     }
 
+    // todo: javadoc
     public static void group(final UnsafeBuffer metadataBuffer, final boolean value) {
         metadataBuffer.putInt(LOG_GROUP_OFFSET, value ? 1 : 0);
     }
 
+    // todo: javadoc
     public static int maxResend(final UnsafeBuffer metadataBuffer) {
         return metadataBuffer.getInt(LOG_MAX_RESEND_OFFSET);
     }
 
+    // todo: javadoc
     public static void maxResend(final UnsafeBuffer metadataBuffer, final int value) {
         metadataBuffer.putInt(LOG_MAX_RESEND_OFFSET, value);
     }
 
+    // todo: javadoc
     public static long lingerTimeoutNs(final UnsafeBuffer metadataBuffer) {
         return metadataBuffer.getLong(LOG_LINGER_TIMEOUT_NS_OFFSET);
     }
 
+    // todo: javadoc
     public static void lingerTimeoutNs(final UnsafeBuffer metadataBuffer, final long value) {
         metadataBuffer.putLong(LOG_LINGER_TIMEOUT_NS_OFFSET, value);
     }
 
+    // todo: javadoc
     public static boolean signalEos(final UnsafeBuffer metadataBuffer) {
         return metadataBuffer.getInt(LOG_SIGNAL_EOS_OFFSET) == 1;
     }
 
+    // todo: javadoc
     public static void signalEos(final UnsafeBuffer metadataBuffer, final boolean value) {
         metadataBuffer.putInt(LOG_SIGNAL_EOS_OFFSET,value ? 1 : 0);
     }
 
+    // todo: javadoc
     public static boolean spiesSimulateConnection(final UnsafeBuffer metadataBuffer) {
         return metadataBuffer.getInt(LOG_SPIES_SIMULATE_CONNECTION_OFFSET) == 1;
     }
 
+    // todo: javadoc
     public static void spiesSimulateConnection(final UnsafeBuffer metadataBuffer, final boolean value) {
         metadataBuffer.putInt(LOG_SPIES_SIMULATE_CONNECTION_OFFSET, value ? 1 : 0);
     }

From a0b64938ea757c28e93f7a3777070511cda62fb3 Mon Sep 17 00:00:00 2001
From: Peter Veentjer 
Date: Fri, 20 Dec 2024 09:16:14 +0200
Subject: [PATCH 03/24] Minor cleanup

---
 .../aeron/logbuffer/LogBufferDescriptor.java  | 28 ++++++++-----------
 .../java/io/aeron/driver/DriverConductor.java | 19 +++++--------
 2 files changed, 18 insertions(+), 29 deletions(-)

diff --git a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java
index 3ee34c8eb4..57f146223d 100644
--- a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java
+++ b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java
@@ -144,7 +144,6 @@ public class LogBufferDescriptor
 
 
     // todo: Add documentation
-    public static final int LOG_ACTIVE_TERM_ID_OFFSET;
     public static final int LOG_TERM_OFFSET_OFFSET;
     public static final int LOG_IS_SPARSE_OFFSET;
     public static final int LOG_IS_TETHER_OFFSET;
@@ -240,15 +239,14 @@ public class LogBufferDescriptor
         LOG_DEFAULT_FRAME_HEADER_OFFSET = offset;
 
         // the new fields will be added with 1 cacheline of padding after the frame header.
-        offset+= LOG_DEFAULT_FRAME_HEADER_MAX_LENGTH+CACHE_LINE_LENGTH;
-
-        LOG_ACTIVE_TERM_ID_OFFSET = offset;
-        offset += SIZE_OF_INT;
+        offset+= LOG_DEFAULT_FRAME_HEADER_MAX_LENGTH + CACHE_LINE_LENGTH;
 
         LOG_TERM_OFFSET_OFFSET = offset;
         offset += SIZE_OF_INT;
 
-         LOG_IS_SPARSE_OFFSET = offset;
+        // todo: use a single int for a boolean? I can stick it into a byte (need to take care of alignment for
+        // other fields. Or I can use a 'bit' and have multiple booleans in the same byte.
+        LOG_IS_SPARSE_OFFSET = offset;
         offset += SIZE_OF_INT;
 
         LOG_IS_TETHER_OFFSET = offset;
@@ -279,14 +277,21 @@ public class LogBufferDescriptor
         offset += SIZE_OF_INT;
 
         LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET = offset;
+
+        // todo: This will be removed
+        // It is temporary here to ensure that all fields are naturally aligned.
         if((LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET % SIZE_OF_LONG)!=0){
             throw new Error();
         }
         offset += SIZE_OF_LONG;
 
+        // todo: remove
+        // will be aligned if previous field is aligned.
         LOG_UNTETHERED_RESTING_TIMEOUT_NS_OFFSET = offset;
         offset += SIZE_OF_LONG;
 
+        // todo: remove
+        // will be aligned if previous field is aligned.
         LOG_LINGER_TIMEOUT_NS_OFFSET = offset;
         offset += SIZE_OF_LONG;
 
@@ -296,7 +301,6 @@ public class LogBufferDescriptor
         LOG_SPIES_SIMULATE_CONNECTION_OFFSET = offset;
         offset += SIZE_OF_INT;
 
-
         LOG_META_DATA_LENGTH = align(offset, PAGE_MIN_SIZE);
         System.out.println("Offset:"+offset);
         System.out.println("LOG_META_DATA_LENGTH:"+LOG_META_DATA_LENGTH);
@@ -961,16 +965,6 @@ public static int computeAssembledFrameLength(final int length, final int maxPay
         return HEADER_LENGTH + (numMaxPayloads * maxPayloadSize) + remainingPayload;
     }
 
-    // todo: javadoc
-    public static int activeTermId(final UnsafeBuffer metadataBuffer) {
-        return metadataBuffer.getInt(LOG_ACTIVE_TERM_ID_OFFSET);
-    }
-
-    // todo: javadoc
-    public static void activeTermId(final UnsafeBuffer metadataBuffer, final int value) {
-        metadataBuffer.putInt(LOG_ACTIVE_TERM_ID_OFFSET, value);
-    }
-
     // todo: javadoc
     public static int termOffset(final UnsafeBuffer metadataBuffer) {
         return metadataBuffer.getInt(LOG_TERM_OFFSET_OFFSET);
diff --git a/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java b/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java
index adb06a4cc5..e8711178c8 100644
--- a/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java
+++ b/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java
@@ -1860,25 +1860,20 @@ private RawLog newIpcPublicationLog(
         final PublicationParams params)
     {
         final RawLog rawLog = logFactory.newPublication(registrationId, params.termLength, params.isSparse);
-        final int socketRcvBufLength = 0;
-        final int socketSndBufLength = 0;
-        final int receiverWindowLength = 0;
-        final boolean tether = false;
-        final boolean rejoin = false;
-        final boolean reliable = false;
+
         initLogMetadata(
             sessionId,
             streamId,
             initialTermId,
             params.mtuLength,
             registrationId,
-            socketRcvBufLength,
-            socketSndBufLength,
+            0,
+            0,
             termOffset,
-            receiverWindowLength,
-            tether,
-            rejoin,
-            reliable,
+            0,
+            false,
+            false,
+            false,
             params.isSparse,
             params.publicationWindowLength,
             params.untetheredWindowLimitTimeoutNs,

From ce1040fb87ca3a8982bd863f374a2d3260ffbb8a Mon Sep 17 00:00:00 2001
From: Peter Veentjer 
Date: Fri, 20 Dec 2024 09:48:01 +0200
Subject: [PATCH 04/24] Further improvements

---
 .../aeron/logbuffer/LogBufferDescriptor.java  | 412 ++++++++++++++----
 .../java/io/aeron/driver/DriverConductor.java |  36 +-
 2 files changed, 355 insertions(+), 93 deletions(-)

diff --git a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java
index 57f146223d..d66fa88188 100644
--- a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java
+++ b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java
@@ -143,22 +143,84 @@ public class LogBufferDescriptor
     public static final int LOG_DEFAULT_FRAME_HEADER_MAX_LENGTH = CACHE_LINE_LENGTH * 2;
 
 
-    // todo: Add documentation
+    /**
+     * Offset within the log metadata where the term offset is stored.
+     */
     public static final int LOG_TERM_OFFSET_OFFSET;
+
+    /**
+     * Offset within the log metadata where the sparse property is stored.
+     */
     public static final int LOG_IS_SPARSE_OFFSET;
+
+    /**
+     * Offset within the log metadata where the tether property is stored.
+     */
     public static final int LOG_IS_TETHER_OFFSET;
+
+    /**
+     * Offset within the log metadata where the rejoin property is stored.
+     */
     public static final int LOG_IS_REJOIN_OFFSET;
+
+    /**
+     * Offset within the log metadata where the reliable property is stored.
+     */
     public static final int LOG_IS_RELIABLE_OFFSET;
+
+    /**
+     * Offset within the log metadata where the socket receive buffer length is stored.
+     */
     public static final int LOG_SOCKET_RCVBUF_LENGTH_OFFSET;
+
+    /**
+     * Offset within the log metadata where the socket send buffer length is stored.
+     */
     public static final int LOG_SOCKET_SNDBUF_LENGTH_OFFSET;
+
+    /**
+     * Offset within the log metadata where the receiver window length is stored.
+     */
     public static final int LOG_RECEIVER_WINDOW_LENGTH_OFFSET;
+
+    /**
+     * Offset within the log metadata where the publication window length is stored.
+     */
     public static final int LOG_PUBLICATION_WINDOW_LENGTH_OFFSET;
+
+    /**
+     * Offset within the log metadata where the group offset is stored.
+     */
     public static final int LOG_GROUP_OFFSET;
+
+    /**
+     * Offset within the log metadata where the window limit timeout ns is stored.
+     */
     public static final int LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET;
+
+    /**
+     * Offset within the log metadata where the untether resting timeout ns is stored.
+     */
     public static final int LOG_UNTETHERED_RESTING_TIMEOUT_NS_OFFSET;
+
+    /**
+     * Offset within the log metadata where the max resend is stored.
+     */
     public static final int LOG_MAX_RESEND_OFFSET;
+
+    /**
+     * Offset within the log metadata where the linger timeout ns is stored.
+     */
     public static final int LOG_LINGER_TIMEOUT_NS_OFFSET;
+
+    /**
+     * Offset within the log metadata where the signal eos is stored.
+     */
     public static final int LOG_SIGNAL_EOS_OFFSET;
+
+    /**
+     * Offset within the log metadata where the spies simulate connection is stored.
+     */
     public static final int LOG_SPIES_SIMULATE_CONNECTION_OFFSET;
 
     /**
@@ -210,6 +272,7 @@ public class LogBufferDescriptor
      *  |                     Default Frame Header                     ...
      * ...                                                              |
      *  +---------------------------------------------------------------+
+     *  //todo: Add the missing fields.
      * 
*/ public static final int LOG_META_DATA_LENGTH; @@ -239,7 +302,7 @@ public class LogBufferDescriptor LOG_DEFAULT_FRAME_HEADER_OFFSET = offset; // the new fields will be added with 1 cacheline of padding after the frame header. - offset+= LOG_DEFAULT_FRAME_HEADER_MAX_LENGTH + CACHE_LINE_LENGTH; + offset += LOG_DEFAULT_FRAME_HEADER_MAX_LENGTH + CACHE_LINE_LENGTH; LOG_TERM_OFFSET_OFFSET = offset; offset += SIZE_OF_INT; @@ -270,9 +333,6 @@ public class LogBufferDescriptor LOG_PUBLICATION_WINDOW_LENGTH_OFFSET = offset; offset += SIZE_OF_INT; - LOG_GROUP_OFFSET = offset; - offset += SIZE_OF_INT; - LOG_MAX_RESEND_OFFSET = offset; offset += SIZE_OF_INT; @@ -280,18 +340,16 @@ public class LogBufferDescriptor // todo: This will be removed // It is temporary here to ensure that all fields are naturally aligned. - if((LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET % SIZE_OF_LONG)!=0){ - throw new Error(); + if ((LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET % SIZE_OF_LONG) != 0) + { + throw new Error("LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET should be 8 bytes aligned, value: " + + LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET); } offset += SIZE_OF_LONG; - // todo: remove - // will be aligned if previous field is aligned. LOG_UNTETHERED_RESTING_TIMEOUT_NS_OFFSET = offset; offset += SIZE_OF_LONG; - // todo: remove - // will be aligned if previous field is aligned. LOG_LINGER_TIMEOUT_NS_OFFSET = offset; offset += SIZE_OF_LONG; @@ -301,9 +359,15 @@ public class LogBufferDescriptor LOG_SPIES_SIMULATE_CONNECTION_OFFSET = offset; offset += SIZE_OF_INT; + LOG_GROUP_OFFSET = offset; + offset += SIZE_OF_INT; + + LOG_META_DATA_LENGTH = align(offset, PAGE_MIN_SIZE); - System.out.println("Offset:"+offset); - System.out.println("LOG_META_DATA_LENGTH:"+LOG_META_DATA_LENGTH); + + // todo: will be removed before finalizing + System.out.println("Offset:" + offset); + System.out.println("LOG_META_DATA_LENGTH:" + LOG_META_DATA_LENGTH); } /** @@ -965,163 +1029,355 @@ public static int computeAssembledFrameLength(final int length, final int maxPay return HEADER_LENGTH + (numMaxPayloads * maxPayloadSize) + remainingPayload; } - // todo: javadoc - public static int termOffset(final UnsafeBuffer metadataBuffer) { + /** + * Get the term offset from the log metadata. + * + * @param metadataBuffer containing the meta data. + * @return the term offset. + */ + public static int termOffset(final UnsafeBuffer metadataBuffer) + { return metadataBuffer.getInt(LOG_TERM_OFFSET_OFFSET); } - // todo: javadoc - public static void termOffset(final UnsafeBuffer metadataBuffer, final int value) { + /** + * Set the term offset in the log metadata. + * + * @param metadataBuffer containing the meta data. + * @param value the term offset to set. + */ + public static void termOffset(final UnsafeBuffer metadataBuffer, final int value) + { metadataBuffer.putInt(LOG_TERM_OFFSET_OFFSET, value); } - // todo: javadoc - public static boolean isSparse(final UnsafeBuffer metadataBuffer) { + /** + * Get whether the log is sparse from the metadata. + * + * @param metadataBuffer containing the meta data. + * @return true if the log is sparse, otherwise false. + */ + public static boolean isSparse(final UnsafeBuffer metadataBuffer) + { return metadataBuffer.getInt(LOG_IS_SPARSE_OFFSET) == 1; } - // todo: javadoc - public static void isSparse(final UnsafeBuffer metadataBuffer, final boolean value) { + /** + * Set whether the log is sparse in the metadata. + * + * @param metadataBuffer containing the meta data. + * @param value true if the log is sparse, otherwise false. + */ + public static void isSparse(final UnsafeBuffer metadataBuffer, final boolean value) + { metadataBuffer.putInt(LOG_IS_SPARSE_OFFSET, value ? 1 : 0); } - // todo: javadoc - public static boolean isTether(final UnsafeBuffer metadataBuffer) { + /** + * Get whether the log is tethered from the metadata. + * + * @param metadataBuffer containing the meta data. + * @return true if the log is tethered, otherwise false. + */ + public static boolean isTether(final UnsafeBuffer metadataBuffer) + { return metadataBuffer.getInt(LOG_IS_TETHER_OFFSET) == 1; } - // todo: javadoc - public static void isTether(final UnsafeBuffer metadataBuffer, final boolean value) { + /** + * Set whether the log is tethered in the metadata. + * + * @param metadataBuffer containing the meta data. + * @param value true if the log is tethered, otherwise false. + */ + public static void isTether(final UnsafeBuffer metadataBuffer, final boolean value) + { metadataBuffer.putInt(LOG_IS_TETHER_OFFSET, value ? 1 : 0); } - // todo: javadoc - public static boolean isRejoin(final UnsafeBuffer metadataBuffer) { + /** + * Get whether the log is rejoining from the metadata. + * + * @param metadataBuffer containing the meta data. + * @return true if the log is rejoining, otherwise false. + */ + public static boolean isRejoin(final UnsafeBuffer metadataBuffer) + { return metadataBuffer.getInt(LOG_IS_REJOIN_OFFSET) == 1; } - // todo: javadoc - public static void isRejoin(final UnsafeBuffer metadataBuffer, final boolean value) { + /** + * Set whether the log is rejoining in the metadata. + * + * @param metadataBuffer containing the meta data. + * @param value true if the log is rejoining, otherwise false. + */ + public static void isRejoin(final UnsafeBuffer metadataBuffer, final boolean value) + { metadataBuffer.putInt(LOG_IS_REJOIN_OFFSET, value ? 1 : 0); } - // todo: javadoc - public static boolean isReliable(final UnsafeBuffer metadataBuffer) { + /** + * Get whether the log is reliable from the metadata. + * + * @param metadataBuffer containing the meta data. + * @return true if the log is reliable, otherwise false. + */ + public static boolean isReliable(final UnsafeBuffer metadataBuffer) + { return metadataBuffer.getInt(LOG_IS_RELIABLE_OFFSET) == 1; } - // todo: javadoc - public static void isReliable(final UnsafeBuffer metadataBuffer, final boolean value) { + /** + * Set whether the log is reliable in the metadata. + * + * @param metadataBuffer containing the meta data. + * @param value true if the log is reliable, otherwise false. + */ + public static void isReliable(final UnsafeBuffer metadataBuffer, final boolean value) + { metadataBuffer.putInt(LOG_IS_RELIABLE_OFFSET, value ? 1 : 0); } - // todo: javadoc - public static int socketRcvbufLength(final UnsafeBuffer metadataBuffer) { + /** + * Get the socket receive buffer length from the metadata. + * + * @param metadataBuffer containing the meta data. + * @return the socket receive buffer length. + */ + public static int socketRcvbufLength(final UnsafeBuffer metadataBuffer) + { return metadataBuffer.getInt(LOG_SOCKET_RCVBUF_LENGTH_OFFSET); } - // todo: javadoc - public static void socketRcvbufLength(final UnsafeBuffer metadataBuffer, final int value) { + /** + * Set the socket receive buffer length in the metadata. + * + * @param metadataBuffer containing the meta data. + * @param value the socket receive buffer length to set. + */ + public static void socketRcvbufLength(final UnsafeBuffer metadataBuffer, final int value) + { metadataBuffer.putInt(LOG_SOCKET_RCVBUF_LENGTH_OFFSET, value); } - // todo: javadoc - public static int socketSndbufLength(final UnsafeBuffer metadataBuffer) { + /** + * Get the socket send buffer length from the metadata. + * + * @param metadataBuffer containing the meta data. + * @return the socket send buffer length. + */ + public static int socketSndbufLength(final UnsafeBuffer metadataBuffer) + { return metadataBuffer.getInt(LOG_SOCKET_SNDBUF_LENGTH_OFFSET); } - // todo: javadoc - public static void socketSndbufLength(final UnsafeBuffer metadataBuffer, final int value) { + /** + * Set the socket send buffer length in the metadata. + * + * @param metadataBuffer containing the meta data. + * @param value the socket send buffer length to set. + */ + public static void socketSndbufLength(final UnsafeBuffer metadataBuffer, final int value) + { metadataBuffer.putInt(LOG_SOCKET_SNDBUF_LENGTH_OFFSET, value); } - // todo: javadoc - public static int receiverWindowLength(final UnsafeBuffer metadataBuffer) { + /** + * Get the receiver window length from the metadata. + * + * @param metadataBuffer containing the meta data. + * @return the receiver window length. + */ + public static int receiverWindowLength(final UnsafeBuffer metadataBuffer) + { return metadataBuffer.getInt(LOG_RECEIVER_WINDOW_LENGTH_OFFSET); } - // todo: javadoc - public static void receiverWindowLength(final UnsafeBuffer metadataBuffer, final int value) { + /** + * Set the receiver window length in the metadata. + * + * @param metadataBuffer containing the meta data. + * @param value the receiver window length to set. + */ + public static void receiverWindowLength(final UnsafeBuffer metadataBuffer, final int value) + { metadataBuffer.putInt(LOG_RECEIVER_WINDOW_LENGTH_OFFSET, value); } - // todo: javadoc - public static int publicationWindowLength(final UnsafeBuffer metadataBuffer) { + /** + * Get the publication window length from the metadata. + * + * @param metadataBuffer containing the meta data. + * @return the publication window length. + */ + public static int publicationWindowLength(final UnsafeBuffer metadataBuffer) + { return metadataBuffer.getInt(LOG_PUBLICATION_WINDOW_LENGTH_OFFSET); } - // todo: javadoc - public static void publicationWindowLength(final UnsafeBuffer metadataBuffer, final int value) { + /** + * Set the publication window length in the metadata. + * + * @param metadataBuffer containing the meta data. + * @param value the publication window length to set. + */ + public static void publicationWindowLength(final UnsafeBuffer metadataBuffer, final int value) + { metadataBuffer.putInt(LOG_PUBLICATION_WINDOW_LENGTH_OFFSET, value); } - // todo: javadoc - public static long untetheredWindowLimitTimeoutNs(final UnsafeBuffer metadataBuffer) { + /** + * Get the untethered window limit timeout in nanoseconds from the metadata. + * + * @param metadataBuffer containing the meta data. + * @return the untethered window limit timeout in nanoseconds. + */ + public static long untetheredWindowLimitTimeoutNs(final UnsafeBuffer metadataBuffer) + { return metadataBuffer.getLong(LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET); } - // todo: javadoc - public static void untetheredWindowLimitTimeoutNs(final UnsafeBuffer metadataBuffer, final long value) { + /** + * Set the untethered window limit timeout in nanoseconds in the metadata. + * + * @param metadataBuffer containing the meta data. + * @param value the untethered window limit timeout to set. + */ + public static void untetheredWindowLimitTimeoutNs(final UnsafeBuffer metadataBuffer, final long value) + { metadataBuffer.putLong(LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET, value); } - // todo: javadoc - public static long untetheredRestingTimeoutNs(final UnsafeBuffer metadataBuffer) { + /** + * Get the untethered resting timeout in nanoseconds from the metadata. + * + * @param metadataBuffer containing the meta data. + * @return the untethered resting timeout in nanoseconds. + */ + public static long untetheredRestingTimeoutNs(final UnsafeBuffer metadataBuffer) + { return metadataBuffer.getLong(LOG_UNTETHERED_RESTING_TIMEOUT_NS_OFFSET); } - // todo: javadoc - public static void untetheredRestingTimeoutNs(final UnsafeBuffer metadataBuffer, final long value) { + /** + * Set the untethered resting timeout in nanoseconds in the metadata. + * + * @param metadataBuffer containing the meta data. + * @param value the untethered resting timeout to set. + */ + public static void untetheredRestingTimeoutNs(final UnsafeBuffer metadataBuffer, final long value) + { metadataBuffer.putLong(LOG_UNTETHERED_RESTING_TIMEOUT_NS_OFFSET, value); } - // todo: javadoc - public static boolean group(final UnsafeBuffer metadataBuffer) { + /** + * Get whether the log group is enabled from the metadata. + * + * @param metadataBuffer containing the meta data. + * @return true if the log group is enabled, otherwise false. + */ + public static boolean group(final UnsafeBuffer metadataBuffer) + { return metadataBuffer.getInt(LOG_GROUP_OFFSET) == 1; } - // todo: javadoc - public static void group(final UnsafeBuffer metadataBuffer, final boolean value) { + /** + * Set whether the log group is enabled in the metadata. + * + * @param metadataBuffer containing the meta data. + * @param value true if the log group is enabled, otherwise false. + */ + public static void group(final UnsafeBuffer metadataBuffer, final boolean value) + { metadataBuffer.putInt(LOG_GROUP_OFFSET, value ? 1 : 0); } - // todo: javadoc - public static int maxResend(final UnsafeBuffer metadataBuffer) { + /** + * Get the maximum resend count from the metadata. + * + * @param metadataBuffer containing the meta data. + * @return the maximum resend count. + */ + public static int maxResend(final UnsafeBuffer metadataBuffer) + { return metadataBuffer.getInt(LOG_MAX_RESEND_OFFSET); } - // todo: javadoc - public static void maxResend(final UnsafeBuffer metadataBuffer, final int value) { + /** + * Set the maximum resend count in the metadata. + * + * @param metadataBuffer containing the meta data. + * @param value the maximum resend count to set. + */ + public static void maxResend(final UnsafeBuffer metadataBuffer, final int value) + { metadataBuffer.putInt(LOG_MAX_RESEND_OFFSET, value); } - // todo: javadoc - public static long lingerTimeoutNs(final UnsafeBuffer metadataBuffer) { + /** + * Get the linger timeout in nanoseconds from the metadata. + * + * @param metadataBuffer containing the meta data. + * @return the linger timeout in nanoseconds. + */ + public static long lingerTimeoutNs(final UnsafeBuffer metadataBuffer) + { return metadataBuffer.getLong(LOG_LINGER_TIMEOUT_NS_OFFSET); } - // todo: javadoc - public static void lingerTimeoutNs(final UnsafeBuffer metadataBuffer, final long value) { + /** + * Set the linger timeout in nanoseconds in the metadata. + * + * @param metadataBuffer containing the meta data. + * @param value the linger timeout to set. + */ + public static void lingerTimeoutNs(final UnsafeBuffer metadataBuffer, final long value) + { metadataBuffer.putLong(LOG_LINGER_TIMEOUT_NS_OFFSET, value); } - // todo: javadoc - public static boolean signalEos(final UnsafeBuffer metadataBuffer) { + /** + * Get whether the signal EOS is enabled from the metadata. + * + * @param metadataBuffer containing the meta data. + * @return true if signal EOS is enabled, otherwise false. + */ + public static boolean signalEos(final UnsafeBuffer metadataBuffer) + { return metadataBuffer.getInt(LOG_SIGNAL_EOS_OFFSET) == 1; } - // todo: javadoc - public static void signalEos(final UnsafeBuffer metadataBuffer, final boolean value) { - metadataBuffer.putInt(LOG_SIGNAL_EOS_OFFSET,value ? 1 : 0); + /** + * Set whether the signal EOS is enabled in the metadata. + * + * @param metadataBuffer containing the meta data. + * @param value true if signal EOS is enabled, otherwise false. + */ + public static void signalEos(final UnsafeBuffer metadataBuffer, final boolean value) + { + metadataBuffer.putInt(LOG_SIGNAL_EOS_OFFSET, value ? 1 : 0); } - // todo: javadoc - public static boolean spiesSimulateConnection(final UnsafeBuffer metadataBuffer) { + /** + * Get whether spies simulate connection from the metadata. + * + * @param metadataBuffer containing the meta data. + * @return true if spies simulate connection, otherwise false. + */ + public static boolean spiesSimulateConnection(final UnsafeBuffer metadataBuffer) + { return metadataBuffer.getInt(LOG_SPIES_SIMULATE_CONNECTION_OFFSET) == 1; } - // todo: javadoc - public static void spiesSimulateConnection(final UnsafeBuffer metadataBuffer, final boolean value) { + /** + * Set whether spies simulate connection in the metadata. + * + * @param metadataBuffer containing the meta data. + * @param value true if spies simulate connection, otherwise false. + */ + public static void spiesSimulateConnection(final UnsafeBuffer metadataBuffer, final boolean value) + { metadataBuffer.putInt(LOG_SPIES_SIMULATE_CONNECTION_OFFSET, value ? 1 : 0); } } diff --git a/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java b/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java index e8711178c8..2baaae2261 100644 --- a/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java +++ b/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java @@ -1861,19 +1861,25 @@ private RawLog newIpcPublicationLog( { final RawLog rawLog = logFactory.newPublication(registrationId, params.termLength, params.isSparse); + final int socketRcvBufLength = 0; + final int socketSndbufLength = 0; + final int receiverWindowLength = 0; + final boolean tether = false; + final boolean rejoin = false; + final boolean reliable = false; initLogMetadata( sessionId, streamId, initialTermId, params.mtuLength, registrationId, - 0, - 0, + socketRcvBufLength, + socketSndbufLength, termOffset, - 0, - false, - false, - false, + receiverWindowLength, + tether, + rejoin, + reliable, params.isSparse, params.publicationWindowLength, params.untetheredWindowLimitTimeoutNs, @@ -1942,9 +1948,8 @@ private void initLogMetadata( spiesSimulateConnection(logMetaData, spiesSimulateConnection); // channelUriStringBuilder.termId(params.termId); -// channelUriStringBuilder.sessionId(params.sessionId); - // Acts like a release fence; so this should be the last statement here. + // Acts like a release fence; so this should be the last statement. endOfStreamPosition(logMetaData, Long.MAX_VALUE); } @@ -1996,13 +2001,14 @@ private RawLog newPublicationImageLog( final long correlationId) { final RawLog rawLog = logFactory.newImage(correlationId, termBufferLength, isSparse); - int publicationWindowLength = 0; - long untetheredWindowLimitTimeoutNs = 0; - long untetheredRestingTimeoutNs = 0; - int maxResend = 0; - long lingerTimeoutNs = 0; - boolean signalEos = false; - boolean spiesSimulateConnection = false; + + final int publicationWindowLength = 0; + final long untetheredWindowLimitTimeoutNs = 0; + final long untetheredRestingTimeoutNs = 0; + final int maxResend = 0; + final long lingerTimeoutNs = 0; + final boolean signalEos = false; + final boolean spiesSimulateConnection = false; initLogMetadata( sessionId, streamId, From 0c7a358e88f7b41c66455fe7525b7d9042076856 Mon Sep 17 00:00:00 2001 From: Peter Veentjer Date: Fri, 20 Dec 2024 10:03:41 +0200 Subject: [PATCH 05/24] Minor fixes --- .../java/io/aeron/driver/DriverConductor.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java b/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java index 2baaae2261..8d3b048b52 100644 --- a/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java +++ b/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java @@ -312,10 +312,7 @@ void onCreatePublicationImage( subscriptionChannel.socketRcvbufLength(), subscriptionChannel.socketSndbufLength(), termOffset, - subscriptionParams.receiverWindowLength, - subscriptionParams.isTether, - subscriptionParams.isRejoin, - subscriptionParams.isReliable, + subscriptionParams, registrationId); congestionControl = ctx.congestionControlSupplier().newInstance( @@ -1994,10 +1991,7 @@ private RawLog newPublicationImageLog( final int socketRcvBufLength, final int socketSndBufLength, final int termOffset, - final int receiverWindowLength, - final boolean tether, - final boolean rejoin, - final boolean reliable, + final SubscriptionParams params, final long correlationId) { final RawLog rawLog = logFactory.newImage(correlationId, termBufferLength, isSparse); @@ -2018,11 +2012,11 @@ private RawLog newPublicationImageLog( socketRcvBufLength, socketSndBufLength, termOffset, - receiverWindowLength, - tether, - rejoin, - reliable, - isSparse, + params.receiverWindowLength, + params.isTether, + params.isRejoin, + params.isReliable, + params.isSparse, publicationWindowLength, untetheredWindowLimitTimeoutNs, untetheredRestingTimeoutNs, From 2bd98309d2fbb9057c9535f4208ade40548c01f0 Mon Sep 17 00:00:00 2001 From: Peter Veentjer Date: Fri, 20 Dec 2024 13:01:33 +0200 Subject: [PATCH 06/24] Booleans are now encoded as byte instead of int --- .../aeron/logbuffer/LogBufferDescriptor.java | 73 ++++++++++--------- .../src/main/java/io/aeron/driver/Main.java | 68 ----------------- 2 files changed, 39 insertions(+), 102 deletions(-) diff --git a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java index d66fa88188..9e4bee3377 100644 --- a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java +++ b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java @@ -136,7 +136,6 @@ public class LogBufferDescriptor public static final int LOG_DEFAULT_FRAME_HEADER_OFFSET; - /** * Maximum length of a frame header. */ @@ -307,19 +306,29 @@ public class LogBufferDescriptor LOG_TERM_OFFSET_OFFSET = offset; offset += SIZE_OF_INT; - // todo: use a single int for a boolean? I can stick it into a byte (need to take care of alignment for - // other fields. Or I can use a 'bit' and have multiple booleans in the same byte. LOG_IS_SPARSE_OFFSET = offset; - offset += SIZE_OF_INT; + offset += SIZE_OF_BYTE; LOG_IS_TETHER_OFFSET = offset; - offset += SIZE_OF_INT; + offset += SIZE_OF_BYTE; LOG_IS_REJOIN_OFFSET = offset; - offset += SIZE_OF_INT; + offset += SIZE_OF_BYTE; LOG_IS_RELIABLE_OFFSET = offset; - offset += SIZE_OF_INT; + offset += SIZE_OF_BYTE; + + LOG_SIGNAL_EOS_OFFSET = offset; + offset += SIZE_OF_BYTE; + + // padding to ensure 4 byte aligned. + offset += 3; + + // todo: will be removed + if (offset % 4 != 0) + { + throw new Error("Bad alignment: offset=" + offset); + } LOG_SOCKET_RCVBUF_LENGTH_OFFSET = offset; offset += SIZE_OF_INT; @@ -353,16 +362,12 @@ public class LogBufferDescriptor LOG_LINGER_TIMEOUT_NS_OFFSET = offset; offset += SIZE_OF_LONG; - LOG_SIGNAL_EOS_OFFSET = offset; - offset += SIZE_OF_INT; - LOG_SPIES_SIMULATE_CONNECTION_OFFSET = offset; offset += SIZE_OF_INT; LOG_GROUP_OFFSET = offset; offset += SIZE_OF_INT; - LOG_META_DATA_LENGTH = align(offset, PAGE_MIN_SIZE); // todo: will be removed before finalizing @@ -569,7 +574,7 @@ public static int activeTransportCount(final UnsafeBuffer metadataBuffer) /** * Set the number of active transports for the Image. * - * @param metadataBuffer containing the meta data. + * @param metadataBuffer containing the meta data. * @param numberOfActiveTransports value to be set. */ public static void activeTransportCount(final UnsafeBuffer metadataBuffer, final int numberOfActiveTransports) @@ -678,7 +683,7 @@ public static int indexByTerm(final int initialTermId, final int activeTermId) */ public static int indexByTermCount(final long termCount) { - return (int)(termCount % PARTITION_COUNT); + return (int) (termCount % PARTITION_COUNT); } /** @@ -690,7 +695,7 @@ public static int indexByTermCount(final long termCount) */ public static int indexByPosition(final long position, final int positionBitsToShift) { - return (int)((position >>> positionBitsToShift) % PARTITION_COUNT); + return (int) ((position >>> positionBitsToShift) % PARTITION_COUNT); } /** @@ -737,7 +742,7 @@ public static long computeTermBeginPosition( public static int computeTermIdFromPosition( final long position, final int positionBitsToShift, final int initialTermId) { - return (int)(position >>> positionBitsToShift) + initialTermId; + return (int) (position >>> positionBitsToShift) + initialTermId; } /** @@ -751,7 +756,7 @@ public static int computeTermIdFromPosition( */ public static long computeLogLength(final int termLength, final int filePageSize) { - return align((PARTITION_COUNT * (long)termLength) + LOG_META_DATA_LENGTH, filePageSize); + return align((PARTITION_COUNT * (long) termLength) + LOG_META_DATA_LENGTH, filePageSize); } /** @@ -849,7 +854,7 @@ public static void initialiseTailWithTermId( */ public static int termId(final long rawTail) { - return (int)(rawTail >> 32); + return (int) (rawTail >> 32); } /** @@ -863,7 +868,7 @@ public static int termOffset(final long rawTail, final long termLength) { final long tail = rawTail & 0xFFFF_FFFFL; - return (int)Math.min(tail, termLength); + return (int) Math.min(tail, termLength); } /** @@ -874,7 +879,7 @@ public static int termOffset(final long rawTail, final long termLength) */ public static int termOffset(final long result) { - return (int)result; + return (int) result; } /** @@ -886,7 +891,7 @@ public static int termOffset(final long result) */ public static long packTail(final int termId, final int termOffset) { - return ((long)termId << 32) | termOffset; + return ((long) termId << 32) | termOffset; } /** @@ -1000,7 +1005,7 @@ public static int positionBitsToShift(final int termBufferLength) /** * Compute frame length for a message that is fragmented into chunks of {@code maxPayloadSize}. * - * @param length of the message. + * @param length of the message. * @param maxPayloadSize fragment size without the header. * @return message length after fragmentation. */ @@ -1017,7 +1022,7 @@ public static int computeFragmentedFrameLength(final int length, final int maxPa /** * Compute frame length for a message that has been reassembled from chunks of {@code maxPayloadSize}. * - * @param length of the message. + * @param length of the message. * @param maxPayloadSize fragment size without the header. * @return message length after fragmentation. */ @@ -1059,7 +1064,7 @@ public static void termOffset(final UnsafeBuffer metadataBuffer, final int value */ public static boolean isSparse(final UnsafeBuffer metadataBuffer) { - return metadataBuffer.getInt(LOG_IS_SPARSE_OFFSET) == 1; + return metadataBuffer.getByte(LOG_IS_SPARSE_OFFSET) == 1; } /** @@ -1070,7 +1075,7 @@ public static boolean isSparse(final UnsafeBuffer metadataBuffer) */ public static void isSparse(final UnsafeBuffer metadataBuffer, final boolean value) { - metadataBuffer.putInt(LOG_IS_SPARSE_OFFSET, value ? 1 : 0); + metadataBuffer.putByte(LOG_IS_SPARSE_OFFSET, (byte) (value ? 1 : 0)); } /** @@ -1081,7 +1086,7 @@ public static void isSparse(final UnsafeBuffer metadataBuffer, final boolean val */ public static boolean isTether(final UnsafeBuffer metadataBuffer) { - return metadataBuffer.getInt(LOG_IS_TETHER_OFFSET) == 1; + return metadataBuffer.getByte(LOG_IS_TETHER_OFFSET) == 1; } /** @@ -1092,7 +1097,7 @@ public static boolean isTether(final UnsafeBuffer metadataBuffer) */ public static void isTether(final UnsafeBuffer metadataBuffer, final boolean value) { - metadataBuffer.putInt(LOG_IS_TETHER_OFFSET, value ? 1 : 0); + metadataBuffer.putByte(LOG_IS_TETHER_OFFSET, (byte) (value ? 1 : 0)); } /** @@ -1103,7 +1108,7 @@ public static void isTether(final UnsafeBuffer metadataBuffer, final boolean val */ public static boolean isRejoin(final UnsafeBuffer metadataBuffer) { - return metadataBuffer.getInt(LOG_IS_REJOIN_OFFSET) == 1; + return metadataBuffer.getByte(LOG_IS_REJOIN_OFFSET) == 1; } /** @@ -1114,7 +1119,7 @@ public static boolean isRejoin(final UnsafeBuffer metadataBuffer) */ public static void isRejoin(final UnsafeBuffer metadataBuffer, final boolean value) { - metadataBuffer.putInt(LOG_IS_REJOIN_OFFSET, value ? 1 : 0); + metadataBuffer.putByte(LOG_IS_REJOIN_OFFSET, (byte) (value ? 1 : 0)); } /** @@ -1125,7 +1130,7 @@ public static void isRejoin(final UnsafeBuffer metadataBuffer, final boolean val */ public static boolean isReliable(final UnsafeBuffer metadataBuffer) { - return metadataBuffer.getInt(LOG_IS_RELIABLE_OFFSET) == 1; + return metadataBuffer.getByte(LOG_IS_RELIABLE_OFFSET) == 1; } /** @@ -1136,7 +1141,7 @@ public static boolean isReliable(final UnsafeBuffer metadataBuffer) */ public static void isReliable(final UnsafeBuffer metadataBuffer, final boolean value) { - metadataBuffer.putInt(LOG_IS_RELIABLE_OFFSET, value ? 1 : 0); + metadataBuffer.putByte(LOG_IS_RELIABLE_OFFSET, (byte) (value ? 1 : 0)); } /** @@ -1345,7 +1350,7 @@ public static void lingerTimeoutNs(final UnsafeBuffer metadataBuffer, final long */ public static boolean signalEos(final UnsafeBuffer metadataBuffer) { - return metadataBuffer.getInt(LOG_SIGNAL_EOS_OFFSET) == 1; + return metadataBuffer.getByte(LOG_SIGNAL_EOS_OFFSET) == 1; } /** @@ -1356,7 +1361,7 @@ public static boolean signalEos(final UnsafeBuffer metadataBuffer) */ public static void signalEos(final UnsafeBuffer metadataBuffer, final boolean value) { - metadataBuffer.putInt(LOG_SIGNAL_EOS_OFFSET, value ? 1 : 0); + metadataBuffer.putByte(LOG_SIGNAL_EOS_OFFSET, (byte) (value ? 1 : 0)); } /** @@ -1367,7 +1372,7 @@ public static void signalEos(final UnsafeBuffer metadataBuffer, final boolean va */ public static boolean spiesSimulateConnection(final UnsafeBuffer metadataBuffer) { - return metadataBuffer.getInt(LOG_SPIES_SIMULATE_CONNECTION_OFFSET) == 1; + return metadataBuffer.getByte(LOG_SPIES_SIMULATE_CONNECTION_OFFSET) == 1; } /** @@ -1378,6 +1383,6 @@ public static boolean spiesSimulateConnection(final UnsafeBuffer metadataBuffer) */ public static void spiesSimulateConnection(final UnsafeBuffer metadataBuffer, final boolean value) { - metadataBuffer.putInt(LOG_SPIES_SIMULATE_CONNECTION_OFFSET, value ? 1 : 0); + metadataBuffer.putByte(LOG_SPIES_SIMULATE_CONNECTION_OFFSET, (byte) (value ? 1 : 0)); } } diff --git a/aeron-driver/src/main/java/io/aeron/driver/Main.java b/aeron-driver/src/main/java/io/aeron/driver/Main.java index 3fc0198994..bd67f8cf77 100644 --- a/aeron-driver/src/main/java/io/aeron/driver/Main.java +++ b/aeron-driver/src/main/java/io/aeron/driver/Main.java @@ -127,72 +127,4 @@ else if (result == Publication.ADMIN_ACTION) } - private static String enrichImagePublicationChannelUri( - final ReceiveChannelEndpoint receiveChannelEndpoint, - final SubscriptionParams params, - final CongestionControl congestionControl) - { - final ChannelUriStringBuilder channelUriStringBuilder = new ChannelUriStringBuilder( - receiveChannelEndpoint.udpChannel().channelUri()); - - final int streamId=0; - final int initialTermId=0; - final int activeTermId=0; - final int termBufferLength=0; - final int termOffset=0; - final int senderMtuLength=0; - final boolean isSparse=false; - boolean isTether = params.isTether; - boolean isRejoin = params.isRejoin; - boolean isReliable = params.isReliable; - String name = congestionControl.getClass().getName(); - boolean hasSessionId = params.hasSessionId; - int sessionId = params.sessionId; - int socketRcvbufLength = receiveChannelEndpoint.socketRcvbufLength(); - int receiverWindowLength = params.receiverWindowLength; - int socketSndbufLength = receiveChannelEndpoint.socketSndbufLength(); - boolean group = FORCE_TRUE == params.group; - - - channelUriStringBuilder.sessionId(sessionId); - - channelUriStringBuilder.streamId(streamId); - - channelUriStringBuilder.termLength(termBufferLength); - channelUriStringBuilder.mtu(senderMtuLength); - - channelUriStringBuilder.initialTermId(initialTermId); - channelUriStringBuilder.termId(activeTermId); - - channelUriStringBuilder.termOffset(termOffset); - - channelUriStringBuilder.tether(isTether); - channelUriStringBuilder.rejoin(isRejoin); - channelUriStringBuilder.reliable(isReliable); - if (INFER != params.group) - { - channelUriStringBuilder.group(group); - } - channelUriStringBuilder.sparse(isSparse); - - channelUriStringBuilder.congestionControl(name); - - if (hasSessionId) - { - channelUriStringBuilder.sessionId(sessionId); - } - - channelUriStringBuilder.socketRcvbufLength(socketRcvbufLength); - channelUriStringBuilder.socketSndbufLength(socketSndbufLength); - - channelUriStringBuilder.receiverWindowLength(receiverWindowLength); - - // channelUriStringBuilder.group(params.group); - -// boolean hasJoinPosition = false; -// boolean isResponse = false; -// InferableBoolean group = InferableBoolean.INFER; -// - return channelUriStringBuilder.toString(); - } } From 57ea62dd3d841e00767e1f58990490e938f24eb6 Mon Sep 17 00:00:00 2001 From: Peter Veentjer Date: Fri, 20 Dec 2024 13:32:26 +0200 Subject: [PATCH 07/24] Removed the extra cacheline of padding after the frame header --- .../src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java index 9e4bee3377..952cdaf937 100644 --- a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java +++ b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java @@ -300,8 +300,7 @@ public class LogBufferDescriptor offset += CACHE_LINE_LENGTH; LOG_DEFAULT_FRAME_HEADER_OFFSET = offset; - // the new fields will be added with 1 cacheline of padding after the frame header. - offset += LOG_DEFAULT_FRAME_HEADER_MAX_LENGTH + CACHE_LINE_LENGTH; + offset += LOG_DEFAULT_FRAME_HEADER_MAX_LENGTH ; LOG_TERM_OFFSET_OFFSET = offset; offset += SIZE_OF_INT; From 6c4e28e1285df8bf2d1e32fefec2bc05058f5f10 Mon Sep 17 00:00:00 2001 From: Peter Veentjer Date: Fri, 20 Dec 2024 15:37:51 +0200 Subject: [PATCH 08/24] Fixed checkstyle issues --- .../aeron/logbuffer/LogBufferDescriptor.java | 71 +++------- .../java/io/aeron/driver/DriverConductor.java | 5 - .../src/main/java/io/aeron/driver/Main.java | 130 ------------------ 3 files changed, 18 insertions(+), 188 deletions(-) delete mode 100644 aeron-driver/src/main/java/io/aeron/driver/Main.java diff --git a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java index 952cdaf937..f27594f099 100644 --- a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java +++ b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java @@ -135,7 +135,6 @@ public class LogBufferDescriptor */ public static final int LOG_DEFAULT_FRAME_HEADER_OFFSET; - /** * Maximum length of a frame header. */ @@ -187,11 +186,6 @@ public class LogBufferDescriptor */ public static final int LOG_PUBLICATION_WINDOW_LENGTH_OFFSET; - /** - * Offset within the log metadata where the group offset is stored. - */ - public static final int LOG_GROUP_OFFSET; - /** * Offset within the log metadata where the window limit timeout ns is stored. */ @@ -300,7 +294,7 @@ public class LogBufferDescriptor offset += CACHE_LINE_LENGTH; LOG_DEFAULT_FRAME_HEADER_OFFSET = offset; - offset += LOG_DEFAULT_FRAME_HEADER_MAX_LENGTH ; + offset += LOG_DEFAULT_FRAME_HEADER_MAX_LENGTH; LOG_TERM_OFFSET_OFFSET = offset; offset += SIZE_OF_INT; @@ -364,14 +358,7 @@ public class LogBufferDescriptor LOG_SPIES_SIMULATE_CONNECTION_OFFSET = offset; offset += SIZE_OF_INT; - LOG_GROUP_OFFSET = offset; - offset += SIZE_OF_INT; - LOG_META_DATA_LENGTH = align(offset, PAGE_MIN_SIZE); - - // todo: will be removed before finalizing - System.out.println("Offset:" + offset); - System.out.println("LOG_META_DATA_LENGTH:" + LOG_META_DATA_LENGTH); } /** @@ -573,7 +560,7 @@ public static int activeTransportCount(final UnsafeBuffer metadataBuffer) /** * Set the number of active transports for the Image. * - * @param metadataBuffer containing the meta data. + * @param metadataBuffer containing the meta data. * @param numberOfActiveTransports value to be set. */ public static void activeTransportCount(final UnsafeBuffer metadataBuffer, final int numberOfActiveTransports) @@ -682,7 +669,7 @@ public static int indexByTerm(final int initialTermId, final int activeTermId) */ public static int indexByTermCount(final long termCount) { - return (int) (termCount % PARTITION_COUNT); + return (int)(termCount % PARTITION_COUNT); } /** @@ -694,7 +681,7 @@ public static int indexByTermCount(final long termCount) */ public static int indexByPosition(final long position, final int positionBitsToShift) { - return (int) ((position >>> positionBitsToShift) % PARTITION_COUNT); + return (int)((position >>> positionBitsToShift) % PARTITION_COUNT); } /** @@ -741,7 +728,7 @@ public static long computeTermBeginPosition( public static int computeTermIdFromPosition( final long position, final int positionBitsToShift, final int initialTermId) { - return (int) (position >>> positionBitsToShift) + initialTermId; + return (int)(position >>> positionBitsToShift) + initialTermId; } /** @@ -755,7 +742,7 @@ public static int computeTermIdFromPosition( */ public static long computeLogLength(final int termLength, final int filePageSize) { - return align((PARTITION_COUNT * (long) termLength) + LOG_META_DATA_LENGTH, filePageSize); + return align((PARTITION_COUNT * (long)termLength) + LOG_META_DATA_LENGTH, filePageSize); } /** @@ -853,7 +840,7 @@ public static void initialiseTailWithTermId( */ public static int termId(final long rawTail) { - return (int) (rawTail >> 32); + return (int)(rawTail >> 32); } /** @@ -867,7 +854,7 @@ public static int termOffset(final long rawTail, final long termLength) { final long tail = rawTail & 0xFFFF_FFFFL; - return (int) Math.min(tail, termLength); + return (int)Math.min(tail, termLength); } /** @@ -878,7 +865,7 @@ public static int termOffset(final long rawTail, final long termLength) */ public static int termOffset(final long result) { - return (int) result; + return (int)result; } /** @@ -890,7 +877,7 @@ public static int termOffset(final long result) */ public static long packTail(final int termId, final int termOffset) { - return ((long) termId << 32) | termOffset; + return ((long)termId << 32) | termOffset; } /** @@ -1004,7 +991,7 @@ public static int positionBitsToShift(final int termBufferLength) /** * Compute frame length for a message that is fragmented into chunks of {@code maxPayloadSize}. * - * @param length of the message. + * @param length of the message. * @param maxPayloadSize fragment size without the header. * @return message length after fragmentation. */ @@ -1021,7 +1008,7 @@ public static int computeFragmentedFrameLength(final int length, final int maxPa /** * Compute frame length for a message that has been reassembled from chunks of {@code maxPayloadSize}. * - * @param length of the message. + * @param length of the message. * @param maxPayloadSize fragment size without the header. * @return message length after fragmentation. */ @@ -1074,7 +1061,7 @@ public static boolean isSparse(final UnsafeBuffer metadataBuffer) */ public static void isSparse(final UnsafeBuffer metadataBuffer, final boolean value) { - metadataBuffer.putByte(LOG_IS_SPARSE_OFFSET, (byte) (value ? 1 : 0)); + metadataBuffer.putByte(LOG_IS_SPARSE_OFFSET, (byte)(value ? 1 : 0)); } /** @@ -1096,7 +1083,7 @@ public static boolean isTether(final UnsafeBuffer metadataBuffer) */ public static void isTether(final UnsafeBuffer metadataBuffer, final boolean value) { - metadataBuffer.putByte(LOG_IS_TETHER_OFFSET, (byte) (value ? 1 : 0)); + metadataBuffer.putByte(LOG_IS_TETHER_OFFSET, (byte)(value ? 1 : 0)); } /** @@ -1118,7 +1105,7 @@ public static boolean isRejoin(final UnsafeBuffer metadataBuffer) */ public static void isRejoin(final UnsafeBuffer metadataBuffer, final boolean value) { - metadataBuffer.putByte(LOG_IS_REJOIN_OFFSET, (byte) (value ? 1 : 0)); + metadataBuffer.putByte(LOG_IS_REJOIN_OFFSET, (byte)(value ? 1 : 0)); } /** @@ -1140,7 +1127,7 @@ public static boolean isReliable(final UnsafeBuffer metadataBuffer) */ public static void isReliable(final UnsafeBuffer metadataBuffer, final boolean value) { - metadataBuffer.putByte(LOG_IS_RELIABLE_OFFSET, (byte) (value ? 1 : 0)); + metadataBuffer.putByte(LOG_IS_RELIABLE_OFFSET, (byte)(value ? 1 : 0)); } /** @@ -1275,28 +1262,6 @@ public static void untetheredRestingTimeoutNs(final UnsafeBuffer metadataBuffer, metadataBuffer.putLong(LOG_UNTETHERED_RESTING_TIMEOUT_NS_OFFSET, value); } - /** - * Get whether the log group is enabled from the metadata. - * - * @param metadataBuffer containing the meta data. - * @return true if the log group is enabled, otherwise false. - */ - public static boolean group(final UnsafeBuffer metadataBuffer) - { - return metadataBuffer.getInt(LOG_GROUP_OFFSET) == 1; - } - - /** - * Set whether the log group is enabled in the metadata. - * - * @param metadataBuffer containing the meta data. - * @param value true if the log group is enabled, otherwise false. - */ - public static void group(final UnsafeBuffer metadataBuffer, final boolean value) - { - metadataBuffer.putInt(LOG_GROUP_OFFSET, value ? 1 : 0); - } - /** * Get the maximum resend count from the metadata. * @@ -1360,7 +1325,7 @@ public static boolean signalEos(final UnsafeBuffer metadataBuffer) */ public static void signalEos(final UnsafeBuffer metadataBuffer, final boolean value) { - metadataBuffer.putByte(LOG_SIGNAL_EOS_OFFSET, (byte) (value ? 1 : 0)); + metadataBuffer.putByte(LOG_SIGNAL_EOS_OFFSET, (byte)(value ? 1 : 0)); } /** @@ -1382,6 +1347,6 @@ public static boolean spiesSimulateConnection(final UnsafeBuffer metadataBuffer) */ public static void spiesSimulateConnection(final UnsafeBuffer metadataBuffer, final boolean value) { - metadataBuffer.putByte(LOG_SPIES_SIMULATE_CONNECTION_OFFSET, (byte) (value ? 1 : 0)); + metadataBuffer.putByte(LOG_SPIES_SIMULATE_CONNECTION_OFFSET, (byte)(value ? 1 : 0)); } } diff --git a/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java b/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java index 8d3b048b52..f587c48be8 100644 --- a/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java +++ b/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java @@ -1914,8 +1914,6 @@ private void initLogMetadata( final boolean spiesSimulateConnection, final RawLog rawLog) { - // peter - final UnsafeBuffer logMetaData = rawLog.metaData(); defaultDataHeader.sessionId(sessionId).streamId(streamId).termId(initialTermId); @@ -1927,7 +1925,6 @@ private void initLogMetadata( pageSize(logMetaData, ctx.filePageSize()); correlationId(logMetaData, registrationId); - // new termOffset(logMetaData, termOffset); socketRcvbufLength(logMetaData, socketRcvBufLength); socketSndbufLength(logMetaData, socketSndbufLength); @@ -1944,8 +1941,6 @@ private void initLogMetadata( signalEos(logMetaData, signalEos); spiesSimulateConnection(logMetaData, spiesSimulateConnection); -// channelUriStringBuilder.termId(params.termId); - // Acts like a release fence; so this should be the last statement. endOfStreamPosition(logMetaData, Long.MAX_VALUE); } diff --git a/aeron-driver/src/main/java/io/aeron/driver/Main.java b/aeron-driver/src/main/java/io/aeron/driver/Main.java deleted file mode 100644 index bd67f8cf77..0000000000 --- a/aeron-driver/src/main/java/io/aeron/driver/Main.java +++ /dev/null @@ -1,130 +0,0 @@ -package io.aeron.driver; - -import io.aeron.Aeron; -import io.aeron.ChannelUriStringBuilder; -import io.aeron.Publication; -import io.aeron.Subscription; -import io.aeron.driver.media.ReceiveChannelEndpoint; -import io.aeron.logbuffer.FragmentHandler; -import org.agrona.concurrent.UnsafeBuffer; - -import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; - -import static io.aeron.CommonContext.InferableBoolean.FORCE_TRUE; -import static io.aeron.CommonContext.InferableBoolean.INFER; - -// todo: will be removed in final commit. -public class Main -{ - - private static final String CHANNEL = "aeron:udp?endpoint=localhost:40123"; - private static final int STREAM_ID = 1001; - - public static void main(String[] args) - { - // Start an embedded MediaDriver - MediaDriver mediaDriver = MediaDriver.launchEmbedded(); - - // Aeron context using the embedded driver's directory - Aeron.Context ctx = new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()); - - // Start Aeron - Aeron aeron = Aeron.connect(ctx); - - // Start the server in a separate thread - Thread serverThread = new Thread(() -> runServer(aeron)); - serverThread.start(); - - // Start the client - runClient(aeron); - - // Clean up - try - { - serverThread.join(); - } - catch (InterruptedException e) - { - Thread.currentThread().interrupt(); - } - finally - { - aeron.close(); - mediaDriver.close(); - } - } - - private static void runServer(Aeron aeron) - { - try (Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID)) - { - System.out.println("Server started. Listening on channel: " + CHANNEL + ", stream ID: " + STREAM_ID); - - FragmentHandler fragmentHandler = (buffer, offset, length, header) -> - { - String message = buffer.getStringWithoutLengthUtf8(offset, length); - System.out.println("Server received message: " + message); - }; - - while (!Thread.currentThread().isInterrupted()) - { - int fragmentsRead = subscription.poll(fragmentHandler, 10); - if (fragmentsRead == 0) - { - Thread.onSpinWait(); - } - } - } - } - - private static void runClient(Aeron aeron) - { - try (Publication publication = aeron.addPublication(CHANNEL, STREAM_ID)) - { - String message = "Hello from the client!"; - byte[] messageBytes = message.getBytes(StandardCharsets.UTF_8); - - // Wrap the byte array in an UnsafeBuffer - UnsafeBuffer buffer = new UnsafeBuffer(ByteBuffer.allocateDirect(messageBytes.length)); - buffer.putBytes(0, messageBytes); - - while (true) - { - long result = publication.offer(buffer, 0, messageBytes.length); - if (result > 0) - { - System.out.println("Client sent message: " + message); - break; - } - else if (result == Publication.BACK_PRESSURED) - { - System.out.println("Client back pressured. Retrying..."); - } - else if (result == Publication.NOT_CONNECTED) - { - System.out.println("Client not connected to the subscription."); - } - else if (result == Publication.ADMIN_ACTION) - { - System.out.println("Publication is being administratively managed. Retrying..."); - } - else - { - System.out.println("Unexpected offer result: " + result); - } - - try - { - Thread.sleep(100); - } - catch (InterruptedException e) - { - throw new RuntimeException(e); - } - } - } - } - - -} From e6039b35568932b24fffabec72df8cbd80f62f40 Mon Sep 17 00:00:00 2001 From: Peter Veentjer Date: Mon, 30 Dec 2024 10:08:24 +0200 Subject: [PATCH 09/24] Moved as many fields as possible before the frame header --- .../aeron/logbuffer/LogBufferDescriptor.java | 69 +++++-------------- 1 file changed, 16 insertions(+), 53 deletions(-) diff --git a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java index f27594f099..d91f0e1d48 100644 --- a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java +++ b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java @@ -291,62 +291,28 @@ public class LogBufferDescriptor LOG_TERM_LENGTH_OFFSET = LOG_MTU_LENGTH_OFFSET + SIZE_OF_INT; LOG_PAGE_SIZE_OFFSET = LOG_TERM_LENGTH_OFFSET + SIZE_OF_INT; + LOG_TERM_OFFSET_OFFSET = LOG_PAGE_SIZE_OFFSET + SIZE_OF_INT; + LOG_SOCKET_RCVBUF_LENGTH_OFFSET = LOG_TERM_OFFSET_OFFSET + SIZE_OF_BYTE + 3; + LOG_SOCKET_SNDBUF_LENGTH_OFFSET = LOG_SOCKET_RCVBUF_LENGTH_OFFSET + SIZE_OF_INT; + LOG_RECEIVER_WINDOW_LENGTH_OFFSET = LOG_SOCKET_SNDBUF_LENGTH_OFFSET + SIZE_OF_INT; + LOG_PUBLICATION_WINDOW_LENGTH_OFFSET = LOG_RECEIVER_WINDOW_LENGTH_OFFSET + SIZE_OF_INT; + LOG_SPIES_SIMULATE_CONNECTION_OFFSET = LOG_PUBLICATION_WINDOW_LENGTH_OFFSET + SIZE_OF_INT; + LOG_MAX_RESEND_OFFSET = LOG_SPIES_SIMULATE_CONNECTION_OFFSET+SIZE_OF_INT; + + LOG_IS_SPARSE_OFFSET = LOG_MAX_RESEND_OFFSET + SIZE_OF_INT; + LOG_IS_TETHER_OFFSET = LOG_IS_SPARSE_OFFSET + SIZE_OF_BYTE; + LOG_IS_REJOIN_OFFSET = LOG_IS_TETHER_OFFSET + SIZE_OF_BYTE; + LOG_IS_RELIABLE_OFFSET = LOG_IS_REJOIN_OFFSET + SIZE_OF_BYTE; + LOG_SIGNAL_EOS_OFFSET = LOG_IS_RELIABLE_OFFSET + SIZE_OF_BYTE; + + // the last 3 bytes of the current cache line are not used. + offset += CACHE_LINE_LENGTH; LOG_DEFAULT_FRAME_HEADER_OFFSET = offset; offset += LOG_DEFAULT_FRAME_HEADER_MAX_LENGTH; - LOG_TERM_OFFSET_OFFSET = offset; - offset += SIZE_OF_INT; - - LOG_IS_SPARSE_OFFSET = offset; - offset += SIZE_OF_BYTE; - - LOG_IS_TETHER_OFFSET = offset; - offset += SIZE_OF_BYTE; - - LOG_IS_REJOIN_OFFSET = offset; - offset += SIZE_OF_BYTE; - - LOG_IS_RELIABLE_OFFSET = offset; - offset += SIZE_OF_BYTE; - - LOG_SIGNAL_EOS_OFFSET = offset; - offset += SIZE_OF_BYTE; - - // padding to ensure 4 byte aligned. - offset += 3; - - // todo: will be removed - if (offset % 4 != 0) - { - throw new Error("Bad alignment: offset=" + offset); - } - - LOG_SOCKET_RCVBUF_LENGTH_OFFSET = offset; - offset += SIZE_OF_INT; - - LOG_SOCKET_SNDBUF_LENGTH_OFFSET = offset; - offset += SIZE_OF_INT; - - LOG_RECEIVER_WINDOW_LENGTH_OFFSET = offset; - offset += SIZE_OF_INT; - - LOG_PUBLICATION_WINDOW_LENGTH_OFFSET = offset; - offset += SIZE_OF_INT; - - LOG_MAX_RESEND_OFFSET = offset; - offset += SIZE_OF_INT; - LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET = offset; - - // todo: This will be removed - // It is temporary here to ensure that all fields are naturally aligned. - if ((LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET % SIZE_OF_LONG) != 0) - { - throw new Error("LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET should be 8 bytes aligned, value: " + - LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET); - } offset += SIZE_OF_LONG; LOG_UNTETHERED_RESTING_TIMEOUT_NS_OFFSET = offset; @@ -355,9 +321,6 @@ public class LogBufferDescriptor LOG_LINGER_TIMEOUT_NS_OFFSET = offset; offset += SIZE_OF_LONG; - LOG_SPIES_SIMULATE_CONNECTION_OFFSET = offset; - offset += SIZE_OF_INT; - LOG_META_DATA_LENGTH = align(offset, PAGE_MIN_SIZE); } From b5cf57cf03bee048bf187bffac3e1cf4b9df5d8d Mon Sep 17 00:00:00 2001 From: Peter Veentjer Date: Mon, 30 Dec 2024 11:03:17 +0200 Subject: [PATCH 10/24] Checkstyle fixes --- .../aeron/logbuffer/LogBufferDescriptor.java | 34 ++----------------- .../java/io/aeron/driver/DriverConductor.java | 13 +++---- 2 files changed, 10 insertions(+), 37 deletions(-) diff --git a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java index d91f0e1d48..fd913eec7e 100644 --- a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java +++ b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java @@ -140,12 +140,6 @@ public class LogBufferDescriptor */ public static final int LOG_DEFAULT_FRAME_HEADER_MAX_LENGTH = CACHE_LINE_LENGTH * 2; - - /** - * Offset within the log metadata where the term offset is stored. - */ - public static final int LOG_TERM_OFFSET_OFFSET; - /** * Offset within the log metadata where the sparse property is stored. */ @@ -291,13 +285,12 @@ public class LogBufferDescriptor LOG_TERM_LENGTH_OFFSET = LOG_MTU_LENGTH_OFFSET + SIZE_OF_INT; LOG_PAGE_SIZE_OFFSET = LOG_TERM_LENGTH_OFFSET + SIZE_OF_INT; - LOG_TERM_OFFSET_OFFSET = LOG_PAGE_SIZE_OFFSET + SIZE_OF_INT; - LOG_SOCKET_RCVBUF_LENGTH_OFFSET = LOG_TERM_OFFSET_OFFSET + SIZE_OF_BYTE + 3; + LOG_SOCKET_RCVBUF_LENGTH_OFFSET = LOG_PAGE_SIZE_OFFSET + SIZE_OF_INT; LOG_SOCKET_SNDBUF_LENGTH_OFFSET = LOG_SOCKET_RCVBUF_LENGTH_OFFSET + SIZE_OF_INT; LOG_RECEIVER_WINDOW_LENGTH_OFFSET = LOG_SOCKET_SNDBUF_LENGTH_OFFSET + SIZE_OF_INT; LOG_PUBLICATION_WINDOW_LENGTH_OFFSET = LOG_RECEIVER_WINDOW_LENGTH_OFFSET + SIZE_OF_INT; LOG_SPIES_SIMULATE_CONNECTION_OFFSET = LOG_PUBLICATION_WINDOW_LENGTH_OFFSET + SIZE_OF_INT; - LOG_MAX_RESEND_OFFSET = LOG_SPIES_SIMULATE_CONNECTION_OFFSET+SIZE_OF_INT; + LOG_MAX_RESEND_OFFSET = LOG_SPIES_SIMULATE_CONNECTION_OFFSET + SIZE_OF_INT; LOG_IS_SPARSE_OFFSET = LOG_MAX_RESEND_OFFSET + SIZE_OF_INT; LOG_IS_TETHER_OFFSET = LOG_IS_SPARSE_OFFSET + SIZE_OF_BYTE; @@ -305,7 +298,7 @@ public class LogBufferDescriptor LOG_IS_RELIABLE_OFFSET = LOG_IS_REJOIN_OFFSET + SIZE_OF_BYTE; LOG_SIGNAL_EOS_OFFSET = LOG_IS_RELIABLE_OFFSET + SIZE_OF_BYTE; - // the last 3 bytes of the current cache line are not used. + // the last 7 bytes of the current cache line are not used. offset += CACHE_LINE_LENGTH; LOG_DEFAULT_FRAME_HEADER_OFFSET = offset; @@ -983,27 +976,6 @@ public static int computeAssembledFrameLength(final int length, final int maxPay return HEADER_LENGTH + (numMaxPayloads * maxPayloadSize) + remainingPayload; } - /** - * Get the term offset from the log metadata. - * - * @param metadataBuffer containing the meta data. - * @return the term offset. - */ - public static int termOffset(final UnsafeBuffer metadataBuffer) - { - return metadataBuffer.getInt(LOG_TERM_OFFSET_OFFSET); - } - - /** - * Set the term offset in the log metadata. - * - * @param metadataBuffer containing the meta data. - * @param value the term offset to set. - */ - public static void termOffset(final UnsafeBuffer metadataBuffer, final int value) - { - metadataBuffer.putInt(LOG_TERM_OFFSET_OFFSET, value); - } /** * Get whether the log is sparse from the metadata. diff --git a/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java b/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java index f587c48be8..c0318b520e 100644 --- a/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java +++ b/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java @@ -1916,7 +1916,7 @@ private void initLogMetadata( { final UnsafeBuffer logMetaData = rawLog.metaData(); - defaultDataHeader.sessionId(sessionId).streamId(streamId).termId(initialTermId); + defaultDataHeader.sessionId(sessionId).streamId(streamId).termId(initialTermId).termOffset(termOffset); storeDefaultFrameHeader(logMetaData, defaultDataHeader); initialTermId(logMetaData, initialTermId); @@ -1925,21 +1925,22 @@ private void initLogMetadata( pageSize(logMetaData, ctx.filePageSize()); correlationId(logMetaData, registrationId); - termOffset(logMetaData, termOffset); socketRcvbufLength(logMetaData, socketRcvBufLength); socketSndbufLength(logMetaData, socketSndbufLength); receiverWindowLength(logMetaData, receiverWindowLength); + publicationWindowLength(logMetaData, publicationWindowLength); + maxResend(logMetaData, maxResend); + spiesSimulateConnection(logMetaData, spiesSimulateConnection); + isTether(logMetaData, tether); isRejoin(logMetaData, rejoin); isReliable(logMetaData, reliable); isSparse(logMetaData, sparse); - publicationWindowLength(logMetaData, publicationWindowLength); + signalEos(logMetaData, signalEos); + untetheredWindowLimitTimeoutNs(logMetaData, untetheredWindowLimitTimeoutNs); untetheredRestingTimeoutNs(logMetaData, untetheredRestingTimeoutNs); - maxResend(logMetaData, maxResend); lingerTimeoutNs(logMetaData, lingerTimeoutNs); - signalEos(logMetaData, signalEos); - spiesSimulateConnection(logMetaData, spiesSimulateConnection); // Acts like a release fence; so this should be the last statement. endOfStreamPosition(logMetaData, Long.MAX_VALUE); From ee988649a1b6163164a0985267416b0dc63ff647 Mon Sep 17 00:00:00 2001 From: Peter Veentjer Date: Tue, 31 Dec 2024 09:46:56 +0200 Subject: [PATCH 11/24] Lot of minor improvements --- .../c/concurrent/aeron_logbuffer_descriptor.h | 130 +++++++++++++++++- .../aeron/logbuffer/LogBufferDescriptor.java | 100 +++++++++++++- .../src/main/java/io/aeron/driver/Main.java | 94 +++++++++++++ 3 files changed, 316 insertions(+), 8 deletions(-) create mode 100644 aeron-driver/src/main/java/io/aeron/driver/Main.java diff --git a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h index e7c9bd2434..3ec2f22558 100644 --- a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h +++ b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h @@ -33,6 +33,10 @@ #define AERON_MAX_UDP_PAYLOAD_LENGTH (65504) +#ifdef _MSC_VER +#define _Static_assert static_assert +#endif + #pragma pack(push) #pragma pack(4) typedef struct aeron_logbuffer_metadata_stct @@ -50,11 +54,135 @@ typedef struct aeron_logbuffer_metadata_stct int32_t mtu_length; int32_t term_length; int32_t page_size; - uint8_t pad3[(AERON_CACHE_LINE_LENGTH) - (7 * sizeof(int32_t))]; + + // new fields since Aeron 1.47.0 + int32_t socket_rcvbuf_length; + int32_t socket_sndbuf_length; + int32_t receiver_window_length; + int32_t publication_window_length; + int32_t max_resend; + + uint8_t sparse; + uint8_t tether; + uint8_t rejoin; + uint8_t reliable; + uint8_t signal_eos; + uint8_t spies_simulate_connection; + + uint8_t pad3[3]; + int64_t linger_timeout_ns; + + uint8_t default_header[AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH]; + + int64_t untethered_window_limit_timeout_ns; + int64_t untethered_resting_timeout_ns; + +// int64_t entity_tag; +// int64_t response_correlation_id; +// uint8_t group; +// uint8_t is_response; + + // todo: is this padding correct + + uint8_t pad4[(AERON_CACHE_LINE_LENGTH) - (7 * sizeof(int32_t))]; } aeron_logbuffer_metadata_t; #pragma pack(pop) +//_Static_assert( +// offsetof(aeron_logbuffer_metadata_t, term_tail_counters) == 0, +// "offsetof(aeron_logbuffer_metadata_t, term_tail_counters) is wrong"); +//_Static_assert( +// offsetof(aeron_logbuffer_metadata_t, active_term_count) == 24, +// "offsetof(aeron_logbuffer_metadata_t, active_term_count) is wrong"); +//_Static_assert( +// offsetof(aeron_logbuffer_metadata_t, end_of_stream_position) == 128, +// "offsetof(aeron_logbuffer_metadata_t, end_of_stream_position) is wrong"); +//_Static_assert( +// offsetof(aeron_logbuffer_metadata_t, is_connected) == 136, +// "offsetof(aeron_logbuffer_metadata_t, is_connected) is wrong"); +//_Static_assert( +// offsetof(aeron_logbuffer_metadata_t, active_transport_count) == 140, +// "offsetof(aeron_logbuffer_metadata_t, active_transport_count) is wrong"); +//_Static_assert( +// offsetof(aeron_logbuffer_metadata_t, correlation_id) == 256, +// "offsetof(aeron_logbuffer_metadata_t, correlation_id) is wrong"); +//_Static_assert( +// offsetof(aeron_logbuffer_metadata_t, initial_term_id) == 264, +// "offsetof(aeron_logbuffer_metadata_t, initial_term_id) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, default_frame_header_length) == 268, + "offsetof(aeron_logbuffer_metadata_t, default_frame_header_length) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, mtu_length) == 272, + "offsetof(aeron_logbuffer_metadata_t, mtu_length) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, term_length) == 276, + "offsetof(aeron_logbuffer_metadata_t, term_length) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, page_size) == 280, + "offsetof(aeron_logbuffer_metadata_t, page_size) is wrong"); + +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, socket_rcvbuf_length) == 284, + "offsetof(aeron_logbuffer_metadata_t, socket_rcvbuf_length) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, socket_sndbuf_length) == 288, + "offsetof(aeron_logbuffer_metadata_t, socket_sndbuf_length) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, receiver_window_length) == 292, + "offsetof(aeron_logbuffer_metadata_t, receiver_window_length) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, publication_window_length) == 296, + "offsetof(aeron_logbuffer_metadata_t, publication_window_length) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, max_resend) == 300, + "offsetof(aeron_logbuffer_metadata_t, max_resend) is wrong"); + +//_Static_assert( +// offsetof(aeron_logbuffer_metadata_t, linger_timeout_ns) == 312, +// "offsetof(aeron_logbuffer_metadata_t, linger_timeout_ns) is wrong"); + +//_Static_assert( +// offsetof(aeron_logbuffer_metadata_t, default_header) == 320, +// "offsetof(aeron_logbuffer_metadata_t, default_header) is wrong"); +//_Static_assert( +// AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH >= AERON_DATA_HEADER_LENGTH, +// "AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH < AERON_DATA_HEADER_LENGTH"); +//_Static_assert( +// offsetof(aeron_logbuffer_metadata_t, untethered_window_limit_timeout_ns) == 456, +// "offsetof(aeron_logbuffer_metadata_t, untethered_window_limit_timeout_ns) is wrong"); +//_Static_assert( +// offsetof(aeron_logbuffer_metadata_t, untethered_resting_timeout_ns) == 464, +// "offsetof(aeron_logbuffer_metadata_t, untethered_resting_timeout_ns) is wrong"); +//_Static_assert( +// offsetof(aeron_logbuffer_metadata_t, group) == 472, +// "offsetof(aeron_logbuffer_metadata_t, group) is wrong"); +//_Static_assert( +// offsetof(aeron_logbuffer_metadata_t, is_response) == 473, +// "offsetof(aeron_logbuffer_metadata_t, is_response) is wrong"); +//_Static_assert( +// offsetof(aeron_logbuffer_metadata_t, rejoin) == 474, +// "offsetof(aeron_logbuffer_metadata_t, rejoin) is wrong"); +//_Static_assert( +// offsetof(aeron_logbuffer_metadata_t, reliable) == 475, +// "offsetof(aeron_logbuffer_metadata_t, reliable) is wrong"); +//_Static_assert( +// offsetof(aeron_logbuffer_metadata_t, sparse) == 476, +// "offsetof(aeron_logbuffer_metadata_t, sparse) is wrong"); +//_Static_assert( +// offsetof(aeron_logbuffer_metadata_t, signal_eos) == 477, +// "offsetof(aeron_logbuffer_metadata_t, signal_eos) is wrong"); +//_Static_assert( +// offsetof(aeron_logbuffer_metadata_t, spies_simulate_connection) == 478, +// "offsetof(aeron_logbuffer_metadata_t, spies_simulate_connection) is wrong"); +//_Static_assert( +// offsetof(aeron_logbuffer_metadata_t, tether) == 479, +// "offsetof(aeron_logbuffer_metadata_t, tether) is wrong"); +//_Static_assert( +// sizeof(aeron_logbuffer_metadata_t) == 480, +// "sizeof(aeron_logbuffer_metadata_t) is wrong") + #define AERON_LOGBUFFER_META_DATA_LENGTH \ (AERON_ALIGN((sizeof(aeron_logbuffer_metadata_t) + AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH), AERON_PAGE_MIN_SIZE)) diff --git a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java index fd913eec7e..f150c0fe62 100644 --- a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java +++ b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java @@ -253,12 +253,43 @@ public class LogBufferDescriptor * +---------------------------------------------------------------+ * | Page Size | * +---------------------------------------------------------------+ + * | Socket Receive Buffer Length | + * +---------------------------------------------------------------+ + * | Socket Send Buffer Length | + * +---------------------------------------------------------------+ + * | Receiver Window Length | + * +---------------------------------------------------------------+ + * | Publication Window Length | + * +---------------------------------------------------------------+ + * | Maximum Resend | + * +---------------------------------------------------------------+ + * | Is Sparse | + * +---------------------------------------------------------------+ + * | Is Tether | + * +---------------------------------------------------------------+ + * | Is Rejoin | + * +---------------------------------------------------------------+ + * | Is Reliable | + * +---------------------------------------------------------------+ + * | Signal EOS | + * +---------------------------------------------------------------+ + * | Spies Simulate Connection | + * +---------------------------------------------------------------+ + * | Linger Timeout (ns) | + * | | + * +---------------------------------------------------------------+ * | Cache Line Padding ... * ... | * +---------------------------------------------------------------+ * | Default Frame Header ... * ... | * +---------------------------------------------------------------+ + * | Untethered Window Limit Timeout (ns) | + * | | + * +---------------------------------------------------------------+ + * | Untethered Resting Timeout (ns) | + * | | + * +---------------------------------------------------------------+ * //todo: Add the missing fields. * */ @@ -278,6 +309,9 @@ public class LogBufferDescriptor LOG_ACTIVE_TRANSPORT_COUNT = LOG_IS_CONNECTED_OFFSET + SIZE_OF_INT; offset += (CACHE_LINE_LENGTH * 2); + + int targetOffset = offset + CACHE_LINE_LENGTH; + LOG_CORRELATION_ID_OFFSET = offset; LOG_INITIAL_TERM_ID_OFFSET = LOG_CORRELATION_ID_OFFSET + SIZE_OF_LONG; LOG_DEFAULT_FRAME_HEADER_LENGTH_OFFSET = LOG_INITIAL_TERM_ID_OFFSET + SIZE_OF_INT; @@ -285,24 +319,79 @@ public class LogBufferDescriptor LOG_TERM_LENGTH_OFFSET = LOG_MTU_LENGTH_OFFSET + SIZE_OF_INT; LOG_PAGE_SIZE_OFFSET = LOG_TERM_LENGTH_OFFSET + SIZE_OF_INT; + // new fields LOG_SOCKET_RCVBUF_LENGTH_OFFSET = LOG_PAGE_SIZE_OFFSET + SIZE_OF_INT; LOG_SOCKET_SNDBUF_LENGTH_OFFSET = LOG_SOCKET_RCVBUF_LENGTH_OFFSET + SIZE_OF_INT; LOG_RECEIVER_WINDOW_LENGTH_OFFSET = LOG_SOCKET_SNDBUF_LENGTH_OFFSET + SIZE_OF_INT; LOG_PUBLICATION_WINDOW_LENGTH_OFFSET = LOG_RECEIVER_WINDOW_LENGTH_OFFSET + SIZE_OF_INT; - LOG_SPIES_SIMULATE_CONNECTION_OFFSET = LOG_PUBLICATION_WINDOW_LENGTH_OFFSET + SIZE_OF_INT; - LOG_MAX_RESEND_OFFSET = LOG_SPIES_SIMULATE_CONNECTION_OFFSET + SIZE_OF_INT; + LOG_MAX_RESEND_OFFSET = LOG_PUBLICATION_WINDOW_LENGTH_OFFSET + SIZE_OF_INT; LOG_IS_SPARSE_OFFSET = LOG_MAX_RESEND_OFFSET + SIZE_OF_INT; LOG_IS_TETHER_OFFSET = LOG_IS_SPARSE_OFFSET + SIZE_OF_BYTE; LOG_IS_REJOIN_OFFSET = LOG_IS_TETHER_OFFSET + SIZE_OF_BYTE; LOG_IS_RELIABLE_OFFSET = LOG_IS_REJOIN_OFFSET + SIZE_OF_BYTE; LOG_SIGNAL_EOS_OFFSET = LOG_IS_RELIABLE_OFFSET + SIZE_OF_BYTE; - - // the last 7 bytes of the current cache line are not used. + LOG_SPIES_SIMULATE_CONNECTION_OFFSET = LOG_IS_RELIABLE_OFFSET + SIZE_OF_BYTE; + + int startNewOffset = LOG_PAGE_SIZE_OFFSET+SIZE_OF_INT; + int totalSpace = CACHE_LINE_LENGTH; + int initialConsumed = LOG_PAGE_SIZE_OFFSET+SIZE_OF_INT-LOG_CORRELATION_ID_OFFSET; + int initialRemaining = CACHE_LINE_LENGTH-initialConsumed; + int endNewOffset = LOG_SPIES_SIMULATE_CONNECTION_OFFSET+SIZE_OF_BYTE; + int newUsed = endNewOffset-startNewOffset; + int newRemaining = initialRemaining-newUsed; + + System.out.println("totalSpace:"+totalSpace+ " bytes"); + System.out.println("initialConsumed:"+initialConsumed+ " bytes"); + System.out.println("initialRemaining:"+initialRemaining+ " bytes"); + System.out.println("new Used:"+newUsed+ " bytes"); + System.out.println("new remanining:"+newRemaining+ " bytes"); + + // then 3 bytes of padding + LOG_LINGER_TIMEOUT_NS_OFFSET = LOG_SPIES_SIMULATE_CONNECTION_OFFSET+SIZE_OF_BYTE+3; + + // Grouped output with alignment checks + System.out.println("LOG_CORRELATION_ID_OFFSET = " + LOG_CORRELATION_ID_OFFSET + + " (alignment = " + SIZE_OF_LONG + ", isAligned = " + (LOG_CORRELATION_ID_OFFSET % SIZE_OF_LONG == 0) + ")"); + System.out.println("LOG_INITIAL_TERM_ID_OFFSET = " + LOG_INITIAL_TERM_ID_OFFSET + + " (alignment = " + SIZE_OF_INT + ", isAligned = " + (LOG_INITIAL_TERM_ID_OFFSET % SIZE_OF_INT == 0) + ")"); + System.out.println("LOG_DEFAULT_FRAME_HEADER_LENGTH_OFFSET = " + LOG_DEFAULT_FRAME_HEADER_LENGTH_OFFSET + + " (alignment = " + SIZE_OF_INT + ", isAligned = " + (LOG_DEFAULT_FRAME_HEADER_LENGTH_OFFSET % SIZE_OF_INT == 0) + ")"); + System.out.println("LOG_MTU_LENGTH_OFFSET = " + LOG_MTU_LENGTH_OFFSET + + " (alignment = " + SIZE_OF_INT + ", isAligned = " + (LOG_MTU_LENGTH_OFFSET % SIZE_OF_INT == 0) + ")"); + System.out.println("LOG_TERM_LENGTH_OFFSET = " + LOG_TERM_LENGTH_OFFSET + + " (alignment = " + SIZE_OF_INT + ", isAligned = " + (LOG_TERM_LENGTH_OFFSET % SIZE_OF_INT == 0) + ")"); + System.out.println("LOG_PAGE_SIZE_OFFSET = " + LOG_PAGE_SIZE_OFFSET + + " (alignment = " + SIZE_OF_INT + ", isAligned = " + (LOG_PAGE_SIZE_OFFSET % SIZE_OF_INT == 0) + ")"); + System.out.println("LOG_SOCKET_RCVBUF_LENGTH_OFFSET = " + LOG_SOCKET_RCVBUF_LENGTH_OFFSET + + " (alignment = " + SIZE_OF_INT + ", isAligned = " + (LOG_SOCKET_RCVBUF_LENGTH_OFFSET % SIZE_OF_INT == 0) + ")"); + System.out.println("LOG_SOCKET_SNDBUF_LENGTH_OFFSET = " + LOG_SOCKET_SNDBUF_LENGTH_OFFSET + + " (alignment = " + SIZE_OF_INT + ", isAligned = " + (LOG_SOCKET_SNDBUF_LENGTH_OFFSET % SIZE_OF_INT == 0) + ")"); + System.out.println("LOG_RECEIVER_WINDOW_LENGTH_OFFSET = " + LOG_RECEIVER_WINDOW_LENGTH_OFFSET + + " (alignment = " + SIZE_OF_INT + ", isAligned = " + (LOG_RECEIVER_WINDOW_LENGTH_OFFSET % SIZE_OF_INT == 0) + ")"); + System.out.println("LOG_PUBLICATION_WINDOW_LENGTH_OFFSET = " + LOG_PUBLICATION_WINDOW_LENGTH_OFFSET + + " (alignment = " + SIZE_OF_INT + ", isAligned = " + (LOG_PUBLICATION_WINDOW_LENGTH_OFFSET % SIZE_OF_INT == 0) + ")"); + System.out.println("LOG_MAX_RESEND_OFFSET = " + LOG_MAX_RESEND_OFFSET + + " (alignment = " + SIZE_OF_INT + ", isAligned = " + (LOG_MAX_RESEND_OFFSET % SIZE_OF_INT == 0) + ")"); + + System.out.println("LOG_IS_SPARSE_OFFSET = " + LOG_IS_SPARSE_OFFSET); + System.out.println("LOG_IS_TETHER_OFFSET = " + LOG_IS_TETHER_OFFSET); + System.out.println("LOG_IS_REJOIN_OFFSET = " + LOG_IS_REJOIN_OFFSET); + System.out.println("LOG_IS_RELIABLE_OFFSET = " + LOG_IS_RELIABLE_OFFSET); + System.out.println("LOG_SIGNAL_EOS_OFFSET = " + LOG_SIGNAL_EOS_OFFSET); + System.out.println("LOG_SPIES_SIMULATE_CONNECTION_OFFSET = " + LOG_SPIES_SIMULATE_CONNECTION_OFFSET); + System.out.println("LOG_LINGER_TIMEOUT_NS_OFFSET = " + LOG_LINGER_TIMEOUT_NS_OFFSET + + " (alignment = " + SIZE_OF_LONG + ", isAligned = " + (LOG_LINGER_TIMEOUT_NS_OFFSET % SIZE_OF_LONG == 0) + ")"); offset += CACHE_LINE_LENGTH; + LOG_DEFAULT_FRAME_HEADER_OFFSET = offset; + System.out.println("LOG_PAGE_SIZE_OFFSET:"+LOG_PAGE_SIZE_OFFSET); + System.out.println("LOG_DEFAULT_FRAME_HEADER_OFFSET:"+LOG_DEFAULT_FRAME_HEADER_OFFSET); + System.out.println("Start offset:"+LOG_PAGE_SIZE_OFFSET+SIZE_OF_INT); + System.out.println("Available:"+(LOG_DEFAULT_FRAME_HEADER_OFFSET-LOG_PAGE_SIZE_OFFSET-SIZE_OF_INT)); + offset += LOG_DEFAULT_FRAME_HEADER_MAX_LENGTH; LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET = offset; @@ -311,9 +400,6 @@ public class LogBufferDescriptor LOG_UNTETHERED_RESTING_TIMEOUT_NS_OFFSET = offset; offset += SIZE_OF_LONG; - LOG_LINGER_TIMEOUT_NS_OFFSET = offset; - offset += SIZE_OF_LONG; - LOG_META_DATA_LENGTH = align(offset, PAGE_MIN_SIZE); } diff --git a/aeron-driver/src/main/java/io/aeron/driver/Main.java b/aeron-driver/src/main/java/io/aeron/driver/Main.java new file mode 100644 index 0000000000..83e76be36b --- /dev/null +++ b/aeron-driver/src/main/java/io/aeron/driver/Main.java @@ -0,0 +1,94 @@ +package io.aeron.driver; + +import io.aeron.Aeron; +import io.aeron.Subscription; +import io.aeron.Publication; +import io.aeron.driver.MediaDriver; +import org.agrona.CloseHelper; +import org.agrona.concurrent.BackoffIdleStrategy; +import org.agrona.concurrent.IdleStrategy; +import org.agrona.concurrent.UnsafeBuffer; + +import java.nio.charset.StandardCharsets; + +public class Main { + + private static final String CHANNEL = "aeron:udp?endpoint=localhost:40123"; + private static final int STREAM_ID = 1001; + private static final String MESSAGE = "Hello, Aeron!"; + + public static void main(String[] args) { + // Start an embedded Media Driver + MediaDriver.Context mediaDriverContext = new MediaDriver.Context(); + MediaDriver mediaDriver = MediaDriver.launchEmbedded(mediaDriverContext); + + Aeron.Context ctx = new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()); + try (Aeron aeron = Aeron.connect(ctx)) { + // Publisher thread + Thread publisherThread = new Thread(() -> runPublisher(aeron), "Publisher"); + + // Subscriber thread + Thread subscriberThread = new Thread(() -> runSubscriber(aeron), "Subscriber"); + + publisherThread.start(); + subscriberThread.start(); + + publisherThread.join(); + subscriberThread.join(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + e.printStackTrace(); + } finally { + CloseHelper.quietClose(mediaDriver); + } + } + + private static void runPublisher(Aeron aeron) { + try (Publication publication = aeron.addPublication(CHANNEL, STREAM_ID)) { + UnsafeBuffer buffer = new UnsafeBuffer(new byte[256]); + buffer.putStringWithoutLengthAscii(0, MESSAGE); + + while (!publication.isConnected()) { + System.out.println("Waiting for subscriber to connect..."); + Thread.sleep(100); + } + + long result; + do { + result = publication.offer(buffer); + if (result < 0) { + System.out.println("Offer failed: " + result); + Thread.sleep(10); + } + } while (result < 0); + + System.out.println("Message published: " + MESSAGE); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static void runSubscriber(Aeron aeron) { + IdleStrategy idleStrategy = new BackoffIdleStrategy(1, 1, 1, 1); + try (Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID)) { + while (!subscription.isConnected()) { + System.out.println("Waiting for publisher to connect..."); + Thread.sleep(100); + } + + while (true) { + int fragmentsRead = subscription.poll((buffer, offset, length, header) -> { + byte[] data = new byte[length]; + buffer.getBytes(offset, data); + String receivedMessage = new String(data, StandardCharsets.US_ASCII); + System.out.println("Received message: " + receivedMessage); + }, 10); + + idleStrategy.idle(fragmentsRead); + } + } catch (Exception e) { + e.printStackTrace(); + } + } +} + From b092c5f6d6e0a9bc8ad606b3bac9a2dd13bf8140 Mon Sep 17 00:00:00 2001 From: Peter Veentjer Date: Tue, 31 Dec 2024 10:10:42 +0200 Subject: [PATCH 12/24] More work on descriptor --- .../c/concurrent/aeron_logbuffer_descriptor.h | 87 +++++++++++-------- .../aeron/logbuffer/LogBufferDescriptor.java | 13 ++- 2 files changed, 60 insertions(+), 40 deletions(-) diff --git a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h index 3ec2f22558..cac876e4d4 100644 --- a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h +++ b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h @@ -69,7 +69,7 @@ typedef struct aeron_logbuffer_metadata_stct uint8_t signal_eos; uint8_t spies_simulate_connection; - uint8_t pad3[3]; + uint8_t pad3[2]; int64_t linger_timeout_ns; uint8_t default_header[AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH]; @@ -104,12 +104,12 @@ aeron_logbuffer_metadata_t; //_Static_assert( // offsetof(aeron_logbuffer_metadata_t, active_transport_count) == 140, // "offsetof(aeron_logbuffer_metadata_t, active_transport_count) is wrong"); -//_Static_assert( -// offsetof(aeron_logbuffer_metadata_t, correlation_id) == 256, -// "offsetof(aeron_logbuffer_metadata_t, correlation_id) is wrong"); -//_Static_assert( -// offsetof(aeron_logbuffer_metadata_t, initial_term_id) == 264, -// "offsetof(aeron_logbuffer_metadata_t, initial_term_id) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, correlation_id) == 256, + "offsetof(aeron_logbuffer_metadata_t, correlation_id) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, initial_term_id) == 264, + "offsetof(aeron_logbuffer_metadata_t, initial_term_id) is wrong"); _Static_assert( offsetof(aeron_logbuffer_metadata_t, default_frame_header_length) == 268, "offsetof(aeron_logbuffer_metadata_t, default_frame_header_length) is wrong"); @@ -139,50 +139,63 @@ _Static_assert( offsetof(aeron_logbuffer_metadata_t, max_resend) == 300, "offsetof(aeron_logbuffer_metadata_t, max_resend) is wrong"); -//_Static_assert( -// offsetof(aeron_logbuffer_metadata_t, linger_timeout_ns) == 312, -// "offsetof(aeron_logbuffer_metadata_t, linger_timeout_ns) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, sparse) == 304, + "offsetof(aeron_logbuffer_metadata_t, sparse) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, tether) == 305, + "offsetof(aeron_logbuffer_metadata_t, tether) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, rejoin) == 306, + "offsetof(aeron_logbuffer_metadata_t, rejoin) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, reliable) == 307, + "offsetof(aeron_logbuffer_metadata_t, reliable) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, signal_eos) == 308, + "offsetof(aeron_logbuffer_metadata_t, signal_eos) is wrong"); + +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, spies_simulate_connection) == 309, + "offsetof(aeron_logbuffer_metadata_t, spies_simulate_connection) is wrong"); + +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, linger_timeout_ns) == 312, + "offsetof(aeron_logbuffer_metadata_t, linger_timeout_ns) is wrong"); + +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, default_header) == 320, + "offsetof(aeron_logbuffer_metadata_t, default_header) is wrong"); + + -//_Static_assert( -// offsetof(aeron_logbuffer_metadata_t, default_header) == 320, -// "offsetof(aeron_logbuffer_metadata_t, default_header) is wrong"); //_Static_assert( // AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH >= AERON_DATA_HEADER_LENGTH, // "AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH < AERON_DATA_HEADER_LENGTH"); -//_Static_assert( -// offsetof(aeron_logbuffer_metadata_t, untethered_window_limit_timeout_ns) == 456, -// "offsetof(aeron_logbuffer_metadata_t, untethered_window_limit_timeout_ns) is wrong"); -//_Static_assert( -// offsetof(aeron_logbuffer_metadata_t, untethered_resting_timeout_ns) == 464, -// "offsetof(aeron_logbuffer_metadata_t, untethered_resting_timeout_ns) is wrong"); + + + //_Static_assert( // offsetof(aeron_logbuffer_metadata_t, group) == 472, // "offsetof(aeron_logbuffer_metadata_t, group) is wrong"); //_Static_assert( // offsetof(aeron_logbuffer_metadata_t, is_response) == 473, // "offsetof(aeron_logbuffer_metadata_t, is_response) is wrong"); -//_Static_assert( -// offsetof(aeron_logbuffer_metadata_t, rejoin) == 474, -// "offsetof(aeron_logbuffer_metadata_t, rejoin) is wrong"); -//_Static_assert( -// offsetof(aeron_logbuffer_metadata_t, reliable) == 475, -// "offsetof(aeron_logbuffer_metadata_t, reliable) is wrong"); -//_Static_assert( -// offsetof(aeron_logbuffer_metadata_t, sparse) == 476, -// "offsetof(aeron_logbuffer_metadata_t, sparse) is wrong"); -//_Static_assert( -// offsetof(aeron_logbuffer_metadata_t, signal_eos) == 477, -// "offsetof(aeron_logbuffer_metadata_t, signal_eos) is wrong"); -//_Static_assert( -// offsetof(aeron_logbuffer_metadata_t, spies_simulate_connection) == 478, -// "offsetof(aeron_logbuffer_metadata_t, spies_simulate_connection) is wrong"); -//_Static_assert( -// offsetof(aeron_logbuffer_metadata_t, tether) == 479, -// "offsetof(aeron_logbuffer_metadata_t, tether) is wrong"); + + +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, untethered_window_limit_timeout_ns) == 448, + "offsetof(aeron_logbuffer_metadata_t, untethered_window_limit_timeout_ns) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, untethered_resting_timeout_ns) == 456, + "offsetof(aeron_logbuffer_metadata_t, untethered_resting_timeout_ns) is wrong"); + //_Static_assert( // sizeof(aeron_logbuffer_metadata_t) == 480, // "sizeof(aeron_logbuffer_metadata_t) is wrong") + + #define AERON_LOGBUFFER_META_DATA_LENGTH \ (AERON_ALIGN((sizeof(aeron_logbuffer_metadata_t) + AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH), AERON_PAGE_MIN_SIZE)) diff --git a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java index f150c0fe62..5908783038 100644 --- a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java +++ b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java @@ -331,7 +331,7 @@ public class LogBufferDescriptor LOG_IS_REJOIN_OFFSET = LOG_IS_TETHER_OFFSET + SIZE_OF_BYTE; LOG_IS_RELIABLE_OFFSET = LOG_IS_REJOIN_OFFSET + SIZE_OF_BYTE; LOG_SIGNAL_EOS_OFFSET = LOG_IS_RELIABLE_OFFSET + SIZE_OF_BYTE; - LOG_SPIES_SIMULATE_CONNECTION_OFFSET = LOG_IS_RELIABLE_OFFSET + SIZE_OF_BYTE; + LOG_SPIES_SIMULATE_CONNECTION_OFFSET = LOG_SIGNAL_EOS_OFFSET + SIZE_OF_BYTE; int startNewOffset = LOG_PAGE_SIZE_OFFSET+SIZE_OF_INT; int totalSpace = CACHE_LINE_LENGTH; @@ -347,8 +347,8 @@ public class LogBufferDescriptor System.out.println("new Used:"+newUsed+ " bytes"); System.out.println("new remanining:"+newRemaining+ " bytes"); - // then 3 bytes of padding - LOG_LINGER_TIMEOUT_NS_OFFSET = LOG_SPIES_SIMULATE_CONNECTION_OFFSET+SIZE_OF_BYTE+3; + // then 2 bytes of padding + LOG_LINGER_TIMEOUT_NS_OFFSET = LOG_SPIES_SIMULATE_CONNECTION_OFFSET+SIZE_OF_BYTE+2; // Grouped output with alignment checks System.out.println("LOG_CORRELATION_ID_OFFSET = " + LOG_CORRELATION_ID_OFFSET + @@ -400,6 +400,13 @@ public class LogBufferDescriptor LOG_UNTETHERED_RESTING_TIMEOUT_NS_OFFSET = offset; offset += SIZE_OF_LONG; + + System.out.println("LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET = " + LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET + + " (alignment = " + SIZE_OF_LONG + ", isAligned = " + (LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET % SIZE_OF_INT == 0) + ")"); + System.out.println("LOG_UNTETHERED_RESTING_TIMEOUT_NS_OFFSET = " + LOG_UNTETHERED_RESTING_TIMEOUT_NS_OFFSET + + " (alignment = " + SIZE_OF_LONG + ", isAligned = " + (LOG_UNTETHERED_RESTING_TIMEOUT_NS_OFFSET % SIZE_OF_INT == 0) + ")"); + + LOG_META_DATA_LENGTH = align(offset, PAGE_MIN_SIZE); } From 8ee1291fad7448f2ea5d6781800654cb4fd84bb7 Mon Sep 17 00:00:00 2001 From: Peter Veentjer Date: Tue, 31 Dec 2024 13:27:07 +0200 Subject: [PATCH 13/24] More work log buffer descriptor --- .../c/concurrent/aeron_logbuffer_descriptor.h | 62 ++++++++----------- 1 file changed, 25 insertions(+), 37 deletions(-) diff --git a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h index cac876e4d4..6f87cc06ca 100644 --- a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h +++ b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h @@ -37,6 +37,10 @@ #define _Static_assert static_assert #endif +#ifdef __cplusplus +#define _Static_assert static_assert +#endif + #pragma pack(push) #pragma pack(4) typedef struct aeron_logbuffer_metadata_stct @@ -89,21 +93,21 @@ typedef struct aeron_logbuffer_metadata_stct aeron_logbuffer_metadata_t; #pragma pack(pop) -//_Static_assert( -// offsetof(aeron_logbuffer_metadata_t, term_tail_counters) == 0, -// "offsetof(aeron_logbuffer_metadata_t, term_tail_counters) is wrong"); -//_Static_assert( -// offsetof(aeron_logbuffer_metadata_t, active_term_count) == 24, -// "offsetof(aeron_logbuffer_metadata_t, active_term_count) is wrong"); -//_Static_assert( -// offsetof(aeron_logbuffer_metadata_t, end_of_stream_position) == 128, -// "offsetof(aeron_logbuffer_metadata_t, end_of_stream_position) is wrong"); -//_Static_assert( -// offsetof(aeron_logbuffer_metadata_t, is_connected) == 136, -// "offsetof(aeron_logbuffer_metadata_t, is_connected) is wrong"); -//_Static_assert( -// offsetof(aeron_logbuffer_metadata_t, active_transport_count) == 140, -// "offsetof(aeron_logbuffer_metadata_t, active_transport_count) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, term_tail_counters) == 0, + "offsetof(aeron_logbuffer_metadata_t, term_tail_counters) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, active_term_count) == 24, + "offsetof(aeron_logbuffer_metadata_t, active_term_count) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, end_of_stream_position) == 128, + "offsetof(aeron_logbuffer_metadata_t, end_of_stream_position) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, is_connected) == 136, + "offsetof(aeron_logbuffer_metadata_t, is_connected) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, active_transport_count) == 140, + "offsetof(aeron_logbuffer_metadata_t, active_transport_count) is wrong"); _Static_assert( offsetof(aeron_logbuffer_metadata_t, correlation_id) == 256, "offsetof(aeron_logbuffer_metadata_t, correlation_id) is wrong"); @@ -138,7 +142,6 @@ _Static_assert( _Static_assert( offsetof(aeron_logbuffer_metadata_t, max_resend) == 300, "offsetof(aeron_logbuffer_metadata_t, max_resend) is wrong"); - _Static_assert( offsetof(aeron_logbuffer_metadata_t, sparse) == 304, "offsetof(aeron_logbuffer_metadata_t, sparse) is wrong"); @@ -154,34 +157,19 @@ _Static_assert( _Static_assert( offsetof(aeron_logbuffer_metadata_t, signal_eos) == 308, "offsetof(aeron_logbuffer_metadata_t, signal_eos) is wrong"); - _Static_assert( offsetof(aeron_logbuffer_metadata_t, spies_simulate_connection) == 309, "offsetof(aeron_logbuffer_metadata_t, spies_simulate_connection) is wrong"); - _Static_assert( offsetof(aeron_logbuffer_metadata_t, linger_timeout_ns) == 312, "offsetof(aeron_logbuffer_metadata_t, linger_timeout_ns) is wrong"); - _Static_assert( offsetof(aeron_logbuffer_metadata_t, default_header) == 320, "offsetof(aeron_logbuffer_metadata_t, default_header) is wrong"); - - -//_Static_assert( -// AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH >= AERON_DATA_HEADER_LENGTH, -// "AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH < AERON_DATA_HEADER_LENGTH"); - - - -//_Static_assert( -// offsetof(aeron_logbuffer_metadata_t, group) == 472, -// "offsetof(aeron_logbuffer_metadata_t, group) is wrong"); -//_Static_assert( -// offsetof(aeron_logbuffer_metadata_t, is_response) == 473, -// "offsetof(aeron_logbuffer_metadata_t, is_response) is wrong"); - +_Static_assert( + AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH >= AERON_DATA_HEADER_LENGTH, + "AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH < AERON_DATA_HEADER_LENGTH"); _Static_assert( offsetof(aeron_logbuffer_metadata_t, untethered_window_limit_timeout_ns) == 448, @@ -190,9 +178,9 @@ _Static_assert( offsetof(aeron_logbuffer_metadata_t, untethered_resting_timeout_ns) == 456, "offsetof(aeron_logbuffer_metadata_t, untethered_resting_timeout_ns) is wrong"); -//_Static_assert( -// sizeof(aeron_logbuffer_metadata_t) == 480, -// "sizeof(aeron_logbuffer_metadata_t) is wrong") +////_Static_assert( +//// sizeof(aeron_logbuffer_metadata_t) == 480, +//// "sizeof(aeron_logbuffer_metadata_t) is wrong") From a94276ab05f72edf97630bb773f2b36d28be340f Mon Sep 17 00:00:00 2001 From: Peter Veentjer Date: Thu, 2 Jan 2025 09:43:35 +0200 Subject: [PATCH 14/24] hacks --- .../c/concurrent/aeron_logbuffer_descriptor.h | 16 +++- .../aeron/logbuffer/LogBufferDescriptor.java | 74 ++------------- .../java/io/aeron/driver/DriverConductor.java | 6 +- .../src/main/java/io/aeron/driver/Main.java | 94 ------------------- 4 files changed, 25 insertions(+), 165 deletions(-) delete mode 100644 aeron-driver/src/main/java/io/aeron/driver/Main.java diff --git a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h index 6f87cc06ca..3fb409f83e 100644 --- a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h +++ b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h @@ -87,12 +87,24 @@ typedef struct aeron_logbuffer_metadata_stct // uint8_t is_response; // todo: is this padding correct - - uint8_t pad4[(AERON_CACHE_LINE_LENGTH) - (7 * sizeof(int32_t))]; + uint8_t pad4[(AERON_CACHE_LINE_LENGTH) - (7 * sizeof(int32_t)) - (2 * sizeof(int64_t))]; } aeron_logbuffer_metadata_t; #pragma pack(pop) + // ================ remove +#define STRINGIFY(x) #x +#define TOSTRING(x) STRINGIFY(x) + +_Static_assert( + sizeof(aeron_logbuffer_metadata_t) == sizeof(aeron_logbuffer_metadata_t), + "Size of aeron_logbuffer_metadata_t: " TOSTRING(sizeof(aeron_logbuffer_metadata_t))); +_Static_assert(sizeof(aeron_logbuffer_metadata_t) == 480, "aeron_logbuffer_metadata_t size mismatch"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, term_tail_counters) == 1, + "offsetof(aeron_logbuffer_metadata_t, term_tail_counters) is wrong"); +// ================ remove + _Static_assert( offsetof(aeron_logbuffer_metadata_t, term_tail_counters) == 0, "offsetof(aeron_logbuffer_metadata_t, term_tail_counters) is wrong"); diff --git a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java index 5908783038..7504f4c157 100644 --- a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java +++ b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java @@ -255,11 +255,11 @@ public class LogBufferDescriptor * +---------------------------------------------------------------+ * | Socket Receive Buffer Length | * +---------------------------------------------------------------+ - * | Socket Send Buffer Length | + * | Socket Send Buffer Length | * +---------------------------------------------------------------+ - * | Receiver Window Length | + * | Receiver Window Length | * +---------------------------------------------------------------+ - * | Publication Window Length | + * | Publication Window Length | * +---------------------------------------------------------------+ * | Maximum Resend | * +---------------------------------------------------------------+ @@ -287,7 +287,7 @@ public class LogBufferDescriptor * | Untethered Window Limit Timeout (ns) | * | | * +---------------------------------------------------------------+ - * | Untethered Resting Timeout (ns) | + * | Untethered Resting Timeout (ns) | * | | * +---------------------------------------------------------------+ * //todo: Add the missing fields. @@ -310,8 +310,6 @@ public class LogBufferDescriptor offset += (CACHE_LINE_LENGTH * 2); - int targetOffset = offset + CACHE_LINE_LENGTH; - LOG_CORRELATION_ID_OFFSET = offset; LOG_INITIAL_TERM_ID_OFFSET = LOG_CORRELATION_ID_OFFSET + SIZE_OF_LONG; LOG_DEFAULT_FRAME_HEADER_LENGTH_OFFSET = LOG_INITIAL_TERM_ID_OFFSET + SIZE_OF_INT; @@ -333,65 +331,12 @@ public class LogBufferDescriptor LOG_SIGNAL_EOS_OFFSET = LOG_IS_RELIABLE_OFFSET + SIZE_OF_BYTE; LOG_SPIES_SIMULATE_CONNECTION_OFFSET = LOG_SIGNAL_EOS_OFFSET + SIZE_OF_BYTE; - int startNewOffset = LOG_PAGE_SIZE_OFFSET+SIZE_OF_INT; - int totalSpace = CACHE_LINE_LENGTH; - int initialConsumed = LOG_PAGE_SIZE_OFFSET+SIZE_OF_INT-LOG_CORRELATION_ID_OFFSET; - int initialRemaining = CACHE_LINE_LENGTH-initialConsumed; - int endNewOffset = LOG_SPIES_SIMULATE_CONNECTION_OFFSET+SIZE_OF_BYTE; - int newUsed = endNewOffset-startNewOffset; - int newRemaining = initialRemaining-newUsed; - - System.out.println("totalSpace:"+totalSpace+ " bytes"); - System.out.println("initialConsumed:"+initialConsumed+ " bytes"); - System.out.println("initialRemaining:"+initialRemaining+ " bytes"); - System.out.println("new Used:"+newUsed+ " bytes"); - System.out.println("new remanining:"+newRemaining+ " bytes"); - - // then 2 bytes of padding - LOG_LINGER_TIMEOUT_NS_OFFSET = LOG_SPIES_SIMULATE_CONNECTION_OFFSET+SIZE_OF_BYTE+2; - - // Grouped output with alignment checks - System.out.println("LOG_CORRELATION_ID_OFFSET = " + LOG_CORRELATION_ID_OFFSET + - " (alignment = " + SIZE_OF_LONG + ", isAligned = " + (LOG_CORRELATION_ID_OFFSET % SIZE_OF_LONG == 0) + ")"); - System.out.println("LOG_INITIAL_TERM_ID_OFFSET = " + LOG_INITIAL_TERM_ID_OFFSET + - " (alignment = " + SIZE_OF_INT + ", isAligned = " + (LOG_INITIAL_TERM_ID_OFFSET % SIZE_OF_INT == 0) + ")"); - System.out.println("LOG_DEFAULT_FRAME_HEADER_LENGTH_OFFSET = " + LOG_DEFAULT_FRAME_HEADER_LENGTH_OFFSET + - " (alignment = " + SIZE_OF_INT + ", isAligned = " + (LOG_DEFAULT_FRAME_HEADER_LENGTH_OFFSET % SIZE_OF_INT == 0) + ")"); - System.out.println("LOG_MTU_LENGTH_OFFSET = " + LOG_MTU_LENGTH_OFFSET + - " (alignment = " + SIZE_OF_INT + ", isAligned = " + (LOG_MTU_LENGTH_OFFSET % SIZE_OF_INT == 0) + ")"); - System.out.println("LOG_TERM_LENGTH_OFFSET = " + LOG_TERM_LENGTH_OFFSET + - " (alignment = " + SIZE_OF_INT + ", isAligned = " + (LOG_TERM_LENGTH_OFFSET % SIZE_OF_INT == 0) + ")"); - System.out.println("LOG_PAGE_SIZE_OFFSET = " + LOG_PAGE_SIZE_OFFSET + - " (alignment = " + SIZE_OF_INT + ", isAligned = " + (LOG_PAGE_SIZE_OFFSET % SIZE_OF_INT == 0) + ")"); - System.out.println("LOG_SOCKET_RCVBUF_LENGTH_OFFSET = " + LOG_SOCKET_RCVBUF_LENGTH_OFFSET + - " (alignment = " + SIZE_OF_INT + ", isAligned = " + (LOG_SOCKET_RCVBUF_LENGTH_OFFSET % SIZE_OF_INT == 0) + ")"); - System.out.println("LOG_SOCKET_SNDBUF_LENGTH_OFFSET = " + LOG_SOCKET_SNDBUF_LENGTH_OFFSET + - " (alignment = " + SIZE_OF_INT + ", isAligned = " + (LOG_SOCKET_SNDBUF_LENGTH_OFFSET % SIZE_OF_INT == 0) + ")"); - System.out.println("LOG_RECEIVER_WINDOW_LENGTH_OFFSET = " + LOG_RECEIVER_WINDOW_LENGTH_OFFSET + - " (alignment = " + SIZE_OF_INT + ", isAligned = " + (LOG_RECEIVER_WINDOW_LENGTH_OFFSET % SIZE_OF_INT == 0) + ")"); - System.out.println("LOG_PUBLICATION_WINDOW_LENGTH_OFFSET = " + LOG_PUBLICATION_WINDOW_LENGTH_OFFSET + - " (alignment = " + SIZE_OF_INT + ", isAligned = " + (LOG_PUBLICATION_WINDOW_LENGTH_OFFSET % SIZE_OF_INT == 0) + ")"); - System.out.println("LOG_MAX_RESEND_OFFSET = " + LOG_MAX_RESEND_OFFSET + - " (alignment = " + SIZE_OF_INT + ", isAligned = " + (LOG_MAX_RESEND_OFFSET % SIZE_OF_INT == 0) + ")"); - - System.out.println("LOG_IS_SPARSE_OFFSET = " + LOG_IS_SPARSE_OFFSET); - System.out.println("LOG_IS_TETHER_OFFSET = " + LOG_IS_TETHER_OFFSET); - System.out.println("LOG_IS_REJOIN_OFFSET = " + LOG_IS_REJOIN_OFFSET); - System.out.println("LOG_IS_RELIABLE_OFFSET = " + LOG_IS_RELIABLE_OFFSET); - System.out.println("LOG_SIGNAL_EOS_OFFSET = " + LOG_SIGNAL_EOS_OFFSET); - System.out.println("LOG_SPIES_SIMULATE_CONNECTION_OFFSET = " + LOG_SPIES_SIMULATE_CONNECTION_OFFSET); - System.out.println("LOG_LINGER_TIMEOUT_NS_OFFSET = " + LOG_LINGER_TIMEOUT_NS_OFFSET + - " (alignment = " + SIZE_OF_LONG + ", isAligned = " + (LOG_LINGER_TIMEOUT_NS_OFFSET % SIZE_OF_LONG == 0) + ")"); + // 2 bytes of padding + LOG_LINGER_TIMEOUT_NS_OFFSET = LOG_SPIES_SIMULATE_CONNECTION_OFFSET + SIZE_OF_BYTE + 2; offset += CACHE_LINE_LENGTH; LOG_DEFAULT_FRAME_HEADER_OFFSET = offset; - - System.out.println("LOG_PAGE_SIZE_OFFSET:"+LOG_PAGE_SIZE_OFFSET); - System.out.println("LOG_DEFAULT_FRAME_HEADER_OFFSET:"+LOG_DEFAULT_FRAME_HEADER_OFFSET); - System.out.println("Start offset:"+LOG_PAGE_SIZE_OFFSET+SIZE_OF_INT); - System.out.println("Available:"+(LOG_DEFAULT_FRAME_HEADER_OFFSET-LOG_PAGE_SIZE_OFFSET-SIZE_OF_INT)); - offset += LOG_DEFAULT_FRAME_HEADER_MAX_LENGTH; LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET = offset; @@ -400,13 +345,6 @@ public class LogBufferDescriptor LOG_UNTETHERED_RESTING_TIMEOUT_NS_OFFSET = offset; offset += SIZE_OF_LONG; - - System.out.println("LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET = " + LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET + - " (alignment = " + SIZE_OF_LONG + ", isAligned = " + (LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET % SIZE_OF_INT == 0) + ")"); - System.out.println("LOG_UNTETHERED_RESTING_TIMEOUT_NS_OFFSET = " + LOG_UNTETHERED_RESTING_TIMEOUT_NS_OFFSET + - " (alignment = " + SIZE_OF_LONG + ", isAligned = " + (LOG_UNTETHERED_RESTING_TIMEOUT_NS_OFFSET % SIZE_OF_INT == 0) + ")"); - - LOG_META_DATA_LENGTH = align(offset, PAGE_MIN_SIZE); } diff --git a/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java b/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java index c0318b520e..39719073f1 100644 --- a/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java +++ b/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java @@ -1916,7 +1916,11 @@ private void initLogMetadata( { final UnsafeBuffer logMetaData = rawLog.metaData(); - defaultDataHeader.sessionId(sessionId).streamId(streamId).termId(initialTermId).termOffset(termOffset); + defaultDataHeader.sessionId(sessionId) + .streamId(streamId) + .termId(initialTermId); + // todo: restore. + // .termOffset(termOffset); storeDefaultFrameHeader(logMetaData, defaultDataHeader); initialTermId(logMetaData, initialTermId); diff --git a/aeron-driver/src/main/java/io/aeron/driver/Main.java b/aeron-driver/src/main/java/io/aeron/driver/Main.java deleted file mode 100644 index 83e76be36b..0000000000 --- a/aeron-driver/src/main/java/io/aeron/driver/Main.java +++ /dev/null @@ -1,94 +0,0 @@ -package io.aeron.driver; - -import io.aeron.Aeron; -import io.aeron.Subscription; -import io.aeron.Publication; -import io.aeron.driver.MediaDriver; -import org.agrona.CloseHelper; -import org.agrona.concurrent.BackoffIdleStrategy; -import org.agrona.concurrent.IdleStrategy; -import org.agrona.concurrent.UnsafeBuffer; - -import java.nio.charset.StandardCharsets; - -public class Main { - - private static final String CHANNEL = "aeron:udp?endpoint=localhost:40123"; - private static final int STREAM_ID = 1001; - private static final String MESSAGE = "Hello, Aeron!"; - - public static void main(String[] args) { - // Start an embedded Media Driver - MediaDriver.Context mediaDriverContext = new MediaDriver.Context(); - MediaDriver mediaDriver = MediaDriver.launchEmbedded(mediaDriverContext); - - Aeron.Context ctx = new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()); - try (Aeron aeron = Aeron.connect(ctx)) { - // Publisher thread - Thread publisherThread = new Thread(() -> runPublisher(aeron), "Publisher"); - - // Subscriber thread - Thread subscriberThread = new Thread(() -> runSubscriber(aeron), "Subscriber"); - - publisherThread.start(); - subscriberThread.start(); - - publisherThread.join(); - subscriberThread.join(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - e.printStackTrace(); - } finally { - CloseHelper.quietClose(mediaDriver); - } - } - - private static void runPublisher(Aeron aeron) { - try (Publication publication = aeron.addPublication(CHANNEL, STREAM_ID)) { - UnsafeBuffer buffer = new UnsafeBuffer(new byte[256]); - buffer.putStringWithoutLengthAscii(0, MESSAGE); - - while (!publication.isConnected()) { - System.out.println("Waiting for subscriber to connect..."); - Thread.sleep(100); - } - - long result; - do { - result = publication.offer(buffer); - if (result < 0) { - System.out.println("Offer failed: " + result); - Thread.sleep(10); - } - } while (result < 0); - - System.out.println("Message published: " + MESSAGE); - } catch (Exception e) { - e.printStackTrace(); - } - } - - private static void runSubscriber(Aeron aeron) { - IdleStrategy idleStrategy = new BackoffIdleStrategy(1, 1, 1, 1); - try (Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID)) { - while (!subscription.isConnected()) { - System.out.println("Waiting for publisher to connect..."); - Thread.sleep(100); - } - - while (true) { - int fragmentsRead = subscription.poll((buffer, offset, length, header) -> { - byte[] data = new byte[length]; - buffer.getBytes(offset, data); - String receivedMessage = new String(data, StandardCharsets.US_ASCII); - System.out.println("Received message: " + receivedMessage); - }, 10); - - idleStrategy.idle(fragmentsRead); - } - } catch (Exception e) { - e.printStackTrace(); - } - } -} - From 84c9146dccbc22ebe7e2dd04385cd6e285d20d67 Mon Sep 17 00:00:00 2001 From: Peter Veentjer Date: Thu, 2 Jan 2025 10:24:20 +0200 Subject: [PATCH 15/24] Disabled the fields after the end of the original record; now java_system_tests_c_media_driver doesn't fail --- .../c/concurrent/aeron_logbuffer_descriptor.h | 52 +++++++------------ .../java/io/aeron/driver/DriverConductor.java | 5 +- 2 files changed, 22 insertions(+), 35 deletions(-) diff --git a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h index 3fb409f83e..1f00805ff8 100644 --- a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h +++ b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h @@ -76,10 +76,10 @@ typedef struct aeron_logbuffer_metadata_stct uint8_t pad3[2]; int64_t linger_timeout_ns; - uint8_t default_header[AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH]; - - int64_t untethered_window_limit_timeout_ns; - int64_t untethered_resting_timeout_ns; +// uint8_t default_header[AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH]; +// +// int64_t untethered_window_limit_timeout_ns; +// int64_t untethered_resting_timeout_ns; // int64_t entity_tag; // int64_t response_correlation_id; @@ -87,24 +87,12 @@ typedef struct aeron_logbuffer_metadata_stct // uint8_t is_response; // todo: is this padding correct - uint8_t pad4[(AERON_CACHE_LINE_LENGTH) - (7 * sizeof(int32_t)) - (2 * sizeof(int64_t))]; + //uint8_t pad4[(AERON_CACHE_LINE_LENGTH) - (7 * sizeof(int32_t)) - (2 * sizeof(int64_t))]; + //uint8_t pad4[(AERON_CACHE_LINE_LENGTH) - (7 * sizeof(int32_t)) ]; } aeron_logbuffer_metadata_t; #pragma pack(pop) - // ================ remove -#define STRINGIFY(x) #x -#define TOSTRING(x) STRINGIFY(x) - -_Static_assert( - sizeof(aeron_logbuffer_metadata_t) == sizeof(aeron_logbuffer_metadata_t), - "Size of aeron_logbuffer_metadata_t: " TOSTRING(sizeof(aeron_logbuffer_metadata_t))); -_Static_assert(sizeof(aeron_logbuffer_metadata_t) == 480, "aeron_logbuffer_metadata_t size mismatch"); -_Static_assert( - offsetof(aeron_logbuffer_metadata_t, term_tail_counters) == 1, - "offsetof(aeron_logbuffer_metadata_t, term_tail_counters) is wrong"); -// ================ remove - _Static_assert( offsetof(aeron_logbuffer_metadata_t, term_tail_counters) == 0, "offsetof(aeron_logbuffer_metadata_t, term_tail_counters) is wrong"); @@ -175,20 +163,20 @@ _Static_assert( _Static_assert( offsetof(aeron_logbuffer_metadata_t, linger_timeout_ns) == 312, "offsetof(aeron_logbuffer_metadata_t, linger_timeout_ns) is wrong"); -_Static_assert( - offsetof(aeron_logbuffer_metadata_t, default_header) == 320, - "offsetof(aeron_logbuffer_metadata_t, default_header) is wrong"); - -_Static_assert( - AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH >= AERON_DATA_HEADER_LENGTH, - "AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH < AERON_DATA_HEADER_LENGTH"); - -_Static_assert( - offsetof(aeron_logbuffer_metadata_t, untethered_window_limit_timeout_ns) == 448, - "offsetof(aeron_logbuffer_metadata_t, untethered_window_limit_timeout_ns) is wrong"); -_Static_assert( - offsetof(aeron_logbuffer_metadata_t, untethered_resting_timeout_ns) == 456, - "offsetof(aeron_logbuffer_metadata_t, untethered_resting_timeout_ns) is wrong"); +//_Static_assert( +// offsetof(aeron_logbuffer_metadata_t, default_header) == 320, +// "offsetof(aeron_logbuffer_metadata_t, default_header) is wrong"); +// +//_Static_assert( +// AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH >= AERON_DATA_HEADER_LENGTH, +// "AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH < AERON_DATA_HEADER_LENGTH"); +// +//_Static_assert( +// offsetof(aeron_logbuffer_metadata_t, untethered_window_limit_timeout_ns) == 448, +// "offsetof(aeron_logbuffer_metadata_t, untethered_window_limit_timeout_ns) is wrong"); +//_Static_assert( +// offsetof(aeron_logbuffer_metadata_t, untethered_resting_timeout_ns) == 456, +// "offsetof(aeron_logbuffer_metadata_t, untethered_resting_timeout_ns) is wrong"); ////_Static_assert( //// sizeof(aeron_logbuffer_metadata_t) == 480, diff --git a/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java b/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java index 39719073f1..63cc39cbe5 100644 --- a/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java +++ b/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java @@ -1918,9 +1918,8 @@ private void initLogMetadata( defaultDataHeader.sessionId(sessionId) .streamId(streamId) - .termId(initialTermId); - // todo: restore. - // .termOffset(termOffset); + .termId(initialTermId) + .termOffset(termOffset); storeDefaultFrameHeader(logMetaData, defaultDataHeader); initialTermId(logMetaData, initialTermId); From 37e060edd5149a2fcacc0ba3a7a7a42b22202867 Mon Sep 17 00:00:00 2001 From: Peter Veentjer Date: Thu, 2 Jan 2025 11:03:33 +0200 Subject: [PATCH 16/24] Added the default_header to the struct --- .../main/c/concurrent/aeron_logbuffer_descriptor.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h index 1f00805ff8..c333e49b66 100644 --- a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h +++ b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h @@ -76,7 +76,7 @@ typedef struct aeron_logbuffer_metadata_stct uint8_t pad3[2]; int64_t linger_timeout_ns; -// uint8_t default_header[AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH]; + uint8_t default_header[AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH]; // // int64_t untethered_window_limit_timeout_ns; // int64_t untethered_resting_timeout_ns; @@ -316,8 +316,10 @@ inline void aeron_logbuffer_fill_default_header( uint8_t *log_meta_data_buffer, int32_t session_id, int32_t stream_id, int32_t initial_term_id) { aeron_logbuffer_metadata_t *log_meta_data = (aeron_logbuffer_metadata_t *)log_meta_data_buffer; - aeron_data_header_t *data_header = - (aeron_data_header_t *)(log_meta_data_buffer + sizeof(aeron_logbuffer_metadata_t)); + // todo: original + //aeron_data_header_t *data_header = + // (aeron_data_header_t *)(log_meta_data_buffer + sizeof(aeron_logbuffer_metadata_t)); + aeron_data_header_t *data_header = (aeron_data_header_t *)(log_meta_data->default_header); log_meta_data->default_frame_header_length = AERON_DATA_HEADER_LENGTH; data_header->frame_header.frame_length = 0; @@ -334,9 +336,11 @@ inline void aeron_logbuffer_fill_default_header( inline void aeron_logbuffer_apply_default_header(uint8_t *log_meta_data_buffer, uint8_t *buffer) { aeron_logbuffer_metadata_t *log_meta_data = (aeron_logbuffer_metadata_t *)log_meta_data_buffer; - uint8_t *default_header = log_meta_data_buffer + sizeof(aeron_logbuffer_metadata_t); + //uint8_t *default_header = log_meta_data_buffer + sizeof(aeron_logbuffer_metadata_t); - memcpy(buffer, default_header, (size_t)log_meta_data->default_frame_header_length); + //memcpy(buffer, default_header, (size_t)log_meta_data->default_frame_header_length); + + memcpy(buffer, log_meta_data->default_header, (size_t)log_meta_data->default_frame_header_length); } inline size_t aeron_logbuffer_compute_fragmented_length(size_t length, size_t max_payload_length) From 7a7fe9a5818c98b9a91facef926ebc24f6b6276e Mon Sep 17 00:00:00 2001 From: Peter Veentjer Date: Thu, 2 Jan 2025 14:22:29 +0200 Subject: [PATCH 17/24] All working apart from the assert from aeron_logbuffer_metadata_t size --- .../c/concurrent/aeron_logbuffer_descriptor.h | 59 +++++++------------ .../java/io/aeron/driver/DriverConductor.java | 3 +- 2 files changed, 24 insertions(+), 38 deletions(-) diff --git a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h index c333e49b66..6b026bc106 100644 --- a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h +++ b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h @@ -77,18 +77,13 @@ typedef struct aeron_logbuffer_metadata_stct int64_t linger_timeout_ns; uint8_t default_header[AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH]; -// -// int64_t untethered_window_limit_timeout_ns; -// int64_t untethered_resting_timeout_ns; - -// int64_t entity_tag; -// int64_t response_correlation_id; -// uint8_t group; -// uint8_t is_response; - - // todo: is this padding correct - //uint8_t pad4[(AERON_CACHE_LINE_LENGTH) - (7 * sizeof(int32_t)) - (2 * sizeof(int64_t))]; - //uint8_t pad4[(AERON_CACHE_LINE_LENGTH) - (7 * sizeof(int32_t)) ]; + + int64_t untethered_window_limit_timeout_ns; + int64_t untethered_resting_timeout_ns; + + // Padding at the end will fill it up the aeron_logbuffer_metadata_t to 512 bytes + // (which is 9x AERON_CACHE_LINE_LENGTH) + uint8_t pad4[44]; } aeron_logbuffer_metadata_t; #pragma pack(pop) @@ -163,26 +158,22 @@ _Static_assert( _Static_assert( offsetof(aeron_logbuffer_metadata_t, linger_timeout_ns) == 312, "offsetof(aeron_logbuffer_metadata_t, linger_timeout_ns) is wrong"); -//_Static_assert( -// offsetof(aeron_logbuffer_metadata_t, default_header) == 320, -// "offsetof(aeron_logbuffer_metadata_t, default_header) is wrong"); -// -//_Static_assert( -// AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH >= AERON_DATA_HEADER_LENGTH, -// "AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH < AERON_DATA_HEADER_LENGTH"); -// -//_Static_assert( -// offsetof(aeron_logbuffer_metadata_t, untethered_window_limit_timeout_ns) == 448, -// "offsetof(aeron_logbuffer_metadata_t, untethered_window_limit_timeout_ns) is wrong"); -//_Static_assert( -// offsetof(aeron_logbuffer_metadata_t, untethered_resting_timeout_ns) == 456, -// "offsetof(aeron_logbuffer_metadata_t, untethered_resting_timeout_ns) is wrong"); - -////_Static_assert( -//// sizeof(aeron_logbuffer_metadata_t) == 480, -//// "sizeof(aeron_logbuffer_metadata_t) is wrong") - +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, default_header) == 320, + "offsetof(aeron_logbuffer_metadata_t, default_header) is wrong"); +_Static_assert( + AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH >= AERON_DATA_HEADER_LENGTH, + "AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH < AERON_DATA_HEADER_LENGTH"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, untethered_window_limit_timeout_ns) == 448, + "offsetof(aeron_logbuffer_metadata_t, untethered_window_limit_timeout_ns) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, untethered_resting_timeout_ns) == 456, + "offsetof(aeron_logbuffer_metadata_t, untethered_resting_timeout_ns) is wrong"); +//_Static_assert( +// sizeof(aeron_logbuffer_metadata_t) == 512, +// "sizeof(aeron_logbuffer_metadata_t) is wrong"); #define AERON_LOGBUFFER_META_DATA_LENGTH \ (AERON_ALIGN((sizeof(aeron_logbuffer_metadata_t) + AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH), AERON_PAGE_MIN_SIZE)) @@ -316,9 +307,6 @@ inline void aeron_logbuffer_fill_default_header( uint8_t *log_meta_data_buffer, int32_t session_id, int32_t stream_id, int32_t initial_term_id) { aeron_logbuffer_metadata_t *log_meta_data = (aeron_logbuffer_metadata_t *)log_meta_data_buffer; - // todo: original - //aeron_data_header_t *data_header = - // (aeron_data_header_t *)(log_meta_data_buffer + sizeof(aeron_logbuffer_metadata_t)); aeron_data_header_t *data_header = (aeron_data_header_t *)(log_meta_data->default_header); log_meta_data->default_frame_header_length = AERON_DATA_HEADER_LENGTH; @@ -336,9 +324,6 @@ inline void aeron_logbuffer_fill_default_header( inline void aeron_logbuffer_apply_default_header(uint8_t *log_meta_data_buffer, uint8_t *buffer) { aeron_logbuffer_metadata_t *log_meta_data = (aeron_logbuffer_metadata_t *)log_meta_data_buffer; - //uint8_t *default_header = log_meta_data_buffer + sizeof(aeron_logbuffer_metadata_t); - - //memcpy(buffer, default_header, (size_t)log_meta_data->default_frame_header_length); memcpy(buffer, log_meta_data->default_header, (size_t)log_meta_data->default_frame_header_length); } diff --git a/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java b/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java index 63cc39cbe5..61f14dbe9c 100644 --- a/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java +++ b/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java @@ -1945,7 +1945,8 @@ private void initLogMetadata( untetheredRestingTimeoutNs(logMetaData, untetheredRestingTimeoutNs); lingerTimeoutNs(logMetaData, lingerTimeoutNs); - // Acts like a release fence; so this should be the last statement. + // Acts like a release fence; so this should be the last statement to ensure that all above writes + // are ordered before the eos-position. endOfStreamPosition(logMetaData, Long.MAX_VALUE); } From e4625f32b982c6fcfce30bf0ff9e727ca0ca2b2e Mon Sep 17 00:00:00 2001 From: Peter Veentjer Date: Thu, 2 Jan 2025 14:45:39 +0200 Subject: [PATCH 18/24] Fixed padding problem --- .../src/main/c/concurrent/aeron_logbuffer_descriptor.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h index 6b026bc106..92a1e33cf9 100644 --- a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h +++ b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h @@ -83,7 +83,7 @@ typedef struct aeron_logbuffer_metadata_stct // Padding at the end will fill it up the aeron_logbuffer_metadata_t to 512 bytes // (which is 9x AERON_CACHE_LINE_LENGTH) - uint8_t pad4[44]; + uint8_t pad4[48]; } aeron_logbuffer_metadata_t; #pragma pack(pop) @@ -171,9 +171,9 @@ _Static_assert( offsetof(aeron_logbuffer_metadata_t, untethered_resting_timeout_ns) == 456, "offsetof(aeron_logbuffer_metadata_t, untethered_resting_timeout_ns) is wrong"); -//_Static_assert( -// sizeof(aeron_logbuffer_metadata_t) == 512, -// "sizeof(aeron_logbuffer_metadata_t) is wrong"); +_Static_assert( + sizeof(aeron_logbuffer_metadata_t) == 512, + "sizeof(aeron_logbuffer_metadata_t) is wrong"); #define AERON_LOGBUFFER_META_DATA_LENGTH \ (AERON_ALIGN((sizeof(aeron_logbuffer_metadata_t) + AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH), AERON_PAGE_MIN_SIZE)) From 6066761af0f3ceed352e1b13e5d02d126571d1a3 Mon Sep 17 00:00:00 2001 From: Peter Veentjer Date: Thu, 2 Jan 2025 17:49:40 +0200 Subject: [PATCH 19/24] Update the order of the fields to reflect master --- .../c/concurrent/aeron_logbuffer_descriptor.h | 129 ++++++++++-------- .../aeron/logbuffer/LogBufferDescriptor.java | 66 ++++++--- 2 files changed, 119 insertions(+), 76 deletions(-) diff --git a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h index 92a1e33cf9..52a418e1a5 100644 --- a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h +++ b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h @@ -33,9 +33,9 @@ #define AERON_MAX_UDP_PAYLOAD_LENGTH (65504) -#ifdef _MSC_VER -#define _Static_assert static_assert -#endif +//#ifdef _MSC_VER +//#define _Static_assert static_assert +//#endif #ifdef __cplusplus #define _Static_assert static_assert @@ -47,10 +47,12 @@ typedef struct aeron_logbuffer_metadata_stct { volatile int64_t term_tail_counters[AERON_LOGBUFFER_PARTITION_COUNT]; volatile int32_t active_term_count; + uint8_t pad1[(2 * AERON_CACHE_LINE_LENGTH) - ((AERON_LOGBUFFER_PARTITION_COUNT * sizeof(int64_t)) + sizeof(int32_t))]; volatile int64_t end_of_stream_position; volatile int32_t is_connected; volatile int32_t active_transport_count; + uint8_t pad2[(2 * AERON_CACHE_LINE_LENGTH) - (sizeof(int64_t) + (2 * sizeof(int32_t)))]; int64_t correlation_id; int32_t initial_term_id; @@ -58,32 +60,27 @@ typedef struct aeron_logbuffer_metadata_stct int32_t mtu_length; int32_t term_length; int32_t page_size; - - // new fields since Aeron 1.47.0 - int32_t socket_rcvbuf_length; - int32_t socket_sndbuf_length; - int32_t receiver_window_length; int32_t publication_window_length; + int32_t receiver_window_length; + int32_t socket_sndbuf_length; + int32_t socket_rcvbuf_length; int32_t max_resend; - - uint8_t sparse; - uint8_t tether; - uint8_t rejoin; - uint8_t reliable; - uint8_t signal_eos; - uint8_t spies_simulate_connection; - - uint8_t pad3[2]; - int64_t linger_timeout_ns; - - uint8_t default_header[AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH]; - - int64_t untethered_window_limit_timeout_ns; - int64_t untethered_resting_timeout_ns; - - // Padding at the end will fill it up the aeron_logbuffer_metadata_t to 512 bytes - // (which is 9x AERON_CACHE_LINE_LENGTH) - uint8_t pad4[48]; + int64_t entity_tag; + int64_t response_correlation_id; + uint8_t default_header[AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH]; + int64_t linger_timeout_ns; + int64_t untethered_window_limit_timeout_ns; + int64_t untethered_resting_timeout_ns; + uint8_t group; + uint8_t is_response; + uint8_t rejoin; + uint8_t reliable; + uint8_t sparse; + uint8_t signal_eos; + uint8_t spies_simulate_connection; + uint8_t tether; + + uint8_t pad_end[32]; // Padding to align the structure size to 512 bytes } aeron_logbuffer_metadata_t; #pragma pack(pop) @@ -121,43 +118,30 @@ _Static_assert( _Static_assert( offsetof(aeron_logbuffer_metadata_t, page_size) == 280, "offsetof(aeron_logbuffer_metadata_t, page_size) is wrong"); - _Static_assert( - offsetof(aeron_logbuffer_metadata_t, socket_rcvbuf_length) == 284, - "offsetof(aeron_logbuffer_metadata_t, socket_rcvbuf_length) is wrong"); -_Static_assert( - offsetof(aeron_logbuffer_metadata_t, socket_sndbuf_length) == 288, - "offsetof(aeron_logbuffer_metadata_t, socket_sndbuf_length) is wrong"); + offsetof(aeron_logbuffer_metadata_t, publication_window_length) == 284, + "offsetof(aeron_logbuffer_metadata_t, publication_window_length) is wrong"); _Static_assert( - offsetof(aeron_logbuffer_metadata_t, receiver_window_length) == 292, + offsetof(aeron_logbuffer_metadata_t, receiver_window_length) == 288, "offsetof(aeron_logbuffer_metadata_t, receiver_window_length) is wrong"); _Static_assert( - offsetof(aeron_logbuffer_metadata_t, publication_window_length) == 296, - "offsetof(aeron_logbuffer_metadata_t, publication_window_length) is wrong"); + offsetof(aeron_logbuffer_metadata_t, socket_sndbuf_length) == 292, + "offsetof(aeron_logbuffer_metadata_t, socket_sndbuf_length) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, socket_rcvbuf_length) == 296, + "offsetof(aeron_logbuffer_metadata_t, socket_rcvbuf_length) is wrong"); _Static_assert( offsetof(aeron_logbuffer_metadata_t, max_resend) == 300, "offsetof(aeron_logbuffer_metadata_t, max_resend) is wrong"); _Static_assert( - offsetof(aeron_logbuffer_metadata_t, sparse) == 304, - "offsetof(aeron_logbuffer_metadata_t, sparse) is wrong"); -_Static_assert( - offsetof(aeron_logbuffer_metadata_t, tether) == 305, - "offsetof(aeron_logbuffer_metadata_t, tether) is wrong"); -_Static_assert( - offsetof(aeron_logbuffer_metadata_t, rejoin) == 306, - "offsetof(aeron_logbuffer_metadata_t, rejoin) is wrong"); -_Static_assert( - offsetof(aeron_logbuffer_metadata_t, reliable) == 307, - "offsetof(aeron_logbuffer_metadata_t, reliable) is wrong"); -_Static_assert( - offsetof(aeron_logbuffer_metadata_t, signal_eos) == 308, - "offsetof(aeron_logbuffer_metadata_t, signal_eos) is wrong"); + offsetof(aeron_logbuffer_metadata_t, entity_tag) == 304, + "offsetof(aeron_logbuffer_metadata_t, entity_tag) is wrong"); _Static_assert( - offsetof(aeron_logbuffer_metadata_t, spies_simulate_connection) == 309, - "offsetof(aeron_logbuffer_metadata_t, spies_simulate_connection) is wrong"); + offsetof(aeron_logbuffer_metadata_t, entity_tag) % sizeof(int64_t) == 0, + "offsetof(aeron_logbuffer_metadata_t, entity_tag) not aligned"); _Static_assert( - offsetof(aeron_logbuffer_metadata_t, linger_timeout_ns) == 312, - "offsetof(aeron_logbuffer_metadata_t, linger_timeout_ns) is wrong"); + offsetof(aeron_logbuffer_metadata_t, response_correlation_id) == 312, + "offsetof(aeron_logbuffer_metadata_t, response_correlation_id) is wrong"); _Static_assert( offsetof(aeron_logbuffer_metadata_t, default_header) == 320, "offsetof(aeron_logbuffer_metadata_t, default_header) is wrong"); @@ -165,18 +149,47 @@ _Static_assert( AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH >= AERON_DATA_HEADER_LENGTH, "AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH < AERON_DATA_HEADER_LENGTH"); _Static_assert( - offsetof(aeron_logbuffer_metadata_t, untethered_window_limit_timeout_ns) == 448, + offsetof(aeron_logbuffer_metadata_t, linger_timeout_ns) == 448, + "offsetof(aeron_logbuffer_metadata_t, linger_timeout_ns) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, untethered_window_limit_timeout_ns) == 456, "offsetof(aeron_logbuffer_metadata_t, untethered_window_limit_timeout_ns) is wrong"); _Static_assert( - offsetof(aeron_logbuffer_metadata_t, untethered_resting_timeout_ns) == 456, + offsetof(aeron_logbuffer_metadata_t, untethered_resting_timeout_ns) == 464, "offsetof(aeron_logbuffer_metadata_t, untethered_resting_timeout_ns) is wrong"); - +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, group) == 472, + "offsetof(aeron_logbuffer_metadata_t, group) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, is_response) == 473, + "offsetof(aeron_logbuffer_metadata_t, is_response) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, rejoin) == 474, + "offsetof(aeron_logbuffer_metadata_t, rejoin) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, reliable) == 475, + "offsetof(aeron_logbuffer_metadata_t, reliable) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, sparse) == 476, + "offsetof(aeron_logbuffer_metadata_t, sparse) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, signal_eos) == 477, + "offsetof(aeron_logbuffer_metadata_t, signal_eos) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, spies_simulate_connection) == 478, + "offsetof(aeron_logbuffer_metadata_t, spies_simulate_connection) is wrong"); +_Static_assert( + offsetof(aeron_logbuffer_metadata_t, tether) == 479, + "offsetof(aeron_logbuffer_metadata_t, tether) is wrong"); _Static_assert( sizeof(aeron_logbuffer_metadata_t) == 512, "sizeof(aeron_logbuffer_metadata_t) is wrong"); #define AERON_LOGBUFFER_META_DATA_LENGTH \ - (AERON_ALIGN((sizeof(aeron_logbuffer_metadata_t) + AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH), AERON_PAGE_MIN_SIZE)) + (AERON_ALIGN(sizeof(aeron_logbuffer_metadata_t), AERON_PAGE_MIN_SIZE)) +_Static_assert( + AERON_LOGBUFFER_META_DATA_LENGTH == AERON_PAGE_MIN_SIZE, + "AERON_LOGBUFFER_META_DATA_LENGTH != AERON_PAGE_MIN_SIZE"); #define AERON_LOGBUFFER_FRAME_ALIGNMENT (32) diff --git a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java index 7504f4c157..c47b4ae229 100644 --- a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java +++ b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java @@ -201,15 +201,27 @@ public class LogBufferDescriptor public static final int LOG_LINGER_TIMEOUT_NS_OFFSET; /** - * Offset within the log metadata where the signal eos is stored. + * Offset within the log metadata where the signal-eos is stored. */ public static final int LOG_SIGNAL_EOS_OFFSET; /** - * Offset within the log metadata where the spies simulate connection is stored. + * Offset within the log metadata where the spies-simulate-connection is stored. */ public static final int LOG_SPIES_SIMULATE_CONNECTION_OFFSET; + /** + * Offset within the log metadata where the group is stored. + */ + public static final int LOG_GROUP_OFFSET; + + + /** + * Offset within the log metadata where is-response is stored. + */ + public static final int LOG_IS_RESPONSE_OFFSET; + + /** * Total length of the log metadata buffer in bytes. *
@@ -317,34 +329,52 @@ public class LogBufferDescriptor
         LOG_TERM_LENGTH_OFFSET = LOG_MTU_LENGTH_OFFSET + SIZE_OF_INT;
         LOG_PAGE_SIZE_OFFSET = LOG_TERM_LENGTH_OFFSET + SIZE_OF_INT;
 
-        // new fields
-        LOG_SOCKET_RCVBUF_LENGTH_OFFSET = LOG_PAGE_SIZE_OFFSET + SIZE_OF_INT;
-        LOG_SOCKET_SNDBUF_LENGTH_OFFSET = LOG_SOCKET_RCVBUF_LENGTH_OFFSET + SIZE_OF_INT;
-        LOG_RECEIVER_WINDOW_LENGTH_OFFSET = LOG_SOCKET_SNDBUF_LENGTH_OFFSET + SIZE_OF_INT;
-        LOG_PUBLICATION_WINDOW_LENGTH_OFFSET = LOG_RECEIVER_WINDOW_LENGTH_OFFSET + SIZE_OF_INT;
-        LOG_MAX_RESEND_OFFSET = LOG_PUBLICATION_WINDOW_LENGTH_OFFSET + SIZE_OF_INT;
-
-        LOG_IS_SPARSE_OFFSET = LOG_MAX_RESEND_OFFSET + SIZE_OF_INT;
-        LOG_IS_TETHER_OFFSET = LOG_IS_SPARSE_OFFSET + SIZE_OF_BYTE;
-        LOG_IS_REJOIN_OFFSET = LOG_IS_TETHER_OFFSET + SIZE_OF_BYTE;
-        LOG_IS_RELIABLE_OFFSET = LOG_IS_REJOIN_OFFSET + SIZE_OF_BYTE;
-        LOG_SIGNAL_EOS_OFFSET = LOG_IS_RELIABLE_OFFSET + SIZE_OF_BYTE;
-        LOG_SPIES_SIMULATE_CONNECTION_OFFSET = LOG_SIGNAL_EOS_OFFSET + SIZE_OF_BYTE;
-
-        // 2 bytes of padding
-        LOG_LINGER_TIMEOUT_NS_OFFSET = LOG_SPIES_SIMULATE_CONNECTION_OFFSET + SIZE_OF_BYTE + 2;
+        // new field
+        LOG_PUBLICATION_WINDOW_LENGTH_OFFSET = LOG_PAGE_SIZE_OFFSET + SIZE_OF_INT;
+        LOG_RECEIVER_WINDOW_LENGTH_OFFSET = LOG_PUBLICATION_WINDOW_LENGTH_OFFSET + SIZE_OF_INT;
+        LOG_SOCKET_SNDBUF_LENGTH_OFFSET = LOG_RECEIVER_WINDOW_LENGTH_OFFSET + SIZE_OF_INT;
+        LOG_SOCKET_RCVBUF_LENGTH_OFFSET = LOG_SOCKET_SNDBUF_LENGTH_OFFSET + SIZE_OF_INT;
+        LOG_MAX_RESEND_OFFSET = LOG_SOCKET_RCVBUF_LENGTH_OFFSET + SIZE_OF_INT;
 
         offset += CACHE_LINE_LENGTH;
 
         LOG_DEFAULT_FRAME_HEADER_OFFSET = offset;
         offset += LOG_DEFAULT_FRAME_HEADER_MAX_LENGTH;
 
+        // 2 bytes of padding
+        LOG_LINGER_TIMEOUT_NS_OFFSET = offset;
+        offset += SIZE_OF_LONG;
+
         LOG_UNTETHERED_WINDOW_LIMIT_TIMEOUT_NS_OFFSET = offset;
         offset += SIZE_OF_LONG;
 
         LOG_UNTETHERED_RESTING_TIMEOUT_NS_OFFSET = offset;
         offset += SIZE_OF_LONG;
 
+        LOG_GROUP_OFFSET = offset;
+        offset += SIZE_OF_BYTE;
+
+        LOG_IS_RESPONSE_OFFSET = offset;
+        offset+=SIZE_OF_BYTE;
+
+        LOG_IS_REJOIN_OFFSET = offset;
+        offset += SIZE_OF_BYTE;
+
+        LOG_IS_RELIABLE_OFFSET = offset;
+        offset += SIZE_OF_BYTE;
+
+        LOG_IS_SPARSE_OFFSET = offset;
+        offset += SIZE_OF_BYTE;
+
+        LOG_SIGNAL_EOS_OFFSET = offset;
+        offset += SIZE_OF_BYTE;
+
+        LOG_SPIES_SIMULATE_CONNECTION_OFFSET = offset;
+        offset += SIZE_OF_BYTE;
+
+        LOG_IS_TETHER_OFFSET = offset;
+        offset += SIZE_OF_BYTE;
+
         LOG_META_DATA_LENGTH = align(offset, PAGE_MIN_SIZE);
     }
 

From e177c9c47c11b689dcbc003820ebee537b8c911c Mon Sep 17 00:00:00 2001
From: Peter Veentjer 
Date: Thu, 2 Jan 2025 18:15:53 +0200
Subject: [PATCH 20/24] Furher alignment

---
 .../c/concurrent/aeron_logbuffer_descriptor.h    |  2 +-
 .../io/aeron/logbuffer/LogBufferDescriptor.java  | 16 +++++++++++++---
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h
index 52a418e1a5..e312044eab 100644
--- a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h
+++ b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h
@@ -80,7 +80,7 @@ typedef struct aeron_logbuffer_metadata_stct
     uint8_t spies_simulate_connection;
     uint8_t tether;
 
-    uint8_t pad_end[32]; // Padding to align the structure size to 512 bytes
+    uint8_t pad_end[32]; // Padding to align the structure size to 512 bytes (9x AERON_CACHE_LINE_LENGTH)
 }
 aeron_logbuffer_metadata_t;
 #pragma pack(pop)
diff --git a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java
index c47b4ae229..3d6fd26ef9 100644
--- a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java
+++ b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java
@@ -215,6 +215,15 @@ public class LogBufferDescriptor
      */
     public static final int LOG_GROUP_OFFSET;
 
+    /**
+     * Offset within the log metadata where the entity tag is stored.
+     */
+    public static final int LOG_ENTITY_TAG_OFFSET;
+
+    /**
+     * Offset within the log metadata where the response correlation id is stored.
+     */
+    public static final int LOG_RESPONSE_CORRELATION_ID_OFFSET;
 
     /**
      * Offset within the log metadata where is-response is stored.
@@ -307,6 +316,7 @@ public class LogBufferDescriptor
      */
     public static final int LOG_META_DATA_LENGTH;
 
+
     static
     {
         int offset = 0;
@@ -329,19 +339,19 @@ public class LogBufferDescriptor
         LOG_TERM_LENGTH_OFFSET = LOG_MTU_LENGTH_OFFSET + SIZE_OF_INT;
         LOG_PAGE_SIZE_OFFSET = LOG_TERM_LENGTH_OFFSET + SIZE_OF_INT;
 
-        // new field
         LOG_PUBLICATION_WINDOW_LENGTH_OFFSET = LOG_PAGE_SIZE_OFFSET + SIZE_OF_INT;
         LOG_RECEIVER_WINDOW_LENGTH_OFFSET = LOG_PUBLICATION_WINDOW_LENGTH_OFFSET + SIZE_OF_INT;
         LOG_SOCKET_SNDBUF_LENGTH_OFFSET = LOG_RECEIVER_WINDOW_LENGTH_OFFSET + SIZE_OF_INT;
         LOG_SOCKET_RCVBUF_LENGTH_OFFSET = LOG_SOCKET_SNDBUF_LENGTH_OFFSET + SIZE_OF_INT;
         LOG_MAX_RESEND_OFFSET = LOG_SOCKET_RCVBUF_LENGTH_OFFSET + SIZE_OF_INT;
+        LOG_ENTITY_TAG_OFFSET = LOG_MAX_RESEND_OFFSET + SIZE_OF_INT;
+        LOG_RESPONSE_CORRELATION_ID_OFFSET = LOG_ENTITY_TAG_OFFSET + SIZE_OF_LONG;
 
         offset += CACHE_LINE_LENGTH;
 
         LOG_DEFAULT_FRAME_HEADER_OFFSET = offset;
         offset += LOG_DEFAULT_FRAME_HEADER_MAX_LENGTH;
 
-        // 2 bytes of padding
         LOG_LINGER_TIMEOUT_NS_OFFSET = offset;
         offset += SIZE_OF_LONG;
 
@@ -355,7 +365,7 @@ public class LogBufferDescriptor
         offset += SIZE_OF_BYTE;
 
         LOG_IS_RESPONSE_OFFSET = offset;
-        offset+=SIZE_OF_BYTE;
+        offset += SIZE_OF_BYTE;
 
         LOG_IS_REJOIN_OFFSET = offset;
         offset += SIZE_OF_BYTE;

From 13264fe8a48c98f3af036b2da7d801aa3fe86bcd Mon Sep 17 00:00:00 2001
From: Peter Veentjer 
Date: Thu, 2 Jan 2025 18:41:55 +0200
Subject: [PATCH 21/24] Fixes

---
 .../c/concurrent/aeron_logbuffer_descriptor.c |   2 +-
 .../c/concurrent/aeron_logbuffer_descriptor.h | 112 ------------------
 2 files changed, 1 insertion(+), 113 deletions(-)

diff --git a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.c b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.c
index ec9ea6905f..f18c21e3b6 100644
--- a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.c
+++ b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.c
@@ -151,7 +151,7 @@ _Static_assert(
     "offsetof(aeron_logbuffer_metadata_t, tether) is wrong");
 
 _Static_assert(
-    sizeof(aeron_logbuffer_metadata_t) == 480,
+    sizeof(aeron_logbuffer_metadata_t) == 512,
     "sizeof(aeron_logbuffer_metadata_t) is wrong");
 
 _Static_assert(
diff --git a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h
index c320a2c0b6..448cefc06d 100644
--- a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h
+++ b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h
@@ -33,14 +33,6 @@
 
 #define AERON_MAX_UDP_PAYLOAD_LENGTH (65504)
 
-//#ifdef _MSC_VER
-//#define _Static_assert static_assert
-//#endif
-
-#ifdef __cplusplus
-#define _Static_assert static_assert
-#endif
-
 #pragma pack(push)
 #pragma pack(4)
 typedef struct aeron_logbuffer_metadata_stct
@@ -84,113 +76,9 @@ typedef struct aeron_logbuffer_metadata_stct
 aeron_logbuffer_metadata_t;
 #pragma pack(pop)
 
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, term_tail_counters) == 0,
-    "offsetof(aeron_logbuffer_metadata_t, term_tail_counters) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, active_term_count) == 24,
-    "offsetof(aeron_logbuffer_metadata_t, active_term_count) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, end_of_stream_position) == 128,
-    "offsetof(aeron_logbuffer_metadata_t, end_of_stream_position) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, is_connected) == 136,
-    "offsetof(aeron_logbuffer_metadata_t, is_connected) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, active_transport_count) == 140,
-    "offsetof(aeron_logbuffer_metadata_t, active_transport_count) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, correlation_id) == 256,
-    "offsetof(aeron_logbuffer_metadata_t, correlation_id) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, initial_term_id) == 264,
-    "offsetof(aeron_logbuffer_metadata_t, initial_term_id) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, default_frame_header_length) == 268,
-    "offsetof(aeron_logbuffer_metadata_t, default_frame_header_length) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, mtu_length) == 272,
-    "offsetof(aeron_logbuffer_metadata_t, mtu_length) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, term_length) == 276,
-    "offsetof(aeron_logbuffer_metadata_t, term_length) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, page_size) == 280,
-    "offsetof(aeron_logbuffer_metadata_t, page_size) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, publication_window_length) == 284,
-    "offsetof(aeron_logbuffer_metadata_t, publication_window_length) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, receiver_window_length) == 288,
-    "offsetof(aeron_logbuffer_metadata_t, receiver_window_length) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, socket_sndbuf_length) == 292,
-    "offsetof(aeron_logbuffer_metadata_t, socket_sndbuf_length) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, socket_rcvbuf_length) == 296,
-    "offsetof(aeron_logbuffer_metadata_t, socket_rcvbuf_length) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, max_resend) == 300,
-    "offsetof(aeron_logbuffer_metadata_t, max_resend) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, entity_tag) == 304,
-    "offsetof(aeron_logbuffer_metadata_t, entity_tag) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, entity_tag) % sizeof(int64_t) == 0,
-    "offsetof(aeron_logbuffer_metadata_t, entity_tag) not aligned");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, response_correlation_id) == 312,
-    "offsetof(aeron_logbuffer_metadata_t, response_correlation_id) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, default_header) == 320,
-    "offsetof(aeron_logbuffer_metadata_t, default_header) is wrong");
-_Static_assert(
-    AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH >= AERON_DATA_HEADER_LENGTH,
-    "AERON_LOGBUFFER_DEFAULT_FRAME_HEADER_MAX_LENGTH < AERON_DATA_HEADER_LENGTH");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, linger_timeout_ns) == 448,
-    "offsetof(aeron_logbuffer_metadata_t, linger_timeout_ns) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, untethered_window_limit_timeout_ns) == 456,
-    "offsetof(aeron_logbuffer_metadata_t, untethered_window_limit_timeout_ns) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, untethered_resting_timeout_ns) == 464,
-    "offsetof(aeron_logbuffer_metadata_t, untethered_resting_timeout_ns) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, group) == 472,
-    "offsetof(aeron_logbuffer_metadata_t, group) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, is_response) == 473,
-    "offsetof(aeron_logbuffer_metadata_t, is_response) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, rejoin) == 474,
-    "offsetof(aeron_logbuffer_metadata_t, rejoin) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, reliable) == 475,
-    "offsetof(aeron_logbuffer_metadata_t, reliable) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, sparse) == 476,
-    "offsetof(aeron_logbuffer_metadata_t, sparse) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, signal_eos) == 477,
-    "offsetof(aeron_logbuffer_metadata_t, signal_eos) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, spies_simulate_connection) == 478,
-    "offsetof(aeron_logbuffer_metadata_t, spies_simulate_connection) is wrong");
-_Static_assert(
-    offsetof(aeron_logbuffer_metadata_t, tether) == 479,
-    "offsetof(aeron_logbuffer_metadata_t, tether) is wrong");
-_Static_assert(
-    sizeof(aeron_logbuffer_metadata_t) == 512,
-    "sizeof(aeron_logbuffer_metadata_t) is wrong");
-
 #define AERON_LOGBUFFER_META_DATA_LENGTH \
     (AERON_ALIGN(sizeof(aeron_logbuffer_metadata_t), AERON_PAGE_MIN_SIZE))
 
-_Static_assert(
-    AERON_LOGBUFFER_META_DATA_LENGTH == AERON_PAGE_MIN_SIZE,
-    "AERON_LOGBUFFER_META_DATA_LENGTH != AERON_PAGE_MIN_SIZE");
-
 #define AERON_LOGBUFFER_FRAME_ALIGNMENT (32)
 
 #define AERON_LOGBUFFER_RAWTAIL_VOLATILE(d, m) \

From c7e8a57dfb463b034a6596974ca09515dd99388c Mon Sep 17 00:00:00 2001
From: Peter Veentjer 
Date: Fri, 3 Jan 2025 09:11:57 +0200
Subject: [PATCH 22/24] Updated javadoc field layout

---
 .../aeron/logbuffer/LogBufferDescriptor.java  | 45 +++++++++++--------
 1 file changed, 27 insertions(+), 18 deletions(-)

diff --git a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java
index 3d6fd26ef9..6ac02104fc 100644
--- a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java
+++ b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java
@@ -274,44 +274,53 @@ public class LogBufferDescriptor
      *  +---------------------------------------------------------------+
      *  |                          Page Size                            |
      *  +---------------------------------------------------------------+
-     *  |                  Socket Receive Buffer Length                 |
-     *  +---------------------------------------------------------------+
-     *  |                    Socket Send Buffer Length                  |
+     *  |                    Publication Window Length                  |
      *  +---------------------------------------------------------------+
      *  |                      Receiver Window Length                   |
      *  +---------------------------------------------------------------+
-     *  |                    Publication Window Length                  |
+     *  |                    Socket Send Buffer Length                  |
+     *  +---------------------------------------------------------------+
+     *  |                  Socket Receive Buffer Length                 |
      *  +---------------------------------------------------------------+
      *  |                        Maximum Resend                         |
      *  +---------------------------------------------------------------+
-     *  |                          Is Sparse                            |
+     *  |                           Entity tag                          |
+     *  |                                                               |
      *  +---------------------------------------------------------------+
-     *  |                          Is Tether                            |
+     *  |                    Response correlation id                    |
+     *  |                                                               |
+     *  +---------------------------------------------------------------+
+     *  |                     Default Frame Header                     ...
+     * ...                                                              |
+     *  +---------------------------------------------------------------+
+     *  |                        Linger Timeout (ns)                    |
+     *  |                                                               |
+     *  +---------------------------------------------------------------+
+     *  |               Untethered Window Limit Timeout (ns)            |
+     *  |                                                               |
+     *  +---------------------------------------------------------------+
+     *  |                 Untethered Resting Timeout (ns)               |
+     *  |                                                               |
+     *  +---------------------------------------------------------------+
+     *  |                            Group                              |
+     *  +---------------------------------------------------------------+
+     *  |                          Is response                          |
      *  +---------------------------------------------------------------+
      *  |                          Is Rejoin                            |
      *  +---------------------------------------------------------------+
      *  |                         Is Reliable                           |
      *  +---------------------------------------------------------------+
+     *  |                          Is Sparse                            |
+     *  +---------------------------------------------------------------+
      *  |                         Signal EOS                            |
      *  +---------------------------------------------------------------+
      *  |                 Spies Simulate Connection                     |
      *  +---------------------------------------------------------------+
-     *  |                    Linger Timeout (ns)                        |
-     *  |                                                               |
+     *  |                          Is Tether                            |
      *  +---------------------------------------------------------------+
      *  |                      Cache Line Padding                      ...
      * ...                                                              |
      *  +---------------------------------------------------------------+
-     *  |                     Default Frame Header                     ...
-     * ...                                                              |
-     *  +---------------------------------------------------------------+
-     *  |               Untethered Window Limit Timeout (ns)            |
-     *  |                                                               |
-     *  +---------------------------------------------------------------+
-     *  |                 Untethered Resting Timeout (ns)               |
-     *  |                                                               |
-     *  +---------------------------------------------------------------+
-     *  //todo: Add the missing fields.
      * 
*/ public static final int LOG_META_DATA_LENGTH; From 1fbfb2c547535bf167af95c6ab74c5b73a731961 Mon Sep 17 00:00:00 2001 From: Peter Veentjer Date: Tue, 7 Jan 2025 13:29:48 +0200 Subject: [PATCH 23/24] Processed review comments --- .../c/concurrent/aeron_logbuffer_descriptor.c | 2 +- .../c/concurrent/aeron_logbuffer_descriptor.h | 1 - .../aeron/logbuffer/LogBufferDescriptor.java | 57 +++++++++---------- .../java/io/aeron/driver/DriverConductor.java | 14 ++--- 4 files changed, 35 insertions(+), 39 deletions(-) diff --git a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.c b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.c index f18c21e3b6..ec9ea6905f 100644 --- a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.c +++ b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.c @@ -151,7 +151,7 @@ _Static_assert( "offsetof(aeron_logbuffer_metadata_t, tether) is wrong"); _Static_assert( - sizeof(aeron_logbuffer_metadata_t) == 512, + sizeof(aeron_logbuffer_metadata_t) == 480, "sizeof(aeron_logbuffer_metadata_t) is wrong"); _Static_assert( diff --git a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h index 448cefc06d..f0762b2ee8 100644 --- a/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h +++ b/aeron-client/src/main/c/concurrent/aeron_logbuffer_descriptor.h @@ -71,7 +71,6 @@ typedef struct aeron_logbuffer_metadata_stct uint8_t signal_eos; uint8_t spies_simulate_connection; uint8_t tether; - uint8_t pad_end[32]; // Padding to align the structure size to 512 bytes (9x AERON_CACHE_LINE_LENGTH) } aeron_logbuffer_metadata_t; #pragma pack(pop) diff --git a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java index 6ac02104fc..b678344582 100644 --- a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java +++ b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java @@ -143,22 +143,22 @@ public class LogBufferDescriptor /** * Offset within the log metadata where the sparse property is stored. */ - public static final int LOG_IS_SPARSE_OFFSET; + public static final int LOG_SPARSE_OFFSET; /** * Offset within the log metadata where the tether property is stored. */ - public static final int LOG_IS_TETHER_OFFSET; + public static final int LOG_TETHER_OFFSET; /** * Offset within the log metadata where the rejoin property is stored. */ - public static final int LOG_IS_REJOIN_OFFSET; + public static final int LOG_REJOIN_OFFSET; /** * Offset within the log metadata where the reliable property is stored. */ - public static final int LOG_IS_RELIABLE_OFFSET; + public static final int LOG_RELIABLE_OFFSET; /** * Offset within the log metadata where the socket receive buffer length is stored. @@ -306,17 +306,17 @@ public class LogBufferDescriptor * +---------------------------------------------------------------+ * | Is response | * +---------------------------------------------------------------+ - * | Is Rejoin | + * | Rejoin | * +---------------------------------------------------------------+ - * | Is Reliable | + * | Reliable | * +---------------------------------------------------------------+ - * | Is Sparse | + * | Sparse | * +---------------------------------------------------------------+ * | Signal EOS | * +---------------------------------------------------------------+ * | Spies Simulate Connection | * +---------------------------------------------------------------+ - * | Is Tether | + * | Tether | * +---------------------------------------------------------------+ * | Cache Line Padding ... * ... | @@ -376,13 +376,13 @@ public class LogBufferDescriptor LOG_IS_RESPONSE_OFFSET = offset; offset += SIZE_OF_BYTE; - LOG_IS_REJOIN_OFFSET = offset; + LOG_REJOIN_OFFSET = offset; offset += SIZE_OF_BYTE; - LOG_IS_RELIABLE_OFFSET = offset; + LOG_RELIABLE_OFFSET = offset; offset += SIZE_OF_BYTE; - LOG_IS_SPARSE_OFFSET = offset; + LOG_SPARSE_OFFSET = offset; offset += SIZE_OF_BYTE; LOG_SIGNAL_EOS_OFFSET = offset; @@ -391,7 +391,7 @@ public class LogBufferDescriptor LOG_SPIES_SIMULATE_CONNECTION_OFFSET = offset; offset += SIZE_OF_BYTE; - LOG_IS_TETHER_OFFSET = offset; + LOG_TETHER_OFFSET = offset; offset += SIZE_OF_BYTE; LOG_META_DATA_LENGTH = align(offset, PAGE_MIN_SIZE); @@ -1056,16 +1056,15 @@ public static int computeAssembledFrameLength(final int length, final int maxPay return HEADER_LENGTH + (numMaxPayloads * maxPayloadSize) + remainingPayload; } - /** * Get whether the log is sparse from the metadata. * * @param metadataBuffer containing the meta data. * @return true if the log is sparse, otherwise false. */ - public static boolean isSparse(final UnsafeBuffer metadataBuffer) + public static boolean sparse(final UnsafeBuffer metadataBuffer) { - return metadataBuffer.getByte(LOG_IS_SPARSE_OFFSET) == 1; + return metadataBuffer.getByte(LOG_SPARSE_OFFSET) == 1; } /** @@ -1074,9 +1073,9 @@ public static boolean isSparse(final UnsafeBuffer metadataBuffer) * @param metadataBuffer containing the meta data. * @param value true if the log is sparse, otherwise false. */ - public static void isSparse(final UnsafeBuffer metadataBuffer, final boolean value) + public static void sparse(final UnsafeBuffer metadataBuffer, final boolean value) { - metadataBuffer.putByte(LOG_IS_SPARSE_OFFSET, (byte)(value ? 1 : 0)); + metadataBuffer.putByte(LOG_SPARSE_OFFSET, (byte)(value ? 1 : 0)); } /** @@ -1085,9 +1084,9 @@ public static void isSparse(final UnsafeBuffer metadataBuffer, final boolean val * @param metadataBuffer containing the meta data. * @return true if the log is tethered, otherwise false. */ - public static boolean isTether(final UnsafeBuffer metadataBuffer) + public static boolean tether(final UnsafeBuffer metadataBuffer) { - return metadataBuffer.getByte(LOG_IS_TETHER_OFFSET) == 1; + return metadataBuffer.getByte(LOG_TETHER_OFFSET) == 1; } /** @@ -1096,9 +1095,9 @@ public static boolean isTether(final UnsafeBuffer metadataBuffer) * @param metadataBuffer containing the meta data. * @param value true if the log is tethered, otherwise false. */ - public static void isTether(final UnsafeBuffer metadataBuffer, final boolean value) + public static void tether(final UnsafeBuffer metadataBuffer, final boolean value) { - metadataBuffer.putByte(LOG_IS_TETHER_OFFSET, (byte)(value ? 1 : 0)); + metadataBuffer.putByte(LOG_TETHER_OFFSET, (byte)(value ? 1 : 0)); } /** @@ -1107,9 +1106,9 @@ public static void isTether(final UnsafeBuffer metadataBuffer, final boolean val * @param metadataBuffer containing the meta data. * @return true if the log is rejoining, otherwise false. */ - public static boolean isRejoin(final UnsafeBuffer metadataBuffer) + public static boolean rejoin(final UnsafeBuffer metadataBuffer) { - return metadataBuffer.getByte(LOG_IS_REJOIN_OFFSET) == 1; + return metadataBuffer.getByte(LOG_REJOIN_OFFSET) == 1; } /** @@ -1118,9 +1117,9 @@ public static boolean isRejoin(final UnsafeBuffer metadataBuffer) * @param metadataBuffer containing the meta data. * @param value true if the log is rejoining, otherwise false. */ - public static void isRejoin(final UnsafeBuffer metadataBuffer, final boolean value) + public static void rejoin(final UnsafeBuffer metadataBuffer, final boolean value) { - metadataBuffer.putByte(LOG_IS_REJOIN_OFFSET, (byte)(value ? 1 : 0)); + metadataBuffer.putByte(LOG_REJOIN_OFFSET, (byte)(value ? 1 : 0)); } /** @@ -1129,9 +1128,9 @@ public static void isRejoin(final UnsafeBuffer metadataBuffer, final boolean val * @param metadataBuffer containing the meta data. * @return true if the log is reliable, otherwise false. */ - public static boolean isReliable(final UnsafeBuffer metadataBuffer) + public static boolean reliable(final UnsafeBuffer metadataBuffer) { - return metadataBuffer.getByte(LOG_IS_RELIABLE_OFFSET) == 1; + return metadataBuffer.getByte(LOG_RELIABLE_OFFSET) == 1; } /** @@ -1140,9 +1139,9 @@ public static boolean isReliable(final UnsafeBuffer metadataBuffer) * @param metadataBuffer containing the meta data. * @param value true if the log is reliable, otherwise false. */ - public static void isReliable(final UnsafeBuffer metadataBuffer, final boolean value) + public static void reliable(final UnsafeBuffer metadataBuffer, final boolean value) { - metadataBuffer.putByte(LOG_IS_RELIABLE_OFFSET, (byte)(value ? 1 : 0)); + metadataBuffer.putByte(LOG_RELIABLE_OFFSET, (byte)(value ? 1 : 0)); } /** diff --git a/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java b/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java index 61f14dbe9c..ed02fe172e 100644 --- a/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java +++ b/aeron-driver/src/main/java/io/aeron/driver/DriverConductor.java @@ -1728,8 +1728,7 @@ private NetworkPublication newNetworkPublication( params.initialTermId, params.termLength); - // todo: - final int termOffset = 0; + final int termOffset = params.termOffset; final RawLog rawLog = newNetworkPublicationLog(params.sessionId, streamId, params.initialTermId, registrationId, udpChannel.socketRcvbufLength(), udpChannel.socketSndbufLength(), termOffset, params); UnsafeBufferPosition publisherPos = null; @@ -1935,10 +1934,10 @@ private void initLogMetadata( maxResend(logMetaData, maxResend); spiesSimulateConnection(logMetaData, spiesSimulateConnection); - isTether(logMetaData, tether); - isRejoin(logMetaData, rejoin); - isReliable(logMetaData, reliable); - isSparse(logMetaData, sparse); + tether(logMetaData, tether); + rejoin(logMetaData, rejoin); + reliable(logMetaData, reliable); + sparse(logMetaData, sparse); signalEos(logMetaData, signalEos); untetheredWindowLimitTimeoutNs(logMetaData, untetheredWindowLimitTimeoutNs); @@ -2408,8 +2407,7 @@ private IpcPublication addIpcPublication( final boolean isExclusive, final PublicationParams params) { - // todo: - final int termOffset = 0; + final int termOffset = params.termOffset; final RawLog rawLog = newIpcPublicationLog(params.sessionId, streamId, params.initialTermId, registrationId, termOffset, params); From 7742a73f079160fda789053c087f228ca4a44679 Mon Sep 17 00:00:00 2001 From: Peter Veentjer Date: Tue, 7 Jan 2025 13:34:24 +0200 Subject: [PATCH 24/24] Removed padding from LogBufferDescriptor documentation --- .../src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java index b678344582..520c2233b9 100644 --- a/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java +++ b/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java @@ -318,9 +318,6 @@ public class LogBufferDescriptor * +---------------------------------------------------------------+ * | Tether | * +---------------------------------------------------------------+ - * | Cache Line Padding ... - * ... | - * +---------------------------------------------------------------+ * */ public static final int LOG_META_DATA_LENGTH;