Fix DeleteCollection not protected (#25599)

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
pull/25630/head
congqixia 2023-07-14 17:04:31 +08:00 committed by GitHub
parent 69d274d233
commit a7e6f08183
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 1 deletions

View File

@ -232,8 +232,13 @@ func DeleteCollection(collection *Collection) {
void
deleteCollection(CCollection collection);
*/
collection.mu.Lock()
defer collection.mu.Unlock()
cPtr := collection.collectionPtr
C.DeleteCollection(cPtr)
if cPtr != nil {
C.DeleteCollection(cPtr)
}
collection.collectionPtr = nil
}

View File

@ -32,6 +32,7 @@ import (
"github.com/cockroachdb/errors"
"github.com/milvus-io/milvus/internal/proto/querypb"
"github.com/milvus-io/milvus/pkg/util/merr"
. "github.com/milvus-io/milvus/pkg/util/typeutil"
)
@ -178,6 +179,10 @@ func NewRetrievePlan(col *Collection, expr []byte, timestamp Timestamp, msgID Un
col.mu.RLock()
defer col.mu.RUnlock()
if col.collectionPtr == nil {
return nil, merr.WrapErrCollectionNotFound(col.id, "collection released")
}
var cPlan C.CRetrievePlan
status := C.CreateRetrievePlanByExpr(col.collectionPtr, unsafe.Pointer(&expr[0]), (C.int64_t)(len(expr)), &cPlan)

View File

@ -70,6 +70,12 @@ func (suite *PlanSuite) TestPlanFail() {
suite.Error(err)
}
func (suite *PlanSuite) TestQueryPlanCollectionReleased() {
collection := &Collection{id: suite.collectionID}
_, err := NewRetrievePlan(collection, nil, 0, 0)
suite.Error(err)
}
func TestPlan(t *testing.T) {
suite.Run(t, new(PlanSuite))
}