layer1: derive namespace phases step 10

This commit is contained in:
Naeel
2026-04-26 10:02:03 +03:00
parent 910f65b6d4
commit 66a3dc2a3c
4 changed files with 83 additions and 4 deletions
+27
View File
@@ -152,6 +152,7 @@ func (m *inMemoryNamespaceManager) MarkPartState(namespace string, part string,
state.UpdatedAt = time.Now().UTC()
}
record.RegisteredParts[part] = state
record.Phase = deriveNamespacePhase(record)
record.UpdatedAt = state.UpdatedAt
m.records[namespace] = record
return record.Clone(), true
@@ -166,4 +167,30 @@ func (m *inMemoryNamespaceManager) Remove(name string) bool {
}
delete(m.records, name)
return true
}
func deriveNamespacePhase(record NamespaceRecord) NamespacePhase {
if len(record.RegisteredParts) == 0 {
return record.Phase
}
hasRegistering := false
for _, part := range record.RegisteredParts {
switch part.State {
case NamespacePartStateFailed:
return NamespacePhaseFailed
case NamespacePartStateRegistering:
hasRegistering = true
case NamespacePartStateActive:
continue
default:
hasRegistering = true
}
}
if hasRegistering {
return NamespacePhaseRegistering
}
return NamespacePhaseActive
}