Skip to content

Optimize ts v2 pool#7373

Merged
CharlieTLe merged 1 commit intocortexproject:masterfrom
SungJin1212:Optimize-tsv2-pool
Apr 2, 2026
Merged

Optimize ts v2 pool#7373
CharlieTLe merged 1 commit intocortexproject:masterfrom
SungJin1212:Optimize-tsv2-pool

Conversation

@SungJin1212
Copy link
Copy Markdown
Member

This PR improves V2 write request memory pooling by preventing string pointer leaks, adding explicit string clearing in ReuseWriteRequestV2 to prevent memory leaks when reusing pooled requests, and removing redundant exemplar label cleanup from ReuseTimeseriesV2.

Which issue(s) this PR fixes:
Fixes #

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Copy link
Copy Markdown
Member

@CharlieTLe CharlieTLe left a comment

Choose a reason for hiding this comment

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

The V2 pool was introduced in 918aa41 and shipped in v1.20.0, so the missing symbol clearing is a bug in a released version. Should a [BUGFIX] CHANGELOG entry be added?

Comment thread pkg/cortexpb/timeseriesv2_test.go Outdated
Comment on lines +83 to +84
assert.Equal(t, "", underlyingArray[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.

Three symbols are appended ("", "name", "test") but only indices 0 and 1 are checked. Should index 2 be asserted as well?

Suggested change
assert.Equal(t, "", underlyingArray[1])
}
assert.Equal(t, "", underlyingArray[1])
assert.Equal(t, "", underlyingArray[2])
}

})
}

func TestReuseWriteRequestV2(t *testing.T) {
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.

Could this test flake since sync.Pool doesn't guarantee Get returns the same object that was just Put? If the GC runs between the ReuseWriteRequestV2 and PreallocWriteRequestV2FromPool calls, a fresh object would be returned and the backing array assertions would be skipped.

Would it be more robust to capture a reference to the backing array before the reuse call, so the clearing can be verified directly without depending on the pool?

// Capture backing array before reuse
backingArray := req.Symbols[:cap(req.Symbols)]

ReuseWriteRequestV2(req)

// Verify clearing directly on the backing array
for i, s := range backingArray[:3] {
    assert.Equalf(t, "", s, "symbol at index %d not cleared", i)
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I fixed it at the latest commit to check if the symbol table is reset without GC.
Thanks for the comment!

@SungJin1212 SungJin1212 force-pushed the Optimize-tsv2-pool branch 2 times, most recently from fdb24ce to f263b6c Compare March 30, 2026 00:07
@SungJin1212 SungJin1212 requested a review from CharlieTLe March 30, 2026 00:30
@SungJin1212 SungJin1212 force-pushed the Optimize-tsv2-pool branch 2 times, most recently from c2a3c20 to d3ad749 Compare March 30, 2026 00:45
@SungJin1212
Copy link
Copy Markdown
Member Author

@CharlieTLe
Can you take a look when you have time?

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Apr 2, 2026
@CharlieTLe CharlieTLe merged commit 51ec847 into cortexproject:master Apr 2, 2026
35 checks passed
CharlieTLe pushed a commit to CharlieTLe/cortex that referenced this pull request Apr 6, 2026
Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
Signed-off-by: Charlie Le <charlie_le@apple.com>
friedrichg pushed a commit that referenced this pull request Apr 16, 2026
Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com>
friedrichg added a commit that referenced this pull request Apr 17, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
friedrichg added a commit that referenced this pull request Apr 17, 2026
Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com>
friedrichg added a commit that referenced this pull request Apr 17, 2026
* Memberlist cas error code false positive (#7408)

* use errors.As in getCasErrorCode to unwrap memberlist errors

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

* fix test

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

---------

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com>

* Fix nil when ingesterQueryMaxAttempts > 1 (#7369)

* Trigger nil with test

Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com>

* Fix nil results

Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com>

* fix changelog

Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com>

---------

Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com>

* fix: alertmanager user config disappearing when ring is unreachable  (#7372)

* Fix multitenant alertmanager user config disappearing when ring is unreachable

Signed-off-by: Kishore K G <kishorekg@google.com>

* Add change log

Signed-off-by: Kishore K G <kishorekg@google.com>

* format multitenant

Signed-off-by: Kishore K G <kishorekg@google.com>

* fix pr number

Signed-off-by: Kishore K G <kishorekg@google.com>

* use ErrNotFound for error validation in unit test

Signed-off-by: kishorekg1999 <kishorekg.github@gmail.com>

---------

Signed-off-by: Kishore K G <kishorekg@google.com>
Signed-off-by: kishorekg1999 <kishorekg@google.com>
Signed-off-by: kishorekg1999 <kishorekg.github@gmail.com>
Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com>

* Clean Symbol Tables (#7373)

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com>

* Fix root cause of nil return in queryWithRetry and labelsWithRetry (#7375)

Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com>

* fix regex resolver match 0 or 1 tenant bug (#7424)

* fix regex resolver match 0 or 1 tenant bug

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

* fix test

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

---------

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com>

* skip nil values in Memberlist WatchPrefix (#7429)

* skip nil values in Memberlist WatchPrefix

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

* fix lint

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>

---------

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com>

* Remove duplicate CHANGELOG entry for #7373

Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com>

* Fix integration test flag name for release-1.21

The cherry-pick of #7424 brought the master flag name
-limits.query-ingesters-within, but release-1.21 still uses
-querier.query-ingesters-within (renamed in #7160, master-only).

Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com>

---------

Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com>
Signed-off-by: Kishore K G <kishorekg@google.com>
Signed-off-by: kishorekg1999 <kishorekg@google.com>
Signed-off-by: kishorekg1999 <kishorekg.github@gmail.com>
Co-authored-by: SungJin1212 <tjdwls1201@gmail.com>
Co-authored-by: kishorekg1999 <kishorekg.github@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size/M type/performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants