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>
28#include <vrs/VrsExport.h>
39struct DiskRecordIndexStruct;
42namespace IndexRecord {
55 DiskStreamId() : typeId(
static_cast<int32_t
>(RecordableTypeId::Undefined)), instanceId(0) {}
57 : typeId(
static_cast<int32_t
>(streamId.getTypeId())), instanceId(streamId.getInstanceId()) {}
63 return FileFormat::readRecordableTypeId(typeId);
66 inline uint16_t getInstanceId()
const {
67 return static_cast<uint16_t
>(instanceId);
70 inline StreamId getStreamId()
const {
71 return {getTypeId(), getInstanceId()};
80 uint32_t recordSizeIn,
83 : timestamp(timestampIn),
84 recordSize(recordSizeIn),
85 recordType(
static_cast<uint8_t
>(recordTypeIn)),
86 streamId(streamIdIn) {}
89 recordSize(
static_cast<uint32_t
>(record->
getSize())),
91 streamId(streamIdIn) {}
94 uint32_t recordSize{};
102 inline StreamId getStreamId()
const {
103 return streamId.getStreamId();
114 int64_t fileOffsetIn,
117 : timestamp(timestampIn),
118 fileOffset(fileOffsetIn),
119 streamId(streamIdIn),
120 recordType(recordTypeIn) {}
123 int64_t fileOffset{};
128 return this->timestamp < rhs.
timestamp ||
134 bool operator==(
const RecordInfo& rhs)
const {
135 return this->timestamp == rhs.timestamp && this->fileOffset == rhs.fileOffset &&
136 this->streamId == rhs.streamId && this->recordType == rhs.recordType;
147 writtenRecords_.clear();
148 writtenBytesCount_ = 0;
149 writtenIndexCount_ = 0;
150 splitHeadFile_.reset();
154 splitHeadFile_ = std::make_unique<DiskFile>();
155 return *splitHeadFile_;
158 const std::unique_ptr<DiskFile>& getSplitHead()
const {
159 return splitHeadFile_;
163 streamIds_.insert(
id);
168 int preallocateClassicIndexRecord(
170 const deque<DiskRecordInfo>& preliminaryIndex,
171 uint32_t& outLastRecordSize);
172 void useClassicIndexRecord() {
173 preallocatedIndexRecordSize_ = 0;
175 int finalizeClassicIndexRecord(
177 int64_t endOfRecordsOffset,
178 uint32_t& outLastRecordSize);
180 int createSplitIndexRecord(uint32_t& outLastRecordSize);
181 int finalizeSplitIndexRecord(
const unique_ptr<NewChunkHandler>& chunkHandler);
184 int appendToSplitIndexRecord();
185 int completeSplitIndexRecord();
188 std::unique_ptr<DiskFile> splitHeadFile_;
191 uint32_t preallocatedIndexRecordSize_{};
193 set<StreamId> streamIds_;
194 deque<IndexRecord::DiskRecordInfo> writtenRecords_;
195 size_t writtenBytesCount_{};
196 size_t writtenIndexCount_{};
206 set<StreamId>& outStreamIds,
207 vector<RecordInfo>& outIndex);
209 bool isIndexComplete()
const {
210 return indexComplete_;
213 int readRecord(int64_t firstUserRecordOffset, int64_t& outUsedFileSize);
219 int rebuildIndex(
bool writeFixedIndex);
223 int64_t indexRecordOffset,
224 int64_t firstUserRecordOffset,
225 int64_t& outUsedFileSize);
226 int readClassicIndexRecord(
227 size_t indexRecordPayloadSize,
228 size_t uncompressedSize,
229 int64_t firstUserRecordOffset,
230 int64_t& outUsedFileSize);
231 int readSplitIndexRecord(
size_t indexByteSize,
size_t uncompressedSize, int64_t& outUsedFileSize);
232 int readDiskInfo(vector<DiskRecordInfo>& outRecords);
234 bool determineSplitIndexLayout(
235 size_t& inOutIndexByteSize,
236 int64_t& outUsedFileSize,
238 int readSplitIndexData(
239 size_t indexByteSize,
240 size_t uncompressedSize,
241 vector<DiskRecordInfo>& outRecords,
243 bool processSplitIndexRecords(
const vector<DiskRecordInfo>& records, int64_t& outUsedFileSize);
244 int determineClassicIndexLayout(
245 size_t indexRecordPayloadSize,
246 uint32_t& outRecordCount,
247 size_t& outIndexSize);
248 int readClassicIndexData(
250 size_t uncompressedSize,
251 uint32_t recordCount,
252 vector<DiskRecordInfo>& outRecords);
253 bool processClassicIndexRecords(
254 const vector<DiskRecordInfo>& records,
256 int64_t& outUsedFileSize);
260 const int64_t totalFileSize_;
263 set<StreamId>& streamIds_;
264 vector<RecordInfo>& index_;
265 unique_ptr<deque<IndexRecord::DiskRecordInfo>> diskIndex_;
266 bool indexComplete_{};
267 bool hasSplitHeadChunk_{};
268 int32_t sortErrorCount_{};
269 int32_t droppedRecordCount_{};
278 return this->recordType < rhs.recordType ||
279 (this->recordType == rhs.recordType && this->streamId < rhs.streamId);
Helper class to compress data using lz4 or zstd presets.
Definition Compressor.h:83
FileHandler implementation for disk files, with chunked file support.
Definition DiskFile.h:34
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:200
Helper class to write VRS index records.
Definition IndexRecord.h:141
ProgressLogger class to be notified of some process' progress.
Definition ProgressLogger.h:33
Essential VRS class holding a record's details and payload in memory during creation.
Definition Record.h:82
Type getRecordType() const
Get the record's record type.
Definition Record.h:150
Type
Definition Record.h:91
double getTimestamp() const
Get the record's timestamp.
Definition Record.h:136
size_t getSize() const
Get the record's payload size, uncompressed.
Definition Record.h:145
VRS stream identifier class.
Definition StreamId.h:251
The WriteFileHandler interface adds write operations to the FileHandler interface.
Definition WriteFileHandler.h:43
@ kSplitIndexFormatVersion
Definition IndexRecord.h:48
@ kClassicIndexFormatVersion
Definition IndexRecord.h:45
Definition Compressor.cpp:113
RecordableTypeId
VRS stream type or class identifier enum.
Definition StreamId.h:51
Helper class to store details about a single VRS record on disk.
Definition IndexRecord.h:76
Helper class to store StreamID objects on disk.
Definition IndexRecord.h:54
Helper class to hold the details about a single VRS record in memory.
Definition IndexRecord.h:110
double timestamp
timestamp of the record
Definition IndexRecord.h:122
StreamId streamId
creator of the record
Definition IndexRecord.h:124
int64_t fileOffset
absolute byte offset of the record in the whole file
Definition IndexRecord.h:123
This is used to count records to different kinds.
Definition IndexRecord.h:273