Esempio n. 1
0
        private static void PongHandler(IDirectBuffer buffer, int offset, int length, Header header)
        {
            var pingTimestamp = buffer.GetLong(offset);
            var rttNs         = Stopwatch.GetTimestamp() - pingTimestamp;

            var b = rttNs * 1000 * 1000 * 1000d / Stopwatch.Frequency;

            Histogram.RecordValue((long)b);
        }
Esempio n. 2
0
        /// <summary>
        /// Is the recording counter still active.
        /// </summary>
        /// <param name="counters"> to search within. </param>
        /// <param name="counterId">   to search for. </param>
        /// <param name="recordingId"> to confirm it is still the same value. </param>
        /// <returns> true if the counter is still active otherwise false. </returns>
        public static bool IsActive(CountersReader counters, int counterId, long recordingId)
        {
            IDirectBuffer buffer       = counters.MetaDataBuffer;
            int           recordOffset = MetaDataOffset(counterId);

            return(counters.GetCounterTypeId(counterId) == RECORDING_POSITION_TYPE_ID &&
                   buffer.GetLong(recordOffset + KEY_OFFSET + RECORDING_ID_OFFSET) == recordingId &&
                   counters.GetCounterState(counterId) == RECORD_ALLOCATED);
        }
        /// <summary>
        /// Is the counter active for usage? Checks to see if reclaimed or reused and matches registration id.
        /// </summary>
        /// <param name="countersReader"> to search within. </param>
        /// <param name="counterId">      to test. </param>
        /// <param name="counterTypeId">  to validate type. </param>
        /// <param name="registrationId"> for the entity. </param>
        /// <returns> true if still valid otherwise false. </returns>
        public static bool IsActive(CountersReader countersReader, int counterId, int counterTypeId,
                                    long registrationId)
        {
            IDirectBuffer buffer       = countersReader.MetaDataBuffer;
            int           recordOffset = CountersReader.MetaDataOffset(counterId);

            return(countersReader.GetCounterTypeId(counterId) == counterTypeId &&
                   buffer.GetLong(recordOffset + CountersReader.KEY_OFFSET + REGISTRATION_ID_OFFSET) ==
                   registrationId && countersReader.GetCounterState(counterId) == CountersReader.RECORD_ALLOCATED);
        }
Esempio n. 4
0
        /// <summary>
        /// Get the timestamp at the beginning of recovery. <see cref="Adaptive.Aeron.Aeron.NULL_VALUE"/> if no snapshot for recovery.
        /// </summary>
        /// <param name="counters">  to search within. </param>
        /// <param name="counterId"> for the active recovery counter. </param>
        /// <returns> the timestamp if found otherwise <see cref="Adaptive.Aeron.Aeron.NULL_VALUE"/>. </returns>
        public static long GetTimestamp(CountersReader counters, int counterId)
        {
            IDirectBuffer buffer = counters.MetaDataBuffer;

            if (counters.GetCounterState(counterId) == CountersReader.RECORD_ALLOCATED &&
                counters.GetCounterTypeId(counterId) == RECOVERY_STATE_TYPE_ID)
            {
                return(buffer.GetLong(CountersReader.MetaDataOffset(counterId) + CountersReader.KEY_OFFSET + TIMESTAMP_OFFSET));
            }

            return(Aeron.Aeron.NULL_VALUE);
        }
Esempio n. 5
0
        /// <summary>
        /// Get the recording id for a given counter id.
        /// </summary>
        /// <param name="countersReader"> to search within. </param>
        /// <param name="counterId">      for the active recording. </param>
        /// <returns> the counter id if found otherwise <seealso cref="NULL_RECORDING_ID"/>. </returns>
        public static long GetRecordingId(CountersReader countersReader, int counterId)
        {
            IDirectBuffer buffer = countersReader.MetaDataBuffer;

            if (countersReader.GetCounterState(counterId) == RECORD_ALLOCATED &&
                countersReader.GetCounterTypeId(counterId) == RECORDING_POSITION_TYPE_ID)
            {
                return(buffer.GetLong(MetaDataOffset(counterId) + KEY_OFFSET +
                                      RECORDING_ID_OFFSET));
            }

            return(NULL_RECORDING_ID);
        }
Esempio n. 6
0
        /// <summary>
        /// Is the recording counter still active.
        /// </summary>
        /// <param name="countersReader"> to search within. </param>
        /// <param name="counterId">      to search for. </param>
        /// <param name="recordingId">    to confirm it is still the same value. </param>
        /// <returns> true if the counter is still active otherwise false. </returns>
        public static bool IsActive(CountersReader countersReader, int counterId, long recordingId)
        {
            IDirectBuffer buffer = countersReader.MetaDataBuffer;

            if (countersReader.GetCounterState(counterId) == CountersReader.RECORD_ALLOCATED)
            {
                int recordOffset = CountersReader.MetaDataOffset(counterId);

                return(buffer.GetInt(recordOffset + CountersReader.TYPE_ID_OFFSET) == RECORDING_POSITION_TYPE_ID &&
                       buffer.GetLong(recordOffset + CountersReader.KEY_OFFSET + RECORDING_ID_OFFSET) == recordingId);
            }

            return(false);
        }
Esempio n. 7
0
        /// <summary>
        ///  Get the position at which the snapshot was taken. <seealso cref="Aeron.NULL_VALUE"/> if no snapshot for recovery.
        /// </summary>
        /// <param name="counters">  to search within. </param>
        /// <param name="counterId"> for the active consensus position. </param>
        /// <returns> the log position if found otherwise <seealso cref="Aeron.NULL_VALUE"/>. </returns>
        public static long GetLogPosition(CountersReader counters, int counterId)
        {
            IDirectBuffer buffer = counters.MetaDataBuffer;

            if (counters.GetCounterState(counterId) == CountersReader.RECORD_ALLOCATED)
            {
                int recordOffset = CountersReader.MetaDataOffset(counterId);

                if (buffer.GetInt(recordOffset + CountersReader.TYPE_ID_OFFSET) == RECOVERY_STATE_TYPE_ID)
                {
                    return(buffer.GetLong(recordOffset + CountersReader.KEY_OFFSET + LOG_POSITION_OFFSET));
                }
            }

            return(Aeron.Aeron.NULL_VALUE);
        }
Esempio n. 8
0
        /// <summary>
        /// Get the timestamp at the beginning of recovery.
        /// </summary>
        /// <param name="counters">  to search within. </param>
        /// <param name="counterId"> for the active recovery counter. </param>
        /// <returns> the timestamp if found otherwise <seealso cref="NULL_VALUE"/>. </returns>
        public static long GetTimestamp(CountersReader counters, int counterId)
        {
            IDirectBuffer buffer = counters.MetaDataBuffer;

            if (counters.GetCounterState(counterId) == CountersReader.RECORD_ALLOCATED)
            {
                int recordOffset = CountersReader.MetaDataOffset(counterId);

                if (buffer.GetInt(recordOffset + CountersReader.TYPE_ID_OFFSET) == RECOVERY_STATE_TYPE_ID)
                {
                    return(buffer.GetLong(recordOffset + CountersReader.KEY_OFFSET + TIMESTAMP_OFFSET));
                }
            }

            return(NULL_VALUE);
        }
Esempio n. 9
0
        /// <summary>
        /// Get the recording id for a given counter id.
        /// </summary>
        /// <param name="countersReader"> to search within. </param>
        /// <param name="counterId">      for the active recording. </param>
        /// <returns> the counter id if found otherwise <seealso cref="NULL_RECORDING_ID"/>. </returns>
        public static long GetRecordingId(CountersReader countersReader, int counterId)
        {
            IDirectBuffer buffer = countersReader.MetaDataBuffer;

            if (countersReader.GetCounterState(counterId) == CountersReader.RECORD_ALLOCATED)
            {
                int recordOffset = CountersReader.MetaDataOffset(counterId);

                if (buffer.GetInt(recordOffset + CountersReader.TYPE_ID_OFFSET) == RECORDING_POSITION_TYPE_ID)
                {
                    return(buffer.GetLong(recordOffset + CountersReader.KEY_OFFSET + RECORDING_ID_OFFSET));
                }
            }

            return(NULL_RECORDING_ID);
        }
Esempio n. 10
0
        /// <summary>
        /// Get the accumulated log position as a base for this leadership term.
        /// </summary>
        /// <param name="counters">  to search within. </param>
        /// <param name="counterId"> for the active commit position. </param>
        /// <returns> the base log position if found otherwise <seealso cref="NULL_VALUE"/>. </returns>
        public static long GetTermBaseLogPosition(CountersReader counters, int counterId)
        {
            IDirectBuffer buffer = counters.MetaDataBuffer;

            if (counters.GetCounterState(counterId) == CountersReader.RECORD_ALLOCATED)
            {
                int recordOffset = CountersReader.MetaDataOffset(counterId);

                if (buffer.GetInt(recordOffset + CountersReader.TYPE_ID_OFFSET) == COMMIT_POSITION_TYPE_ID)
                {
                    return(buffer.GetLong(recordOffset + CountersReader.KEY_OFFSET + TERM_BASE_LOG_POSITION_OFFSET));
                }
            }

            return(NULL_VALUE);
        }
Esempio n. 11
0
        /// <summary>
        /// Get the leadership term id for the given commit position.
        /// </summary>
        /// <param name="counters">  to search within. </param>
        /// <param name="counterId"> for the active commit position. </param>
        /// <returns> the leadership term id if found otherwise <seealso cref="NULL_VALUE"/>. </returns>
        public static long GetLeadershipTermId(CountersReader counters, int counterId)
        {
            IDirectBuffer buffer = counters.MetaDataBuffer;

            if (counters.GetCounterState(counterId) == CountersReader.RECORD_ALLOCATED)
            {
                int recordOffset = CountersReader.MetaDataOffset(counterId);

                if (buffer.GetInt(recordOffset + CountersReader.TYPE_ID_OFFSET) == COMMIT_POSITION_TYPE_ID)
                {
                    return(buffer.GetLong(recordOffset + CountersReader.KEY_OFFSET + LEADERSHIP_TERM_ID_OFFSET));
                }
            }

            return(NULL_VALUE);
        }
Esempio n. 12
0
        /// <summary>
        /// Find the active counter id for a stream based on the recording id.
        /// </summary>
        /// <param name="countersReader"> to search within. </param>
        /// <param name="recordingId">    for the active recording. </param>
        /// <returns> the counter id if found otherwise <seealso cref="CountersReader.NULL_COUNTER_ID"/>. </returns>
        public static int FindCounterIdByRecording(CountersReader countersReader, long recordingId)
        {
            IDirectBuffer buffer = countersReader.MetaDataBuffer;

            for (int i = 0, size = countersReader.MaxCounterId; i < size; i++)
            {
                if (countersReader.GetCounterState(i) == RECORD_ALLOCATED &&
                    countersReader.GetCounterTypeId(i) == RECORDING_POSITION_TYPE_ID)
                {
                    if (buffer.GetLong(MetaDataOffset(i) + KEY_OFFSET +
                                       RECORDING_ID_OFFSET) == recordingId)
                    {
                        return(i);
                    }
                }
            }

            return(NULL_COUNTER_ID);
        }
Esempio n. 13
0
        /// <summary>
        /// Get the recording id of the snapshot for a service.
        /// </summary>
        /// <param name="counters">  to search within. </param>
        /// <param name="counterId"> for the active recovery counter. </param>
        /// <param name="serviceId"> for the snapshot required. </param>
        /// <returns> the count of replay terms if found otherwise <see cref="Adaptive.Aeron.Aeron.NULL_VALUE"/>. </returns>
        public static long GetSnapshotRecordingId(CountersReader counters, int counterId, int serviceId)
        {
            IDirectBuffer buffer = counters.MetaDataBuffer;

            if (counters.GetCounterState(counterId) == CountersReader.RECORD_ALLOCATED &&
                counters.GetCounterTypeId(counterId) == RECOVERY_STATE_TYPE_ID)
            {
                int recordOffset = CountersReader.MetaDataOffset(counterId);

                int serviceCount = buffer.GetInt(recordOffset + CountersReader.KEY_OFFSET + SERVICE_COUNT_OFFSET);
                if (serviceId < 0 || serviceId >= serviceCount)
                {
                    throw new ClusterException("invalid serviceId " + serviceId + " for count of " + serviceCount);
                }

                return(buffer.GetLong(recordOffset + CountersReader.KEY_OFFSET + SNAPSHOT_RECORDING_IDS_OFFSET +
                                      (serviceId * BitUtil.SIZE_OF_LONG)));
            }

            throw new ClusterException("active counter not found " + counterId);
        }
        /// <summary>
        /// Find the active counter id for a heartbeat timestamp.
        /// </summary>
        /// <param name="countersReader"> to search within. </param>
        /// <param name="counterTypeId">  to match on. </param>
        /// <param name="registrationId"> for the active client. </param>
        /// <returns> the counter id if found otherwise <seealso cref="CountersReader.NULL_COUNTER_ID"/>. </returns>
        public static int FindCounterIdByRegistrationId(CountersReader countersReader, int counterTypeId,
                                                        long registrationId)
        {
            IDirectBuffer buffer = countersReader.MetaDataBuffer;

            for (int i = 0, size = countersReader.MaxCounterId; i < size; i++)
            {
                if (countersReader.GetCounterState(i) == CountersReader.RECORD_ALLOCATED &&
                    countersReader.GetCounterTypeId(i) == counterTypeId)
                {
                    int recordOffset = CountersReader.MetaDataOffset(i);

                    if (buffer.GetLong(recordOffset + CountersReader.KEY_OFFSET + REGISTRATION_ID_OFFSET) ==
                        registrationId)
                    {
                        return(i);
                    }
                }
            }

            return(CountersReader.NULL_COUNTER_ID);
        }
Esempio n. 15
0
 public long CorrelationId()
 {
     return(_buffer.GetLong(_offset + 0, ByteOrder.LittleEndian));
 }
Esempio n. 16
0
 /// <summary>
 /// Get the start timestamp in milliseconds for the media driver.
 /// </summary>
 /// <param name="metaDataBuffer"> for the CnC file. </param>
 /// <returns> the start timestamp in milliseconds for the media driver. </returns>
 public static long StartTimestamp(IDirectBuffer metaDataBuffer)
 {
     return(metaDataBuffer.GetLong(StartTimestampOffset(0)));
 }
Esempio n. 17
0
 public long RecordingId()
 {
     return(_buffer.GetLong(_offset + 0, ByteOrder.LittleEndian));
 }
 public long ControlSessionId()
 {
     return(_buffer.GetLong(_offset + 0, ByteOrder.LittleEndian));
 }
Esempio n. 19
0
 public static long ClientLivenessTimeout(IDirectBuffer metaDataBuffer)
 {
     return(metaDataBuffer.GetLong(ClientLivenessTimeoutOffset(0)));
 }
Esempio n. 20
0
 public long LeadershipTermId()
 {
     return(_buffer.GetLong(_offset + 0, ByteOrder.LittleEndian));
 }
Esempio n. 21
0
 public long CandidateTermId()
 {
     return(_buffer.GetLong(_offset + 0, ByteOrder.LittleEndian));
 }
Esempio n. 22
0
 public long RecordingStartPosition()
 {
     return(_buffer.GetLong(_offset + 0, ByteOrder.LittleEndian));
 }
Esempio n. 23
0
 public long ActivityTimestamp()
 {
     return(_buffer.GetLong(_offset + 8, ByteOrder.LittleEndian));
 }
Esempio n. 24
0
        private static void PongHandler(IDirectBuffer buffer, int offset, int length, Header header)
        {
            var pingTimestamp = buffer.GetLong(offset);
            var rttNs = Stopwatch.GetTimestamp() - pingTimestamp;

            var b = rttNs*1000*1000*1000d/Stopwatch.Frequency;

            Histogram.RecordValue((long) b);
        }
Esempio n. 25
0
 public static long ClientLivenessTimeout(IDirectBuffer metaDataBuffer)
 {
     return metaDataBuffer.GetLong(ClientLivenessTimeoutOffset(0));
 }
Esempio n. 26
0
 public long LogPosition()
 {
     return(_buffer.GetLong(_offset + 0, ByteOrder.LittleEndian));
 }
Esempio n. 27
0
 /// <summary>
 /// Get the process PID hosting the driver.
 /// </summary>
 /// <param name="metaDataBuffer"> for the CnC file. </param>
 /// <returns> the process PID hosting the driver. </returns>
 public static long Pid(IDirectBuffer metaDataBuffer)
 {
     return(metaDataBuffer.GetLong(PidOffset(0)));
 }