2023-04-23 09:00:32 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you 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.
|
|
|
|
|
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
"time"
|
|
|
|
|
2023-06-09 01:28:37 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
|
2023-04-23 09:00:32 +08:00
|
|
|
)
|
|
|
|
|
2023-09-12 21:07:19 +08:00
|
|
|
func (s *MiniClusterSuite) WaitForFlush(ctx context.Context, segIDs []int64, flushTs uint64, dbName, collectionName string) {
|
2023-05-23 17:51:25 +08:00
|
|
|
flushed := func() bool {
|
|
|
|
resp, err := s.Cluster.Proxy.GetFlushState(ctx, &milvuspb.GetFlushStateRequest{
|
2023-09-12 21:07:19 +08:00
|
|
|
SegmentIDs: segIDs,
|
|
|
|
FlushTs: flushTs,
|
|
|
|
DbName: dbName,
|
|
|
|
CollectionName: collectionName,
|
2023-05-23 17:51:25 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return resp.GetFlushed()
|
|
|
|
}
|
|
|
|
for !flushed() {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
s.FailNow("failed to wait for flush until ctx done")
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewInt64FieldData(fieldName string, numRows int) *schemapb.FieldData {
|
2023-04-23 09:00:32 +08:00
|
|
|
return &schemapb.FieldData{
|
|
|
|
Type: schemapb.DataType_Int64,
|
|
|
|
FieldName: fieldName,
|
|
|
|
Field: &schemapb.FieldData_Scalars{
|
|
|
|
Scalars: &schemapb.ScalarField{
|
|
|
|
Data: &schemapb.ScalarField_LongData{
|
|
|
|
LongData: &schemapb.LongArray{
|
2023-05-23 17:51:25 +08:00
|
|
|
Data: GenerateInt64Array(numRows),
|
2023-04-23 09:00:32 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-23 17:51:25 +08:00
|
|
|
func NewStringFieldData(fieldName string, numRows int) *schemapb.FieldData {
|
2023-04-23 09:00:32 +08:00
|
|
|
return &schemapb.FieldData{
|
|
|
|
Type: schemapb.DataType_Int64,
|
|
|
|
FieldName: fieldName,
|
|
|
|
Field: &schemapb.FieldData_Scalars{
|
|
|
|
Scalars: &schemapb.ScalarField{
|
|
|
|
Data: &schemapb.ScalarField_StringData{
|
|
|
|
StringData: &schemapb.StringArray{
|
2023-05-23 17:51:25 +08:00
|
|
|
Data: GenerateStringArray(numRows),
|
2023-04-23 09:00:32 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-23 17:51:25 +08:00
|
|
|
func NewFloatVectorFieldData(fieldName string, numRows, dim int) *schemapb.FieldData {
|
2023-04-23 09:00:32 +08:00
|
|
|
return &schemapb.FieldData{
|
|
|
|
Type: schemapb.DataType_FloatVector,
|
|
|
|
FieldName: fieldName,
|
|
|
|
Field: &schemapb.FieldData_Vectors{
|
|
|
|
Vectors: &schemapb.VectorField{
|
|
|
|
Dim: int64(dim),
|
|
|
|
Data: &schemapb.VectorField_FloatVector{
|
|
|
|
FloatVector: &schemapb.FloatArray{
|
2023-05-23 17:51:25 +08:00
|
|
|
Data: GenerateFloatVectors(numRows, dim),
|
2023-04-23 09:00:32 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-08 10:03:16 +08:00
|
|
|
func NewFloat16VectorFieldData(fieldName string, numRows, dim int) *schemapb.FieldData {
|
|
|
|
return &schemapb.FieldData{
|
|
|
|
Type: schemapb.DataType_Float16Vector,
|
|
|
|
FieldName: fieldName,
|
|
|
|
Field: &schemapb.FieldData_Vectors{
|
|
|
|
Vectors: &schemapb.VectorField{
|
|
|
|
Dim: int64(dim),
|
|
|
|
Data: &schemapb.VectorField_Float16Vector{
|
|
|
|
Float16Vector: GenerateFloat16Vectors(numRows, dim),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-11 15:48:51 +08:00
|
|
|
// func NewBFloat16VectorFieldData(fieldName string, numRows, dim int) *schemapb.FieldData {
|
|
|
|
// return &schemapb.FieldData{
|
|
|
|
// Type: schemapb.DataType_BFloat16Vector,
|
|
|
|
// FieldName: fieldName,
|
|
|
|
// Field: &schemapb.FieldData_Vectors{
|
|
|
|
// Vectors: &schemapb.VectorField{
|
|
|
|
// Dim: int64(dim),
|
|
|
|
// Data: &schemapb.VectorField_Bfloat16Vector{
|
|
|
|
// Bfloat16Vector: GenerateBFloat16Vectors(numRows, dim),
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
2023-05-23 17:51:25 +08:00
|
|
|
func NewBinaryVectorFieldData(fieldName string, numRows, dim int) *schemapb.FieldData {
|
2023-04-23 09:00:32 +08:00
|
|
|
return &schemapb.FieldData{
|
|
|
|
Type: schemapb.DataType_BinaryVector,
|
|
|
|
FieldName: fieldName,
|
|
|
|
Field: &schemapb.FieldData_Vectors{
|
|
|
|
Vectors: &schemapb.VectorField{
|
|
|
|
Dim: int64(dim),
|
|
|
|
Data: &schemapb.VectorField_BinaryVector{
|
2023-05-23 17:51:25 +08:00
|
|
|
BinaryVector: GenerateBinaryVectors(numRows, dim),
|
2023-04-23 09:00:32 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-23 17:51:25 +08:00
|
|
|
func GenerateInt64Array(numRows int) []int64 {
|
2023-04-23 09:00:32 +08:00
|
|
|
ret := make([]int64, numRows)
|
|
|
|
for i := 0; i < numRows; i++ {
|
|
|
|
ret[i] = int64(i)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2023-05-23 17:51:25 +08:00
|
|
|
func GenerateStringArray(numRows int) []string {
|
2023-04-23 09:00:32 +08:00
|
|
|
ret := make([]string, numRows)
|
|
|
|
for i := 0; i < numRows; i++ {
|
|
|
|
ret[i] = fmt.Sprintf("%d", i)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2023-05-23 17:51:25 +08:00
|
|
|
func GenerateFloatVectors(numRows, dim int) []float32 {
|
2023-04-23 09:00:32 +08:00
|
|
|
total := numRows * dim
|
|
|
|
ret := make([]float32, 0, total)
|
|
|
|
for i := 0; i < total; i++ {
|
|
|
|
ret = append(ret, rand.Float32())
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2023-05-23 17:51:25 +08:00
|
|
|
func GenerateBinaryVectors(numRows, dim int) []byte {
|
2023-04-23 09:00:32 +08:00
|
|
|
total := (numRows * dim) / 8
|
|
|
|
ret := make([]byte, total)
|
|
|
|
_, err := rand.Read(ret)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2023-09-08 10:03:16 +08:00
|
|
|
func GenerateFloat16Vectors(numRows, dim int) []byte {
|
|
|
|
total := numRows * dim * 2
|
|
|
|
ret := make([]byte, total)
|
|
|
|
_, err := rand.Read(ret)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2024-01-11 15:48:51 +08:00
|
|
|
// func GenerateBFloat16Vectors(numRows, dim int) []byte {
|
|
|
|
// total := numRows * dim * 2
|
|
|
|
// ret := make([]byte, total)
|
|
|
|
// _, err := rand.Read(ret)
|
|
|
|
// if err != nil {
|
|
|
|
// panic(err)
|
|
|
|
// }
|
|
|
|
// return ret
|
|
|
|
// }
|
|
|
|
|
2023-05-23 17:51:25 +08:00
|
|
|
func GenerateHashKeys(numRows int) []uint32 {
|
2023-04-23 09:00:32 +08:00
|
|
|
ret := make([]uint32, 0, numRows)
|
|
|
|
for i := 0; i < numRows; i++ {
|
|
|
|
ret = append(ret, rand.Uint32())
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|