Skip to content

Commit

Permalink
fix: [GoSDK] reset cache after UsingDatabase (milvus-io#35638)
Browse files Browse the repository at this point in the history
Related to milvus-io/milvus-sdk-go#809

---------

Signed-off-by: Congqi Xia <[email protected]>
  • Loading branch information
congqixia authored Aug 29, 2024
1 parent 6926597 commit 4373c69
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions client/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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](),
Expand Down
4 changes: 2 additions & 2 deletions client/index/hnsw.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

0 comments on commit 4373c69

Please sign in to comment.