Rebuild: the batch store (catalog upserts, write-once chunks, candidates, rule counts, fragments, resume point)
A batch is stored in one transaction and only at its range's resume point, so a retried batch can't count twice. Garbage is judged before per-article: a dropped tool isn't worth reading bodies for either. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0714b2c81a
commit
20910647fa
6 files changed
+242
-7
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import db from '@adonisjs/lucid/services/db'
|
||||
import env from '#start/env'
|
||||
|
||||
/** Months ahead that always have a release_chunks partition. */
|
||||
const AHEAD = 2
|
||||
|
||||
/**
|
||||
* release_chunks is partitioned by month of writing (REBUILD.md, decision a).
|
||||
* Inserts fail without a partition for now(), so the current and the next
|
||||
* months' partitions are created before they are needed; checked once per
|
||||
* process and month.
|
||||
*/
|
||||
class ChunkPartitions {
|
||||
private ensuredFor: string | null = null
|
||||
|
||||
async ensure(now = new Date()) {
|
||||
const month = now.toISOString().slice(0, 7)
|
||||
if (this.ensuredFor === month) return
|
||||
const tablespace = env.get('CHUNK_TABLESPACE')
|
||||
for (let i = 0; i <= AHEAD; i++) {
|
||||
const from = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth() + i, 1))
|
||||
const to = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth() + i + 1, 1))
|
||||
const name = `release_chunks_${from.toISOString().slice(0, 7).replace('-', '')}`
|
||||
await db.rawQuery(
|
||||
`CREATE TABLE IF NOT EXISTS ${name} PARTITION OF release_chunks FOR VALUES FROM ('${from.toISOString()}') TO ('${to.toISOString()}')${tablespace ? ` TABLESPACE ${tablespace}` : ''}`
|
||||
)
|
||||
}
|
||||
this.ensuredFor = month
|
||||
}
|
||||
}
|
||||
|
||||
export default new ChunkPartitions()
|
||||
Reference in new issue
Block a user