Пример #1
0
        private long NewPosition(int resultingOffset)
        {
            if (resultingOffset > 0)
            {
                _termOffset = resultingOffset;

                return(_termBeginPosition + resultingOffset);
            }

            if ((_termBeginPosition + TermBufferLength) >= MaxPossiblePosition)
            {
                return(MAX_POSITION_EXCEEDED);
            }

            int nextIndex  = LogBufferDescriptor.NextPartitionIndex(_activePartitionIndex);
            int nextTermId = _termId + 1;

            _activePartitionIndex = nextIndex;
            _termOffset           = 0;
            _termId            = nextTermId;
            _termBeginPosition =
                LogBufferDescriptor.ComputeTermBeginPosition(nextTermId, PositionBitsToShift, InitialTermId);

            var termCount = nextTermId - InitialTermId;

            LogBufferDescriptor.InitialiseTailWithTermId(_logMetaDataBuffer, nextIndex, nextTermId);
            LogBufferDescriptor.ActiveTermCountOrdered(_logMetaDataBuffer, termCount);

            return(ADMIN_ACTION);
        }
        private void RotateTerm()
        {
            int nextIndex  = LogBufferDescriptor.NextPartitionIndex(_activePartitionIndex);
            int nextTermId = _termId + 1;

            _activePartitionIndex = nextIndex;
            _termOffset           = 0;
            _termId             = nextTermId;
            _termBeginPosition += TermBufferLength;

            var termCount = nextTermId - InitialTermId;

            LogBufferDescriptor.InitialiseTailWithTermId(_logMetaDataBuffer, nextIndex, nextTermId);
            LogBufferDescriptor.ActiveTermCountOrdered(_logMetaDataBuffer, termCount);
        }