Stop now counts the origin changes inside a running write, in a new writingOriginChanges field, and adds them to the count it logs. The prune test checks which rows survive, including a prefix with rows on both sides of 72 hours. The prefix page tests cover 5,000 and 5,001 rows and a row's time and peer count. New tests cover the dropped-rows warning and the dropped count's reset. The prune floor is named minOriginChangesPerPrefix. The README, TODO, package doc and doc comments are corrected to match. Model: deepseek-v4-pro
This commit is contained in:
@@ -9,13 +9,13 @@ import (
|
||||
"git.eeqj.de/sneak/routewatch/internal/routetable"
|
||||
)
|
||||
|
||||
// maxOriginChangesPerPrefix is how many origin changes the prune keeps for
|
||||
// each prefix: the newest ones. A prefix with more has its older rows deleted.
|
||||
const maxOriginChangesPerPrefix = 500
|
||||
// minOriginChangesPerPrefix is how many of a prefix's newest origin changes
|
||||
// the prune always keeps, whatever their age.
|
||||
const minOriginChangesPerPrefix = 500
|
||||
|
||||
// originChangesRetention is how long the prune keeps an origin change: rows
|
||||
// older than this are deleted, unless they are among the prefix's newest
|
||||
// maxOriginChangesPerPrefix.
|
||||
// minOriginChangesPerPrefix.
|
||||
const originChangesRetention = 72 * time.Hour
|
||||
|
||||
// The statements of the origin_changes table (schema.sql).
|
||||
@@ -122,13 +122,13 @@ func (d *Database) GetOriginChanges(
|
||||
}
|
||||
|
||||
// PruneOriginChanges deletes, for each prefix with more than
|
||||
// maxOriginChangesPerPrefix rows, the rows older than originChangesRetention
|
||||
// that are not among its newest maxOriginChangesPerPrefix. It finds those
|
||||
// minOriginChangesPerPrefix rows, the rows older than originChangesRetention
|
||||
// that are not among its newest minOriginChangesPerPrefix. It finds those
|
||||
// prefixes on a reading connection and deletes one prefix per write, so no
|
||||
// write holds the lock for long.
|
||||
func (d *Database) PruneOriginChanges(ctx context.Context) error {
|
||||
rows, err := d.db.QueryContext(ctx, prunePrefixesSQL,
|
||||
maxOriginChangesPerPrefix)
|
||||
minOriginChangesPerPrefix)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to find prefixes to prune: %w", err)
|
||||
}
|
||||
@@ -158,7 +158,7 @@ func (d *Database) PruneOriginChanges(ctx context.Context) error {
|
||||
d.lock("PruneOriginChanges")
|
||||
|
||||
_, err := d.writer.ExecContext(ctx, pruneOriginChangesSQL,
|
||||
prefix, cutoff, prefix, maxOriginChangesPerPrefix-1)
|
||||
prefix, cutoff, prefix, minOriginChangesPerPrefix-1)
|
||||
|
||||
d.unlock()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user