2021-04-19 11:12:56 +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-01-21 10:01:29 +08:00
package masterservice
import (
"fmt"
"math/rand"
"testing"
"time"
2021-04-09 16:10:12 +08:00
"github.com/golang/protobuf/proto"
2021-04-22 14:45:57 +08:00
"github.com/milvus-io/milvus/internal/kv"
"github.com/milvus-io/milvus/internal/proto/commonpb"
"github.com/milvus-io/milvus/internal/proto/datapb"
pb "github.com/milvus-io/milvus/internal/proto/etcdpb"
"github.com/milvus-io/milvus/internal/proto/schemapb"
"github.com/milvus-io/milvus/internal/util/typeutil"
2021-01-21 10:01:29 +08:00
"github.com/stretchr/testify/assert"
"go.etcd.io/etcd/clientv3"
)
2021-04-09 16:10:12 +08:00
type mockTestKV struct {
2021-04-12 18:09:28 +08:00
kv . TxnKV
2021-04-09 16:10:12 +08:00
2021-05-18 14:18:02 +08:00
loadWithPrefix func ( key string , ts typeutil . Timestamp ) ( [ ] string , [ ] string , error )
save func ( key , value string ) ( typeutil . Timestamp , error )
2021-05-20 14:14:14 +08:00
multiSave func ( kvs map [ string ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error )
multiSaveAndRemoveWithPrefix func ( saves map [ string ] string , removals [ ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error )
2021-04-09 16:10:12 +08:00
}
2021-05-18 14:18:02 +08:00
func ( m * mockTestKV ) LoadWithPrefix ( key string , ts typeutil . Timestamp ) ( [ ] string , [ ] string , error ) {
return m . loadWithPrefix ( key , ts )
}
func ( m * mockTestKV ) Load ( key string , ts typeutil . Timestamp ) ( string , error ) {
return "" , nil
2021-04-09 16:10:12 +08:00
}
2021-05-18 14:18:02 +08:00
func ( m * mockTestKV ) Save ( key , value string ) ( typeutil . Timestamp , error ) {
2021-04-09 16:10:12 +08:00
return m . save ( key , value )
}
2021-05-20 14:14:14 +08:00
func ( m * mockTestKV ) MultiSave ( kvs map [ string ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error ) {
return m . multiSave ( kvs , addition )
2021-04-09 16:10:12 +08:00
}
2021-05-20 14:14:14 +08:00
func ( m * mockTestKV ) MultiSaveAndRemoveWithPrefix ( saves map [ string ] string , removals [ ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error ) {
return m . multiSaveAndRemoveWithPrefix ( saves , removals , addition )
2021-04-12 15:03:23 +08:00
}
2021-04-09 16:10:12 +08:00
func Test_MockKV ( t * testing . T ) {
k1 := & mockTestKV { }
prefix := make ( map [ string ] [ ] string )
2021-05-18 14:18:02 +08:00
k1 . loadWithPrefix = func ( key string , ts typeutil . Timestamp ) ( [ ] string , [ ] string , error ) {
2021-04-09 16:10:12 +08:00
if val , ok := prefix [ key ] ; ok {
return nil , val , nil
}
2021-04-10 10:53:58 +08:00
return nil , nil , fmt . Errorf ( "load prefix error" )
2021-04-09 16:10:12 +08:00
}
_ , err := NewMetaTable ( k1 )
assert . NotNil ( t , err )
2021-04-10 10:53:58 +08:00
assert . EqualError ( t , err , "load prefix error" )
2021-04-09 16:10:12 +08:00
2021-04-10 10:53:58 +08:00
prefix [ TenantMetaPrefix ] = [ ] string { "tenant-prefix" }
2021-04-09 16:10:12 +08:00
_ , err = NewMetaTable ( k1 )
assert . NotNil ( t , err )
2021-04-10 10:53:58 +08:00
assert . EqualError ( t , err , "MasterService UnmarshalText pb.TenantMeta err:line 1.0: unknown field name \"tenant-prefix\" in milvus.proto.etcd.TenantMeta" )
2021-04-09 16:10:12 +08:00
prefix [ TenantMetaPrefix ] = [ ] string { proto . MarshalTextString ( & pb . TenantMeta { } ) }
_ , err = NewMetaTable ( k1 )
assert . NotNil ( t , err )
2021-04-10 10:53:58 +08:00
prefix [ ProxyMetaPrefix ] = [ ] string { "porxy-meta" }
2021-04-09 16:10:12 +08:00
_ , err = NewMetaTable ( k1 )
assert . NotNil ( t , err )
2021-04-10 10:53:58 +08:00
assert . EqualError ( t , err , "MasterService UnmarshalText pb.ProxyMeta err:line 1.0: unknown field name \"porxy-meta\" in milvus.proto.etcd.ProxyMeta" )
2021-04-09 16:10:12 +08:00
prefix [ ProxyMetaPrefix ] = [ ] string { proto . MarshalTextString ( & pb . ProxyMeta { } ) }
_ , err = NewMetaTable ( k1 )
assert . NotNil ( t , err )
2021-04-10 10:53:58 +08:00
prefix [ CollectionMetaPrefix ] = [ ] string { "collection-meta" }
2021-04-09 16:10:12 +08:00
_ , err = NewMetaTable ( k1 )
assert . NotNil ( t , err )
2021-04-10 10:53:58 +08:00
assert . EqualError ( t , err , "MasterService UnmarshalText pb.CollectionInfo err:line 1.0: unknown field name \"collection-meta\" in milvus.proto.etcd.CollectionInfo" )
2021-04-09 16:10:12 +08:00
prefix [ CollectionMetaPrefix ] = [ ] string { proto . MarshalTextString ( & pb . CollectionInfo { Schema : & schemapb . CollectionSchema { } } ) }
_ , err = NewMetaTable ( k1 )
assert . NotNil ( t , err )
2021-04-10 10:53:58 +08:00
prefix [ PartitionMetaPrefix ] = [ ] string { "partition-meta" }
2021-04-09 16:10:12 +08:00
_ , err = NewMetaTable ( k1 )
assert . NotNil ( t , err )
2021-04-10 10:53:58 +08:00
assert . EqualError ( t , err , "MasterService UnmarshalText pb.PartitionInfo err:line 1.0: unknown field name \"partition-meta\" in milvus.proto.etcd.PartitionInfo" )
2021-04-09 16:10:12 +08:00
prefix [ PartitionMetaPrefix ] = [ ] string { proto . MarshalTextString ( & pb . PartitionInfo { } ) }
_ , err = NewMetaTable ( k1 )
assert . NotNil ( t , err )
2021-04-10 10:53:58 +08:00
prefix [ SegmentIndexMetaPrefix ] = [ ] string { "segment-index-meta" }
2021-04-09 16:10:12 +08:00
_ , err = NewMetaTable ( k1 )
assert . NotNil ( t , err )
2021-04-10 10:53:58 +08:00
assert . EqualError ( t , err , "MasterService UnmarshalText pb.SegmentIndexInfo err:line 1.0: unknown field name \"segment-index-meta\" in milvus.proto.etcd.SegmentIndexInfo" )
2021-04-09 16:10:12 +08:00
prefix [ SegmentIndexMetaPrefix ] = [ ] string { proto . MarshalTextString ( & pb . SegmentIndexInfo { } ) }
_ , err = NewMetaTable ( k1 )
assert . NotNil ( t , err )
prefix [ SegmentIndexMetaPrefix ] = [ ] string { proto . MarshalTextString ( & pb . SegmentIndexInfo { } ) , proto . MarshalTextString ( & pb . SegmentIndexInfo { } ) }
_ , err = NewMetaTable ( k1 )
assert . NotNil ( t , err )
2021-04-10 10:53:58 +08:00
assert . EqualError ( t , err , "load prefix error" )
2021-04-09 16:10:12 +08:00
2021-04-10 10:53:58 +08:00
prefix [ IndexMetaPrefix ] = [ ] string { "index-meta" }
2021-04-09 16:10:12 +08:00
_ , err = NewMetaTable ( k1 )
assert . NotNil ( t , err )
2021-04-10 10:53:58 +08:00
assert . EqualError ( t , err , "MasterService UnmarshalText pb.IndexInfo err:line 1.0: unknown field name \"index-meta\" in milvus.proto.etcd.IndexInfo" )
2021-04-09 16:10:12 +08:00
prefix [ IndexMetaPrefix ] = [ ] string { proto . MarshalTextString ( & pb . IndexInfo { } ) }
m1 , err := NewMetaTable ( k1 )
assert . Nil ( t , err )
2021-05-18 14:18:02 +08:00
k1 . save = func ( key , value string ) ( typeutil . Timestamp , error ) {
return 0 , fmt . Errorf ( "save tenant error" )
2021-04-09 16:10:12 +08:00
}
2021-05-18 14:18:02 +08:00
_ , err = m1 . AddTenant ( & pb . TenantMeta { } )
2021-04-09 16:10:12 +08:00
assert . NotNil ( t , err )
2021-04-10 10:53:58 +08:00
assert . EqualError ( t , err , "save tenant error" )
2021-04-09 16:10:12 +08:00
2021-05-18 14:18:02 +08:00
k1 . save = func ( key , value string ) ( typeutil . Timestamp , error ) {
return 0 , fmt . Errorf ( "save proxy error" )
2021-04-10 10:53:58 +08:00
}
2021-05-18 14:18:02 +08:00
_ , err = m1 . AddProxy ( & pb . ProxyMeta { } )
2021-04-09 16:10:12 +08:00
assert . NotNil ( t , err )
2021-04-10 10:53:58 +08:00
assert . EqualError ( t , err , "save proxy error" )
2021-04-09 16:10:12 +08:00
}
2021-01-21 10:01:29 +08:00
func TestMetaTable ( t * testing . T ) {
2021-05-17 19:15:01 +08:00
const (
collID = typeutil . UniqueID ( 1 )
collIDInvalid = typeutil . UniqueID ( 2 )
partIDDefault = typeutil . UniqueID ( 10 )
partID = typeutil . UniqueID ( 20 )
partIDInvalid = typeutil . UniqueID ( 21 )
segID = typeutil . UniqueID ( 100 )
segID2 = typeutil . UniqueID ( 101 )
fieldID = typeutil . UniqueID ( 110 )
fieldID2 = typeutil . UniqueID ( 111 )
indexID = typeutil . UniqueID ( 10000 )
indexID2 = typeutil . UniqueID ( 10001 )
buildID = typeutil . UniqueID ( 201 )
)
2021-05-14 21:26:06 +08:00
2021-01-21 10:01:29 +08:00
rand . Seed ( time . Now ( ) . UnixNano ( ) )
randVal := rand . Int ( )
2021-01-23 17:56:57 +08:00
Params . Init ( )
2021-01-21 10:01:29 +08:00
rootPath := fmt . Sprintf ( "/test/meta/%d" , randVal )
2021-05-18 14:18:02 +08:00
var vtso typeutil . Timestamp
ftso := func ( ) typeutil . Timestamp {
vtso ++
return vtso
}
2021-06-11 22:04:41 +08:00
etcdCli , err := clientv3 . New ( clientv3 . Config { Endpoints : Params . EtcdEndpoints } )
2021-01-21 10:01:29 +08:00
assert . Nil ( t , err )
2021-05-18 17:12:17 +08:00
defer etcdCli . Close ( )
2021-05-18 14:18:02 +08:00
skv , err := newMetaSnapshot ( etcdCli , rootPath , TimestampPrefix , 7 , ftso )
assert . Nil ( t , err )
assert . NotNil ( t , skv )
mt , err := NewMetaTable ( skv )
2021-01-21 10:01:29 +08:00
assert . Nil ( t , err )
collInfo := & pb . CollectionInfo {
2021-05-14 21:26:06 +08:00
ID : collID ,
2021-01-21 10:01:29 +08:00
Schema : & schemapb . CollectionSchema {
Name : "testColl" ,
Description : "" ,
AutoID : false ,
Fields : [ ] * schemapb . FieldSchema {
{
2021-05-14 21:26:06 +08:00
FieldID : fieldID ,
2021-01-21 10:01:29 +08:00
Name : "field110" ,
IsPrimaryKey : false ,
Description : "" ,
DataType : 0 ,
TypeParams : [ ] * commonpb . KeyValuePair {
{
Key : "field110-k1" ,
Value : "field110-v1" ,
} ,
{
Key : "field110-k2" ,
Value : "field110-v2" ,
} ,
} ,
IndexParams : [ ] * commonpb . KeyValuePair {
{
Key : "field110-i1" ,
Value : "field110-v1" ,
} ,
{
Key : "field110-i2" ,
Value : "field110-v2" ,
} ,
} ,
} ,
} ,
} ,
2021-02-11 08:41:59 +08:00
FieldIndexes : [ ] * pb . FieldIndexInfo {
{
2021-05-14 21:26:06 +08:00
FiledID : fieldID ,
2021-05-17 19:15:01 +08:00
IndexID : indexID ,
2021-02-11 08:41:59 +08:00
} ,
} ,
2021-01-21 10:01:29 +08:00
CreateTime : 0 ,
PartitionIDs : nil ,
}
2021-05-14 21:26:06 +08:00
partInfoDefault := & pb . PartitionInfo {
PartitionName : "_default" ,
PartitionID : partIDDefault ,
SegmentIDs : nil ,
}
2021-01-21 10:01:29 +08:00
partInfo := & pb . PartitionInfo {
PartitionName : "testPart" ,
2021-05-14 21:26:06 +08:00
PartitionID : partID ,
2021-01-21 10:01:29 +08:00
SegmentIDs : nil ,
}
2021-02-11 08:41:59 +08:00
idxInfo := [ ] * pb . IndexInfo {
{
IndexName : "testColl_index_110" ,
2021-05-17 19:15:01 +08:00
IndexID : indexID ,
2021-02-11 08:41:59 +08:00
IndexParams : [ ] * commonpb . KeyValuePair {
{
Key : "field110-i1" ,
Value : "field110-v1" ,
} ,
{
Key : "field110-i2" ,
Value : "field110-v2" ,
} ,
} ,
} ,
}
2021-01-21 10:01:29 +08:00
2021-05-20 14:14:14 +08:00
ddOp := func ( ts typeutil . Timestamp ) ( string , error ) {
return "" , nil
}
2021-01-21 10:01:29 +08:00
t . Run ( "add collection" , func ( t * testing . T ) {
2021-05-14 21:26:06 +08:00
partInfoDefault . SegmentIDs = [ ] int64 { segID }
2021-05-20 14:14:14 +08:00
_ , err = mt . AddCollection ( collInfo , partInfoDefault , idxInfo , ddOp )
2021-04-08 17:31:39 +08:00
assert . NotNil ( t , err )
2021-05-14 21:26:06 +08:00
partInfoDefault . SegmentIDs = [ ] int64 { }
2021-04-08 17:31:39 +08:00
2021-05-14 21:26:06 +08:00
collInfo . PartitionIDs = [ ] int64 { segID }
2021-05-20 14:14:14 +08:00
_ , err = mt . AddCollection ( collInfo , partInfoDefault , idxInfo , ddOp )
2021-04-08 17:31:39 +08:00
assert . NotNil ( t , err )
collInfo . PartitionIDs = [ ] int64 { }
2021-05-20 14:14:14 +08:00
_ , err = mt . AddCollection ( collInfo , partInfoDefault , nil , ddOp )
2021-04-08 17:31:39 +08:00
assert . NotNil ( t , err )
2021-05-20 14:14:14 +08:00
_ , err = mt . AddCollection ( collInfo , partInfoDefault , idxInfo , ddOp )
2021-01-21 10:01:29 +08:00
assert . Nil ( t , err )
2021-05-18 14:18:02 +08:00
collMeta , err := mt . GetCollectionByName ( "testColl" , 0 )
2021-01-21 10:01:29 +08:00
assert . Nil ( t , err )
2021-05-17 19:15:01 +08:00
assert . Equal ( t , partIDDefault , collMeta . PartitionIDs [ 0 ] )
assert . Equal ( t , 1 , len ( collMeta . PartitionIDs ) )
2021-05-18 14:18:02 +08:00
assert . True ( t , mt . HasCollection ( collInfo . ID , 0 ) )
2021-04-08 17:31:39 +08:00
field , err := mt . GetFieldSchema ( "testColl" , "field110" )
assert . Nil ( t , err )
2021-05-17 19:15:01 +08:00
assert . Equal ( t , collInfo . Schema . Fields [ 0 ] . FieldID , field . FieldID )
2021-05-14 21:26:06 +08:00
// check DD operation flag
2021-05-18 14:18:02 +08:00
flag , err := mt . client . Load ( DDMsgSendPrefix , 0 )
2021-05-14 21:26:06 +08:00
assert . Nil ( t , err )
assert . Equal ( t , "false" , flag )
} )
t . Run ( "add partition" , func ( t * testing . T ) {
2021-05-20 14:14:14 +08:00
_ , err := mt . AddPartition ( collID , partInfo . PartitionName , partInfo . PartitionID , ddOp )
2021-05-18 14:18:02 +08:00
assert . Nil ( t , err )
2021-05-14 21:26:06 +08:00
// check DD operation flag
2021-05-18 14:18:02 +08:00
flag , err := mt . client . Load ( DDMsgSendPrefix , 0 )
2021-05-14 21:26:06 +08:00
assert . Nil ( t , err )
assert . Equal ( t , "false" , flag )
2021-01-21 10:01:29 +08:00
} )
t . Run ( "add segment" , func ( t * testing . T ) {
2021-05-24 14:19:52 +08:00
segInfo := & datapb . SegmentInfo {
2021-05-14 21:26:06 +08:00
ID : segID ,
CollectionID : collID ,
PartitionID : partID ,
2021-01-21 10:01:29 +08:00
}
2021-05-24 14:19:52 +08:00
_ , err := mt . AddSegment ( [ ] * datapb . SegmentInfo { segInfo } , "" , "" )
2021-05-18 14:18:02 +08:00
assert . Nil ( t , err )
2021-05-24 14:19:52 +08:00
_ , err = mt . AddSegment ( [ ] * datapb . SegmentInfo { segInfo } , "" , "" )
2021-05-18 14:18:02 +08:00
assert . NotNil ( t , err )
2021-05-24 14:19:52 +08:00
segInfo . ID = segID2
segInfo . CollectionID = collIDInvalid
_ , err = mt . AddSegment ( [ ] * datapb . SegmentInfo { segInfo } , "" , "" )
2021-05-18 14:18:02 +08:00
assert . NotNil ( t , err )
2021-05-24 14:19:52 +08:00
segInfo . CollectionID = collID
segInfo . PartitionID = partIDInvalid
_ , err = mt . AddSegment ( [ ] * datapb . SegmentInfo { segInfo } , "" , "" )
2021-05-18 14:18:02 +08:00
assert . NotNil ( t , err )
2021-05-24 14:19:52 +08:00
segInfo . PartitionID = partID
_ , err = mt . AddSegment ( [ ] * datapb . SegmentInfo { segInfo } , "" , "" )
2021-05-18 14:18:02 +08:00
assert . Nil ( t , err )
2021-01-21 10:01:29 +08:00
} )
t . Run ( "add segment index" , func ( t * testing . T ) {
2021-05-15 18:08:08 +08:00
segIdxInfo := pb . SegmentIndexInfo {
2021-05-14 21:26:06 +08:00
SegmentID : segID ,
FieldID : fieldID ,
2021-05-17 19:15:01 +08:00
IndexID : indexID ,
BuildID : buildID ,
2021-01-21 10:01:29 +08:00
}
2021-05-24 14:19:52 +08:00
_ , err := mt . AddIndex ( [ ] * pb . SegmentIndexInfo { & segIdxInfo } , "" , "" )
2021-01-21 10:01:29 +08:00
assert . Nil ( t , err )
2021-05-15 18:08:08 +08:00
// it's legal to add index twice
2021-05-24 14:19:52 +08:00
_ , err = mt . AddIndex ( [ ] * pb . SegmentIndexInfo { & segIdxInfo } , "" , "" )
2021-05-15 18:08:08 +08:00
assert . Nil ( t , err )
segIdxInfo . BuildID = 202
2021-05-24 14:19:52 +08:00
_ , err = mt . AddIndex ( [ ] * pb . SegmentIndexInfo { & segIdxInfo } , "" , "" )
2021-05-15 18:08:08 +08:00
assert . NotNil ( t , err )
assert . EqualError ( t , err , fmt . Sprintf ( "index id = %d exist" , segIdxInfo . IndexID ) )
2021-01-21 10:01:29 +08:00
} )
t . Run ( "get not indexed segments" , func ( t * testing . T ) {
params := [ ] * commonpb . KeyValuePair {
{
Key : "field110-i1" ,
Value : "field110-v1" ,
} ,
{
Key : "field110-i2" ,
Value : "field110-v2" ,
} ,
}
tparams := [ ] * commonpb . KeyValuePair {
{
Key : "field110-k1" ,
Value : "field110-v1" ,
} ,
{
Key : "field110-k2" ,
Value : "field110-v2" ,
} ,
}
2021-02-09 13:11:55 +08:00
idxInfo := & pb . IndexInfo {
IndexName : "field110" ,
IndexID : 2000 ,
IndexParams : params ,
}
2021-01-21 10:01:29 +08:00
2021-03-06 17:47:11 +08:00
_ , _ , err := mt . GetNotIndexedSegments ( "collTest" , "field110" , idxInfo )
2021-01-21 10:01:29 +08:00
assert . NotNil ( t , err )
2021-02-09 13:11:55 +08:00
seg , field , err := mt . GetNotIndexedSegments ( "testColl" , "field110" , idxInfo )
2021-01-21 10:01:29 +08:00
assert . Nil ( t , err )
2021-05-17 19:15:01 +08:00
assert . Equal ( t , 1 , len ( seg ) )
assert . Equal ( t , segID2 , seg [ 0 ] )
2021-01-21 10:01:29 +08:00
assert . True ( t , EqualKeyPairArray ( field . TypeParams , tparams ) )
params = [ ] * commonpb . KeyValuePair {
{
Key : "field110-i1" ,
Value : "field110-v1" ,
} ,
}
2021-02-09 13:11:55 +08:00
idxInfo . IndexParams = params
2021-02-11 08:41:59 +08:00
idxInfo . IndexID = 2001
idxInfo . IndexName = "field110-1"
2021-01-21 10:01:29 +08:00
2021-02-09 13:11:55 +08:00
seg , field , err = mt . GetNotIndexedSegments ( "testColl" , "field110" , idxInfo )
2021-01-21 10:01:29 +08:00
assert . Nil ( t , err )
2021-05-17 19:15:01 +08:00
assert . Equal ( t , 2 , len ( seg ) )
assert . Equal ( t , segID , seg [ 0 ] )
assert . Equal ( t , segID2 , seg [ 1 ] )
2021-01-21 10:01:29 +08:00
assert . True ( t , EqualKeyPairArray ( field . TypeParams , tparams ) )
} )
t . Run ( "get index by name" , func ( t * testing . T ) {
2021-04-27 10:30:55 +08:00
_ , idx , err := mt . GetIndexByName ( "testColl" , "field110" )
2021-01-21 10:01:29 +08:00
assert . Nil ( t , err )
2021-05-17 19:15:01 +08:00
assert . Equal ( t , 1 , len ( idx ) )
assert . Equal ( t , indexID , idx [ 0 ] . IndexID )
2021-01-21 10:01:29 +08:00
params := [ ] * commonpb . KeyValuePair {
{
Key : "field110-i1" ,
Value : "field110-v1" ,
} ,
{
Key : "field110-i2" ,
Value : "field110-v2" ,
} ,
}
assert . True ( t , EqualKeyPairArray ( idx [ 0 ] . IndexParams , params ) )
2021-04-27 10:30:55 +08:00
_ , idx , err = mt . GetIndexByName ( "testColl" , "idx201" )
2021-01-21 10:01:29 +08:00
assert . Nil ( t , err )
assert . Zero ( t , len ( idx ) )
} )
2021-04-08 17:31:39 +08:00
t . Run ( "reload meta" , func ( t * testing . T ) {
te := pb . TenantMeta {
ID : 100 ,
}
2021-05-18 14:18:02 +08:00
_ , err := mt . AddTenant ( & te )
2021-04-08 17:31:39 +08:00
assert . Nil ( t , err )
po := pb . ProxyMeta {
ID : 101 ,
}
2021-05-18 14:18:02 +08:00
_ , err = mt . AddProxy ( & po )
2021-04-08 17:31:39 +08:00
assert . Nil ( t , err )
2021-05-18 14:18:02 +08:00
_ , err = NewMetaTable ( skv )
2021-04-08 17:31:39 +08:00
assert . Nil ( t , err )
} )
2021-02-20 15:38:44 +08:00
t . Run ( "drop index" , func ( t * testing . T ) {
2021-05-18 14:18:02 +08:00
_ , idx , ok , err := mt . DropIndex ( "testColl" , "field110" , "field110" )
2021-02-20 15:38:44 +08:00
assert . Nil ( t , err )
assert . True ( t , ok )
2021-05-17 19:15:01 +08:00
assert . Equal ( t , indexID , idx )
2021-02-20 15:38:44 +08:00
2021-05-18 14:18:02 +08:00
_ , _ , ok , err = mt . DropIndex ( "testColl" , "field110" , "field110-error" )
2021-02-20 15:38:44 +08:00
assert . Nil ( t , err )
assert . False ( t , ok )
2021-04-27 10:30:55 +08:00
_ , idxs , err := mt . GetIndexByName ( "testColl" , "field110" )
2021-02-20 15:38:44 +08:00
assert . Nil ( t , err )
assert . Zero ( t , len ( idxs ) )
2021-04-27 10:30:55 +08:00
_ , idxs , err = mt . GetIndexByName ( "testColl" , "field110-1" )
2021-02-20 15:38:44 +08:00
assert . Nil ( t , err )
assert . Equal ( t , len ( idxs ) , 1 )
assert . Equal ( t , idxs [ 0 ] . IndexID , int64 ( 2001 ) )
2021-05-14 21:26:06 +08:00
_ , err = mt . GetSegmentIndexInfoByID ( segID , - 1 , "" )
2021-02-20 15:38:44 +08:00
assert . NotNil ( t , err )
2021-05-14 21:26:06 +08:00
} )
2021-02-20 15:38:44 +08:00
2021-05-14 21:26:06 +08:00
t . Run ( "drop partition" , func ( t * testing . T ) {
2021-05-20 14:14:14 +08:00
_ , id , err := mt . DeletePartition ( collID , partInfo . PartitionName , nil )
2021-05-14 21:26:06 +08:00
assert . Nil ( t , err )
assert . Equal ( t , partID , id )
// check DD operation flag
2021-05-18 14:18:02 +08:00
flag , err := mt . client . Load ( DDMsgSendPrefix , 0 )
2021-05-14 21:26:06 +08:00
assert . Nil ( t , err )
assert . Equal ( t , "false" , flag )
2021-02-20 15:38:44 +08:00
} )
2021-04-08 17:31:39 +08:00
t . Run ( "drop collection" , func ( t * testing . T ) {
2021-05-20 14:14:14 +08:00
_ , err = mt . DeleteCollection ( collIDInvalid , nil )
2021-04-08 17:31:39 +08:00
assert . NotNil ( t , err )
2021-05-20 14:14:14 +08:00
_ , err = mt . DeleteCollection ( collID , nil )
2021-05-14 21:26:06 +08:00
assert . Nil ( t , err )
// check DD operation flag
2021-05-18 14:18:02 +08:00
flag , err := mt . client . Load ( DDMsgSendPrefix , 0 )
2021-04-08 17:31:39 +08:00
assert . Nil ( t , err )
2021-05-14 21:26:06 +08:00
assert . Equal ( t , "false" , flag )
2021-04-08 17:31:39 +08:00
} )
2021-04-09 16:10:12 +08:00
/////////////////////////// these tests should run at last, it only used to hit the error lines ////////////////////////
mockKV := & mockTestKV { }
mt . client = mockKV
t . Run ( "add collection failed" , func ( t * testing . T ) {
2021-05-18 14:18:02 +08:00
mockKV . loadWithPrefix = func ( key string , ts typeutil . Timestamp ) ( [ ] string , [ ] string , error ) {
2021-04-09 16:10:12 +08:00
return nil , nil , nil
}
2021-05-20 14:14:14 +08:00
mockKV . multiSave = func ( kvs map [ string ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error ) {
2021-05-18 14:18:02 +08:00
return 0 , fmt . Errorf ( "multi save error" )
2021-04-09 16:10:12 +08:00
}
collInfo . PartitionIDs = nil
2021-05-20 14:14:14 +08:00
_ , err := mt . AddCollection ( collInfo , partInfo , idxInfo , nil )
2021-04-09 16:10:12 +08:00
assert . NotNil ( t , err )
2021-04-10 10:53:58 +08:00
assert . EqualError ( t , err , "multi save error" )
2021-04-09 16:10:12 +08:00
} )
t . Run ( "delete collection failed" , func ( t * testing . T ) {
2021-05-20 14:14:14 +08:00
mockKV . multiSave = func ( kvs map [ string ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error ) {
2021-05-18 14:18:02 +08:00
return 0 , nil
2021-04-09 16:10:12 +08:00
}
2021-05-20 14:14:14 +08:00
mockKV . multiSaveAndRemoveWithPrefix = func ( save map [ string ] string , keys [ ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error ) {
2021-05-18 14:18:02 +08:00
return 0 , fmt . Errorf ( "milti save and remove with prefix error" )
2021-04-09 16:10:12 +08:00
}
collInfo . PartitionIDs = nil
2021-05-20 14:14:14 +08:00
_ , err := mt . AddCollection ( collInfo , partInfo , idxInfo , nil )
2021-04-09 16:10:12 +08:00
assert . Nil ( t , err )
mt . partitionID2Meta = make ( map [ typeutil . UniqueID ] pb . PartitionInfo )
mt . indexID2Meta = make ( map [ int64 ] pb . IndexInfo )
2021-05-20 14:14:14 +08:00
_ , err = mt . DeleteCollection ( collInfo . ID , nil )
2021-04-09 16:10:12 +08:00
assert . NotNil ( t , err )
2021-05-12 15:33:53 +08:00
assert . EqualError ( t , err , "milti save and remove with prefix error" )
2021-04-09 16:10:12 +08:00
} )
t . Run ( "get collection failed" , func ( t * testing . T ) {
2021-05-18 14:18:02 +08:00
mockKV . save = func ( key , value string ) ( typeutil . Timestamp , error ) {
return 0 , nil
2021-04-09 16:10:12 +08:00
}
collInfo . PartitionIDs = nil
2021-05-20 14:14:14 +08:00
_ , err := mt . AddCollection ( collInfo , partInfo , idxInfo , nil )
2021-04-09 16:10:12 +08:00
assert . Nil ( t , err )
2021-05-24 14:19:52 +08:00
segInfo := & datapb . SegmentInfo {
2021-04-09 16:10:12 +08:00
ID : 100 ,
2021-05-14 21:26:06 +08:00
CollectionID : collID ,
PartitionID : partID ,
2021-04-09 16:10:12 +08:00
}
2021-05-24 14:19:52 +08:00
_ , err = mt . AddSegment ( [ ] * datapb . SegmentInfo { segInfo } , "" , "" )
2021-05-18 14:18:02 +08:00
assert . Nil ( t , err )
2021-04-09 16:10:12 +08:00
mt . collID2Meta = make ( map [ int64 ] pb . CollectionInfo )
2021-05-18 14:18:02 +08:00
_ , err = mt . GetCollectionByName ( collInfo . Schema . Name , 0 )
2021-04-09 16:10:12 +08:00
assert . NotNil ( t , err )
2021-04-10 10:53:58 +08:00
assert . EqualError ( t , err , fmt . Sprintf ( "can't find collection: %s" , collInfo . Schema . Name ) )
2021-05-24 14:19:52 +08:00
_ , err = mt . GetCollectionBySegmentID ( segInfo . ID )
2021-04-09 16:10:12 +08:00
assert . NotNil ( t , err )
2021-04-10 10:53:58 +08:00
assert . EqualError ( t , err , fmt . Sprintf ( "can't find collection id: %d" , collInfo . ID ) )
2021-04-09 16:10:12 +08:00
mt . segID2CollID = make ( map [ int64 ] int64 )
2021-05-24 14:19:52 +08:00
_ , err = mt . GetCollectionBySegmentID ( segInfo . ID )
2021-04-09 16:10:12 +08:00
assert . NotNil ( t , err )
2021-05-24 14:19:52 +08:00
assert . EqualError ( t , err , fmt . Sprintf ( "segment id %d not belong to any collection" , segInfo . ID ) )
2021-04-10 10:53:58 +08:00
} )
t . Run ( "add partition failed" , func ( t * testing . T ) {
2021-05-18 14:18:02 +08:00
mockKV . save = func ( key , value string ) ( typeutil . Timestamp , error ) {
return 0 , nil
2021-04-10 10:53:58 +08:00
}
2021-05-18 14:18:02 +08:00
mockKV . loadWithPrefix = func ( key string , ts typeutil . Timestamp ) ( [ ] string , [ ] string , error ) {
2021-04-10 10:53:58 +08:00
return nil , nil , nil
}
err := mt . reloadFromKV ( )
assert . Nil ( t , err )
collInfo . PartitionIDs = nil
2021-05-20 14:14:14 +08:00
_ , err = mt . AddCollection ( collInfo , partInfo , idxInfo , nil )
2021-04-10 10:53:58 +08:00
assert . Nil ( t , err )
2021-05-20 14:14:14 +08:00
_ , err = mt . AddPartition ( 2 , "no-part" , 22 , nil )
2021-04-10 10:53:58 +08:00
assert . NotNil ( t , err )
assert . EqualError ( t , err , "can't find collection. id = 2" )
coll := mt . collID2Meta [ collInfo . ID ]
coll . PartitionIDs = make ( [ ] int64 , Params . MaxPartitionNum )
mt . collID2Meta [ coll . ID ] = coll
2021-05-20 14:14:14 +08:00
_ , err = mt . AddPartition ( coll . ID , "no-part" , 22 , nil )
2021-04-10 10:53:58 +08:00
assert . NotNil ( t , err )
assert . EqualError ( t , err , fmt . Sprintf ( "maximum partition's number should be limit to %d" , Params . MaxPartitionNum ) )
coll . PartitionIDs = [ ] int64 { partInfo . PartitionID }
mt . collID2Meta [ coll . ID ] = coll
mt . partitionID2Meta = make ( map [ int64 ] pb . PartitionInfo )
2021-05-20 14:14:14 +08:00
mockKV . multiSave = func ( kvs map [ string ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error ) {
2021-05-18 14:18:02 +08:00
return 0 , fmt . Errorf ( "multi save error" )
2021-04-10 10:53:58 +08:00
}
2021-05-20 14:14:14 +08:00
_ , err = mt . AddPartition ( coll . ID , "no-part" , 22 , nil )
2021-04-10 10:53:58 +08:00
assert . NotNil ( t , err )
assert . EqualError ( t , err , "multi save error" )
2021-05-20 14:14:14 +08:00
mockKV . multiSave = func ( kvs map [ string ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error ) {
2021-05-18 14:18:02 +08:00
return 0 , nil
2021-04-10 10:53:58 +08:00
}
collInfo . PartitionIDs = nil
2021-05-20 14:14:14 +08:00
_ , err = mt . AddCollection ( collInfo , partInfo , idxInfo , nil )
2021-04-10 10:53:58 +08:00
assert . Nil ( t , err )
2021-05-20 14:14:14 +08:00
_ , err = mt . AddPartition ( coll . ID , partInfo . PartitionName , 22 , nil )
2021-04-10 10:53:58 +08:00
assert . NotNil ( t , err )
assert . EqualError ( t , err , fmt . Sprintf ( "partition name = %s already exists" , partInfo . PartitionName ) )
2021-05-20 14:14:14 +08:00
_ , err = mt . AddPartition ( coll . ID , "no-part" , partInfo . PartitionID , nil )
2021-04-10 10:53:58 +08:00
assert . NotNil ( t , err )
assert . EqualError ( t , err , fmt . Sprintf ( "partition id = %d already exists" , partInfo . PartitionID ) )
2021-04-09 16:10:12 +08:00
} )
2021-04-12 15:03:23 +08:00
t . Run ( "has partition failed" , func ( t * testing . T ) {
2021-05-18 14:18:02 +08:00
mockKV . loadWithPrefix = func ( key string , ts typeutil . Timestamp ) ( [ ] string , [ ] string , error ) {
2021-04-12 15:03:23 +08:00
return nil , nil , nil
}
2021-05-20 14:14:14 +08:00
mockKV . multiSave = func ( kvs map [ string ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error ) {
2021-05-18 14:18:02 +08:00
return 0 , nil
2021-04-12 15:03:23 +08:00
}
err := mt . reloadFromKV ( )
assert . Nil ( t , err )
collInfo . PartitionIDs = nil
2021-05-20 14:14:14 +08:00
_ , err = mt . AddCollection ( collInfo , partInfo , idxInfo , nil )
2021-04-12 15:03:23 +08:00
assert . Nil ( t , err )
mt . partitionID2Meta = make ( map [ int64 ] pb . PartitionInfo )
2021-05-18 14:18:02 +08:00
assert . False ( t , mt . HasPartition ( collInfo . ID , partInfo . PartitionName , 0 ) )
2021-04-12 15:03:23 +08:00
mt . collID2Meta = make ( map [ int64 ] pb . CollectionInfo )
2021-05-18 14:18:02 +08:00
assert . False ( t , mt . HasPartition ( collInfo . ID , partInfo . PartitionName , 0 ) )
2021-04-12 15:03:23 +08:00
} )
t . Run ( "delete partition failed" , func ( t * testing . T ) {
2021-05-18 14:18:02 +08:00
mockKV . loadWithPrefix = func ( key string , ts typeutil . Timestamp ) ( [ ] string , [ ] string , error ) {
2021-04-12 15:03:23 +08:00
return nil , nil , nil
}
2021-05-20 14:14:14 +08:00
mockKV . multiSave = func ( kvs map [ string ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error ) {
2021-05-18 14:18:02 +08:00
return 0 , nil
2021-04-12 15:03:23 +08:00
}
err := mt . reloadFromKV ( )
assert . Nil ( t , err )
collInfo . PartitionIDs = nil
2021-05-20 14:14:14 +08:00
_ , err = mt . AddCollection ( collInfo , partInfo , idxInfo , nil )
2021-04-12 15:03:23 +08:00
assert . Nil ( t , err )
2021-05-20 14:14:14 +08:00
_ , _ , err = mt . DeletePartition ( collInfo . ID , Params . DefaultPartitionName , nil )
2021-04-12 15:03:23 +08:00
assert . NotNil ( t , err )
assert . EqualError ( t , err , "default partition cannot be deleted" )
2021-05-20 14:14:14 +08:00
_ , _ , err = mt . DeletePartition ( collInfo . ID , "abc" , nil )
2021-04-12 15:03:23 +08:00
assert . NotNil ( t , err )
assert . EqualError ( t , err , "partition abc does not exist" )
pm := mt . partitionID2Meta [ partInfo . PartitionID ]
pm . SegmentIDs = [ ] int64 { 11 , 12 , 13 }
mt . partitionID2Meta [ pm . PartitionID ] = pm
2021-05-20 14:14:14 +08:00
mockKV . multiSaveAndRemoveWithPrefix = func ( saves map [ string ] string , removals [ ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error ) {
2021-05-18 14:18:02 +08:00
return 0 , fmt . Errorf ( "multi save and remove with prefix error" )
2021-04-12 15:03:23 +08:00
}
2021-05-20 14:14:14 +08:00
_ , _ , err = mt . DeletePartition ( collInfo . ID , pm . PartitionName , nil )
2021-04-12 15:03:23 +08:00
assert . NotNil ( t , err )
assert . EqualError ( t , err , "multi save and remove with prefix error" )
mt . collID2Meta = make ( map [ int64 ] pb . CollectionInfo )
2021-05-20 14:14:14 +08:00
_ , _ , err = mt . DeletePartition ( collInfo . ID , "abc" , nil )
2021-04-12 15:03:23 +08:00
assert . NotNil ( t , err )
assert . EqualError ( t , err , fmt . Sprintf ( "can't find collection id = %d" , collInfo . ID ) )
2021-05-18 14:18:02 +08:00
_ , err = mt . GetPartitionByID ( 1 , 11 , 0 )
2021-04-12 15:03:23 +08:00
assert . NotNil ( t , err )
assert . EqualError ( t , err , "partition id = 11 not exist" )
} )
t . Run ( "add segment failed" , func ( t * testing . T ) {
2021-05-18 14:18:02 +08:00
mockKV . loadWithPrefix = func ( key string , ts typeutil . Timestamp ) ( [ ] string , [ ] string , error ) {
2021-04-12 15:03:23 +08:00
return nil , nil , nil
}
2021-05-20 14:14:14 +08:00
mockKV . multiSave = func ( kvs map [ string ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error ) {
2021-05-18 14:18:02 +08:00
return 0 , nil
2021-04-12 15:03:23 +08:00
}
err := mt . reloadFromKV ( )
assert . Nil ( t , err )
collInfo . PartitionIDs = nil
2021-05-20 14:14:14 +08:00
_ , err = mt . AddCollection ( collInfo , partInfo , idxInfo , nil )
2021-04-12 15:03:23 +08:00
assert . Nil ( t , err )
noPart := pb . PartitionInfo {
PartitionName : "no-part" ,
PartitionID : partInfo . PartitionID + 1 ,
SegmentIDs : nil ,
}
mt . partitionID2Meta [ noPart . PartitionID ] = noPart
2021-05-24 14:19:52 +08:00
segInfo := & datapb . SegmentInfo {
2021-04-12 15:03:23 +08:00
ID : 100 ,
CollectionID : collInfo . ID ,
PartitionID : noPart . PartitionID ,
}
2021-05-24 14:19:52 +08:00
_ , err = mt . AddSegment ( [ ] * datapb . SegmentInfo { segInfo } , "" , "" )
2021-04-12 15:03:23 +08:00
assert . NotNil ( t , err )
2021-05-24 14:19:52 +08:00
assert . EqualError ( t , err , fmt . Sprintf ( "partition id = %d, not belong to collection id = %d" , segInfo . PartitionID , segInfo . CollectionID ) )
2021-04-12 15:03:23 +08:00
2021-05-24 14:19:52 +08:00
segInfo = & datapb . SegmentInfo {
2021-04-12 15:03:23 +08:00
ID : 11 ,
CollectionID : collInfo . ID ,
PartitionID : partInfo . PartitionID ,
}
2021-05-24 14:19:52 +08:00
mockKV . multiSave = func ( kvs map [ string ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error ) {
2021-05-18 14:18:02 +08:00
return 0 , fmt . Errorf ( "save error" )
2021-04-12 15:03:23 +08:00
}
2021-05-24 14:19:52 +08:00
_ , err = mt . AddSegment ( [ ] * datapb . SegmentInfo { segInfo } , "" , "" )
2021-04-12 15:03:23 +08:00
assert . NotNil ( t , err )
assert . EqualError ( t , err , "save error" )
} )
t . Run ( "add index failed" , func ( t * testing . T ) {
2021-05-18 14:18:02 +08:00
mockKV . loadWithPrefix = func ( key string , ts typeutil . Timestamp ) ( [ ] string , [ ] string , error ) {
2021-04-12 15:03:23 +08:00
return nil , nil , nil
}
2021-05-20 14:14:14 +08:00
mockKV . multiSave = func ( kvs map [ string ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error ) {
2021-05-18 14:18:02 +08:00
return 0 , nil
2021-04-12 15:03:23 +08:00
}
2021-05-18 14:18:02 +08:00
mockKV . save = func ( key , value string ) ( typeutil . Timestamp , error ) {
return 0 , nil
2021-04-12 15:03:23 +08:00
}
err := mt . reloadFromKV ( )
assert . Nil ( t , err )
collInfo . PartitionIDs = nil
2021-05-20 14:14:14 +08:00
_ , err = mt . AddCollection ( collInfo , partInfo , idxInfo , nil )
2021-04-12 15:03:23 +08:00
assert . Nil ( t , err )
2021-05-24 14:19:52 +08:00
segInfo := & datapb . SegmentInfo {
2021-04-12 15:03:23 +08:00
ID : 100 ,
2021-05-14 21:26:06 +08:00
CollectionID : collID ,
PartitionID : partID ,
2021-04-12 15:03:23 +08:00
}
2021-05-24 14:19:52 +08:00
_ , err = mt . AddSegment ( [ ] * datapb . SegmentInfo { segInfo } , "" , "" )
2021-05-18 14:18:02 +08:00
assert . Nil ( t , err )
2021-04-12 15:03:23 +08:00
2021-05-24 14:19:52 +08:00
segIdxInfo := pb . SegmentIndexInfo {
2021-05-17 19:15:01 +08:00
SegmentID : segID ,
FieldID : fieldID ,
IndexID : indexID2 ,
BuildID : buildID ,
2021-04-12 15:03:23 +08:00
}
2021-05-24 14:19:52 +08:00
_ , err = mt . AddIndex ( [ ] * pb . SegmentIndexInfo { & segIdxInfo } , "" , "" )
2021-04-12 15:03:23 +08:00
assert . NotNil ( t , err )
2021-05-15 18:08:08 +08:00
assert . EqualError ( t , err , fmt . Sprintf ( "index id = %d not found" , segIdxInfo . IndexID ) )
2021-04-12 15:03:23 +08:00
mt . segID2PartitionID = make ( map [ int64 ] int64 )
2021-05-24 14:19:52 +08:00
_ , err = mt . AddIndex ( [ ] * pb . SegmentIndexInfo { & segIdxInfo } , "" , "" )
2021-04-12 15:03:23 +08:00
assert . NotNil ( t , err )
2021-05-15 18:08:08 +08:00
assert . EqualError ( t , err , fmt . Sprintf ( "segment id = %d not belong to any partition" , segIdxInfo . SegmentID ) )
2021-04-12 15:03:23 +08:00
mt . collID2Meta = make ( map [ int64 ] pb . CollectionInfo )
2021-05-24 14:19:52 +08:00
_ , err = mt . AddIndex ( [ ] * pb . SegmentIndexInfo { & segIdxInfo } , "" , "" )
2021-04-12 15:03:23 +08:00
assert . NotNil ( t , err )
assert . EqualError ( t , err , fmt . Sprintf ( "collection id = %d not found" , collInfo . ID ) )
mt . segID2CollID = make ( map [ int64 ] int64 )
2021-05-24 14:19:52 +08:00
_ , err = mt . AddIndex ( [ ] * pb . SegmentIndexInfo { & segIdxInfo } , "" , "" )
2021-04-12 15:03:23 +08:00
assert . NotNil ( t , err )
2021-05-15 18:08:08 +08:00
assert . EqualError ( t , err , fmt . Sprintf ( "segment id = %d not belong to any collection" , segIdxInfo . SegmentID ) )
2021-04-12 15:03:23 +08:00
err = mt . reloadFromKV ( )
assert . Nil ( t , err )
collInfo . PartitionIDs = nil
2021-05-20 14:14:14 +08:00
_ , err = mt . AddCollection ( collInfo , partInfo , idxInfo , nil )
2021-05-18 14:18:02 +08:00
assert . Nil ( t , err )
2021-05-24 14:19:52 +08:00
_ , err = mt . AddSegment ( [ ] * datapb . SegmentInfo { segInfo } , "" , "" )
2021-04-12 15:03:23 +08:00
assert . Nil ( t , err )
2021-05-17 19:15:01 +08:00
segIdxInfo . IndexID = indexID
2021-05-24 14:19:52 +08:00
mockKV . multiSave = func ( kvs map [ string ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error ) {
2021-05-18 14:18:02 +08:00
return 0 , fmt . Errorf ( "save error" )
2021-04-12 15:03:23 +08:00
}
2021-05-24 14:19:52 +08:00
_ , err = mt . AddIndex ( [ ] * pb . SegmentIndexInfo { & segIdxInfo } , "" , "" )
2021-04-12 15:03:23 +08:00
assert . NotNil ( t , err )
assert . EqualError ( t , err , "save error" )
} )
t . Run ( "drop index failed" , func ( t * testing . T ) {
2021-05-18 14:18:02 +08:00
mockKV . loadWithPrefix = func ( key string , ts typeutil . Timestamp ) ( [ ] string , [ ] string , error ) {
2021-04-12 15:03:23 +08:00
return nil , nil , nil
}
2021-05-20 14:14:14 +08:00
mockKV . multiSave = func ( kvs map [ string ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error ) {
2021-05-18 14:18:02 +08:00
return 0 , nil
2021-04-12 15:03:23 +08:00
}
2021-05-18 14:18:02 +08:00
mockKV . save = func ( key , value string ) ( typeutil . Timestamp , error ) {
return 0 , nil
2021-04-12 15:03:23 +08:00
}
err := mt . reloadFromKV ( )
assert . Nil ( t , err )
collInfo . PartitionIDs = nil
2021-05-20 14:14:14 +08:00
_ , err = mt . AddCollection ( collInfo , partInfo , idxInfo , nil )
2021-04-12 15:03:23 +08:00
assert . Nil ( t , err )
2021-05-18 14:18:02 +08:00
_ , _ , _ , err = mt . DropIndex ( "abc" , "abc" , "abc" )
2021-04-12 15:03:23 +08:00
assert . NotNil ( t , err )
assert . EqualError ( t , err , "collection name = abc not exist" )
mt . collName2ID [ "abc" ] = 2
2021-05-18 14:18:02 +08:00
_ , _ , _ , err = mt . DropIndex ( "abc" , "abc" , "abc" )
2021-04-12 15:03:23 +08:00
assert . NotNil ( t , err )
assert . EqualError ( t , err , "collection name = abc not has meta" )
2021-05-18 14:18:02 +08:00
_ , _ , _ , err = mt . DropIndex ( collInfo . Schema . Name , "abc" , "abc" )
2021-04-12 15:03:23 +08:00
assert . NotNil ( t , err )
assert . EqualError ( t , err , fmt . Sprintf ( "collection %s doesn't have filed abc" , collInfo . Schema . Name ) )
coll := mt . collID2Meta [ collInfo . ID ]
coll . FieldIndexes = [ ] * pb . FieldIndexInfo {
{
2021-05-17 19:15:01 +08:00
FiledID : fieldID2 ,
IndexID : indexID2 ,
2021-04-12 15:03:23 +08:00
} ,
{
2021-05-17 19:15:01 +08:00
FiledID : fieldID ,
IndexID : indexID ,
2021-04-12 15:03:23 +08:00
} ,
}
mt . collID2Meta [ coll . ID ] = coll
mt . indexID2Meta = make ( map [ int64 ] pb . IndexInfo )
2021-05-18 14:18:02 +08:00
_ , idxID , isDroped , err := mt . DropIndex ( collInfo . Schema . Name , collInfo . Schema . Fields [ 0 ] . Name , idxInfo [ 0 ] . IndexName )
2021-04-12 15:03:23 +08:00
assert . Zero ( t , idxID )
assert . False ( t , isDroped )
assert . Nil ( t , err )
err = mt . reloadFromKV ( )
assert . Nil ( t , err )
collInfo . PartitionIDs = nil
2021-05-20 14:14:14 +08:00
_ , err = mt . AddCollection ( collInfo , partInfo , idxInfo , nil )
2021-04-12 15:03:23 +08:00
assert . Nil ( t , err )
mt . partitionID2Meta = make ( map [ int64 ] pb . PartitionInfo )
2021-05-20 14:14:14 +08:00
mockKV . multiSaveAndRemoveWithPrefix = func ( saves map [ string ] string , removals [ ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error ) {
2021-05-18 14:18:02 +08:00
return 0 , fmt . Errorf ( "multi save and remove with prefix error" )
2021-04-12 15:03:23 +08:00
}
2021-05-18 14:18:02 +08:00
_ , _ , _ , err = mt . DropIndex ( collInfo . Schema . Name , collInfo . Schema . Fields [ 0 ] . Name , idxInfo [ 0 ] . IndexName )
2021-04-12 15:03:23 +08:00
assert . NotNil ( t , err )
assert . EqualError ( t , err , "multi save and remove with prefix error" )
} )
t . Run ( "get segment index info by id" , func ( t * testing . T ) {
2021-05-18 14:18:02 +08:00
mockKV . loadWithPrefix = func ( key string , ts typeutil . Timestamp ) ( [ ] string , [ ] string , error ) {
2021-04-12 15:03:23 +08:00
return nil , nil , nil
}
2021-05-20 14:14:14 +08:00
mockKV . multiSave = func ( kvs map [ string ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error ) {
2021-05-18 14:18:02 +08:00
return 0 , nil
2021-04-12 15:03:23 +08:00
}
2021-05-18 14:18:02 +08:00
mockKV . save = func ( key , value string ) ( typeutil . Timestamp , error ) {
return 0 , nil
2021-04-12 15:03:23 +08:00
}
err := mt . reloadFromKV ( )
assert . Nil ( t , err )
collInfo . PartitionIDs = nil
2021-05-20 14:14:14 +08:00
_ , err = mt . AddCollection ( collInfo , partInfo , idxInfo , nil )
2021-04-12 15:03:23 +08:00
assert . Nil ( t , err )
2021-05-17 19:15:01 +08:00
_ , err = mt . GetSegmentIndexInfoByID ( segID2 , fieldID , "abc" )
2021-04-12 15:03:23 +08:00
assert . NotNil ( t , err )
2021-05-17 19:15:01 +08:00
assert . EqualError ( t , err , "segment id 101 hasn't flushed, there is no index meta" )
2021-04-12 15:03:23 +08:00
2021-05-17 19:15:01 +08:00
err = mt . AddFlushedSegment ( segID2 )
2021-04-12 15:03:23 +08:00
assert . Nil ( t , err )
2021-05-17 19:15:01 +08:00
seg , err := mt . GetSegmentIndexInfoByID ( segID2 , fieldID , "abc" )
2021-04-12 15:03:23 +08:00
assert . Nil ( t , err )
2021-05-17 19:15:01 +08:00
assert . Equal ( t , segID2 , seg . SegmentID )
assert . Equal ( t , fieldID , seg . FieldID )
assert . Equal ( t , false , seg . EnableIndex )
2021-04-12 15:03:23 +08:00
segInfo := & datapb . SegmentInfo {
ID : 100 ,
2021-05-14 21:26:06 +08:00
CollectionID : collID ,
PartitionID : partID ,
2021-04-12 15:03:23 +08:00
}
2021-05-24 14:19:52 +08:00
_ , err = mt . AddSegment ( [ ] * datapb . SegmentInfo { segInfo } , "" , "" )
2021-05-18 14:18:02 +08:00
assert . Nil ( t , err )
2021-05-24 14:19:52 +08:00
segIdxInfo := pb . SegmentIndexInfo {
2021-05-17 19:15:01 +08:00
SegmentID : segID ,
FieldID : fieldID ,
IndexID : indexID ,
BuildID : buildID ,
2021-04-12 15:03:23 +08:00
}
2021-05-24 14:19:52 +08:00
_ , err = mt . AddIndex ( [ ] * pb . SegmentIndexInfo { & segIdxInfo } , "" , "" )
2021-05-18 14:18:02 +08:00
assert . Nil ( t , err )
2021-05-24 14:19:52 +08:00
idx , err := mt . GetSegmentIndexInfoByID ( segIdxInfo . SegmentID , segIdxInfo . FieldID , idxInfo [ 0 ] . IndexName )
2021-04-12 15:03:23 +08:00
assert . Nil ( t , err )
2021-05-24 14:19:52 +08:00
assert . Equal ( t , segIdxInfo . IndexID , idx . IndexID )
2021-04-12 15:03:23 +08:00
2021-05-24 14:19:52 +08:00
_ , err = mt . GetSegmentIndexInfoByID ( segIdxInfo . SegmentID , segIdxInfo . FieldID , "abc" )
2021-04-12 15:03:23 +08:00
assert . NotNil ( t , err )
2021-05-24 14:19:52 +08:00
assert . EqualError ( t , err , fmt . Sprintf ( "can't find index name = abc on segment = %d, with filed id = %d" , segIdxInfo . SegmentID , segIdxInfo . FieldID ) )
2021-04-12 15:03:23 +08:00
2021-05-24 14:19:52 +08:00
_ , err = mt . GetSegmentIndexInfoByID ( segIdxInfo . SegmentID , 11 , idxInfo [ 0 ] . IndexName )
2021-04-12 15:03:23 +08:00
assert . NotNil ( t , err )
2021-05-24 14:19:52 +08:00
assert . EqualError ( t , err , fmt . Sprintf ( "can't find index name = %s on segment = %d, with filed id = 11" , idxInfo [ 0 ] . IndexName , segIdxInfo . SegmentID ) )
2021-04-12 15:03:23 +08:00
} )
t . Run ( "get field schema failed" , func ( t * testing . T ) {
2021-05-18 14:18:02 +08:00
mockKV . loadWithPrefix = func ( key string , ts typeutil . Timestamp ) ( [ ] string , [ ] string , error ) {
2021-04-12 15:03:23 +08:00
return nil , nil , nil
}
2021-05-20 14:14:14 +08:00
mockKV . multiSave = func ( kvs map [ string ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error ) {
2021-05-18 14:18:02 +08:00
return 0 , nil
2021-04-12 15:03:23 +08:00
}
2021-05-18 14:18:02 +08:00
mockKV . save = func ( key , value string ) ( typeutil . Timestamp , error ) {
return 0 , nil
2021-04-12 15:03:23 +08:00
}
err := mt . reloadFromKV ( )
assert . Nil ( t , err )
collInfo . PartitionIDs = nil
2021-05-20 14:14:14 +08:00
_ , err = mt . AddCollection ( collInfo , partInfo , idxInfo , nil )
2021-04-12 15:03:23 +08:00
assert . Nil ( t , err )
mt . collID2Meta = make ( map [ int64 ] pb . CollectionInfo )
_ , err = mt . unlockGetFieldSchema ( collInfo . Schema . Name , collInfo . Schema . Fields [ 0 ] . Name )
assert . NotNil ( t , err )
assert . EqualError ( t , err , fmt . Sprintf ( "collection %s not found" , collInfo . Schema . Name ) )
mt . collName2ID = make ( map [ string ] int64 )
_ , err = mt . unlockGetFieldSchema ( collInfo . Schema . Name , collInfo . Schema . Fields [ 0 ] . Name )
assert . NotNil ( t , err )
assert . EqualError ( t , err , fmt . Sprintf ( "collection %s not found" , collInfo . Schema . Name ) )
} )
t . Run ( "is segment indexed" , func ( t * testing . T ) {
2021-05-18 14:18:02 +08:00
mockKV . loadWithPrefix = func ( key string , ts typeutil . Timestamp ) ( [ ] string , [ ] string , error ) {
2021-04-12 15:03:23 +08:00
return nil , nil , nil
}
err := mt . reloadFromKV ( )
assert . Nil ( t , err )
idx := & pb . SegmentIndexInfo {
IndexID : 30 ,
FieldID : 31 ,
SegmentID : 32 ,
}
idxMeta := make ( map [ int64 ] pb . SegmentIndexInfo )
idxMeta [ idx . IndexID ] = * idx
mt . segID2IndexMeta = make ( map [ int64 ] * map [ int64 ] pb . SegmentIndexInfo )
mt . segID2IndexMeta [ idx . SegmentID ] = & idxMeta
field := schemapb . FieldSchema {
FieldID : 31 ,
}
assert . False ( t , mt . IsSegmentIndexed ( idx . SegmentID , & field , nil ) )
field . FieldID = 34
assert . False ( t , mt . IsSegmentIndexed ( idx . SegmentID , & field , nil ) )
} )
t . Run ( "get not indexed segments" , func ( t * testing . T ) {
2021-05-18 14:18:02 +08:00
mockKV . loadWithPrefix = func ( key string , ts typeutil . Timestamp ) ( [ ] string , [ ] string , error ) {
2021-04-12 15:03:23 +08:00
return nil , nil , nil
}
err := mt . reloadFromKV ( )
assert . Nil ( t , err )
idx := & pb . IndexInfo {
IndexName : "no-idx" ,
IndexID : 456 ,
IndexParams : [ ] * commonpb . KeyValuePair {
{
Key : "no-idx-k1" ,
Value : "no-idx-v1" ,
} ,
} ,
}
mt . collName2ID [ "abc" ] = 123
_ , _ , err = mt . GetNotIndexedSegments ( "abc" , "no-field" , idx )
assert . NotNil ( t , err )
assert . EqualError ( t , err , "collection abc not found" )
2021-05-20 14:14:14 +08:00
mockKV . multiSave = func ( kvs map [ string ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error ) {
2021-05-18 14:18:02 +08:00
return 0 , nil
2021-04-12 15:03:23 +08:00
}
2021-05-18 14:18:02 +08:00
mockKV . save = func ( key , value string ) ( typeutil . Timestamp , error ) {
return 0 , nil
2021-04-12 15:03:23 +08:00
}
err = mt . reloadFromKV ( )
assert . Nil ( t , err )
collInfo . PartitionIDs = nil
2021-05-20 14:14:14 +08:00
_ , err = mt . AddCollection ( collInfo , partInfo , idxInfo , nil )
2021-04-12 15:03:23 +08:00
assert . Nil ( t , err )
_ , _ , err = mt . GetNotIndexedSegments ( collInfo . Schema . Name , "no-field" , idx )
assert . NotNil ( t , err )
assert . EqualError ( t , err , fmt . Sprintf ( "collection %s doesn't have filed no-field" , collInfo . Schema . Name ) )
bakMeta := mt . indexID2Meta
mt . indexID2Meta = make ( map [ int64 ] pb . IndexInfo )
_ , _ , err = mt . GetNotIndexedSegments ( collInfo . Schema . Name , collInfo . Schema . Fields [ 0 ] . Name , idx )
assert . NotNil ( t , err )
assert . EqualError ( t , err , fmt . Sprintf ( "index id = %d not found" , idxInfo [ 0 ] . IndexID ) )
mt . indexID2Meta = bakMeta
2021-05-20 14:14:14 +08:00
mockKV . multiSave = func ( kvs map [ string ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error ) {
2021-05-18 14:18:02 +08:00
return 0 , fmt . Errorf ( "multi save error" )
2021-04-12 15:03:23 +08:00
}
_ , _ , err = mt . GetNotIndexedSegments ( collInfo . Schema . Name , collInfo . Schema . Fields [ 0 ] . Name , idx )
assert . NotNil ( t , err )
assert . EqualError ( t , err , "multi save error" )
2021-05-20 14:14:14 +08:00
mockKV . multiSave = func ( kvs map [ string ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error ) {
2021-05-18 14:18:02 +08:00
return 0 , nil
2021-04-12 15:03:23 +08:00
}
collInfo . PartitionIDs = nil
2021-05-20 14:14:14 +08:00
_ , err = mt . AddCollection ( collInfo , partInfo , idxInfo , nil )
2021-04-12 15:03:23 +08:00
assert . Nil ( t , err )
coll := mt . collID2Meta [ collInfo . ID ]
coll . FieldIndexes = append ( coll . FieldIndexes , & pb . FieldIndexInfo { FiledID : coll . FieldIndexes [ 0 ] . FiledID , IndexID : coll . FieldIndexes [ 0 ] . IndexID + 1 } )
mt . collID2Meta [ coll . ID ] = coll
anotherIdx := pb . IndexInfo {
IndexName : "no-index" ,
IndexID : coll . FieldIndexes [ 1 ] . IndexID ,
IndexParams : [ ] * commonpb . KeyValuePair {
{
Key : "no-idx-k1" ,
Value : "no-idx-v1" ,
} ,
} ,
}
mt . indexID2Meta [ anotherIdx . IndexID ] = anotherIdx
idx . IndexName = idxInfo [ 0 ] . IndexName
2021-05-20 14:14:14 +08:00
mockKV . multiSave = func ( kvs map [ string ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error ) {
2021-05-18 14:18:02 +08:00
return 0 , fmt . Errorf ( "multi save error" )
2021-04-12 15:03:23 +08:00
}
_ , _ , err = mt . GetNotIndexedSegments ( collInfo . Schema . Name , collInfo . Schema . Fields [ 0 ] . Name , idx )
assert . NotNil ( t , err )
assert . EqualError ( t , err , "multi save error" )
} )
t . Run ( "get index by name failed" , func ( t * testing . T ) {
2021-05-18 14:18:02 +08:00
mockKV . loadWithPrefix = func ( key string , ts typeutil . Timestamp ) ( [ ] string , [ ] string , error ) {
2021-04-12 15:03:23 +08:00
return nil , nil , nil
}
err := mt . reloadFromKV ( )
assert . Nil ( t , err )
mt . collName2ID [ "abc" ] = 123
2021-04-27 10:30:55 +08:00
_ , _ , err = mt . GetIndexByName ( "abc" , "hij" )
2021-04-12 15:03:23 +08:00
assert . NotNil ( t , err )
assert . EqualError ( t , err , "collection abc not found" )
2021-05-20 14:14:14 +08:00
mockKV . multiSave = func ( kvs map [ string ] string , addition func ( ts typeutil . Timestamp ) ( string , string , error ) ) ( typeutil . Timestamp , error ) {
2021-05-18 14:18:02 +08:00
return 0 , nil
2021-04-12 15:03:23 +08:00
}
2021-05-18 14:18:02 +08:00
mockKV . save = func ( key , value string ) ( typeutil . Timestamp , error ) {
return 0 , nil
2021-04-12 15:03:23 +08:00
}
err = mt . reloadFromKV ( )
assert . Nil ( t , err )
collInfo . PartitionIDs = nil
2021-05-20 14:14:14 +08:00
_ , err = mt . AddCollection ( collInfo , partInfo , idxInfo , nil )
2021-04-12 15:03:23 +08:00
assert . Nil ( t , err )
mt . indexID2Meta = make ( map [ int64 ] pb . IndexInfo )
2021-04-27 10:30:55 +08:00
_ , _ , err = mt . GetIndexByName ( collInfo . Schema . Name , idxInfo [ 0 ] . IndexName )
2021-04-12 15:03:23 +08:00
assert . NotNil ( t , err )
assert . EqualError ( t , err , fmt . Sprintf ( "index id = %d not found" , idxInfo [ 0 ] . IndexID ) )
_ , err = mt . GetIndexByID ( idxInfo [ 0 ] . IndexID )
assert . NotNil ( t , err )
assert . EqualError ( t , err , fmt . Sprintf ( "cannot find index, id = %d" , idxInfo [ 0 ] . IndexID ) )
} )
t . Run ( "add flused segment failed" , func ( t * testing . T ) {
2021-05-18 14:18:02 +08:00
mockKV . loadWithPrefix = func ( key string , ts typeutil . Timestamp ) ( [ ] string , [ ] string , error ) {
2021-04-12 15:03:23 +08:00
return nil , nil , nil
}
err := mt . reloadFromKV ( )
assert . Nil ( t , err )
err = mt . AddFlushedSegment ( 222 )
assert . Nil ( t , err )
err = mt . AddFlushedSegment ( 222 )
assert . NotNil ( t , err )
assert . EqualError ( t , err , "segment id = 222 exist" )
} )
2021-01-21 10:01:29 +08:00
}
2021-05-18 17:12:17 +08:00
func TestMetaWithTimestamp ( t * testing . T ) {
rand . Seed ( time . Now ( ) . UnixNano ( ) )
randVal := rand . Int ( )
Params . Init ( )
rootPath := fmt . Sprintf ( "/test/meta/%d" , randVal )
var tsoStart typeutil . Timestamp = 100
vtso := tsoStart
ftso := func ( ) typeutil . Timestamp {
vtso ++
return vtso
}
2021-06-11 22:04:41 +08:00
etcdCli , err := clientv3 . New ( clientv3 . Config { Endpoints : Params . EtcdEndpoints } )
2021-05-18 17:12:17 +08:00
assert . Nil ( t , err )
defer etcdCli . Close ( )
skv , err := newMetaSnapshot ( etcdCli , rootPath , TimestampPrefix , 7 , ftso )
assert . Nil ( t , err )
assert . NotNil ( t , skv )
mt , err := NewMetaTable ( skv )
assert . Nil ( t , err )
collInfo := & pb . CollectionInfo {
ID : 1 ,
Schema : & schemapb . CollectionSchema {
Name : "t1" ,
} ,
}
partInfo := & pb . PartitionInfo {
PartitionName : "p1" ,
PartitionID : 11 ,
SegmentIDs : nil ,
}
2021-05-20 14:14:14 +08:00
t1 , err := mt . AddCollection ( collInfo , partInfo , nil , nil )
2021-05-18 17:12:17 +08:00
assert . Nil ( t , err )
collInfo . ID = 2
collInfo . PartitionIDs = nil
collInfo . Schema . Name = "t2"
partInfo . PartitionID = 12
partInfo . PartitionName = "p2"
2021-05-20 14:14:14 +08:00
t2 , err := mt . AddCollection ( collInfo , partInfo , nil , nil )
2021-05-18 17:12:17 +08:00
assert . Nil ( t , err )
assert . True ( t , mt . HasCollection ( 1 , 0 ) )
assert . True ( t , mt . HasCollection ( 2 , 0 ) )
assert . True ( t , mt . HasCollection ( 1 , t2 ) )
assert . True ( t , mt . HasCollection ( 2 , t2 ) )
assert . True ( t , mt . HasCollection ( 1 , t1 ) )
assert . False ( t , mt . HasCollection ( 2 , t1 ) )
assert . False ( t , mt . HasCollection ( 1 , tsoStart ) )
assert . False ( t , mt . HasCollection ( 2 , tsoStart ) )
c1 , err := mt . GetCollectionByID ( 1 , 0 )
assert . Nil ( t , err )
c2 , err := mt . GetCollectionByID ( 2 , 0 )
assert . Nil ( t , err )
assert . Equal ( t , int64 ( 1 ) , c1 . ID )
assert . Equal ( t , int64 ( 2 ) , c2 . ID )
c1 , err = mt . GetCollectionByID ( 1 , t2 )
assert . Nil ( t , err )
c2 , err = mt . GetCollectionByID ( 2 , t2 )
assert . Nil ( t , err )
assert . Equal ( t , int64 ( 1 ) , c1 . ID )
assert . Equal ( t , int64 ( 2 ) , c2 . ID )
c1 , err = mt . GetCollectionByID ( 1 , t1 )
assert . Nil ( t , err )
c2 , err = mt . GetCollectionByID ( 2 , t1 )
assert . NotNil ( t , err )
assert . Equal ( t , int64 ( 1 ) , c1 . ID )
c1 , err = mt . GetCollectionByID ( 1 , tsoStart )
assert . NotNil ( t , err )
c2 , err = mt . GetCollectionByID ( 2 , tsoStart )
assert . NotNil ( t , err )
c1 , err = mt . GetCollectionByName ( "t1" , 0 )
assert . Nil ( t , err )
c2 , err = mt . GetCollectionByName ( "t2" , 0 )
assert . Nil ( t , err )
assert . Equal ( t , int64 ( 1 ) , c1 . ID )
assert . Equal ( t , int64 ( 2 ) , c2 . ID )
c1 , err = mt . GetCollectionByName ( "t1" , t2 )
assert . Nil ( t , err )
c2 , err = mt . GetCollectionByName ( "t2" , t2 )
assert . Nil ( t , err )
assert . Equal ( t , int64 ( 1 ) , c1 . ID )
assert . Equal ( t , int64 ( 2 ) , c2 . ID )
c1 , err = mt . GetCollectionByName ( "t1" , t1 )
assert . Nil ( t , err )
c2 , err = mt . GetCollectionByName ( "t2" , t1 )
assert . NotNil ( t , err )
assert . Equal ( t , int64 ( 1 ) , c1 . ID )
c1 , err = mt . GetCollectionByName ( "t1" , tsoStart )
assert . NotNil ( t , err )
c2 , err = mt . GetCollectionByName ( "t2" , tsoStart )
assert . NotNil ( t , err )
2021-06-03 19:09:33 +08:00
getKeys := func ( m map [ string ] typeutil . UniqueID ) [ ] string {
keys := make ( [ ] string , 0 , len ( m ) )
for key := range m {
keys = append ( keys , key )
}
return keys
}
2021-05-18 17:12:17 +08:00
s1 , err := mt . ListCollections ( 0 )
assert . Nil ( t , err )
assert . Equal ( t , 2 , len ( s1 ) )
2021-06-03 19:09:33 +08:00
assert . ElementsMatch ( t , getKeys ( s1 ) , [ ] string { "t1" , "t2" } )
2021-05-18 17:12:17 +08:00
s1 , err = mt . ListCollections ( t2 )
assert . Nil ( t , err )
assert . Equal ( t , 2 , len ( s1 ) )
2021-06-03 19:09:33 +08:00
assert . ElementsMatch ( t , getKeys ( s1 ) , [ ] string { "t1" , "t2" } )
2021-05-18 17:12:17 +08:00
s1 , err = mt . ListCollections ( t1 )
assert . Nil ( t , err )
assert . Equal ( t , 1 , len ( s1 ) )
2021-06-03 19:09:33 +08:00
assert . ElementsMatch ( t , getKeys ( s1 ) , [ ] string { "t1" } )
2021-05-18 17:12:17 +08:00
s1 , err = mt . ListCollections ( tsoStart )
assert . Nil ( t , err )
assert . Equal ( t , 0 , len ( s1 ) )
p1 , err := mt . GetPartitionByName ( 1 , "p1" , 0 )
assert . Nil ( t , err )
p2 , err := mt . GetPartitionByName ( 2 , "p2" , 0 )
assert . Nil ( t , err )
assert . Equal ( t , int64 ( 11 ) , p1 . PartitionID )
assert . Equal ( t , int64 ( 12 ) , p2 . PartitionID )
assert . Nil ( t , err )
p1 , err = mt . GetPartitionByName ( 1 , "p1" , t2 )
assert . Nil ( t , err )
p2 , err = mt . GetPartitionByName ( 2 , "p2" , t2 )
assert . Nil ( t , err )
assert . Equal ( t , int64 ( 11 ) , p1 . PartitionID )
assert . Equal ( t , int64 ( 12 ) , p2 . PartitionID )
p1 , err = mt . GetPartitionByName ( 1 , "p1" , t1 )
assert . Nil ( t , err )
p2 , err = mt . GetPartitionByName ( 2 , "p2" , t1 )
assert . NotNil ( t , err )
assert . Equal ( t , int64 ( 11 ) , p1 . PartitionID )
p1 , err = mt . GetPartitionByName ( 1 , "p1" , tsoStart )
assert . NotNil ( t , err )
p2 , err = mt . GetPartitionByName ( 2 , "p2" , tsoStart )
assert . NotNil ( t , err )
p1 , err = mt . GetPartitionByID ( 1 , 11 , 0 )
assert . Nil ( t , err )
p2 , err = mt . GetPartitionByID ( 2 , 12 , 0 )
assert . Nil ( t , err )
assert . Equal ( t , int64 ( 11 ) , p1 . PartitionID )
assert . Equal ( t , int64 ( 12 ) , p2 . PartitionID )
assert . Nil ( t , err )
p1 , err = mt . GetPartitionByID ( 1 , 11 , t2 )
assert . Nil ( t , err )
p2 , err = mt . GetPartitionByID ( 2 , 12 , t2 )
assert . Nil ( t , err )
assert . Equal ( t , int64 ( 11 ) , p1 . PartitionID )
assert . Equal ( t , int64 ( 12 ) , p2 . PartitionID )
p1 , err = mt . GetPartitionByID ( 1 , 11 , t1 )
assert . Nil ( t , err )
p2 , err = mt . GetPartitionByID ( 2 , 12 , t1 )
assert . NotNil ( t , err )
assert . Equal ( t , int64 ( 11 ) , p1 . PartitionID )
p1 , err = mt . GetPartitionByID ( 1 , 11 , tsoStart )
assert . NotNil ( t , err )
p2 , err = mt . GetPartitionByID ( 2 , 12 , tsoStart )
assert . NotNil ( t , err )
}