Repository navigation
Conversation
A serialized chunk header embeds the measurement/column name verbatim, so a column/measurement name of about 1018 characters or more makes the header longer than the fixed 1024-byte window used by ChunkReader::load_by_meta(), AlignedChunkReader::load_by_aligned_meta() and AlignedChunkReader::load_by_aligned_meta_multi(). Reading the header then hit read_var_str()'s "length beyond the stream" check, which surfaces E_PARTIAL_READ: the write succeeded but the first read of that column failed. Add reader/read_chunk_header.h: it reads and deserializes a chunk header at an offset, doubling the read window while deserialization reports that more bytes are needed, capped at the end of the file. Use it in both chunk readers and in the recovery self-check (parse_chunk_header_and_skip()) as well, which previously mistook such a chunk for a corrupt tail and truncated the recovered file at it. Callers wrap the returned buffer and advance their stream past header.serialized_size_ to the first page header. No on-disk format or writer change: names that could already be written are now readable again, matching Java, which has no name length limit. Tests: new LongMeasurementNameTest writes and reads back 1017/1018/1024/4096 character names for table FIELD columns, table TAG columns (schema lookup and tag filter) and tree measurements; a new restorable-writer case recovers and appends after a 4096-character name. The FIELD, tree and recovery cases fail below 1018/1024/4096 characters without this fix. CLI: no change applicable. The CLI reads through this SDK, and its sketch-layout chunk-header probe already grows its window (up to 1 MiB), so its behavior follows the SDK fix without CLI-side changes.
…TsFile-213) Follow-up to 84cddbc addressing third-party review findings. The chunk-header read window added in 84cddbc grew up to the remaining file size, so a corrupt varint name length could drive a multi-MiB read and allocation. Cap the window at kMaxChunkHeaderWindow (1 MiB, matching the CLI sketch-layout probe limit); a header that does not fit is reported as truncated instead of being read into an unbounded buffer. New ReadChunkHeaderTest cases cover a valid header that needs growth, a corrupt 2 MiB length failing at exactly the cap, and the offset-at-EOF contract. The recovery self-check now fails on E_OOM instead of treating it like a corrupt tail: previously an allocation failure during the scan could truncate a valid file at the last good chunk. The new RestorableTsFileIOWriterTest.OomDuringSelfCheckDoesNotTruncate injects the first realloc failure on the scan path and checks that open() returns E_OOM and that the file size is unchanged. Test corrections: LongMeasurementNameTest now also asserts a second, short FIELD column next to the long-named one. Its TAG-column case is documented as coverage only: in the C++ table model tag values come from the device id rather than a value chunk, so that case passes without the reader fix and is not evidence of the chunk-header bug. Not addressed here: the recovery self-check reads chunk group headers (device id / tag values) with a fixed 4096-byte window. That is a pre-existing limitation of the same family for very long device ids and is left for a separate change. Tests: full C++ gtest suite 1917 passed (2 EncodingCompressionCompatibility cases need cwd at the repository root for compat/compatibility-matrix.csv and pass there); clang-format 17.0.6 clean.
…sFile-213) Follow-up to 7e29b7c addressing the review finding on the OOM path. self_check() now returns on E_OOM before flush_chunk_group(), so the in-progress ChunkGroupMeta stays in the arena. Arena destruction does not run destructors, and close() only clears the device ids of fully built groups in self_check_recovered_cgm_, so the std::shared_ptr<IDeviceID> held by cur_cgm->device_id_ leaked (LeakSanitizer reported 136 bytes for OomDuringSelfCheckDoesNotTruncate before this change). Reset that device id before returning; the file is still left untouched. Known limitation recorded for follow-up: the 1 MiB chunk-header window cap means a header (and therefore a measurement name) larger than 1 MiB can still be written but not read or recovered; enforcing the limit on the write side or documenting it in the skills reference is left for a separate change. Tests: targeted suites 26 passed; AddressSanitizer + LeakSanitizer build (RelWithDebInfo, address,undefined) runs OomDuringSelfCheckDoesNotTruncate and RecoverChunkWithLongMeasurementNameAndAppend without leaks; clang-format 17.0.6 clean.
Contributor
Author
|
Superseded by #1167 after the branch was renamed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A table-model column name of 1018 or more characters made the write succeed but the read return
E_PARTIAL_READ, i.e. a file that is silently unreadable.Root cause
The chunk header embeds the measurement name. The reader parsed chunk headers through a fixed 1024-byte window. For a header of
chunk_type(1) + varint len(2) + name + data_size varint(1) + 3 bytes, a name of 1017 bytes fits in 1024, while 1018 bytes needs 1025 —read_var_strthen returnedE_PARTIAL_READbecause the chunk-header path had no grow-and-retry window (chunk/page header reads did).Changes
ChunkReader, the aligned single-value/multi-value chunk readers, and the restorable recovery scan; keepsE_PARTIAL_READsemantics for truncated data and the same cursor/offset behavior.E_OOMas a corrupt tail and truncating a valid file.Verification
Review
Self-reviewed, then an independent read-only review; the delta review concluded "mergeable". The branch contains the reader fix, a review-hardening follow-up (bounded window, OOM recovery) and an OOM cleanup follow-up.