layer1: add namespace bootstrap dispatch step 26
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user