Record origin changes and show them on the prefix page (closes #161)
check / check (push) Successful in 1m3s
check / check (push) Successful in 1m3s
The routing table records a row each time a prefix and origin AS gets its first peer (announced) or loses its last (withdrawn), with the time and how many peers carry the prefix just after. The prefix handler writes the rows to a new origin_changes table, apart from routes. Every hour the database maintainer keeps each prefix's rows from the last 72 hours or its newest 500, whichever keeps more. The prefix page lists them newest first, at most 5,000. At most 100,000 rows wait in memory to be written; past that the oldest are dropped and logged. A stop loses the rows past its last write. Model: deepseek-v4-pro (implementation); opus-5-5 (commit message)
This commit was merged in pull request #231.
This commit is contained in:
1 parent
15bf20a894
commit
e58c6635e7
20 files changed
+1651
-88
No files matched your search
@@ -175,12 +175,13 @@ func (s *blockingStore) releaseWrites() {
|
||||
//
|
||||
//nolint:tagliatelle // field names are the keys the handlers log
|
||||
type stopLog struct {
|
||||
Msg string `json:"msg"`
|
||||
Updates int `json:"updates"`
|
||||
TableChanges int `json:"table_changes"`
|
||||
HeldMessages int `json:"held_messages"`
|
||||
Paths int `json:"paths"`
|
||||
BatchEntries int `json:"batch_entries"`
|
||||
Msg string `json:"msg"`
|
||||
Updates int `json:"updates"`
|
||||
TableChanges int `json:"table_changes"`
|
||||
HeldMessages int `json:"held_messages"`
|
||||
OriginChanges int `json:"origin_changes"`
|
||||
Paths int `json:"paths"`
|
||||
BatchEntries int `json:"batch_entries"`
|
||||
}
|
||||
|
||||
// newErrorLogger returns a logger that writes only errors, as JSON lines, to
|
||||
@@ -472,6 +473,42 @@ func (s tableWriteBlockingStore) WriteRouteChanges(
|
||||
return s.mockStore.WriteRouteChanges(changes, newPeers)
|
||||
}
|
||||
|
||||
// stopPrefixHandlerWithBlockedWrite stops the prefix handler, whose store
|
||||
// holds the write that fill starts, after handing it the message extra, and
|
||||
// returns what Stop logged. blocking is the store the write waits on; store is
|
||||
// a blockingStore wrapped for the routing table's changes or the origin
|
||||
// changes.
|
||||
func stopPrefixHandlerWithBlockedWrite(
|
||||
t *testing.T,
|
||||
blocking *blockingStore,
|
||||
store database.Store,
|
||||
logs *bytes.Buffer,
|
||||
fill, extra *ristypes.RISMessage,
|
||||
) stopLog {
|
||||
t.Helper()
|
||||
|
||||
h := NewPrefixHandler(store, newErrorLogger(logs),
|
||||
routetable.New(routetable.Params{}))
|
||||
stopWhileAWriteIsBlocked(t, blocking, h, h.done,
|
||||
[]*ristypes.RISMessage{fill}, extra)
|
||||
|
||||
return lastLogged(t, logs)
|
||||
}
|
||||
|
||||
// originChangesBlockingStore is a blockingStore whose writes of the origin
|
||||
// changes also wait until the test calls releaseWrites.
|
||||
type originChangesBlockingStore struct {
|
||||
*blockingStore
|
||||
}
|
||||
|
||||
func (s originChangesBlockingStore) WriteOriginChanges(
|
||||
changes []routetable.OriginChange,
|
||||
) error {
|
||||
s.waitForRelease()
|
||||
|
||||
return s.mockStore.WriteOriginChanges(changes)
|
||||
}
|
||||
|
||||
// TestPrefixHandlerStopCountsTheTableChangesOfAWriteInProgress holds the write
|
||||
// of the routing table's changes that a full batch starts, then hands the
|
||||
// prefix handler one more prefix and stops it with a deadline that passes
|
||||
@@ -485,19 +522,67 @@ func TestPrefixHandlerStopCountsTheTableChangesOfAWriteInProgress(t *testing.T)
|
||||
var logs bytes.Buffer
|
||||
|
||||
blocking := newBlockingStore()
|
||||
h := NewPrefixHandler(tableWriteBlockingStore{blockingStore: blocking},
|
||||
newErrorLogger(&logs), routetable.New(routetable.Params{}))
|
||||
fill := slices.Repeat([]string{testV4Prefix}, prefixBatchSize)
|
||||
stopWhileAWriteIsBlocked(t, blocking, h, h.done,
|
||||
[]*ristypes.RISMessage{prefixAnnouncement(fill)},
|
||||
prefixAnnouncement([]string{extraPrefix}))
|
||||
logged := stopPrefixHandlerWithBlockedWrite(t, blocking,
|
||||
tableWriteBlockingStore{blockingStore: blocking}, &logs,
|
||||
prefixAnnouncement(fill), prefixAnnouncement([]string{extraPrefix}))
|
||||
|
||||
if logged := lastLogged(t, &logs); logged.TableChanges != 2 {
|
||||
if logged.TableChanges != 2 {
|
||||
t.Errorf("Stop logged %d table changes not written, want 2",
|
||||
logged.TableChanges)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPrefixHandlerStopCountsTheOriginChangesOfAWriteInProgress holds the
|
||||
// write of the origin changes that a full batch starts, then hands the prefix
|
||||
// handler one more prefix and stops it with a deadline that passes meanwhile.
|
||||
// Stop must log as not written both the change the held write took and the one
|
||||
// since.
|
||||
func TestPrefixHandlerStopCountsTheOriginChangesOfAWriteInProgress(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const extraPrefix = "198.51.100.0/24"
|
||||
|
||||
var logs bytes.Buffer
|
||||
|
||||
blocking := newBlockingStore()
|
||||
fill := slices.Repeat([]string{testV4Prefix}, prefixBatchSize)
|
||||
logged := stopPrefixHandlerWithBlockedWrite(t, blocking,
|
||||
originChangesBlockingStore{blockingStore: blocking}, &logs,
|
||||
prefixAnnouncement(fill), prefixAnnouncement([]string{extraPrefix}))
|
||||
|
||||
if logged.OriginChanges != 2 {
|
||||
t.Errorf("Stop logged %d origin changes not written, want 2",
|
||||
logged.OriginChanges)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPrefixHandlerStopCountsTheWaitingOriginChanges stops the prefix handler
|
||||
// with a deadline that has already passed, so the flush goroutine skips its
|
||||
// last write. The origin changes still waiting in the routing table are then
|
||||
// not written, and Stop must log them.
|
||||
func TestPrefixHandlerStopCountsTheWaitingOriginChanges(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var logs bytes.Buffer
|
||||
|
||||
store := newMockStore()
|
||||
h := newPrefixHandler(store, newErrorLogger(&logs),
|
||||
routetable.New(routetable.Params{}), longerThanAnyTest,
|
||||
maxTableChangesPerWrite)
|
||||
|
||||
h.HandleMessage(peerAnnouncement(testPeerIP, testV4Prefix, testV6Prefix))
|
||||
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
cancel()
|
||||
h.Stop(ctx)
|
||||
|
||||
if logged := lastLogged(t, &logs); logged.OriginChanges != 2 {
|
||||
t.Errorf("Stop logged %d origin changes not written, want 2",
|
||||
logged.OriginChanges)
|
||||
}
|
||||
}
|
||||
|
||||
// TestASHandlerSkipsItsLastWriteAfterTheStopDeadline also checks what Stop
|
||||
// logs: the asnBatchSize entries of the held write and the entry for testASNB,
|
||||
// handled since, are not written.
|
||||
|
||||
Reference in new issue
Block a user