buzz icon indicating copy to clipboard operation
buzz copied to clipboard

Partition manager cannot reclaim a pre-existing catch-all partition — monthly partitioning silently stops

Open grahamCr4ckr opened this issue 4 months ago • 1 comments

Summary

Once a fresh deployment's initial migration boundary is crossed, ensure_future_partitions can never create the "current month" partition again, because the migration's own *_p_future catch-all already covers that range. The collision is caught and swallowed as a benign, expected case — so partitioning for that range silently and permanently stops, with no error, no metric, and no operator-visible signal beyond a Postgres server-log line most people don't watch.

Where

  • migrations/0001_initial_schema.sql (events: lines ~237-252, delivery_log: lines ~343-354) hardcodes monthly partitions with literal dates authored mid-2026, ending with a catch-all:

    CREATE TABLE events_p_future PARTITION OF events
        FOR VALUES FROM ('2026-07-01') TO (MAXVALUE);
    

    Any fresh install that runs this migration in July 2026 or later will have every monthly partition ensure_future_partitions tries to create fall inside _p_future's range and collide. This isn't an edge case — it will recur for every fresh install going forward, and again at the next catch-all boundary for any host that hand-repairs it (e.g. re-basing to 2027-01-01 just moves the wall to 2027-01).

  • crates/buzz-db/src/partition.rs (~lines 130-149) explicitly anticipates this:

    match sqlx::query(sqlx::AssertSqlSafe(sql)).execute(pool).await {
        Ok(_) => { info!("added partition {partition_name}"); Ok(()) }
        Err(sqlx::Error::Database(db_err))
            if db_err.code().as_deref() == Some("42P17")
                && db_err.message().contains("would overlap partition") =>
        {
            // Fresh schemas include a right-edge catch-all partition (`*_p_future`).
            // If it already covers this month, the table is still safe for writes;
            // treat the overlap as "ensured" rather than failing startup.
            info!(partition_name, "partition range already covered by an existing partition");
            Ok(())
        }
        Err(e) => Err(e.into()),
    }
    

    Postgres error 42P17 ("would overlap partition") is caught and logged at info, then treated as success. Postgres itself still logs a server-side ERROR for the rejected DDL (independent, unsuppressable), but the application never surfaces it, never fails startup, and gives no indication that the monthly partition was never actually created.

Impact

The monthly partition never gets created; nothing ever shrinks or re-splits the existing catch-all. Every row for the colliding range keeps landing in _p_future indefinitely, defeating the purpose of monthly partitioning (pruning/archival/maintenance by partition boundary). There's no code anywhere in partition.rs or in migrations 0002-0026 that ever reclaims or splits an existing catch-all partition once one exists.

Reproduction

A regression test reproducing this against real Postgres (current_month_partition_is_never_created_once_a_future_catchall_exists, crates/buzz-db) is here, passing in CI: https://github.com/frodoHost/buzz/pull/1

Suggested fix direction (not implemented)

Either detach-and-recreate the overlapping range of _p_future when a monthly-partition collision is detected, or raise the info! to a warn!/metric so this isn't purely a Postgres-log-only symptom.

grahamCr4ckr avatar Aug 01 '26 00:08 grahamCr4ckr

Confirming this still reproduces on current main — ghcr.io/block/buzz@sha256:778d1af3cd1e0ded22d36be0c275d424e5969a8471d98f6a082626402c3d4eeb (revision f029deaf, i.e. after the desktop-v0.5.8 cut), on Postgres 17.10.

Two details that may be worth adding to the diagnosis here:

It is not limited to the first start after migration. It fires on every relay start, once per month-partition the manager tries to create, on both tables:

ERROR:  partition "events_p2026_09" would overlap partition "events_p_future" at character 81
ERROR:  partition "delivery_log_p2026_09" would overlap partition "delivery_log_p_future" at character 93
ERROR:  partition "events_p2026_10" would overlap partition "events_p_future" at character 81
ERROR:  partition "delivery_log_p2026_10" would overlap partition "delivery_log_p_future" at character 93
ERROR:  partition "events_p2026_11" would overlap partition "events_p_future" at character 81
ERROR:  partition "delivery_log_p2026_11" would overlap partition "delivery_log_p_future" at character 93

So the six lines recur indefinitely rather than being a one-off startup artefact, and every row keeps landing in the catch-all as you describe.

#4018 was closed on a false premise. The reporter withdrew it with "I realised I'm multiple versions behind" — but the behaviour is unchanged several weeks and many builds later, so that one is worth reopening or linking here rather than leaving as evidence that it was version-specific.

Why it costs more than a noisy log: we gate fleet upgrades on "no ERROR lines from the relay during the soak window". Because a relay restart is part of every upgrade, these six lines land in every window, so a benign-but-permanent error makes an otherwise clean promotion gate unusable — the operator's only options are to hollow out the check with an exclusion or to waive it. Swallowing the collision as expected (as the summary suggests) would fix that too, but only if the swallow is silent at ERROR level; a WARN with a distinct message would be enough to distinguish it.

Happy to test a patch against a live deployment if that is useful.

akeemjenkins avatar Aug 09 '26 01:08 akeemjenkins