22#include "Compressor.h"
24#include "FileFormat.h"
25#include "ForwardDefinitions.h"
26#include "NewChunkHandler.h"
38struct DiskRecordIndexStruct;
41namespace IndexRecord {
62 return FileFormat::readRecordableTypeId(typeId);
65 uint16_t getInstanceId()
const {
66 return instanceId.
get();
70 return {getTypeId(), getInstanceId()};
78 : timestamp(timestamp),
79 recordSize(recordSize),
80 recordType(
static_cast<uint8_t
>(recordType)),
84 recordSize(
static_cast<uint32_t
>(record->
getSize())),
98 return streamId.getStreamId();
116 return this->timestamp < rhs.
timestamp ||
122 bool operator==(
const RecordInfo& rhs)
const {
123 return this->timestamp == rhs.timestamp && this->fileOffset == rhs.fileOffset &&
124 this->streamId == rhs.streamId && this->recordType == rhs.recordType;
135 writtenRecords_.clear();
136 writtenBytesCount_ = 0;
137 writtenIndexCount_ = 0;
138 splitHeadFile_.reset();
142 splitHeadFile_ = std::make_unique<DiskFile>();
143 return *splitHeadFile_;
146 const std::unique_ptr<DiskFile>& getSplitHead()
const {
147 return splitHeadFile_;
151 streamIds_.insert(
id);
156 int preallocateClassicIndexRecord(
158 const deque<DiskRecordInfo>& preliminaryIndex,
159 uint32_t& outLastRecordSize);
160 void useClassicIndexRecord() {
161 preallocatedIndexRecordSize_ = 0;
163 int finalizeClassicIndexRecord(
165 int64_t endOfRecordsOffset,
166 uint32_t& outLastRecordSize);
168 int createSplitIndexRecord(uint32_t& outLastRecordSize);
169 int finalizeSplitIndexRecord(
const unique_ptr<NewChunkHandler>& chunkHandler);
172 int appendToSplitIndexRecord();
173 int completeSplitIndexRecord();
176 std::unique_ptr<DiskFile> splitHeadFile_;
179 uint32_t preallocatedIndexRecordSize_{};
181 set<StreamId> streamIds_;
182 deque<IndexRecord::DiskRecordInfo> writtenRecords_;
183 size_t writtenBytesCount_{};
184 size_t writtenIndexCount_{};
194 set<StreamId>& outStreamIds,
195 vector<RecordInfo>& outIndex);
197 bool isIndexComplete()
const {
198 return indexComplete_;
201 int readRecord(int64_t firstUserRecordOffset, int64_t& outUsedFileSize);
211 int64_t indexRecordOffset,
212 int64_t firstUserRecordOffset,
213 int64_t& outUsedFileSize);
214 int readClassicIndexRecord(
215 size_t indexRecordPayloadSize,
216 size_t uncompressedSize,
217 int64_t firstUserRecordOffset,
218 int64_t& outUsedFileSize);
219 int readSplitIndexRecord(
size_t indexByteSize,
size_t uncompressedSize, int64_t& outUsedFileSize);
220 int readDiskInfo(vector<DiskRecordInfo>& outRecords);
224 const int64_t totalFileSize_;
227 set<StreamId>& streamIds_;
228 vector<RecordInfo>& index_;
229 unique_ptr<deque<IndexRecord::DiskRecordInfo>> diskIndex_;
230 bool indexComplete_{};
231 bool hasSplitHeadChunk_{};
232 int32_t sortErrorCount_{};
233 int32_t droppedRecordCount_{};
242 return this->recordType < rhs.recordType ||
243 (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:34
Class to abstract VRS file system operations, to enable support for alternate storage methods,...
Definition FileHandler.h:71
Helper class to read VRS index records.
Definition IndexRecord.h:188
int rebuildIndex(bool writeFixedIndex)
Definition IndexRecord.cpp:584
Helper class to write VRS index records.
Definition IndexRecord.h:129
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:79
Type getRecordType() const
Get the record's record type.
Definition Record.h:147
Type
Definition Record.h:88
double getTimestamp() const
Get the record's timestamp.
Definition Record.h:133
size_t getSize() const
Get the record's payload size, uncompressed.
Definition Record.h:142
VRS stream identifier class.
Definition StreamId.h:242
RecordableTypeId getTypeId() const
Definition StreamId.h:251
uint16_t getInstanceId() const
Definition StreamId.h:257
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 AsyncDiskFileChunk.hpp:49
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:105
Record::Type recordType
type of record
Definition IndexRecord.h:113
double timestamp
timestamp of the record
Definition IndexRecord.h:110
StreamId streamId
creator of the record
Definition IndexRecord.h:112
int64_t fileOffset
absolute byte offset of the record in the whole file
Definition IndexRecord.h:111
This is used to count records to different kinds.
Definition IndexRecord.h:237