Major schema refactoring: simplify ASN and prefix tracking
- Remove UUID primary keys from ASNs table, use ASN number as primary key - Update announcements table to reference ASN numbers directly - Rename asns.number column to asns.asn for consistency - Add prefix tracking to PrefixHandler to populate prefixes_v4/v6 tables - Add UpdatePrefixesBatch method for efficient batch updates - Update all database methods and models to use new schema - Fix all references in code to use ASN field instead of Number - Update test mocks to match new interfaces
This commit is contained in:
@@ -182,9 +182,15 @@ func (h *PrefixHandler) flushBatchLocked() {
|
||||
var routesToUpsert []*database.LiveRoute
|
||||
var routesToDelete []database.LiveRouteDeletion
|
||||
|
||||
// Skip the prefix table updates entirely - just update live_routes
|
||||
// The prefix table is not critical for routing lookups
|
||||
// Collect unique prefixes to update
|
||||
prefixesToUpdate := make(map[string]time.Time)
|
||||
|
||||
for _, update := range prefixMap {
|
||||
// Track prefix for both announcements and withdrawals
|
||||
if _, exists := prefixesToUpdate[update.prefix]; !exists || update.timestamp.After(prefixesToUpdate[update.prefix]) {
|
||||
prefixesToUpdate[update.prefix] = update.timestamp
|
||||
}
|
||||
|
||||
if update.messageType == "announcement" && update.originASN > 0 {
|
||||
// Create live route for batch upsert
|
||||
route := h.createLiveRoute(update)
|
||||
@@ -228,6 +234,13 @@ func (h *PrefixHandler) flushBatchLocked() {
|
||||
}
|
||||
}
|
||||
|
||||
// Update prefix tables
|
||||
if len(prefixesToUpdate) > 0 {
|
||||
if err := h.db.UpdatePrefixesBatch(prefixesToUpdate); err != nil {
|
||||
h.logger.Error("Failed to update prefix batch", "error", err, "count", len(prefixesToUpdate))
|
||||
}
|
||||
}
|
||||
|
||||
elapsed := time.Since(startTime)
|
||||
h.logger.Debug("Flushed prefix batch",
|
||||
"batch_size", batchSize,
|
||||
|
||||
Reference in New Issue
Block a user