milvus-io / milvus

A cloud-native vector database, storage for next generation AI applications
https://milvus.io
Apache License 2.0
30.03k stars 2.88k forks source link

[Bug]: [GOSDK] The DBName was specified in the ClientConfig but it does not seem to take effect #34137

Closed ThreadDao closed 2 months ago

ThreadDao commented 3 months ago

Is there an existing issue for this?

Environment

- Milvus version: master-20240621-958ecd50-amd64
- Deployment mode(standalone or cluster): standalone
- MQ type(rocksmq, pulsar or kafka):    
- SDK version(e.g. pymilvus v2.0.0rc2): go-sdk v2
- OS(Ubuntu or CentOS): 
- CPU/Memory: 
- GPU: 
- Others:

Current Behavior

  1. specify an existing db name in ClientConfig and expected an error
    _, err := base.NewMilvusClient(ctx, &clientv2.ClientConfig{Address: *addr, DBName: "dbName"})
    common.CheckErr(t, err, false, "database not found")
  2. specify an valid db name in ClientConfig, then create a collection in this db. However the collection in the default db

    func TestClientWithDb(t *testing.T) {
    teardownSuite := teardownTest(t)
    defer teardownSuite(t)
    ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout)
    
    // connect with not existed db
    /*_, err := base.NewMilvusClient(ctx, &clientv2.ClientConfig{Address: *addr, DBName: "dbName"})
    common.CheckErr(t, err, false, "database not found")*/
    
    // connect default db -> create a collection in default db
    mcDefault, errDefault := base.NewMilvusClient(ctx, &clientv2.ClientConfig{
        Address: *addr,
        //DBName:  common.DefaultDb,
    })
    common.CheckErr(t, errDefault, true)
    _, defCol1 := hp.CollPrepare.CreateCollection(ctx, t, mcDefault, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption())
    defCollections, _ := mcDefault.ListCollections(ctx, clientv2.NewListCollectionOption())
    require.Contains(t, defCollections, defCol1.CollectionName)
    log.Debug("default db collections:", zap.Any("default collections", defCollections))
    
    // create a db and create collection in db
    dbName := common.GenRandomString("db", 5)
    err := mcDefault.CreateDatabase(ctx, clientv2.NewCreateDatabaseOption(dbName))
    common.CheckErr(t, err, true)
    
    // and connect with db
    mcDb, err := base.NewMilvusClient(ctx, &clientv2.ClientConfig{
        Address: *addr,
        DBName:  dbName,
    })
    common.CheckErr(t, err, true)
    _, dbCol1 := hp.CollPrepare.CreateCollection(ctx, t, mcDb, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption())
    
    dbCollections, _ := mcDb.ListCollections(ctx, clientv2.NewListCollectionOption())
    log.Debug("db collections:", zap.Any("db collections", dbCollections))
    require.Containsf(t, dbCollections, dbCol1.CollectionName, fmt.Sprintf("The collection %s not in: %v", dbCol1.CollectionName, dbCollections))
    
    // using default db and collection not in
    _ = mcDb.UsingDatabase(ctx, clientv2.NewUsingDatabaseOption(common.DefaultDb))
    defCollections, _ = mcDb.ListCollections(ctx, clientv2.NewListCollectionOption())
    require.NotContains(t, defCollections, dbCol1.CollectionName)
    
    // connect empty db (actually default db)
    mcEmpty, err := base.NewMilvusClient(ctx, &clientv2.ClientConfig{
        Address: *addr,
        DBName:  "",
    })
    common.CheckErr(t, err, true)
    defCollections, _ = mcEmpty.ListCollections(ctx, clientv2.NewListCollectionOption())
    require.Contains(t, defCollections, defCol1.CollectionName)
    }

    image

Expected Behavior

No response

Steps To Reproduce

No response

Milvus Log

No response

Anything else?

No response

stale[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. Rotten issues close after 30d of inactivity. Reopen the issue with /reopen.

xiaofan-luan commented 2 months ago

keep it