Skip to content

Commit

Permalink
Fix a bug that mmap can enabled even the collection is loaded
Browse files Browse the repository at this point in the history
Signed-off-by: yhmo <[email protected]>
  • Loading branch information
yhmo committed Mar 4, 2024
1 parent fa73520 commit 8b64dcf
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
12 changes: 12 additions & 0 deletions internal/proxy/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,18 @@ func (t *alterCollectionTask) PreExecute(ctx context.Context) error {
t.Base.MsgType = commonpb.MsgType_AlterCollection
t.Base.SourceID = paramtable.GetNodeID()

// The proto definition of AlterCollectionRequest accepts a collection name or a collection id.
// Usually, the client input a collection name, we use the collection name
// to get collection id to call isCollectionLoaded().
collName := t.GetCollectionName()
if collName != "" {
collectionID, err := globalMetaCache.GetCollectionID(ctx, t.GetDbName(), collName)
if err != nil {
return err
}
t.CollectionID = collectionID
}

if hasMmapProp(t.Properties...) || hasLazyLoadProp(t.Properties...) {
loaded, err := isCollectionLoaded(ctx, t.queryCoord, t.CollectionID)
if err != nil {
Expand Down
44 changes: 34 additions & 10 deletions internal/proxy/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3605,14 +3605,38 @@ func TestAlterCollectionCheckLoaded(t *testing.T) {
CollectionIDs: []int64{1},
InMemoryPercentages: []int64{100},
}, nil)
task := &alterCollectionTask{
AlterCollectionRequest: &milvuspb.AlterCollectionRequest{
Base: &commonpb.MsgBase{},
CollectionID: 1,
Properties: []*commonpb.KeyValuePair{{Key: common.MmapEnabledKey, Value: "true"}},
},
queryCoord: qc,
}
err := task.PreExecute(context.Background())
assert.Equal(t, merr.Code(merr.ErrCollectionLoaded), merr.Code(err))

t.Run("collection id not loaded", func(t *testing.T) {
task := &alterCollectionTask{
AlterCollectionRequest: &milvuspb.AlterCollectionRequest{
Base: &commonpb.MsgBase{},
CollectionID: 1,
Properties: []*commonpb.KeyValuePair{{Key: common.MmapEnabledKey, Value: "true"}},
},
queryCoord: qc,
}
err := task.PreExecute(context.Background())
assert.Equal(t, merr.Code(merr.ErrCollectionLoaded), merr.Code(err))
})

t.Run("collection name not loaded", func(t *testing.T) {
cache := NewMockCache(t)
cache.On("GetCollectionID",
mock.Anything, // context.Context
mock.AnythingOfType("string"),
mock.AnythingOfType("string"),
).Return(UniqueID(1), nil)
globalMetaCache = cache

task := &alterCollectionTask{
AlterCollectionRequest: &milvuspb.AlterCollectionRequest{
Base: &commonpb.MsgBase{},
CollectionName: "dummy",
Properties: []*commonpb.KeyValuePair{{Key: common.MmapEnabledKey, Value: "true"}},
},
queryCoord: qc,
}
err := task.PreExecute(context.Background())
assert.Equal(t, merr.Code(merr.ErrCollectionLoaded), merr.Code(err))
})
}

0 comments on commit 8b64dcf

Please sign in to comment.