22#include <vrs/Compressor.h>
23#include <vrs/DiskFile.h>
24#include <vrs/FileFormat.h>
25#include <vrs/ForwardDefinitions.h>
26#include <vrs/NewChunkHandler.h>
27#include <vrs/Record.h>
38struct DiskRecordIndexStruct;
41namespace IndexRecord {
56 : typeId(
static_cast<int32_t
>(streamId.getTypeId())), instanceId(streamId.getInstanceId()) {}
62 return FileFormat::readRecordableTypeId(typeId);
65 inline uint16_t getInstanceId()
const {
66 return static_cast<uint16_t
>(instanceId);
69 inline StreamId getStreamId()
const {
70 return {getTypeId(), getInstanceId()};
79 uint32_t recordSizeIn,
82 : timestamp(timestampIn),
83 recordSize(recordSizeIn),
84 recordType(
static_cast<uint8_t
>(recordTypeIn)),
85 streamId(streamIdIn) {}
88 recordSize(
static_cast<uint32_t
>(record->
getSize())),
90 streamId(streamIdIn) {}
93 uint32_t recordSize{};
101 inline StreamId getStreamId()
const {
102 return streamId.getStreamId();
113 int64_t fileOffsetIn,
133 bool operator==(
const RecordInfo& rhs)
const {
146 writtenRecords_.clear();
147 writtenBytesCount_ = 0;
148 writtenIndexCount_ = 0;
149 splitHeadFile_.reset();
153 splitHeadFile_ = std::make_unique<DiskFile>();
154 return *splitHeadFile_;
157 const std::unique_ptr<DiskFile>& getSplitHead()
const {
158 return splitHeadFile_;
162 streamIds_.insert(
id);
167 int preallocateClassicIndexRecord(
169 const deque<DiskRecordInfo>& preliminaryIndex,
170 uint32_t& outLastRecordSize);
171 void useClassicIndexRecord() {
172 preallocatedIndexRecordSize_ = 0;
174 int finalizeClassicIndexRecord(
176 int64_t endOfRecordsOffset,
177 uint32_t& outLastRecordSize);
179 int createSplitIndexRecord(uint32_t& outLastRecordSize);
180 int finalizeSplitIndexRecord(
const unique_ptr<NewChunkHandler>& chunkHandler);
183 int appendToSplitIndexRecord();
184 int completeSplitIndexRecord();
187 std::unique_ptr<DiskFile> splitHeadFile_;
190 uint32_t preallocatedIndexRecordSize_{};
192 set<StreamId> streamIds_;
193 deque<IndexRecord::DiskRecordInfo> writtenRecords_;
194 size_t writtenBytesCount_{};
195 size_t writtenIndexCount_{};
205 set<StreamId>& outStreamIds,
206 vector<RecordInfo>& outIndex);
208 bool isIndexComplete()
const {
209 return indexComplete_;
212 int readRecord(int64_t firstUserRecordOffset, int64_t& outUsedFileSize);
222 int64_t indexRecordOffset,
223 int64_t firstUserRecordOffset,
224 int64_t& outUsedFileSize);
225 int readClassicIndexRecord(
226 size_t indexRecordPayloadSize,
227 size_t uncompressedSize,
228 int64_t firstUserRecordOffset,
229 int64_t& outUsedFileSize);
230 int readSplitIndexRecord(
size_t indexByteSize,
size_t uncompressedSize, int64_t& outUsedFileSize);
231 int readDiskInfo(vector<DiskRecordInfo>& outRecords);
235 const int64_t totalFileSize_;
238 set<StreamId>& streamIds_;
239 vector<RecordInfo>& index_;
240 unique_ptr<deque<IndexRecord::DiskRecordInfo>> diskIndex_;
241 bool indexComplete_{};
242 bool hasSplitHeadChunk_{};
243 int32_t sortErrorCount_{};
244 int32_t droppedRecordCount_{};
253 return this->recordType < rhs.recordType ||
254 (this->recordType == rhs.recordType && this->streamId < rhs.streamId);
Helper class to compress data using lz4 or zstd presets.
Definition Compressor.h:82
FileHandler implementation for disk files, with chunked file support.
Definition DiskFile.h:33
Class to abstract VRS file system operations, to enable support for alternate storage methods,...
Definition FileHandler.h:75
Helper class to read VRS index records.
Definition IndexRecord.h:199
int rebuildIndex(bool writeFixedIndex)
Definition IndexRecord.cpp:593
Helper class to write VRS index records.
Definition IndexRecord.h:140
ProgressLogger class to be notified of some process' progress.
Definition ProgressLogger.h:31
Essential VRS class holding a record's details and payload in memory during creation.
Definition Record.h:78
Type getRecordType() const
Get the record's record type.
Definition Record.h:146
Type
Definition Record.h:87
double getTimestamp() const
Get the record's timestamp.
Definition Record.h:132
size_t getSize() const
Get the record's payload size, uncompressed.
Definition Record.h:141
VRS stream identifier class.
Definition StreamId.h:245
The WriteFileHandler interface adds write operations to the FileHandler interface.
Definition WriteFileHandler.h:45
@ kSplitIndexFormatVersion
Definition IndexRecord.h:47
@ kClassicIndexFormatVersion
Definition IndexRecord.h:44
Definition Compressor.cpp:112
RecordableTypeId
VRS stream type or class identifier enum.
Definition StreamId.h:49
@ Undefined
Value used for default initializations and marking undefined situations.
Helper class to store details about a single VRS record on disk.
Definition IndexRecord.h:75
Helper class to store StreamID objects on disk.
Definition IndexRecord.h:53
Helper class to hold the details about a single VRS record in memory.
Definition IndexRecord.h:109
Record::Type recordType
type of record
Definition IndexRecord.h:124
double timestamp
timestamp of the record
Definition IndexRecord.h:121
StreamId streamId
creator of the record
Definition IndexRecord.h:123
int64_t fileOffset
absolute byte offset of the record in the whole file
Definition IndexRecord.h:122
This is used to count records to different kinds.
Definition IndexRecord.h:248