Skip to content

Commit

Permalink
chore: replace sync.Map with HashTrieMap
Browse files Browse the repository at this point in the history
Use in for `inmem` and `namespaced` packages.

Closes #455

Signed-off-by: Dmitriy Matrenichev <[email protected]>
  • Loading branch information
DmitriyMV committed Jun 3, 2024
1 parent b2c32a5 commit 2b7f173
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions pkg/state/impl/inmem/inmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"sync"
"sync/atomic"

"github.com/siderolabs/gen/containers"
"github.com/siderolabs/gen/concurrent"

"github.com/cosi-project/runtime/pkg/resource"
"github.com/cosi-project/runtime/pkg/state"
Expand All @@ -20,7 +20,7 @@ var _ state.CoreState = &State{}

// State implements state.CoreState.
type State struct {
collections containers.SyncMap[resource.Type, *ResourceCollection]
collections *concurrent.HashTrieMap[resource.Type, *ResourceCollection]
store BackingStore

ns resource.Namespace
Expand All @@ -44,11 +44,12 @@ func NewStateWithOptions(opts ...StateOption) func(ns resource.Namespace) *State

return func(ns resource.Namespace) *State {
return &State{
collections: concurrent.NewHashTrieMap[resource.Type, *ResourceCollection](),
store: options.BackingStore,
ns: ns,
initialCapacity: options.HistoryInitialCapacity,
maxCapacity: options.HistoryMaxCapacity,
gap: options.HistoryGap,
store: options.BackingStore,
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/state/impl/namespaced/namespaced.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package namespaced
import (
"context"

"github.com/siderolabs/gen/containers"
"github.com/siderolabs/gen/concurrent"

"github.com/cosi-project/runtime/pkg/resource"
"github.com/cosi-project/runtime/pkg/state"
Expand All @@ -23,13 +23,14 @@ var _ state.CoreState = (*State)(nil)
type State struct {
builder StateBuilder

namespaces containers.SyncMap[resource.Namespace, state.CoreState]
namespaces *concurrent.HashTrieMap[resource.Namespace, state.CoreState]
}

// NewState initializes new namespaced State.
func NewState(builder StateBuilder) *State {
return &State{
builder: builder,
builder: builder,
namespaces: concurrent.NewHashTrieMap[resource.Namespace, state.CoreState](),
}
}

Expand Down

0 comments on commit 2b7f173

Please sign in to comment.