Skip to content

Pruner: Drop empty partitions#1819

Merged
mkysel merged 6 commits intomainfrom
mkysel/drop-empty-partitions
Mar 16, 2026
Merged

Pruner: Drop empty partitions#1819
mkysel merged 6 commits intomainfrom
mkysel/drop-empty-partitions

Conversation

@mkysel
Copy link
Copy Markdown
Collaborator

@mkysel mkysel commented Mar 13, 2026

Add partition dropping to pruner to remove empty non-ceiling meta/blob partition pairs

  • Adds a PL/pgSQL function get_prunable_meta_partitions() (migration 00022) that identifies empty, non-ceiling leaf partitions of gateway_envelopes_meta per originator.
  • Adds Executor.DropPrunablePartitions in partition_prune.go that queries prunable partitions and drops paired meta and blob tables via DROP TABLE IF EXISTS ... CASCADE.
  • Refactors Executor.Run in prune.go to delegate to PruneRows() (extracted from previous inline logic) and the new DropPrunablePartitions().
  • Skips originator IDs 0 and 1 and respects the DryRun flag (no tables dropped when true).
  • Behavioral Change: Run now drops empty lower partitions on each execution in addition to pruning rows.

Changes since #1819 opened

  • Replaced literal OriginatorNodeID checks with constant references in partition pruning logic [3078433]
  • Added execution time measurement and logging to partition deletion process [3078433]
  • Updated log message text for row pruning completion [3078433]

Macroscope summarized c86df5b.

@mkysel mkysel requested a review from a team as a code owner March 13, 2026 20:39
@mkysel mkysel linked an issue Mar 13, 2026 that may be closed by this pull request
@mkysel
Copy link
Copy Markdown
Collaborator Author

mkysel commented Mar 13, 2026

This is not exactly a low risk change, so good 👀 required!

@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp Bot commented Mar 13, 2026

Approvability

Verdict: Needs human review

This PR introduces a new database pruning capability that drops empty table partitions, including new SQL migrations and dynamic DROP TABLE operations. While the author owns all changed files and the code includes safeguards, the feature introduces significant runtime behavior changes to database management that warrant human review.

You can customize Macroscope's approvability policy. Learn more.

Comment thread pkg/prune/partition_prune.go
Comment thread pkg/prune/partition_prune.go Outdated
Comment thread pkg/prune/row_pruner.go

for tableName, ceiling := range deletableTables {
result, err := e.writerDB.Exec(
constructVariableMetaTableQuery(tableName, e.config.BatchSize, ceiling),
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.

Perhaps this gets renamed to say what it actually does - this is a constructVariableMetaTableDeleteQuery, right?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

this is all existing code, just moved

Comment thread pkg/prune/row_pruner.go
zap.Error(err),
zap.String("table", tableName),
)
delete(deletableTables, tableName)
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.

Why might also leave it so we retry it again later?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

it might get retried on the next full run, 15/60min later depending on config

Comment thread pkg/prune/row_pruner.go
Comment on lines +85 to +92
for {
if cyclesCompleted >= e.config.MaxCycles {
e.logger.Warn(
"reached maximum pruning cycles",
zap.Int("max_cycles", e.config.MaxCycles),
)
break
}
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.

Why not just have this in the for itself?

Comment thread pkg/prune/row_pruner.go Outdated
Comment thread pkg/prune/partition_prune.go
@@ -0,0 +1,232 @@
package prune_test
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.

Tests that confirm that originators 0 and 1 are ignored might be good.

Also, tests that drop multiple empty partitions might be cool. Though I don't think it's very likely that pruner will in one swoop prune so many rows that there's multiple empty partitions.

Comment thread pkg/prune/partition_prune.go Outdated
@mkysel mkysel merged commit 00a2964 into main Mar 16, 2026
16 checks passed
@mkysel mkysel deleted the mkysel/drop-empty-partitions branch March 16, 2026 13:53
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.

Pruner to drop partitions

3 participants