Skip to content

Allow 2h block conversion if it has no compact mark - #6865

Open
SungJin1212 wants to merge 4 commits into
cortexproject:masterfrom
SungJin1212:Allow-2h-nocompactmark-block-conversion
Open

SungJin1212 wants to merge 4 commits into
cortexproject:masterfrom
SungJin1212:Allow-2h-nocompactmark-block-conversion

Conversation

@SungJin1212

Copy link
Copy Markdown
Member

Allow the parquet converter to convert 2h blocks if the block has a no-compact.mark.json file.

Which issue(s) this PR fixes:
Fixes #6831

Checklist

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

@dosubot dosubot Bot added the storage/blocks Blocks storage engine label Jul 7, 2025
@SungJin1212
SungJin1212 requested a review from yeya24 July 7, 2025 02:49
@SungJin1212
SungJin1212 force-pushed the Allow-2h-nocompactmark-block-conversion branch from b3c1f38 to 528d1af Compare July 7, 2025 03:06

@yeya24 yeya24 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In general, I think it looks good. Just some nits.

We should probably also introduce bucket cache for no compact marker file to reduce number of calls to object store

Comment thread pkg/parquetconverter/converter.go Resolved
@yeya24
yeya24 requested a review from alanprot July 7, 2025 05:32
@SungJin1212
SungJin1212 force-pushed the Allow-2h-nocompactmark-block-conversion branch 2 times, most recently from ce12528 to 369dbf3 Compare July 7, 2025 11:23
@SungJin1212
SungJin1212 requested a review from yeya24 July 9, 2025 00:50
@SungJin1212
SungJin1212 force-pushed the Allow-2h-nocompactmark-block-conversion branch 2 times, most recently from 54d9d99 to 7bb8c24 Compare July 9, 2025 05:39
@SungJin1212

Copy link
Copy Markdown
Member Author

@alanprot
Could you take a look?

@danielblando

Copy link
Copy Markdown
Contributor

Do we need this new config NoCompactMarkCheckAfter? Maybe one thing that we can do is if there is mint >= timeRange[1] or even dont have any. This files are not common and normally if they are there it doesnt go away that fast. We could just also add the cache and leave with it

@SungJin1212

SungJin1212 commented Jul 15, 2025 •

Copy link
Copy Markdown
Member Author

@yeya24
I also think it's better to convert the no-compact-mark blocks only if its mint is over timeRange[1] or timeRange[0] * constant. WDYT?

@sandy2008 sandy2008 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The approach looks right for #6831, but the age check that's meant to limit the extra object-store calls doesn't work as intended (inline).

Comment thread pkg/storage/parquet/util.go Outdated
// since these will never be compacted to 12h block.
// We check if the `no-compact-mark.json` file exists only for blocks
// after the noCompactMarkCheckAfter to reduce object storage calls.
if mint >= noCompactMarkCheckAfter {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

mint is a block timestamp in epoch milliseconds, while noCompactMarkCheckAfter is a duration (13h by default, so 46800000). This condition is therefore true for every real block, and the marker is checked for every unconverted 2h block on every conversion cycle, however recent the block is. I tried a 2h block that ended an hour ago: checkFunc is called and the block is converted. The tests only pass because they use timestamps near the epoch.

If the idea is to skip blocks younger than the threshold, it needs to compare against the current time, e.g. now - maxt >= noCompactMarkCheckAfter with now passed in so it stays testable. The blocks cleaner also calls this for every non-parquet block, so it adds to the Exists calls the bucket-cache suggestion above was about.

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.

Thanks, I fixed it to the latest commit. Also, I changed it to use now - maxt >= timeRanges[1].

@SungJin1212
SungJin1212 force-pushed the Allow-2h-nocompactmark-block-conversion branch from 7bb8c24 to 74f83c6 Compare November 6, 2026 08:23
@SungJin1212
SungJin1212 requested a review from a team as a code owner November 6, 2026 08:23
@SungJin1212
SungJin1212 force-pushed the Allow-2h-nocompactmark-block-conversion branch from 74f83c6 to 51b3154 Compare November 6, 2026 09:43
@SungJin1212

Copy link
Copy Markdown
Member Author

@yeya24 @danielblando
Would you help review this PR?

@SungJin1212
SungJin1212 force-pushed the Allow-2h-nocompactmark-block-conversion branch from 9fb7122 to 2fef52a Compare November 10, 2026 03:07

@sandy2008 sandy2008 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, re-checked at 2fef52a. The age check now compares now - maxt with the second block range, all in milliseconds, in both the converter and the cleaner. The marker is only fetched once a block is old enough, so the cleaner's extra Exists calls are limited to old 2h blocks. TestShouldConvertBlockToParquet_NoCompactMarkCheckAge fails with the old timestamp-vs-duration check, with > instead of >=, with now - mint, and with the marker read before the age check. A few small things inline, mainly that the converter test doesn't reach the new path yet.

Comment thread pkg/parquetconverter/converter_test.go Outdated
Comment on lines +360 to +361
mint := time.Hour * 13
maxt := time.Hour * 15

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These blocks cross a 2h boundary (13h to 15h), so getBlockTimeRange puts them in the 12h range and they get converted with or without the marker. The test still passes with hasNoCompactMark in convertUser stubbed to false, or with ShouldConvertBlockToParquet back to master's range-only check. With aligned blocks they go through the marker check, and both of those then fail (0 converted instead of 2):

Suggested change
mint := time.Hour * 13
maxt := time.Hour * 15
mint := time.Hour * 12
maxt := time.Hour * 14

Comment thread pkg/compactor/blocks_cleaner_test.go Outdated
}

mockNoCompactMarkCheckFunc := func(blockID ulid.ULID) bool {
return false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: this always returns false and none of the blocks above is a 2h block, so this test never reaches the new age check. User-5's blocks in TestBlocksCleaner are only a few ms after the epoch, so they always count as old, and both tests still pass with time.Now().UnixNano() in updateBucketMetrics. Adding a recent 2h-aligned block without a parquet mark (from now.Truncate(2 * time.Hour) minus 2h to now.Truncate(2 * time.Hour)) and returning true here would catch it. The count stays 2 at this head and becomes 3 with UnixNano().

Comment thread CHANGELOG.md Outdated
* [ENHANCEMENT] Upgrade promql-engine and Thanos to latest. #7889
* [ENHANCEMENT] Ruler: Retry a notification the Alertmanager failed to accept with a transport error or a 5xx response, instead of dropping it and leaving its alert undelivered until the next evaluation of the rule group. Enable the retries with `-ruler.notification.backoff-retries` (`0`, no retry, by default), and tune the delay between them with `-ruler.notification.backoff-min-period` and `-ruler.notification.backoff-max-period`. The retries are bounded by `-ruler.notification-timeout` and counted by the new `cortex_ruler_notification_retries_total` metric. #7909
* [ENHANCEMENT] Update Go version to 1.27.3, which includes security fixes to the `crypto/x509` package (CVE-2026-111943). #7906 #7923
* [ENHANCEMENT] Parquet Converter: Allow 2h blocks conversion if the block has a no-compact-mark.json file. #6865

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: maybe say when the marker is checked:

Suggested change
* [ENHANCEMENT] Parquet Converter: Allow 2h blocks conversion if the block has a no-compact-mark.json file. #6865
* [ENHANCEMENT] Parquet Converter: Convert 2h blocks that have a `no-compact-mark.json` file, since they are never compacted. The marker is checked once the block is older than the second `-compactor.block-ranges` entry (12h by default). #6865

@SungJin1212
SungJin1212 force-pushed the Allow-2h-nocompactmark-block-conversion branch from 25b1a74 to aa2a03e Compare November 20, 2026 02:14
@SungJin1212

Copy link
Copy Markdown
Member Author

@sandy2008
Thanks for the comments, all comments are make sense. I applied your comments to the latest commit.

Signed-off-by: Sungjin1212 <tjdwls1201@gmail.com>
Signed-off-by: Sungjin1212 <tjdwls1201@gmail.com>
…ELOG

- Use 2h-aligned blocks (12h-14h) in the converter test so they go through
  the no-compact mark check instead of being classified as 12h blocks.
- Add a recent 2h-aligned block to TestBlocksCleaner_ParquetMetrics so the
  age check is exercised.
- Describe when the no-compact marker is checked in the CHANGELOG entry.

Signed-off-by: Sungjin1212 <tjdwls1201@gmail.com>
@SungJin1212
SungJin1212 force-pushed the Allow-2h-nocompactmark-block-conversion branch from aa2a03e to e127a9f Compare November 24, 2026 01:27
The bucket index updater already returns the blocks marked for no
compaction, so the cleaner can look them up there when counting the
unconverted parquet blocks instead of sending an Exists request per block.

Extend TestBlocksCleaner_ParquetMetrics with old 2h blocks with and without
a no-compact mark.

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

Copy link
Copy Markdown
Member Author

@sandy2008
#7959 changed updateBucketMetrics to take the set of blocks marked for no compaction, which conflicted with this PR.
Since that set is now available, the cleaner looks marks up there instead of sending an Exists request per old 2h block.

@SungJin1212

Copy link
Copy Markdown
Member Author

@danielblando
Could you take a look when you have a chance?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L storage/blocks Blocks storage engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parquet Converter should convert 2h block with no compact marker

4 participants