Skip to content

Commit 772b286

Browse files
committed
chore: create 7 partitions in advance instead of 3
1 parent 0938e37 commit 772b286

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ When the replication slot is invalidated (WAL exceeded `max_slot_wal_keep_size`)
329329
Postgres Stream automatically manages daily partitions in the background:
330330

331331
**Retention policy:**
332-
- **Creates partitions** 3 days in advance (today, tomorrow, day after)
332+
- **Creates partitions** 7 days in advance
333333
- **Drops partitions** older than 7 days
334334
- **Runs on startup** and then daily
335335

src/maintenance.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ use crate::{
1212
store::StreamStore,
1313
};
1414

15+
const DAYS_AHEAD_TO_CREATE: u32 = 7;
16+
const RETENTION_DAYS: u32 = 7;
17+
1518
/// Domain representation of a partition with its date-based metadata.
1619
#[derive(Debug, Clone)]
1720
pub struct PartitionInfo {
@@ -117,9 +120,13 @@ pub async fn run_maintenance<S: SchemaStore>(store: &StreamStore<S>) -> EtlResul
117120
let result = async {
118121
let existing_partitions = store.load_partitions(SCHEMA_NAME, EVENTS_TABLE).await?;
119122

120-
let policy = RetentionPolicy::new(7);
121-
let (to_drop, to_create) =
122-
policy.plan_maintenance(existing_partitions, EVENTS_TABLE, 3, start);
123+
let policy = RetentionPolicy::new(RETENTION_DAYS);
124+
let (to_drop, to_create) = policy.plan_maintenance(
125+
existing_partitions,
126+
EVENTS_TABLE,
127+
DAYS_AHEAD_TO_CREATE,
128+
start,
129+
);
123130

124131
for partition in to_drop {
125132
info!("Dropping partition: {}", partition.name);

0 commit comments

Comments
 (0)