Ejemplo n.º 1
0
        /// <summary>
        /// Pad a length of the term buffer with a padding record.
        /// </summary>
        /// <param name="termId"> for the current term.</param>
        /// <param name="termOffset"> in the term at which to append.</param>
        /// <param name="header"> for writing the default header.</param>
        /// <param name="length"> of the padding to be written.</param>
        /// <returns> the resulting offset of the term after success otherwise <see cref="TRIPPED"/>.</returns>
        public int AppendPadding(
            int termId,
            int termOffset,
            HeaderWriter header,
            int length)
        {
            int          frameLength   = length + DataHeaderFlyweight.HEADER_LENGTH;
            int          alignedLength = BitUtil.Align(frameLength, FrameDescriptor.FRAME_ALIGNMENT);
            UnsafeBuffer termBuffer    = _termBuffer;
            int          termLength    = termBuffer.Capacity;

            int resultingOffset = termOffset + alignedLength;

            PutRawTailOrdered(termId, resultingOffset);

            if (resultingOffset > termLength)
            {
                resultingOffset = HandleEndOfLogCondition(termBuffer, termOffset, header, termLength, termId);
            }
            else
            {
                header.Write(termBuffer, termOffset, frameLength, termId);
                FrameDescriptor.FrameType(termBuffer, termOffset, FrameDescriptor.PADDING_FRAME_TYPE);
                FrameDescriptor.FrameLengthOrdered(termBuffer, termOffset, frameLength);
            }

            return(resultingOffset);
        }
Ejemplo n.º 2
0
        private long HandleEndOfLogCondition(UnsafeBuffer termBuffer, long termOffset, HeaderWriter header,
                                             int termLength, int termId)
        {
            if (termOffset < termLength)
            {
                int offset        = (int)termOffset;
                int paddingLength = termLength - offset;
                header.Write(termBuffer, offset, paddingLength, termId);
                FrameDescriptor.FrameType(termBuffer, offset, FrameDescriptor.PADDING_FRAME_TYPE);
                FrameDescriptor.FrameLengthOrdered(termBuffer, offset, paddingLength);
            }

            return(FAILED);
        }
Ejemplo n.º 3
0
        private long HandleEndOfLogCondition(UnsafeBuffer termBuffer, long termOffset, HeaderWriter header,
                                             int termLength, int termId)
        {
            int resultingOffset = FAILED;

            if (termOffset <= termLength)
            {
                resultingOffset = TRIPPED;

                if (termOffset < termLength)
                {
                    int offset        = (int)termOffset;
                    int paddingLength = termLength - offset;
                    header.Write(termBuffer, offset, paddingLength, termId);
                    FrameDescriptor.FrameType(termBuffer, offset, FrameDescriptor.PADDING_FRAME_TYPE);
                    FrameDescriptor.FrameLengthOrdered(termBuffer, offset, paddingLength);
                }
            }

            return(LogBufferDescriptor.PackTail(termId, resultingOffset));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Try to gap fill the current term at a given offset if the gap contains no data.
        ///
        /// Note: the gap offset plus gap length must end on a <seealso cref="FrameDescriptor.FRAME_ALIGNMENT"/> boundary.
        /// </summary>
        /// <param name="logMetaDataBuffer"> containing the default headers </param>
        /// <param name="termBuffer">        to gap fill </param>
        /// <param name="termId">            for the current term. </param>
        /// <param name="gapOffset">         to fill from </param>
        /// <param name="gapLength">         to length of the gap. </param>
        /// <returns> true if the gap has been filled with a padding record or false if data found. </returns>
        public static bool TryFillGap(UnsafeBuffer logMetaDataBuffer, UnsafeBuffer termBuffer, int termId, int gapOffset, int gapLength)
        {
            int offset = gapOffset + gapLength - FrameDescriptor.FRAME_ALIGNMENT;

            while (offset >= gapOffset)
            {
                if (0 != termBuffer.GetInt(offset))
                {
                    return(false);
                }

                offset -= FrameDescriptor.FRAME_ALIGNMENT;
            }

            LogBufferDescriptor.ApplyDefaultHeader(logMetaDataBuffer, termBuffer, gapOffset);
            FrameDescriptor.FrameType(termBuffer, gapOffset, HeaderFlyweight.HDR_TYPE_PAD);
            FrameDescriptor.FrameTermOffset(termBuffer, gapOffset);
            FrameDescriptor.FrameTermId(termBuffer, gapOffset, termId);
            FrameDescriptor.FrameLengthOrdered(termBuffer, gapOffset, gapLength);

            return(true);
        }