fix: [GoSDK] reset cache after UsingDatabase (#35638)

Related to milvus-io/milvus-sdk-go#809

---------

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
This commit is contained in:
congqixia 2024-08-29 19:41:02 +08:00 committed by GitHub
parent 69265978bf
commit 4373c6994f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 2 deletions

View File

@ -202,6 +202,9 @@ func (c *Client) connectInternal(ctx context.Context) error {
c.config.setServerInfo(resp.GetServerInfo().GetBuildTags())
c.setIdentifier(strconv.FormatInt(resp.GetIdentifier(), 10))
if c.collCache != nil {
c.collCache.Reset()
}
return nil
}

View File

@ -32,6 +32,11 @@ func (c *CollectionCache) GetCollection(ctx context.Context, collName string) (*
return coll, err
}
// Reset clears all cached info, used when client switching env.
func (c *CollectionCache) Reset() {
c.collections = typeutil.NewConcurrentMap[string, *entity.Collection]()
}
func NewCollectionCache(fetcher func(context.Context, string) (*entity.Collection, error)) *CollectionCache {
return &CollectionCache{
collections: typeutil.NewConcurrentMap[string, *entity.Collection](),

View File

@ -41,13 +41,13 @@ func (idx hnswIndex) Params() map[string]string {
}
}
func NewHNSWIndex(metricType MetricType, M int, efConstruction int) Index {
func NewHNSWIndex(metricType MetricType, m int, efConstruction int) Index {
return hnswIndex{
baseIndex: baseIndex{
metricType: metricType,
indexType: HNSW,
},
m: M,
m: m,
efConstruction: efConstruction,
}
}