Exemple #1
0
        public override void Open()
        {
            _indexAndHeaderStorage.Open();
            _appendOnlyDataStorage.Open();
            _compressedStorage.Open();

            _indexAndHeaderStorage.SetPositionOffset(0);
            _indexAndHeaderStorage.ReadStructure(ref _header);

            Initialize();

            if (_header.CompressedBlocksCount > 0)
            {
                var offsetsBufferBytesCount = _header.CompressedBlocksCount * 8;
                var offsetsBuffer           = new byte[offsetsBufferBytesCount];
                _indexAndHeaderStorage.ReadStructureArray(offsetsBuffer);

                var offsets = MemoryMarshal.Cast <byte, long>(offsetsBuffer);
                for (int i = 0; i < _header.CompressedBlocksCount; i++)
                {
                    _blockOffsets.Add(offsets[i]);
                }
            }
        }
Exemple #2
0
        public RaxLogEntry[] GetLogs(long minTimestamp, long maxTimestamp, long skipLogs = 0, long takeLogs = long.MaxValue)
        {
            var range = GetLogsRange(minTimestamp, maxTimestamp, skipLogs, takeLogs);

            var result = new RaxLogEntry[range.LogsCount];

            if (range.LogsCount == 0)
            {
                return(result);
            }

            // MAX_SELECT_LOGS_BUFFER
            var bufferSize = range.LogsCount * _logSize;

            var buffer = new byte[bufferSize];

            _logsStorage.SetPositionOffset(range.FromLogIndex * _logSize);
            _logsStorage.ReadStructureArray(buffer);

            var logs = MemoryMarshal.Cast <byte, RaxFixedSizeLogEntry>(buffer);

            var fromLog = logs[0];
            var toLog   = logs[logs.Length - 1];

            var fromOffset    = fromLog.DataOffset;
            var toOffset      = toLog.DataOffset;
            var logsBytesData = toOffset + toLog.TextLengthInBytes + toLog.CategoriesCount * 8;

            // MAX_SELECT_LOGS_BUFFER
            var dataBuffer = new byte[logsBytesData];

            _logsDataStorage.SetPositionOffset(fromOffset);
            _logsDataStorage.ReadStructureArray(dataBuffer);

            var dataBufferSpan = dataBuffer.AsSpan();

            var dataOffset = 0;

            for (int i = 0; i < logs.Length; i++)
            {
                var log = logs[i];

                var dataSpanBegin = dataBufferSpan.Slice(dataOffset);
                var text          = new string(MemoryMarshal.Cast <byte, char>(dataSpanBegin.Slice(0, log.TextLengthInBytes)));
                var datetime      = new DateTime(log.Timestamp);

                var categories = new string[log.CategoriesCount];

                var logCategoriesSpan = MemoryMarshal.Cast <byte, long>(dataSpanBegin.Slice(log.TextLengthInBytes, log.CategoriesCount * 8));
                for (int catIndex = 0; catIndex < log.CategoriesCount; catIndex++)
                {
                    categories[catIndex] = _categoriesByIndex[logCategoriesSpan[catIndex]].CategoryName;
                }

                result[i] = new RaxLogEntry
                {
                    Text       = text,
                    Date       = datetime,
                    Categories = categories
                };

                dataOffset += ComputeLogDataSizeInBytes(text.Length, log.CategoriesCount);
            }

            return(result);
        }