Skip to content

fix: handle nested low-level files in compaction#26911

Merged
davidby-influx merged 24 commits intomaster-1.xfrom
DSB_compaction_fixes
Oct 28, 2025
Merged

fix: handle nested low-level files in compaction#26911
davidby-influx merged 24 commits intomaster-1.xfrom
DSB_compaction_fixes

Conversation

@davidby-influx
Copy link
Copy Markdown
Contributor

Previously, when a lower-level file (level 1, 2, or 3) was in between level 4 or higher files, it would not be compacted, and it would prevent full compactions from running.

This fix allows lower level files to be compacted even if sandwiched in between higher level files or as the first/earliest file in a shard.

Exampe problem from a customer system:

-rw-r--r--.  1 root root 2.1G Aug  5 20:59 000016684-000000007.tsm
-rw-r--r--.  1 root root 2.1G Aug  5 21:02 000016684-000000008.tsm
-rw-r--r--.  1 root root 2.1G Aug  5 21:04 000016684-000000009.tsm
-rw-r--r--.  1 root root 376M Aug  5 21:05 000016684-000000010.tsm
-rw-r--r--.  1 root root 2.1G Aug  5 18:00 000016812-000000004.tsm
-rw-r--r--.  1 root root 1.4G Aug  5 18:00 000016812-000000005.tsm
-rw-r--r--.  1 root root 1.3G Aug  5 21:21 000016844-000000002.tsm
-rw-r--r--.  1 root root 2.1G Aug  5 18:00 000016948-000000004.tsm
-rw-r--r--.  1 root root 1.4G Aug  5 18:00 000016948-000000005.tsm
-rw-r--r--.  1 root root 2.1G Aug  5 18:00 000017076-000000004.tsm

There is a rogue level 2 file packed within fully compacted files

@davidby-influx
Copy link
Copy Markdown
Contributor Author

@devanbenz - please walk through compact_test.go and check inputs and outputs for sanity before reading the changes in compact.go. Let me know of any concerns or additional tests you recommend.

The new tests start at the comment // Start of nested test cases???? on line 3576. Prior changes in the file are simply reformatting for readability.

@davidby-influx davidby-influx changed the title fix: handle nsted low-level files in compaction fix: handle nested low-level files in compaction Oct 15, 2025
@davidby-influx davidby-influx marked this pull request as ready for review October 21, 2025 23:33
Copy link
Copy Markdown
Member

@gwossum gwossum left a comment

Choose a reason for hiding this comment

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

Couple of questions

gwossum
gwossum previously approved these changes Oct 24, 2025
Copy link
Copy Markdown
Member

@gwossum gwossum left a comment

Choose a reason for hiding this comment

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

It looks like it will solve the nested file issue and I can't find any new issues it introduces.

devanbenz
devanbenz previously approved these changes Oct 28, 2025
Copy link
Copy Markdown

@devanbenz devanbenz left a comment

Choose a reason for hiding this comment

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

Just the one comment about tests. Overall this looks good to me. I ran the code locally and wrote out a few TSM files to disk using inch + influxd, afterwards when I had several files I went ahead and manually renamed the levels on them to have a nested and a leading level 2 file. It was captured by the compaction without issue.

Here is the files on disk as you can see I have nested lower level files:

-rw-r--r--@  1 devan  wheel   1492013 Oct 28 15:18 000000008-000000002.tsm
-rw-r--r--@  1 devan  wheel   1484013 Oct 28 15:18 000000016-000000002.tsm
-rw-r--r--@  1 devan  wheel   1327005 Oct 28 15:18 000000024-000000002.tsm
-rw-r--r--@  1 devan  wheel    284013 Oct 28 15:18 000000025-000000001.tsm
-rw-r--r--@  1 devan  wheel    284013 Oct 28 15:18 000000026-000000001.tsm
-rw-r--r--@  1 devan  wheel    284005 Oct 28 15:18 000000027-000000004.tsm
-rw-r--r--@  1 devan  wheel    284013 Oct 28 15:20 000000028-000000005.tsm
-rw-r--r--@  1 devan  wheel  21818009 Oct 28 15:32 000000159-000000004.tsm
-rw-r--r--@  1 devan  wheel  22375789 Oct 28 15:34 000000287-000000004.tsm
-rw-r--r--@  1 devan  wheel  22450341 Oct 28 15:36 000000415-000000004.tsm
-rw-r--r--@  1 devan  wheel  22396817 Oct 28 15:41 000000543-000000004.tsm
-rw-r--r--@  1 devan  wheel   5620965 Oct 28 15:42 000000575-000000003.tsm
-rw-r--r--@  1 devan  wheel   1431685 Oct 28 15:42 000000583-000000002.tsm
-rw-r--r--@  1 devan  wheel   1424133 Oct 28 15:42 000000591-000000002.tsm
-rw-r--r--@  1 devan  wheel   1424321 Oct 28 15:42 000000599-000000002.tsm
-rw-r--r--@  1 devan  wheel     90985 Oct 28 15:42 000000600-000000001.tsm

After letting influxd sit for a bit after modifying the cold write duration (~5 minutes)

-rw-r--r--@  1 devan  wheel  93835106 Oct 28 16:12 000000543-000000005.tsm
-rw-r--r--@  1 devan  wheel  22415417 Oct 28 16:02 000000672-000000004.tsm
-rw-r--r--@  1 devan  wheel  22290681 Oct 28 16:04 000000800-000000004.tsm
-rw-r--r--@  1 devan  wheel   1424521 Oct 28 16:04 000000808-000000002.tsm
-rw-r--r--@  1 devan  wheel   1417977 Oct 28 16:04 000000816-000000002.tsm
-rw-r--r--@  1 devan  wheel   1414785 Oct 28 16:05 000000824-000000002.tsm
-rw-r--r--@  1 devan  wheel    180693 Oct 28 16:05 000000825-000000001.tsm
-rw-r--r--@  1 devan  wheel    182217 Oct 28 16:05 000000826-000000001.tsm
-rw-r--r--@  1 devan  wheel    182793 Oct 28 16:05 000000827-000000001.tsm
-rw-r--r--@  1 devan  wheel    181793 Oct 28 16:05 000000828-000000001.tsm
-rw-r--r--@  1 devan  wheel    135033 Oct 28 16:05 000000829-000000001.tsm

The lower level nested files are picked up and everything seems good.

},
},
{
name: "Mixed generations with 3 level 2 files",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you add an additional test similar to this one with 3 level 3 files?

@davidby-influx davidby-influx dismissed stale reviews from devanbenz and gwossum via 502ed65 October 28, 2025 21:24
Copy link
Copy Markdown

@devanbenz devanbenz left a comment

Choose a reason for hiding this comment

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

LGTM

@davidby-influx davidby-influx merged commit a099cb7 into master-1.x Oct 28, 2025
9 checks passed
@davidby-influx davidby-influx deleted the DSB_compaction_fixes branch October 28, 2025 21:39
davidby-influx added a commit that referenced this pull request Oct 28, 2025
Simplify and refactor compaction planner
to handle low-level files occurring before
higher-level (more compacted) files.

(cherry picked from commit a099cb7)

Fixes #26947
davidby-influx added a commit that referenced this pull request Oct 29, 2025
Simplify and refactor compaction planner
to handle low-level files occurring before
higher-level (more compacted) files.

(cherry picked from commit a099cb7)

Fixes #26947
@davidby-influx davidby-influx linked an issue Nov 26, 2025 that may be closed by this pull request
devanbenz pushed a commit that referenced this pull request Feb 5, 2026
Simplify and refactor compaction planner
to handle low-level files occurring before
higher-level (more compacted) files.

(cherry picked from commit a099cb7)
devanbenz added a commit that referenced this pull request Feb 5, 2026
Simplify and refactor compaction planner
to handle low-level files occurring before
higher-level (more compacted) files.

(cherry picked from commit a099cb7)

Co-authored-by: davidby-influx <72418212+davidby-influx@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TSM file state leads to inescapable loop where compactFull is not running Issue with findGenerations caching depending on input

3 participants