2021-04-19 13:47:10 +08:00
|
|
|
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
|
|
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
// or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
|
|
|
2021-06-22 16:44:09 +08:00
|
|
|
package querycoord
|
2021-03-11 18:42:25 +08:00
|
|
|
|
|
|
|
import (
|
2021-08-26 14:17:54 +08:00
|
|
|
"fmt"
|
2021-03-11 18:42:25 +08:00
|
|
|
"testing"
|
|
|
|
|
2021-08-26 14:17:54 +08:00
|
|
|
"github.com/golang/protobuf/proto"
|
2021-03-11 18:42:25 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2021-07-13 14:16:00 +08:00
|
|
|
|
|
|
|
etcdkv "github.com/milvus-io/milvus/internal/kv/etcd"
|
2021-08-26 14:17:54 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
2021-03-11 18:42:25 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestReplica_Release(t *testing.T) {
|
2021-08-26 14:17:54 +08:00
|
|
|
refreshParams()
|
2021-08-13 11:04:09 +08:00
|
|
|
etcdKV, err := etcdkv.NewEtcdKV(Params.EtcdEndpoints, Params.MetaRootPath)
|
2021-07-13 14:16:00 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
meta, err := newMeta(etcdKV)
|
2021-06-19 11:45:09 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
err = meta.addCollection(1, nil)
|
2021-03-11 18:42:25 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-06-15 12:41:40 +08:00
|
|
|
collections := meta.showCollections()
|
|
|
|
assert.Equal(t, 1, len(collections))
|
2021-03-11 18:42:25 +08:00
|
|
|
|
2021-06-15 12:41:40 +08:00
|
|
|
err = meta.addPartition(1, 100)
|
2021-03-11 18:42:25 +08:00
|
|
|
assert.NoError(t, err)
|
2021-06-15 12:41:40 +08:00
|
|
|
partitions, err := meta.showPartitions(1)
|
2021-03-11 18:42:25 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 1, len(partitions))
|
|
|
|
|
2021-06-15 12:41:40 +08:00
|
|
|
meta.releasePartition(1, 100)
|
|
|
|
partitions, err = meta.showPartitions(1)
|
2021-03-11 18:42:25 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 0, len(partitions))
|
2021-06-15 12:41:40 +08:00
|
|
|
meta.releasePartition(1, 100)
|
2021-03-11 18:42:25 +08:00
|
|
|
|
2021-06-15 12:41:40 +08:00
|
|
|
meta.releaseCollection(1)
|
|
|
|
collections = meta.showCollections()
|
|
|
|
assert.Equal(t, 0, len(collections))
|
|
|
|
meta.releaseCollection(1)
|
2021-03-11 18:42:25 +08:00
|
|
|
}
|
2021-08-26 14:17:54 +08:00
|
|
|
|
|
|
|
func TestReloadMetaFromKV(t *testing.T) {
|
|
|
|
refreshParams()
|
|
|
|
kv, err := etcdkv.NewEtcdKV(Params.EtcdEndpoints, Params.MetaRootPath)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
meta := &MetaReplica{
|
|
|
|
client: kv,
|
|
|
|
collectionInfos: map[UniqueID]*querypb.CollectionInfo{},
|
|
|
|
segmentInfos: map[UniqueID]*querypb.SegmentInfo{},
|
|
|
|
queryChannelInfos: map[UniqueID]*querypb.QueryChannelInfo{},
|
|
|
|
}
|
|
|
|
|
|
|
|
kvs := make(map[string]string)
|
|
|
|
collectionInfo := &querypb.CollectionInfo{
|
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
}
|
|
|
|
collectionBlobs := proto.MarshalTextString(collectionInfo)
|
|
|
|
collectionKey := fmt.Sprintf("%s/%d", collectionMetaPrefix, defaultCollectionID)
|
|
|
|
kvs[collectionKey] = collectionBlobs
|
|
|
|
|
|
|
|
segmentInfo := &querypb.SegmentInfo{
|
|
|
|
SegmentID: defaultSegmentID,
|
|
|
|
}
|
|
|
|
segmentBlobs := proto.MarshalTextString(segmentInfo)
|
|
|
|
segmentKey := fmt.Sprintf("%s/%d", segmentMetaPrefix, defaultSegmentID)
|
|
|
|
kvs[segmentKey] = segmentBlobs
|
|
|
|
|
|
|
|
queryChannelInfo := &querypb.QueryChannelInfo{
|
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
}
|
|
|
|
queryChannelBlobs := proto.MarshalTextString(queryChannelInfo)
|
|
|
|
queryChannelKey := fmt.Sprintf("%s/%d", queryChannelMetaPrefix, defaultCollectionID)
|
|
|
|
kvs[queryChannelKey] = queryChannelBlobs
|
|
|
|
|
|
|
|
err = kv.MultiSave(kvs)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
err = meta.reloadFromKV()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, 1, len(meta.collectionInfos))
|
|
|
|
assert.Equal(t, 1, len(meta.segmentInfos))
|
|
|
|
assert.Equal(t, 1, len(meta.queryChannelInfos))
|
|
|
|
_, ok := meta.collectionInfos[defaultCollectionID]
|
|
|
|
assert.Equal(t, true, ok)
|
|
|
|
_, ok = meta.segmentInfos[defaultSegmentID]
|
|
|
|
assert.Equal(t, true, ok)
|
|
|
|
_, ok = meta.queryChannelInfos[defaultCollectionID]
|
|
|
|
assert.Equal(t, true, ok)
|
|
|
|
}
|