mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-01 11:29:48 +08:00
Make indexparamcheck thread-safe (#11916)
Signed-off-by: dragondriver <jiquan.long@zilliz.com>
This commit is contained in:
parent
2147507e89
commit
bf391f2449
@ -24,15 +24,13 @@ type ConfAdapterMgr interface {
|
||||
|
||||
// ConfAdapterMgrImpl implements ConfAdapter.
|
||||
type ConfAdapterMgrImpl struct {
|
||||
init bool
|
||||
adapters map[IndexType]ConfAdapter
|
||||
once sync.Once
|
||||
}
|
||||
|
||||
// GetAdapter gets the conf adapter by the index type.
|
||||
func (mgr *ConfAdapterMgrImpl) GetAdapter(indexType string) (ConfAdapter, error) {
|
||||
if !mgr.init {
|
||||
mgr.registerConfAdapter()
|
||||
}
|
||||
mgr.once.Do(mgr.registerConfAdapter)
|
||||
|
||||
adapter, ok := mgr.adapters[indexType]
|
||||
if ok {
|
||||
@ -42,8 +40,6 @@ func (mgr *ConfAdapterMgrImpl) GetAdapter(indexType string) (ConfAdapter, error)
|
||||
}
|
||||
|
||||
func (mgr *ConfAdapterMgrImpl) registerConfAdapter() {
|
||||
mgr.init = true
|
||||
|
||||
mgr.adapters[IndexFaissIDMap] = newBaseConfAdapter()
|
||||
mgr.adapters[IndexFaissIvfFlat] = newIVFConfAdapter()
|
||||
mgr.adapters[IndexFaissIvfPQ] = newIVFPQConfAdapter()
|
||||
@ -63,7 +59,6 @@ func (mgr *ConfAdapterMgrImpl) registerConfAdapter() {
|
||||
|
||||
func newConfAdapterMgrImpl() *ConfAdapterMgrImpl {
|
||||
return &ConfAdapterMgrImpl{
|
||||
init: false,
|
||||
adapters: make(map[IndexType]ConfAdapter),
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
package indexparamcheck
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -220,3 +221,19 @@ func TestConfAdapterMgrImpl_GetAdapter(t *testing.T) {
|
||||
_, ok = adapter.(*NGTONNGConfAdapter)
|
||||
assert.Equal(t, true, ok)
|
||||
}
|
||||
|
||||
func TestConfAdapterMgrImpl_GetAdapter_multiple_threads(t *testing.T) {
|
||||
num := 4
|
||||
mgr := newConfAdapterMgrImpl()
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < num; i++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
adapter, err := mgr.GetAdapter(IndexHNSW)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, adapter)
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user