layer1: add namespace bootstrap dispatch step 26

This commit is contained in:
Naeel
2026-04-26 10:32:43 +03:00
parent 6f77fa5a9a
commit ad0f83fd4b
3 changed files with 84 additions and 0 deletions
+23
View File
@@ -2,6 +2,7 @@ package utils
import (
"context"
"errors"
"sort"
"sync"
"time"
@@ -51,6 +52,7 @@ type NamespaceManager interface {
SnapshotRecords() []NamespaceRecord
Get(name string) (NamespaceRecord, bool)
Bootstrap(namespaces []string, source NamespaceSource, observedAt time.Time) []NamespaceRecord
BootstrapAndDispatch(ctx context.Context, namespaces []string, source NamespaceSource, observedAt time.Time) ([]NamespaceRecord, error)
Subscribe(subscriber NamespaceSubscriber)
SnapshotSubscribers() []string
Upsert(event NamespaceEvent) NamespaceRecord
@@ -107,6 +109,27 @@ func (m *inMemoryNamespaceManager) Bootstrap(namespaces []string, source Namespa
return records
}
func (m *inMemoryNamespaceManager) BootstrapAndDispatch(ctx context.Context, namespaces []string, source NamespaceSource, observedAt time.Time) ([]NamespaceRecord, error) {
records := m.Bootstrap(namespaces, source, observedAt)
var joinErr error
for _, record := range records {
updatedRecord, ok, err := m.DispatchAdd(ctx, record.Name)
if ok {
record = updatedRecord
}
if err != nil {
joinErr = errors.Join(joinErr, err)
}
for index := range records {
if records[index].Name == record.Name {
records[index] = record
break
}
}
}
return records, joinErr
}
func (m *inMemoryNamespaceManager) SnapshotSubscribers() []string {
m.mu.RLock()
defer m.mu.RUnlock()