Skip to content

db: add span policy enforcer background goroutine#5758

Open
xinhaoz wants to merge 2 commits intocockroachdb:masterfrom
xinhaoz:span-policy-enforcer-1
Open

db: add span policy enforcer background goroutine#5758
xinhaoz wants to merge 2 commits intocockroachdb:masterfrom
xinhaoz:span-policy-enforcer-1

Conversation

@xinhaoz
Copy link
Contributor

@xinhaoz xinhaoz commented Jan 29, 2026

manifest: add NextFile functions to ScanCursor

Add NextFile function to ScanCursor, which returns the first file after the
cursor position.

db: add span policy enforcer background goroutine

Add a background span policy enforcer that scans the LSM to detect files
violating compression policies and marks them for policy enforcement compaction
(a new compaction type that will be introduced in a later commit).

Currently disabled by default, this initial implementation scans at a rate of
1 file per second, and checks only for a violation on the compression settings
in the span policy.

Part of: #5657

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@xinhaoz xinhaoz changed the title manifest: add NextFile functions to ScanCursor db: add span policy enforcer background goroutine Jan 29, 2026
@xinhaoz xinhaoz marked this pull request as ready for review January 29, 2026 19:06
@xinhaoz xinhaoz requested a review from a team as a code owner January 29, 2026 19:06
@xinhaoz xinhaoz requested a review from annrpom January 29, 2026 19:06
Copy link
Contributor

@annrpom annrpom left a comment

Choose a reason for hiding this comment

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

:lgtm_strong: cool!!

@annrpom reviewed 8 files and all commit messages, and made 2 comments.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @xinhaoz).


span_policy_enforcer.go line 96 at r2 (raw file):

		}

		nextFile, level, endOfScan := s.getNextFile(true /* waitForPending */)

nit: waitForPendingWork

@xinhaoz xinhaoz force-pushed the span-policy-enforcer-1 branch from 595937b to fa5c524 Compare February 3, 2026 15:51
@github-actions
Copy link

github-actions bot commented Feb 3, 2026

Potential Bug(s) Detected

The three-stage Claude Code analysis has identified potential bug(s) in this PR that may warrant investigation.

Next Steps:
Please review the detailed findings in the workflow run.

Note: When viewing the workflow output, scroll to the bottom to find the Final Analysis Summary.

After you review the findings, please tag the issue as follows:

  • If the detected issue is real or was helpful in any way, please tag the issue with O-AI-Review-Real-Issue-Found
  • If the detected issue was not helpful in any way, please tag the issue with O-AI-Review-Not-Helpful

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

@RaduBerinde made 4 comments.
Reviewable status: 2 of 8 files reviewed, 5 unresolved discussions (waiting on @annrpom and @xinhaoz).


internal/manifest/scan_cursor.go line 87 at r3 (raw file):

// position. This is useful for skipping files that have already been processed.
func (c *ScanCursor) FileIsAfterCursor(cmp base.Compare, f *TableMetadata, level int) bool {
	return c.Compare(cmp, MakeScanCursorAfterFile(f, level)) < 0

[nit] this is equivalent to c.Compare(cmp, MakeScanCursor(f, level)) <= 0, correct? I think that would be more clear.


internal/manifest/scan_cursor.go line 172 at r3 (raw file):

}

// nextFileOnLevel returns the first file on c.Level which is at or after the

which is after the cursor position


internal/manifest/scan_cursor.go line 176 at r3 (raw file):

func (c *ScanCursor) nextFileOnLevel(cmp base.Compare, v *Version) *TableMetadata {
	if c.Level == 0 {
		return c.nextFileOnL0(v)

This is not doing what we advertise - the next file in L0 in terms of seqnums is not the first file on 0 which is at or after the cursor. We would have to look on each sublevel, similar to NextExternalFileOnLevel


internal/manifest/scan_cursor.go line 184 at r3 (raw file):

	f := it.SeekGE(cmp, c.Key)
	// Find the first file at or after the cursor position.
	for f != nil && !c.FileIsAfterCursor(cmp, f, c.Level) {

[nit] "Skip the file if it starts before cursor.Key or is at that same key with lower sequence number." explains better

Add NextFile function to ScanCursor, which returns the first file after the
cursor position.
Add a background span policy enforcer that scans the LSM to detect files
violating compression policies and marks them for policy enforcement compaction
(a new compaction type that will be introduced in a later commit).

Currently disabled by default, this initial implementation scans at a rate of
1 file per second, and checks only for a violation on the compression settings
in the span policy.

Part of: cockroachdb#5657
@xinhaoz xinhaoz force-pushed the span-policy-enforcer-1 branch from 49ad43e to 6e071ac Compare February 12, 2026 23:03
Copy link
Contributor Author

@xinhaoz xinhaoz left a comment

Choose a reason for hiding this comment

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

@xinhaoz made 3 comments and resolved 3 discussions.
Reviewable status: 1 of 8 files reviewed, 2 unresolved discussions (waiting on @annrpom).


span_policy_enforcer.go line 96 at r2 (raw file):

Previously, annrpom (annie pompa) wrote…

nit: waitForPendingWork

Done.


internal/manifest/scan_cursor.go line 87 at r3 (raw file):

Previously, RaduBerinde wrote…

[nit] this is equivalent to c.Compare(cmp, MakeScanCursor(f, level)) <= 0, correct? I think that would be more clear.

Done.


internal/manifest/scan_cursor.go line 176 at r3 (raw file):

Previously, RaduBerinde wrote…

This is not doing what we advertise - the next file in L0 in terms of seqnums is not the first file on 0 which is at or after the cursor. We would have to look on each sublevel, similar to NextExternalFileOnLevel

Done.

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.

4 participants