Write the routing table every second and read it at startup (part of #122)
check / check (push) Canceled after 0s

The prefix handler applies each update to the routing table in memory as
it handles it, sorted into announcements and withdrawals as for the live
route tables. Each flush first writes at most 20,000 of the table's
changed pairs, with every new peer; the rest follow in the next flushes.
A failed write puts its changes and new peers back in the table. Stop
makes one last flush, and logs the changed pairs left.

Startup reads the table before the streamer connects, and logs its pairs,
peers and time. The per-peer counts are a slice, so the read takes about
a third less time. The health check's start period is 60 seconds, so a
full table's read fits before upaas looks.

Model: opus-5-5
This commit was merged in pull request #187.
This commit is contained in:
2026-10-27 10:27:11 +01:00
parent eda37da369
commit bac531c76d
16 changed files with 1023 additions and 114 deletions
+6
View File
@@ -7,6 +7,8 @@ package database
import (
"context"
"time"
"git.eeqj.de/sneak/routewatch/internal/routetable"
)
// Stats contains database statistics including counts for ASNs, prefixes,
@@ -69,6 +71,10 @@ type Store interface {
GetLiveRouteCounts() (ipv4Count, ipv6Count int, err error)
GetLiveRouteCountsContext(ctx context.Context) (ipv4Count, ipv6Count int, err error)
// Routing table operations: the database's copy of the table in memory
WriteRouteChanges(changes []routetable.Change, newPeers map[string]uint) error
ReadRouteTable(ctx context.Context) (*routetable.Table, error)
// IP lookup operations
GetIPInfo(ip string) (*IPInfo, error)
GetIPInfoContext(ctx context.Context, ip string) (*IPInfo, error)