Skip to content

tsdb: honor head isolation in streamed remote reads - #20184

Merged
bwplotka merged 3 commits into
mainfrom
perfloop-pr-open-78p7xrzgq9
Nov 3, 2026
Merged

bwplotka merged 3 commits into
mainfrom
perfloop-pr-open-78p7xrzgq9

Conversation

@perfloop

@perfloop perfloop Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Note

Triggered and guided by @bwplotka -- let me know if this is too spammy etc!

Which issue(s) does the PR fix:

None.

This change makes streamed Remote Read chunks from the local TSDB honor the isolation snapshot for in-order head data. With no overlapping deletion interval, fully visible chunks keep byte pass-through; partially visible chunks are re-encoded from their visible samples, and wholly hidden chunks are skipped. The existing open-chunk copy still protects bytes from later appends. Out-of-order chunks are unchanged and retain their separate reader-lifetime path.

TestRemoteReadStreamIsolation fails on the unmodified TSDB in its open-chunk case: the sample response contains timestamp 0/value 1, while streamed output also contains timestamp 1/value 2. The final source passes all 11 cases, including finite-range open chunks, rotated and mmapped chunks, incomplete appenders, integer and float histograms with and without start timestamps, and isolation-disabled behavior.

TestRemoteReadStreamChunkCopyStability passes on both the unmodified and final source. It commits a later sample after the chunk iterator returns its copy, before the handler reads the bytes. TestTxRingLastAppendID covers empty-ring, cleanup, and wrap cases. The race-enabled storage/remote and tsdb suites, the TSDB isolation-disabled suite, the Prometheus binary build, and scoped lint pass.

The CI jobs Go tests for 32-bit x86 and Go tests on Windows could not run locally for the storage/remote and tsdb packages. These platform tests remain target-CI work because this Linux sandbox cannot execute 32-bit ELF or Windows test binaries; the Linux/amd64 tests for both packages passed here.

The small runner used to report the source comparison is not included in this pull request; the native regression and preservation tests are included.

This condition holds with this change and does not hold at 694f9e00a0b3a51e234c194c618a3bd3a66a08b3: For a local TSDB with head isolation enabled, STREAMED_XOR_CHUNKS Remote Read returns exactly the float and histogram samples visible to its querier-open snapshot for in-order open, rotated, and mmapped head chunks and appenders incomplete at snapshot creation, including supported start-timestamp histogram encodings; with isolation disabled, later appends remain visible..

Release notes for end users (ALL commits must be considered).

[BUGFIX] TSDB: Ensure streamed remote reads respect head isolation for in-order samples.

Generated by Perfloop.

Comment thread tsdb/head_read.go Resolved
Comment thread tsdb/querier.go
if it != nil {
p.bufIter.Iter = it
}
if filtersSamples {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When filtersSamples is false, s.iterator still calls c.Iterator(it) and overwrites p.bufIter.Iter even though p.currDelIter is nil and the iterator goes unused, which allocates an unnecessary chunk iterator and drops any cached *stopIterator. Could iteratorForChunkCopy return nil, false when stopAfter == numSamples, and could we add a test case with a full pre-snapshot chunk where c.isoState != nil to cover this branch?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR head: 3cb01335d9c0bb957417a9d16ce31e693d87d8dd. Response to this feedback.

The copy iterator now returns nil,false before creating a chunk iterator when every sample is visible, so the cached iterator is preserved. Added a full pre-snapshot chunk with a later incomplete appender in the handler test and a TSDB unit test for the no-filter return.

Comment thread storage/remote/read_handler_test.go Resolved
Comment thread storage/remote/read_handler_test.go Outdated
}
if tc.isolationDisabled {
require.Equal(t, initial.timestamp, streamed.chunkBounds[0][0])
require.Equal(t, tc.laterStart, streamed.chunkBounds[0][1])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick nit: this if tc.isolationDisabled block duplicates the streamed.chunkBounds[0] check on line 1323 and assumes laterCount == 1, so we can drop lines 1329 to 1332.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR head: 3cb01335d9c0bb957417a9d16ce31e693d87d8dd. Response to this feedback.

Removed the duplicate isolation-disabled bounds check. The shared assertion now checks the first and last visible timestamps without assuming a single later sample.

@perfloop
perfloop Bot force-pushed the perfloop-pr-open-78p7xrzgq9 branch from 19a1c4c to 3cb0133 Compare October 26, 2026 08:29
@perfloop

perfloop Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Which issue(s) does the PR fix:

None.

This makes streamed Remote Read chunks from the local TSDB honor the isolation snapshot for in-order head data. When no deletion interval overlaps, fully visible chunks keep byte pass-through; partially visible chunks are re-encoded from visible samples, and wholly hidden chunks are omitted. The existing open-chunk copy still protects bytes from later appends. Out-of-order chunks retain their separate reader-lifetime path.

TestRemoteReadStreamIsolation fails on the unmodified TSDB: after the querier opens, a later append appears in the streamed response but not the sample response. The final source passes all 12 cases, including rotation, mmapping, incomplete appenders, a full visible chunk with an incomplete appender, integer and float histograms with and without start timestamps, and isolation-disabled behavior. TestRemoteReadStreamChunkCopyStability passes on both unmodified and final source; it appends after the chunk copy and confirms the response retains two distinct visible timestamps.

TestHeadChunkFromSeriesIsolationFastPath covers empty-ring and no-incomplete shortcuts. TestSafeHeadChunkIteratorForChunkCopySkipsVisibleChunk confirms a full visible chunk does not replace the reusable iterator. TestHeadChunkFromSeriesRetainsIsolationForInterleavedCommits exercises overlapping appenders: a higher-ID commit remains incomplete while a lower-ID appender adds a later timestamp. The ring tail can be lower than an incomplete ID, so the isolation filter remains active for nonempty rings. TestTxRingLastAppendID covers empty, cleanup, and wrap behavior.

The race-enabled storage/remote and tsdb tests, disabled-isolation TSDB tests, Prometheus and promtool builds, and scoped lint pass. These tests establish repository behavior; production frequency is not measured. No performance gain is claimed, and the cost of filtering partially visible chunks is unmeasured. The small source-comparison runner is not included; the native tests are.

The Go tests for 32-bit x86 and Go tests on Windows jobs for storage/remote and tsdb did not run locally. They remain target-CI work because this Linux sandbox cannot execute ELF32 or Windows test binaries.

This condition holds with this change and does not hold at 9d3aa94dd2a178dd3b891aac45fb73d3db565584: For a local TSDB with head isolation enabled, STREAMED_XOR_CHUNKS Remote Read returns exactly the float and histogram samples visible to its querier-open snapshot for in-order open, rotated, and mmapped head chunks and appenders incomplete at snapshot creation, including supported start-timestamp histogram encodings; with isolation disabled, later appends remain visible..

Release notes for end users (ALL commits must be considered).

[BUGFIX] TSDB: Ensure streamed remote reads respect head isolation for in-order samples.

Generated by Perfloop.

@bwplotka bwplotka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now looks good 👍🏽

Comment thread storage/remote/read_handler_test.go Resolved
Comment thread tsdb/head_read_test.go Resolved
@perfloop
perfloop Bot force-pushed the perfloop-pr-open-78p7xrzgq9 branch from 3cb0133 to a435b95 Compare October 26, 2026 16:27
@perfloop

perfloop Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Which issue(s) does the PR fix:

None.

This makes streamed Remote Read chunks from the local TSDB honor the isolation snapshot captured when the querier opens. Fully visible chunks keep byte pass-through; partially visible chunks are re-encoded from visible samples, and hidden chunks are omitted. The existing open-chunk copy continues to protect bytes from later appends.

With the handler regression test present and no product fix, TestRemoteReadStreamIsolation fails: the sample response contains timestamps 0 and 1, while streamed output also contains timestamp 2, committed after the querier opens. The final source passes all 13 cases covering open, finite-range, closed/rotated, and mmapped float chunks; an incomplete appender; integer and float histograms with and without start timestamps; and isolation-disabled behavior. The float-with-start-timestamps case exercises EncXOR2 re-encoding.

TestHeadChunkFromSeriesIsolationFastPath covers the visible-chunk shortcuts and negative cases where the isolation state must remain: the caller does not request a copy, or the latest transaction ID is above the snapshot maximum. TestHeadChunkFromSeriesRetainsIsolationForInterleavedCommits covers a lower-ID commit behind an incomplete higher ID. TestTxRingLastAppendID covers empty, cleanup, and wraparound states. TestSafeHeadChunkIteratorForChunkCopySkipsVisibleChunk checks that fully visible chunks keep the reusable iterator. TestRemoteReadStreamChunkCopyStability passes on the test-only comparison and final source while a later append follows the chunk copy.

The race-enabled storage/remote and tsdb tests, isolation-disabled TSDB tests, Prometheus and promtool builds, and scoped lint pass. Production frequency and the cost of filtering partially visible chunks remain unmeasured; no performance gain is claimed. The small source-comparison shell driver is not included; the native tests are.

The Go tests for 32-bit x86 and Go tests on Windows jobs for storage/remote and tsdb did not run locally. They remain target-CI work because this Linux sandbox cannot execute ELF32 or Windows test binaries.

This condition holds with this change and does not hold at 56d133f55077574eb08f8910f01437fbe7d98b91: For a local TSDB with head isolation enabled, STREAMED_XOR_CHUNKS Remote Read returns exactly the float and histogram samples visible to its querier-open snapshot for in-order open, rotated, and mmapped head chunks and appenders incomplete at snapshot creation, including supported start-timestamp histogram encodings; with isolation disabled, later appends remain visible..

Release notes for end users (ALL commits must be considered).

[BUGFIX] TSDB: Ensure streamed remote reads respect head isolation for in-order samples.

Generated by Perfloop.

Comment thread tsdb/head_read.go Resolved
Signed-off-by: Bartlomiej Plotka <[email protected]>
@bwplotka
bwplotka merged commit 62a2649 into main Nov 3, 2026
39 checks passed
@bwplotka
bwplotka deleted the perfloop-pr-open-78p7xrzgq9 branch November 3, 2026 04:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants