metadata: use resource max and end on registration
Ensure the registered resource type does not conflict with existing resource types or over the max. Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
parent
8367f69fb5
commit
3b82f9e33c
@ -280,6 +280,12 @@ func (m *DB) RegisterMutationCallback(fn func(bool)) {
|
|||||||
// - Collectible Resources must track whether the resource is active and/or
|
// - Collectible Resources must track whether the resource is active and/or
|
||||||
// lease membership.
|
// lease membership.
|
||||||
func (m *DB) RegisterCollectibleResource(t gc.ResourceType, c Collector) {
|
func (m *DB) RegisterCollectibleResource(t gc.ResourceType, c Collector) {
|
||||||
|
if t < resourceEnd {
|
||||||
|
panic("cannot re-register metadata resource")
|
||||||
|
} else if t >= gc.ResourceMax {
|
||||||
|
panic("resource type greater than max")
|
||||||
|
}
|
||||||
|
|
||||||
m.wlock.Lock()
|
m.wlock.Lock()
|
||||||
defer m.wlock.Unlock()
|
defer m.wlock.Unlock()
|
||||||
|
|
||||||
@ -287,15 +293,10 @@ func (m *DB) RegisterCollectibleResource(t gc.ResourceType, c Collector) {
|
|||||||
m.collectors = map[gc.ResourceType]Collector{}
|
m.collectors = map[gc.ResourceType]Collector{}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch t {
|
if _, ok := m.collectors[t]; ok {
|
||||||
case ResourceContainer:
|
panic("cannot register collectible type twice")
|
||||||
panic("cannot re-register metadata resource")
|
|
||||||
default:
|
|
||||||
if _, ok := m.collectors[t]; ok {
|
|
||||||
panic("cannot register collectible type twice")
|
|
||||||
}
|
|
||||||
m.collectors[t] = c
|
|
||||||
}
|
}
|
||||||
|
m.collectors[t] = c
|
||||||
}
|
}
|
||||||
|
|
||||||
// GCStats holds the duration for the different phases of the garbage collector
|
// GCStats holds the duration for the different phases of the garbage collector
|
||||||
|
@ -44,6 +44,8 @@ const (
|
|||||||
ResourceLease
|
ResourceLease
|
||||||
// ResourceIngest specifies a content ingest
|
// ResourceIngest specifies a content ingest
|
||||||
ResourceIngest
|
ResourceIngest
|
||||||
|
// resourceEnd is the end of specified resource types
|
||||||
|
resourceEnd
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
Loading…
Reference in New Issue
Block a user