示例#1
0
        /// <summary>
        /// Allocate a counter to represent the snapshot services should load on start.
        /// </summary>
        /// <param name="aeron">           to allocate the counter. </param>
        /// <param name="tempBuffer">      to use for building the key and label without allocation. </param>
        /// <param name="leadershipTermId">    at which the snapshot was taken. </param>
        /// <param name="termPosition">     at which the snapshot was taken. </param>
        /// <param name="timestamp">       the snapshot was taken. </param>
        /// <param name="replayTermCount"> for the count of terms to be replayed during recovery after snapshot. </param>
        /// <returns> the <seealso cref="Counter"/> for the consensus position. </returns>
        public static Counter Allocate(Aeron.Aeron aeron, IMutableDirectBuffer tempBuffer, long termPosition, long leadershipTermId, long timestamp, int replayTermCount)
        {
            tempBuffer.PutLong(LEADERSHIP_TERM_ID_OFFSET, leadershipTermId);
            tempBuffer.PutLong(TERM_POSITION_OFFSET, termPosition);
            tempBuffer.PutLong(TIMESTAMP_OFFSET, timestamp);
            tempBuffer.PutInt(REPLAY_TERM_COUNT_OFFSET, replayTermCount);

            int labelOffset = 0;

            labelOffset += tempBuffer.PutStringWithoutLengthAscii(KEY_LENGTH + labelOffset, NAME);
            labelOffset += tempBuffer.PutLongAscii(KEY_LENGTH + labelOffset, leadershipTermId);
            labelOffset += tempBuffer.PutStringWithoutLengthAscii(KEY_LENGTH + labelOffset, " termPosition=");
            labelOffset += tempBuffer.PutLongAscii(KEY_LENGTH + labelOffset, termPosition);
            labelOffset += tempBuffer.PutStringWithoutLengthAscii(KEY_LENGTH + labelOffset, " replayTermCount=");
            labelOffset += tempBuffer.PutIntAscii(KEY_LENGTH + labelOffset, replayTermCount);

            return(aeron.AddCounter(RECOVERY_STATE_TYPE_ID, tempBuffer, 0, KEY_LENGTH, tempBuffer, KEY_LENGTH, labelOffset));
        }
示例#2
0
        /// <summary>
        /// Allocate a counter to represent the snapshot services should load on start.
        /// </summary>
        /// <param name="aeron">                to allocate the counter. </param>
        /// <param name="tempBuffer">           to use for building the key and label without allocation. </param>
        /// <param name="leadershipTermId">     at which the snapshot was taken. </param>
        /// <param name="logPosition">          at which the snapshot was taken. </param>
        /// <param name="timestamp">            the snapshot was taken. </param>
        /// <param name="hasReplay">            flag is true if all or part of the log must be replayed. </param>
        /// <param name="snapshotRecordingIds"> for the services to use during recovery indexed by service id. </param>
        /// <returns> the <seealso cref="Counter"/> for the recovery state. </returns>
        public static Counter Allocate(
            Aeron.Aeron aeron,
            IMutableDirectBuffer tempBuffer,
            long leadershipTermId,
            long logPosition,
            long timestamp,
            bool hasReplay,
            params long[] snapshotRecordingIds)
        {
            tempBuffer.PutLong(LEADERSHIP_TERM_ID_OFFSET, leadershipTermId);
            tempBuffer.PutLong(LOG_POSITION_OFFSET, logPosition);
            tempBuffer.PutLong(TIMESTAMP_OFFSET, timestamp);
            tempBuffer.PutInt(REPLAY_FLAG_OFFSET, hasReplay ? 1 : 0);

            int serviceCount = snapshotRecordingIds.Length;

            tempBuffer.PutInt(SERVICE_COUNT_OFFSET, serviceCount);

            int keyLength             = SNAPSHOT_RECORDING_IDS_OFFSET + (serviceCount * BitUtil.SIZE_OF_LONG);
            int maxRecordingIdsLength = SNAPSHOT_RECORDING_IDS_OFFSET + (serviceCount * BitUtil.SIZE_OF_LONG);

            if (maxRecordingIdsLength > CountersReader.MAX_KEY_LENGTH)
            {
                throw new ClusterException(maxRecordingIdsLength + " execeeds max key length " + CountersReader.MAX_KEY_LENGTH);
            }

            for (int i = 0; i < serviceCount; i++)
            {
                tempBuffer.PutLong(SNAPSHOT_RECORDING_IDS_OFFSET + (i * BitUtil.SIZE_OF_LONG), snapshotRecordingIds[i]);
            }


            int labelOffset = 0;

            labelOffset += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelOffset, NAME);
            labelOffset += tempBuffer.PutLongAscii(keyLength + labelOffset, leadershipTermId);
            labelOffset += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelOffset, " logPosition=");
            labelOffset += tempBuffer.PutLongAscii(keyLength + labelOffset, logPosition);
            labelOffset += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelOffset, " hasReplay=" + hasReplay);

            return(aeron.AddCounter(RECOVERY_STATE_TYPE_ID, tempBuffer, 0, keyLength, tempBuffer, keyLength, labelOffset));
        }
示例#3
0
        /// <summary>
        /// Allocate a counter to represent the commit position on stream for the current leadership term.
        /// </summary>
        /// <param name="aeron">            to allocate the counter. </param>
        /// <param name="tempBuffer">       to use for building the key and label without allocation. </param>
        /// <param name="recordingId">      for the current term. </param>
        /// <param name="logPosition">      of the log at the beginning of the leadership term. </param>
        /// <param name="leadershipTermId"> of the log at the beginning of the leadership term. </param>
        /// <param name="sessionId">        of the active log for the current leadership term. </param>
        /// <returns> the <seealso cref="Counter"/> for the consensus position. </returns>
        public static Counter Allocate(Aeron.Aeron aeron, IMutableDirectBuffer tempBuffer, long recordingId, long logPosition, long leadershipTermId, int sessionId)
        {
            tempBuffer.PutLong(RECORDING_ID_OFFSET, recordingId);
            tempBuffer.PutLong(LOG_POSITION_OFFSET, logPosition);
            tempBuffer.PutLong(LEADERSHIP_TERM_ID_OFFSET, leadershipTermId);
            tempBuffer.PutInt(SESSION_ID_OFFSET, sessionId);

            int labelOffset = 0;

            labelOffset += tempBuffer.PutStringWithoutLengthAscii(KEY_LENGTH + labelOffset, NAME);
            labelOffset += tempBuffer.PutLongAscii(KEY_LENGTH + labelOffset, leadershipTermId);
            labelOffset += tempBuffer.PutStringWithoutLengthAscii(KEY_LENGTH + labelOffset, " logSessionId=");
            labelOffset += tempBuffer.PutIntAscii(KEY_LENGTH + labelOffset, sessionId);

            return(aeron.AddCounter(COMMIT_POSITION_TYPE_ID, tempBuffer, 0, KEY_LENGTH, tempBuffer, KEY_LENGTH, labelOffset));
        }
示例#4
0
        public static int AllocateCounterId(
            IMutableDirectBuffer tempBuffer,
            string name,
            int typeId,
            CountersManager countersManager,
            long registrationId)
        {
            tempBuffer.PutLong(REGISTRATION_ID_OFFSET, registrationId);
            int keyLength = REGISTRATION_ID_OFFSET + BitUtil.SIZE_OF_LONG;

            int labelLength = 0;

            labelLength += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelLength, name);
            labelLength += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelLength, ": ");
            labelLength += tempBuffer.PutLongAscii(keyLength + labelLength, registrationId);

            return(countersManager.Allocate(typeId, tempBuffer, 0, keyLength, tempBuffer, keyLength, labelLength));
        }
示例#5
0
        /// <summary>
        /// Allocate a counter to represent the commit position on stream for the current leadership term.
        /// </summary>
        /// <param name="aeron">                to allocate the counter. </param>
        /// <param name="tempBuffer">           to use for building the key and label without allocation. </param>
        /// <param name="leadershipTermId">     of the log at the beginning of the leadership term. </param>
        /// <param name="termBaseLogPosition">  of the log at the beginning of the leadership term. </param>
        /// <param name="leadershipTermLength"> length in bytes of the leadership term for the log. </param>
        /// <returns> the <seealso cref="Counter"/> for the commit position. </returns>
        public static Counter Allocate(
            Aeron.Aeron aeron,
            IMutableDirectBuffer tempBuffer,
            long leadershipTermId,
            long termBaseLogPosition,
            long leadershipTermLength)
        {
            tempBuffer.PutLong(LEADERSHIP_TERM_ID_OFFSET, leadershipTermId);
            tempBuffer.PutLong(TERM_BASE_LOG_POSITION_OFFSET, termBaseLogPosition);
            tempBuffer.PutLong(LEADERSHIP_TERM_LENGTH_OFFSET, leadershipTermLength);


            int labelOffset = 0;

            labelOffset += tempBuffer.PutStringWithoutLengthAscii(KEY_LENGTH + labelOffset, NAME);
            labelOffset += tempBuffer.PutLongAscii(KEY_LENGTH + labelOffset, leadershipTermId);

            return(aeron.AddCounter(COMMIT_POSITION_TYPE_ID, tempBuffer, 0, KEY_LENGTH, tempBuffer, KEY_LENGTH, labelOffset));
        }
示例#6
0
        /// <summary>
        /// Allocate a counter to represent the commit position on stream for the current leadership term.
        /// </summary>
        /// <param name="aeron">                to allocate the counter. </param>
        /// <param name="tempBuffer">           to use for building the key and label without allocation. </param>
        /// <param name="leadershipTermId">     of the log at the beginning of the leadership term. </param>
        /// <param name="logPosition">  of the log at the beginning of the leadership term. </param>
        /// <param name="maxLogPosition"> length in bytes of the leadership term for the log. </param>
        /// <returns> the <seealso cref="Counter"/> for the commit position. </returns>
        public static Counter Allocate(
            Aeron.Aeron aeron,
            IMutableDirectBuffer tempBuffer,
            long leadershipTermId,
            long logPosition,
            long maxLogPosition)
        {
            tempBuffer.PutLong(LEADERSHIP_TERM_ID_OFFSET, leadershipTermId);
            tempBuffer.PutLong(LOG_POSITION_OFFSET, logPosition);
            tempBuffer.PutLong(MAX_LOG_POSITION_OFFSET, maxLogPosition);

            int labelOffset = BitUtil.Align(KEY_LENGTH, BitUtil.SIZE_OF_INT);
            int labelLength = 0;

            labelLength += tempBuffer.PutStringWithoutLengthAscii(labelOffset + labelLength, NAME);
            labelLength += tempBuffer.PutLongAscii(labelOffset + labelLength, leadershipTermId);

            return(aeron.AddCounter(COMMIT_POSITION_TYPE_ID, tempBuffer, 0, KEY_LENGTH, tempBuffer, labelOffset, labelLength));
        }