From 2b7f17334d52e47556489b34eaae235d3fc4a819 Mon Sep 17 00:00:00 2001 From: Dmitriy Matrenichev Date: Mon, 3 Jun 2024 14:04:20 +0300 Subject: [PATCH] chore: replace sync.Map with HashTrieMap Use in for `inmem` and `namespaced` packages. Closes #455 Signed-off-by: Dmitriy Matrenichev --- pkg/state/impl/inmem/inmem.go | 7 ++++--- pkg/state/impl/namespaced/namespaced.go | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/state/impl/inmem/inmem.go b/pkg/state/impl/inmem/inmem.go index 75a88d6..8e27ba6 100644 --- a/pkg/state/impl/inmem/inmem.go +++ b/pkg/state/impl/inmem/inmem.go @@ -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" @@ -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 @@ -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, } } } diff --git a/pkg/state/impl/namespaced/namespaced.go b/pkg/state/impl/namespaced/namespaced.go index 461e44b..194ad3c 100644 --- a/pkg/state/impl/namespaced/namespaced.go +++ b/pkg/state/impl/namespaced/namespaced.go @@ -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" @@ -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](), } }