2021-12-10 21:19:42 +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
|
2021-04-19 13:47:10 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-12-10 21:19:42 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 13:47:10 +08:00
|
|
|
//
|
2021-12-10 21:19:42 +08:00
|
|
|
// 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-04-19 13:47:10 +08:00
|
|
|
|
2021-01-16 10:12:14 +08:00
|
|
|
package querynode
|
2020-09-01 16:23:39 +08:00
|
|
|
|
2020-11-12 11:18:23 +08:00
|
|
|
import (
|
2021-09-07 15:45:59 +08:00
|
|
|
"context"
|
2020-11-17 10:07:42 +08:00
|
|
|
"log"
|
2020-11-12 12:04:12 +08:00
|
|
|
"math"
|
2021-07-29 16:03:22 +08:00
|
|
|
"sync"
|
2020-11-12 12:04:12 +08:00
|
|
|
"testing"
|
|
|
|
|
2022-03-30 21:11:28 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/storage"
|
|
|
|
|
2020-11-12 11:18:23 +08:00
|
|
|
"github.com/golang/protobuf/proto"
|
2020-11-16 21:10:43 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-11-17 10:07:42 +08:00
|
|
|
|
2021-11-02 18:16:32 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/common"
|
2021-09-09 17:36:02 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/milvuspb"
|
2021-09-03 17:12:55 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/planpb"
|
2022-02-08 21:57:46 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
2021-06-04 10:38:34 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/schemapb"
|
2021-09-09 17:36:02 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/segcorepb"
|
2022-02-08 21:57:46 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/funcutil"
|
2020-11-12 11:18:23 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------- constructor and destructor
|
|
|
|
func TestSegment_newSegment(t *testing.T) {
|
2020-12-08 14:41:04 +08:00
|
|
|
collectionID := UniqueID(0)
|
2022-04-29 13:35:49 +08:00
|
|
|
pkType := schemapb.DataType_Int64
|
|
|
|
schema := genTestCollectionSchema(pkType)
|
|
|
|
collectionMeta := genCollectionMeta(collectionID, schema)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2021-01-18 10:38:41 +08:00
|
|
|
collection := newCollection(collectionMeta.ID, collectionMeta.Schema)
|
2020-12-10 16:31:09 +08:00
|
|
|
assert.Equal(t, collection.ID(), collectionID)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
|
|
|
segmentID := UniqueID(0)
|
2022-02-08 21:57:46 +08:00
|
|
|
segment, err := newSegment(collection, segmentID, defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
|
|
|
assert.Nil(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.Equal(t, segmentID, segment.segmentID)
|
2020-11-24 20:14:51 +08:00
|
|
|
deleteSegment(segment)
|
|
|
|
deleteCollection(collection)
|
2021-09-09 17:36:02 +08:00
|
|
|
|
|
|
|
t.Run("test invalid type", func(t *testing.T) {
|
2022-02-08 21:57:46 +08:00
|
|
|
_, err = newSegment(collection,
|
2021-09-09 17:36:02 +08:00
|
|
|
defaultSegmentID,
|
|
|
|
defaultPartitionID,
|
|
|
|
collectionID, "", 100, true)
|
2022-02-08 21:57:46 +08:00
|
|
|
assert.Error(t, err)
|
2021-09-09 17:36:02 +08:00
|
|
|
})
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSegment_deleteSegment(t *testing.T) {
|
2020-12-08 14:41:04 +08:00
|
|
|
collectionID := UniqueID(0)
|
2022-04-29 13:35:49 +08:00
|
|
|
pkType := schemapb.DataType_Int64
|
|
|
|
schema := genTestCollectionSchema(pkType)
|
|
|
|
collectionMeta := genCollectionMeta(collectionID, schema)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
collection := newCollection(collectionMeta.ID, schema)
|
2020-12-10 16:31:09 +08:00
|
|
|
assert.Equal(t, collection.ID(), collectionID)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
|
|
|
segmentID := UniqueID(0)
|
2022-02-08 21:57:46 +08:00
|
|
|
segment, err := newSegment(collection, segmentID, defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.Equal(t, segmentID, segment.segmentID)
|
2022-02-08 21:57:46 +08:00
|
|
|
assert.Nil(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
|
|
|
deleteSegment(segment)
|
2020-11-24 20:14:51 +08:00
|
|
|
deleteCollection(collection)
|
2021-09-09 17:36:02 +08:00
|
|
|
|
|
|
|
t.Run("test delete nil ptr", func(t *testing.T) {
|
2022-04-29 13:35:49 +08:00
|
|
|
s, err := genSimpleSealedSegment(defaultMsgLength)
|
2021-09-09 17:36:02 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
s.segmentPtr = nil
|
|
|
|
deleteSegment(s)
|
|
|
|
})
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------- stats functions
|
|
|
|
func TestSegment_getRowCount(t *testing.T) {
|
2020-12-08 14:41:04 +08:00
|
|
|
collectionID := UniqueID(0)
|
2022-04-29 13:35:49 +08:00
|
|
|
pkType := schemapb.DataType_Int64
|
|
|
|
schema := genTestCollectionSchema(pkType)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
collection := newCollection(collectionID, schema)
|
2020-12-10 16:31:09 +08:00
|
|
|
assert.Equal(t, collection.ID(), collectionID)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
|
|
|
segmentID := UniqueID(0)
|
2022-02-08 21:57:46 +08:00
|
|
|
segment, err := newSegment(collection, segmentID, defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.Equal(t, segmentID, segment.segmentID)
|
2022-02-08 21:57:46 +08:00
|
|
|
assert.Nil(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
insertMsg, err := genSimpleInsertMsg(schema, defaultMsgLength)
|
|
|
|
assert.NoError(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
insertRecord := &segcorepb.InsertRecord{
|
|
|
|
FieldsData: insertMsg.FieldsData,
|
|
|
|
NumRows: int64(insertMsg.NumRows),
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
offset, err := segment.segmentPreInsert(defaultMsgLength)
|
2021-03-12 19:23:06 +08:00
|
|
|
assert.Nil(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.GreaterOrEqual(t, offset, int64(0))
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
err = segment.segmentInsert(offset, insertMsg.RowIDs, insertMsg.Timestamps, insertRecord)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
rowCount := segment.getRowCount()
|
2022-04-29 13:35:49 +08:00
|
|
|
assert.Equal(t, int64(defaultMsgLength), rowCount)
|
2020-11-24 20:14:51 +08:00
|
|
|
|
|
|
|
deleteSegment(segment)
|
|
|
|
deleteCollection(collection)
|
2021-09-09 17:36:02 +08:00
|
|
|
|
|
|
|
t.Run("test getRowCount nil ptr", func(t *testing.T) {
|
2022-04-29 13:35:49 +08:00
|
|
|
s, err := genSimpleSealedSegment(defaultMsgLength)
|
2021-09-09 17:36:02 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
s.segmentPtr = nil
|
|
|
|
res := s.getRowCount()
|
|
|
|
assert.Equal(t, int64(-1), res)
|
|
|
|
})
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
2021-06-04 10:38:34 +08:00
|
|
|
func TestSegment_retrieve(t *testing.T) {
|
|
|
|
collectionID := UniqueID(0)
|
2022-04-29 13:35:49 +08:00
|
|
|
pkType := schemapb.DataType_Int64
|
|
|
|
schema := genTestCollectionSchema(pkType)
|
2021-06-04 10:38:34 +08:00
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
collection := newCollection(collectionID, schema)
|
2021-06-04 10:38:34 +08:00
|
|
|
assert.Equal(t, collection.ID(), collectionID)
|
|
|
|
|
|
|
|
segmentID := UniqueID(0)
|
2022-02-08 21:57:46 +08:00
|
|
|
segment, err := newSegment(collection, segmentID, defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2021-06-04 10:38:34 +08:00
|
|
|
assert.Equal(t, segmentID, segment.segmentID)
|
2022-02-08 21:57:46 +08:00
|
|
|
assert.Nil(t, err)
|
2021-06-04 10:38:34 +08:00
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
insertMsg, err := genSimpleInsertMsg(schema, defaultMsgLength)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
insertRecord := &segcorepb.InsertRecord{
|
|
|
|
FieldsData: insertMsg.FieldsData,
|
|
|
|
NumRows: int64(insertMsg.NumRows),
|
2021-06-04 10:38:34 +08:00
|
|
|
}
|
2022-04-29 13:35:49 +08:00
|
|
|
|
|
|
|
offset, err := segment.segmentPreInsert(defaultMsgLength)
|
2021-06-04 10:38:34 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, offset, int64(0))
|
2022-04-29 13:35:49 +08:00
|
|
|
err = segment.segmentInsert(offset, insertMsg.RowIDs, insertMsg.Timestamps, insertRecord)
|
2021-06-04 10:38:34 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-09-03 17:12:55 +08:00
|
|
|
planNode := &planpb.PlanNode{
|
|
|
|
Node: &planpb.PlanNode_Predicates{
|
|
|
|
Predicates: &planpb.Expr{
|
|
|
|
Expr: &planpb.Expr_TermExpr{
|
|
|
|
TermExpr: &planpb.TermExpr{
|
|
|
|
ColumnInfo: &planpb.ColumnInfo{
|
2022-04-29 13:35:49 +08:00
|
|
|
FieldId: simpleInt32Field.id,
|
|
|
|
DataType: simpleInt32Field.dataType,
|
2021-09-03 17:12:55 +08:00
|
|
|
},
|
|
|
|
Values: []*planpb.GenericValue{
|
|
|
|
{
|
|
|
|
Val: &planpb.GenericValue_Int64Val{
|
|
|
|
Int64Val: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Val: &planpb.GenericValue_Int64Val{
|
|
|
|
Int64Val: 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Val: &planpb.GenericValue_Int64Val{
|
|
|
|
Int64Val: 3,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-04 10:38:34 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-04-29 13:35:49 +08:00
|
|
|
OutputFieldIds: []FieldID{simpleInt32Field.id},
|
2021-06-04 10:38:34 +08:00
|
|
|
}
|
2021-09-03 17:12:55 +08:00
|
|
|
// reqIds := &segcorepb.RetrieveRequest{
|
|
|
|
// Ids: &schemapb.IDs{
|
|
|
|
// IdField: &schemapb.IDs_IntId{
|
|
|
|
// IntId: &schemapb.LongArray{
|
|
|
|
// Data: []int64{2, 3, 1},
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// OutputFieldsId: []int64{100},
|
|
|
|
// }
|
|
|
|
planExpr, err := proto.Marshal(planNode)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
plan, err := createRetrievePlanByExpr(collection, planExpr, 100)
|
2021-06-04 10:38:34 +08:00
|
|
|
defer plan.delete()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-11-10 17:15:37 +08:00
|
|
|
res, err := segment.retrieve(plan)
|
2021-06-04 10:38:34 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-09-03 17:12:55 +08:00
|
|
|
assert.Equal(t, res.GetFieldsData()[0].GetScalars().Data.(*schemapb.ScalarField_IntData).IntData.Data, []int32{1, 2, 3})
|
2021-06-04 10:38:34 +08:00
|
|
|
}
|
|
|
|
|
2020-11-12 11:18:23 +08:00
|
|
|
func TestSegment_getDeletedCount(t *testing.T) {
|
2020-12-08 14:41:04 +08:00
|
|
|
collectionID := UniqueID(0)
|
2022-04-29 13:35:49 +08:00
|
|
|
pkType := schemapb.DataType_Int64
|
|
|
|
schema := genTestCollectionSchema(pkType)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
collection := newCollection(collectionID, schema)
|
2020-12-10 16:31:09 +08:00
|
|
|
assert.Equal(t, collection.ID(), collectionID)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
|
|
|
segmentID := UniqueID(0)
|
2022-02-08 21:57:46 +08:00
|
|
|
segment, err := newSegment(collection, segmentID, defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.Equal(t, segmentID, segment.segmentID)
|
2022-02-08 21:57:46 +08:00
|
|
|
assert.Nil(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
insertMsg, err := genSimpleInsertMsg(schema, defaultMsgLength)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
insertRecord := &segcorepb.InsertRecord{
|
|
|
|
FieldsData: insertMsg.FieldsData,
|
|
|
|
NumRows: int64(insertMsg.NumRows),
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
offsetInsert, err := segment.segmentPreInsert(defaultMsgLength)
|
2021-03-12 19:23:06 +08:00
|
|
|
assert.Nil(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.GreaterOrEqual(t, offsetInsert, int64(0))
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
err = segment.segmentInsert(offsetInsert, insertMsg.RowIDs, insertMsg.Timestamps, insertRecord)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
var offsetDelete = segment.segmentPreDelete(10)
|
|
|
|
assert.GreaterOrEqual(t, offsetDelete, int64(0))
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
pks, err := getPKs(insertMsg, collection.schema)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = segment.segmentDelete(offsetDelete, pks, insertMsg.Timestamps)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
var deletedCount = segment.getDeletedCount()
|
|
|
|
// TODO: assert.Equal(t, deletedCount, len(ids))
|
|
|
|
assert.Equal(t, deletedCount, int64(0))
|
2020-11-24 20:14:51 +08:00
|
|
|
|
|
|
|
deleteCollection(collection)
|
2021-09-09 17:36:02 +08:00
|
|
|
|
|
|
|
t.Run("test getDeletedCount nil ptr", func(t *testing.T) {
|
2022-04-29 13:35:49 +08:00
|
|
|
s, err := genSimpleSealedSegment(defaultMsgLength)
|
2021-09-09 17:36:02 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
s.segmentPtr = nil
|
|
|
|
res := s.getDeletedCount()
|
|
|
|
assert.Equal(t, int64(-1), res)
|
|
|
|
})
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSegment_getMemSize(t *testing.T) {
|
2020-12-08 14:41:04 +08:00
|
|
|
collectionID := UniqueID(0)
|
2022-04-29 13:35:49 +08:00
|
|
|
pkType := schemapb.DataType_Int64
|
|
|
|
schema := genTestCollectionSchema(pkType)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
collection := newCollection(collectionID, schema)
|
2020-12-10 16:31:09 +08:00
|
|
|
assert.Equal(t, collection.ID(), collectionID)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
|
|
|
segmentID := UniqueID(0)
|
2022-02-08 21:57:46 +08:00
|
|
|
segment, err := newSegment(collection, segmentID, defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.Equal(t, segmentID, segment.segmentID)
|
2022-02-08 21:57:46 +08:00
|
|
|
assert.Nil(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
insertMsg, err := genSimpleInsertMsg(schema, defaultMsgLength)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
insertRecord := &segcorepb.InsertRecord{
|
|
|
|
FieldsData: insertMsg.FieldsData,
|
|
|
|
NumRows: int64(insertMsg.NumRows),
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
offsetInsert, err := segment.segmentPreInsert(defaultMsgLength)
|
2021-03-12 19:23:06 +08:00
|
|
|
assert.Nil(t, err)
|
2022-04-29 13:35:49 +08:00
|
|
|
assert.GreaterOrEqual(t, offsetInsert, int64(0))
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
err = segment.segmentInsert(offsetInsert, insertMsg.RowIDs, insertMsg.Timestamps, insertRecord)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
var memSize = segment.getMemSize()
|
2022-04-29 13:35:49 +08:00
|
|
|
assert.Equal(t, memSize, int64(18776064))
|
2020-11-24 20:14:51 +08:00
|
|
|
|
|
|
|
deleteSegment(segment)
|
|
|
|
deleteCollection(collection)
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------- dm & search functions
|
|
|
|
func TestSegment_segmentInsert(t *testing.T) {
|
2020-12-08 14:41:04 +08:00
|
|
|
collectionID := UniqueID(0)
|
2022-04-29 13:35:49 +08:00
|
|
|
pkType := schemapb.DataType_Int64
|
|
|
|
schema := genTestCollectionSchema(pkType)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
collection := newCollection(collectionID, schema)
|
2020-12-10 16:31:09 +08:00
|
|
|
assert.Equal(t, collection.ID(), collectionID)
|
2020-11-12 11:18:23 +08:00
|
|
|
segmentID := UniqueID(0)
|
2022-02-08 21:57:46 +08:00
|
|
|
segment, err := newSegment(collection, segmentID, defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.Equal(t, segmentID, segment.segmentID)
|
2022-02-08 21:57:46 +08:00
|
|
|
assert.Nil(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
insertMsg, err := genSimpleInsertMsg(schema, defaultMsgLength)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
insertRecord := &segcorepb.InsertRecord{
|
|
|
|
FieldsData: insertMsg.FieldsData,
|
|
|
|
NumRows: int64(insertMsg.NumRows),
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
offsetInsert, err := segment.segmentPreInsert(defaultMsgLength)
|
2021-03-12 19:23:06 +08:00
|
|
|
assert.Nil(t, err)
|
2022-04-29 13:35:49 +08:00
|
|
|
assert.GreaterOrEqual(t, offsetInsert, int64(0))
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
err = segment.segmentInsert(offsetInsert, insertMsg.RowIDs, insertMsg.Timestamps, insertRecord)
|
2020-11-25 16:24:57 +08:00
|
|
|
assert.NoError(t, err)
|
2020-11-24 20:14:51 +08:00
|
|
|
deleteSegment(segment)
|
|
|
|
deleteCollection(collection)
|
2021-09-09 17:36:02 +08:00
|
|
|
|
|
|
|
t.Run("test nil segment", func(t *testing.T) {
|
2022-04-29 13:35:49 +08:00
|
|
|
segment, err := genSimpleSealedSegment(defaultMsgLength)
|
2021-09-09 17:36:02 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
segment.setType(segmentTypeGrowing)
|
|
|
|
segment.segmentPtr = nil
|
|
|
|
err = segment.segmentInsert(0, nil, nil, nil)
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test invalid segment type", func(t *testing.T) {
|
2022-04-29 13:35:49 +08:00
|
|
|
segment, err := genSimpleSealedSegment(defaultMsgLength)
|
2021-09-09 17:36:02 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
err = segment.segmentInsert(0, nil, nil, nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSegment_segmentDelete(t *testing.T) {
|
2020-12-08 14:41:04 +08:00
|
|
|
collectionID := UniqueID(0)
|
2022-04-29 13:35:49 +08:00
|
|
|
pkType := schemapb.DataType_Int64
|
|
|
|
schema := genTestCollectionSchema(pkType)
|
|
|
|
collection := newCollection(collectionID, schema)
|
2020-12-10 16:31:09 +08:00
|
|
|
assert.Equal(t, collection.ID(), collectionID)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
|
|
|
segmentID := UniqueID(0)
|
2022-02-08 21:57:46 +08:00
|
|
|
segment, err := newSegment(collection, segmentID, defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.Equal(t, segmentID, segment.segmentID)
|
2022-02-08 21:57:46 +08:00
|
|
|
assert.Nil(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
insertMsg, err := genSimpleInsertMsg(schema, defaultMsgLength)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
insertRecord := &segcorepb.InsertRecord{
|
|
|
|
FieldsData: insertMsg.FieldsData,
|
|
|
|
NumRows: int64(insertMsg.NumRows),
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
offsetInsert, err := segment.segmentPreInsert(defaultMsgLength)
|
2021-03-12 19:23:06 +08:00
|
|
|
assert.Nil(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.GreaterOrEqual(t, offsetInsert, int64(0))
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
err = segment.segmentInsert(offsetInsert, insertMsg.RowIDs, insertMsg.Timestamps, insertRecord)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
var offsetDelete = segment.segmentPreDelete(10)
|
|
|
|
assert.GreaterOrEqual(t, offsetDelete, int64(0))
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
pks, err := getPKs(insertMsg, schema)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = segment.segmentDelete(offsetDelete, pks, insertMsg.Timestamps)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
2020-11-24 20:14:51 +08:00
|
|
|
|
|
|
|
deleteCollection(collection)
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
2020-11-17 10:07:42 +08:00
|
|
|
func TestSegment_segmentSearch(t *testing.T) {
|
2022-04-08 20:27:31 +08:00
|
|
|
nq := int64(10)
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
node, err := genSimpleQueryNode(ctx)
|
|
|
|
assert.NoError(t, err)
|
2020-11-17 10:07:42 +08:00
|
|
|
|
2022-04-08 20:27:31 +08:00
|
|
|
collection, err := node.historical.replica.getCollectionByID(defaultCollectionID)
|
|
|
|
assert.NoError(t, err)
|
2020-11-17 10:07:42 +08:00
|
|
|
|
2022-04-08 20:27:31 +08:00
|
|
|
segment, err := node.historical.replica.getSegmentByID(defaultSegmentID)
|
2020-11-17 10:07:42 +08:00
|
|
|
assert.NoError(t, err)
|
2022-04-08 20:27:31 +08:00
|
|
|
|
|
|
|
// TODO: replace below by genPlaceholderGroup(nq)
|
2022-04-29 13:35:49 +08:00
|
|
|
vec := generateFloatVectors(1, defaultDim)
|
2020-11-17 10:07:42 +08:00
|
|
|
var searchRawData []byte
|
2022-04-08 20:27:31 +08:00
|
|
|
for i, ele := range vec {
|
2020-11-17 10:07:42 +08:00
|
|
|
buf := make([]byte, 4)
|
2022-04-08 20:27:31 +08:00
|
|
|
common.Endian.PutUint32(buf, math.Float32bits(ele+float32(i*2)))
|
2020-11-17 10:07:42 +08:00
|
|
|
searchRawData = append(searchRawData, buf...)
|
|
|
|
}
|
2022-04-08 20:27:31 +08:00
|
|
|
|
2021-01-22 09:36:18 +08:00
|
|
|
placeholderValue := milvuspb.PlaceholderValue{
|
2020-11-17 10:07:42 +08:00
|
|
|
Tag: "$0",
|
2021-03-12 14:22:09 +08:00
|
|
|
Type: milvuspb.PlaceholderType_FloatVector,
|
2022-04-08 20:27:31 +08:00
|
|
|
Values: [][]byte{},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < int(nq); i++ {
|
|
|
|
placeholderValue.Values = append(placeholderValue.Values, searchRawData)
|
2020-11-17 10:07:42 +08:00
|
|
|
}
|
|
|
|
|
2021-01-22 09:36:18 +08:00
|
|
|
placeholderGroup := milvuspb.PlaceholderGroup{
|
|
|
|
Placeholders: []*milvuspb.PlaceholderValue{&placeholderValue},
|
2020-11-17 10:07:42 +08:00
|
|
|
}
|
|
|
|
|
2022-04-08 20:27:31 +08:00
|
|
|
placeGroupByte, err := proto.Marshal(&placeholderGroup)
|
2020-11-17 10:07:42 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Print("marshal placeholderGroup failed")
|
|
|
|
}
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
dslString := "{\"bool\": { \n\"vector\": {\n \"floatVectorField\": {\n \"metric_type\": \"L2\", \n \"params\": {\n \"nprobe\": 10 \n},\n \"query\": \"$0\",\n \"topk\": 10 \n,\"round_decimal\": 6\n } \n } \n } \n }"
|
2022-04-08 20:27:31 +08:00
|
|
|
|
2021-07-13 22:20:33 +08:00
|
|
|
plan, err := createSearchPlan(collection, dslString)
|
2020-11-30 17:58:23 +08:00
|
|
|
assert.NoError(t, err)
|
2022-04-08 20:27:31 +08:00
|
|
|
holder, err := parseSearchRequest(plan, placeGroupByte)
|
2020-11-30 17:58:23 +08:00
|
|
|
assert.NoError(t, err)
|
2022-04-08 20:27:31 +08:00
|
|
|
|
2021-03-30 22:16:58 +08:00
|
|
|
placeholderGroups := make([]*searchRequest, 0)
|
2020-11-26 16:01:31 +08:00
|
|
|
placeholderGroups = append(placeholderGroups, holder)
|
2020-11-17 10:07:42 +08:00
|
|
|
|
2022-04-08 20:27:31 +08:00
|
|
|
searchResult, err := segment.search(plan, placeholderGroups, []Timestamp{0})
|
2021-02-20 10:14:03 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-04-08 20:27:31 +08:00
|
|
|
err = checkSearchResult(nq, plan, searchResult)
|
|
|
|
assert.NoError(t, err)
|
2021-02-20 10:14:03 +08:00
|
|
|
|
2020-11-26 16:01:31 +08:00
|
|
|
plan.delete()
|
|
|
|
holder.delete()
|
2020-11-24 20:14:51 +08:00
|
|
|
deleteSegment(segment)
|
|
|
|
deleteCollection(collection)
|
2020-11-17 10:07:42 +08:00
|
|
|
}
|
2020-09-21 15:10:54 +08:00
|
|
|
|
2020-11-12 11:18:23 +08:00
|
|
|
//-------------------------------------------------------------------------------------- preDm functions
|
|
|
|
func TestSegment_segmentPreInsert(t *testing.T) {
|
2020-12-08 14:41:04 +08:00
|
|
|
collectionID := UniqueID(0)
|
2022-04-29 13:35:49 +08:00
|
|
|
pkType := schemapb.DataType_Int64
|
|
|
|
schema := genTestCollectionSchema(pkType)
|
|
|
|
collection := newCollection(collectionID, schema)
|
2020-12-10 16:31:09 +08:00
|
|
|
assert.Equal(t, collection.ID(), collectionID)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
|
|
|
segmentID := UniqueID(0)
|
2022-02-08 21:57:46 +08:00
|
|
|
segment, err := newSegment(collection, segmentID, defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.Equal(t, segmentID, segment.segmentID)
|
2022-02-08 21:57:46 +08:00
|
|
|
assert.Nil(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
offset, err := segment.segmentPreInsert(defaultMsgLength)
|
2021-03-12 19:23:06 +08:00
|
|
|
assert.Nil(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.GreaterOrEqual(t, offset, int64(0))
|
2020-11-24 20:14:51 +08:00
|
|
|
|
|
|
|
deleteSegment(segment)
|
|
|
|
deleteCollection(collection)
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSegment_segmentPreDelete(t *testing.T) {
|
2020-12-08 14:41:04 +08:00
|
|
|
collectionID := UniqueID(0)
|
2022-04-29 13:35:49 +08:00
|
|
|
pkType := schemapb.DataType_Int64
|
|
|
|
schema := genTestCollectionSchema(pkType)
|
|
|
|
collection := newCollection(collectionID, schema)
|
2020-12-10 16:31:09 +08:00
|
|
|
assert.Equal(t, collection.ID(), collectionID)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
|
|
|
segmentID := UniqueID(0)
|
2022-02-08 21:57:46 +08:00
|
|
|
segment, err := newSegment(collection, segmentID, defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.Equal(t, segmentID, segment.segmentID)
|
2022-02-08 21:57:46 +08:00
|
|
|
assert.Nil(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
insertMsg, err := genSimpleInsertMsg(schema, defaultMsgLength)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
insertRecord := &segcorepb.InsertRecord{
|
|
|
|
FieldsData: insertMsg.FieldsData,
|
|
|
|
NumRows: int64(insertMsg.NumRows),
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
offsetInsert, err := segment.segmentPreInsert(defaultMsgLength)
|
2021-03-12 19:23:06 +08:00
|
|
|
assert.Nil(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.GreaterOrEqual(t, offsetInsert, int64(0))
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
err = segment.segmentInsert(offsetInsert, insertMsg.RowIDs, insertMsg.Timestamps, insertRecord)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
var offsetDelete = segment.segmentPreDelete(10)
|
|
|
|
assert.GreaterOrEqual(t, offsetDelete, int64(0))
|
2020-11-24 20:14:51 +08:00
|
|
|
|
|
|
|
deleteSegment(segment)
|
|
|
|
deleteCollection(collection)
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
2021-01-21 15:20:23 +08:00
|
|
|
|
2021-10-22 18:51:14 +08:00
|
|
|
func TestSegment_segmentLoadDeletedRecord(t *testing.T) {
|
|
|
|
fieldParam := constFieldParam{
|
|
|
|
id: 100,
|
|
|
|
dataType: schemapb.DataType_Int64,
|
|
|
|
}
|
2022-04-29 13:35:49 +08:00
|
|
|
field := genPKFieldSchema(fieldParam)
|
2021-10-22 18:51:14 +08:00
|
|
|
schema := &schemapb.CollectionSchema{
|
|
|
|
Name: defaultCollectionName,
|
|
|
|
AutoID: false,
|
|
|
|
Fields: []*schemapb.FieldSchema{
|
|
|
|
field,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-02-08 21:57:46 +08:00
|
|
|
seg, err := newSegment(newCollection(defaultCollectionID, schema),
|
2021-10-22 18:51:14 +08:00
|
|
|
defaultSegmentID,
|
|
|
|
defaultPartitionID,
|
|
|
|
defaultCollectionID,
|
2021-12-17 20:12:42 +08:00
|
|
|
defaultDMLChannel,
|
2021-10-22 18:51:14 +08:00
|
|
|
segmentTypeSealed,
|
|
|
|
true)
|
2022-02-08 21:57:46 +08:00
|
|
|
assert.Nil(t, err)
|
2022-04-02 17:43:29 +08:00
|
|
|
ids := []int64{1, 2, 3}
|
|
|
|
pks := make([]primaryKey, 0)
|
|
|
|
for _, id := range ids {
|
|
|
|
pks = append(pks, newInt64PrimaryKey(id))
|
|
|
|
}
|
2021-10-22 18:51:14 +08:00
|
|
|
timestamps := []Timestamp{10, 10, 10}
|
|
|
|
var rowCount int64 = 3
|
2022-04-29 13:35:49 +08:00
|
|
|
err = seg.segmentLoadDeletedRecord(pks, timestamps, rowCount)
|
|
|
|
assert.NoError(t, err)
|
2021-10-22 18:51:14 +08:00
|
|
|
}
|
|
|
|
|
2021-01-21 15:20:23 +08:00
|
|
|
func TestSegment_segmentLoadFieldData(t *testing.T) {
|
2022-04-29 13:35:49 +08:00
|
|
|
pkType := schemapb.DataType_Int64
|
|
|
|
schema := genTestCollectionSchema(pkType)
|
|
|
|
_, err := genSealedSegment(schema,
|
|
|
|
defaultCollectionID,
|
|
|
|
defaultPartitionID,
|
|
|
|
defaultSegmentID,
|
|
|
|
defaultDMLChannel,
|
|
|
|
defaultMsgLength)
|
|
|
|
assert.NoError(t, err)
|
2021-01-21 15:20:23 +08:00
|
|
|
}
|
2021-07-29 16:03:22 +08:00
|
|
|
|
|
|
|
func TestSegment_ConcurrentOperation(t *testing.T) {
|
|
|
|
const N = 16
|
|
|
|
var ages = []int32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
ageData := &schemapb.FieldData{
|
|
|
|
Type: simpleInt32Field.dataType,
|
|
|
|
FieldId: simpleInt32Field.id,
|
|
|
|
Field: &schemapb.FieldData_Scalars{
|
|
|
|
Scalars: &schemapb.ScalarField{
|
|
|
|
Data: &schemapb.ScalarField_IntData{
|
|
|
|
IntData: &schemapb.IntArray{
|
|
|
|
Data: ages,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-07-29 16:03:22 +08:00
|
|
|
collectionID := UniqueID(0)
|
|
|
|
partitionID := UniqueID(0)
|
2022-04-29 13:35:49 +08:00
|
|
|
pkType := schemapb.DataType_Int64
|
|
|
|
schema := genTestCollectionSchema(pkType)
|
|
|
|
collection := newCollection(collectionID, schema)
|
2021-07-29 16:03:22 +08:00
|
|
|
assert.Equal(t, collection.ID(), collectionID)
|
|
|
|
|
|
|
|
wg := sync.WaitGroup{}
|
2021-09-07 15:45:59 +08:00
|
|
|
for i := 0; i < 100; i++ {
|
2021-07-29 16:03:22 +08:00
|
|
|
segmentID := UniqueID(i)
|
2022-02-08 21:57:46 +08:00
|
|
|
segment, err := newSegment(collection, segmentID, partitionID, collectionID, "", segmentTypeSealed, true)
|
2021-07-29 16:03:22 +08:00
|
|
|
assert.Equal(t, segmentID, segment.segmentID)
|
|
|
|
assert.Equal(t, partitionID, segment.partitionID)
|
2022-02-08 21:57:46 +08:00
|
|
|
assert.Nil(t, err)
|
2021-07-29 16:03:22 +08:00
|
|
|
|
|
|
|
wg.Add(2)
|
|
|
|
go func() {
|
|
|
|
deleteSegment(segment)
|
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
go func() {
|
|
|
|
// segmentLoadFieldData result error may be nil or not, we just expected this test would not crash.
|
2022-04-29 13:35:49 +08:00
|
|
|
_ = segment.segmentLoadFieldData(simpleInt32Field.id, N, ageData)
|
2021-07-29 16:03:22 +08:00
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
deleteCollection(collection)
|
|
|
|
}
|
2021-09-07 15:45:59 +08:00
|
|
|
|
2022-02-08 21:57:46 +08:00
|
|
|
func TestSegment_indexInfo(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2021-09-07 15:45:59 +08:00
|
|
|
|
2022-02-08 21:57:46 +08:00
|
|
|
tSafe := newTSafeReplica()
|
|
|
|
h, err := genSimpleHistorical(ctx, tSafe)
|
|
|
|
assert.NoError(t, err)
|
2021-09-07 15:45:59 +08:00
|
|
|
|
2022-02-08 21:57:46 +08:00
|
|
|
seg, err := h.replica.getSegmentByID(defaultSegmentID)
|
|
|
|
assert.NoError(t, err)
|
2021-09-07 15:45:59 +08:00
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
fieldID := simpleFloatVecField.id
|
2022-02-08 21:57:46 +08:00
|
|
|
|
|
|
|
indexName := "query-node-test-index"
|
|
|
|
indexParam := make(map[string]string)
|
|
|
|
indexParam["index_type"] = "IVF_PQ"
|
|
|
|
indexParam["index_mode"] = "cpu"
|
|
|
|
indexPaths := []string{"query-node-test-index-path"}
|
|
|
|
indexID := UniqueID(0)
|
|
|
|
buildID := UniqueID(0)
|
|
|
|
|
2022-03-30 21:11:28 +08:00
|
|
|
indexInfo := &querypb.FieldIndexInfo{
|
2022-02-08 21:57:46 +08:00
|
|
|
IndexName: indexName,
|
|
|
|
IndexParams: funcutil.Map2KeyValuePair(indexParam),
|
|
|
|
IndexFilePaths: indexPaths,
|
|
|
|
IndexID: indexID,
|
|
|
|
BuildID: buildID,
|
|
|
|
}
|
2021-09-07 15:45:59 +08:00
|
|
|
|
2022-03-30 21:11:28 +08:00
|
|
|
seg.setIndexedFieldInfo(fieldID, &IndexedFieldInfo{indexInfo: indexInfo})
|
2021-09-09 17:36:02 +08:00
|
|
|
|
2022-03-30 21:11:28 +08:00
|
|
|
fieldInfo, err := seg.getIndexedFieldInfo(fieldID)
|
2022-02-08 21:57:46 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
info := fieldInfo.indexInfo
|
|
|
|
assert.Equal(t, indexName, info.IndexName)
|
|
|
|
params := funcutil.KeyValuePair2Map(indexInfo.IndexParams)
|
|
|
|
assert.Equal(t, len(indexParam), len(params))
|
|
|
|
assert.Equal(t, indexParam["index_type"], params["index_type"])
|
|
|
|
assert.Equal(t, indexParam["index_mode"], params["index_mode"])
|
|
|
|
assert.Equal(t, len(indexPaths), len(info.IndexFilePaths))
|
|
|
|
assert.Equal(t, indexPaths[0], info.IndexFilePaths[0])
|
|
|
|
assert.Equal(t, indexID, info.IndexID)
|
|
|
|
assert.Equal(t, buildID, info.BuildID)
|
2021-09-09 17:36:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSegment_BasicMetrics(t *testing.T) {
|
2022-04-29 13:35:49 +08:00
|
|
|
pkType := schemapb.DataType_Int64
|
|
|
|
schema := genTestCollectionSchema(pkType)
|
2021-09-09 17:36:02 +08:00
|
|
|
collection := newCollection(defaultCollectionID, schema)
|
2022-02-08 21:57:46 +08:00
|
|
|
segment, err := newSegment(collection,
|
2021-09-09 17:36:02 +08:00
|
|
|
defaultSegmentID,
|
|
|
|
defaultPartitionID,
|
|
|
|
defaultCollectionID,
|
2021-12-17 20:12:42 +08:00
|
|
|
defaultDMLChannel,
|
2021-09-09 17:36:02 +08:00
|
|
|
segmentTypeSealed,
|
|
|
|
true)
|
2022-02-08 21:57:46 +08:00
|
|
|
assert.Nil(t, err)
|
2021-09-09 17:36:02 +08:00
|
|
|
|
|
|
|
t.Run("test id binlog row size", func(t *testing.T) {
|
|
|
|
size := int64(1024)
|
|
|
|
segment.setIDBinlogRowSizes([]int64{size})
|
|
|
|
sizes := segment.getIDBinlogRowSizes()
|
|
|
|
assert.Len(t, sizes, 1)
|
|
|
|
assert.Equal(t, size, sizes[0])
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test type", func(t *testing.T) {
|
|
|
|
sType := segmentTypeGrowing
|
|
|
|
segment.setType(sType)
|
|
|
|
resType := segment.getType()
|
|
|
|
assert.Equal(t, sType, resType)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test onService", func(t *testing.T) {
|
|
|
|
segment.setOnService(false)
|
|
|
|
resOnService := segment.getOnService()
|
|
|
|
assert.Equal(t, false, resOnService)
|
|
|
|
})
|
|
|
|
|
2022-03-30 21:11:28 +08:00
|
|
|
t.Run("test IndexedFieldInfo", func(t *testing.T) {
|
2021-09-09 17:36:02 +08:00
|
|
|
fieldID := rowIDFieldID
|
2022-03-30 21:11:28 +08:00
|
|
|
info := &IndexedFieldInfo{
|
2021-09-09 17:36:02 +08:00
|
|
|
fieldBinlog: &datapb.FieldBinlog{
|
|
|
|
FieldID: fieldID,
|
2021-12-19 20:00:42 +08:00
|
|
|
Binlogs: []*datapb.Binlog{},
|
2021-09-09 17:36:02 +08:00
|
|
|
},
|
|
|
|
}
|
2022-03-30 21:11:28 +08:00
|
|
|
segment.setIndexedFieldInfo(fieldID, info)
|
|
|
|
resInfo, err := segment.getIndexedFieldInfo(fieldID)
|
2021-09-09 17:36:02 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, info, resInfo)
|
|
|
|
|
2022-03-30 21:11:28 +08:00
|
|
|
_, err = segment.getIndexedFieldInfo(FieldID(1000))
|
2021-09-09 17:36:02 +08:00
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-03-30 21:11:28 +08:00
|
|
|
func TestSegment_fillIndexedFieldsData(t *testing.T) {
|
2021-09-09 17:36:02 +08:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
pkType := schemapb.DataType_Int64
|
|
|
|
schema := genTestCollectionSchema(pkType)
|
2021-09-09 17:36:02 +08:00
|
|
|
collection := newCollection(defaultCollectionID, schema)
|
2022-02-08 21:57:46 +08:00
|
|
|
segment, err := newSegment(collection,
|
2021-09-09 17:36:02 +08:00
|
|
|
defaultSegmentID,
|
|
|
|
defaultPartitionID,
|
|
|
|
defaultCollectionID,
|
2021-12-17 20:12:42 +08:00
|
|
|
defaultDMLChannel,
|
2021-09-09 17:36:02 +08:00
|
|
|
segmentTypeSealed,
|
|
|
|
true)
|
2022-02-08 21:57:46 +08:00
|
|
|
assert.Nil(t, err)
|
2021-09-09 17:36:02 +08:00
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
vecCM, err := genVectorChunkManager(ctx, collection)
|
2021-09-09 17:36:02 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-03-30 21:11:28 +08:00
|
|
|
t.Run("test fillIndexedFieldsData float-vector invalid vectorChunkManager", func(t *testing.T) {
|
2021-09-09 17:36:02 +08:00
|
|
|
fieldID := FieldID(100)
|
|
|
|
fieldName := "float-vector-field-0"
|
2022-03-30 21:11:28 +08:00
|
|
|
info := &IndexedFieldInfo{
|
2021-09-09 17:36:02 +08:00
|
|
|
fieldBinlog: &datapb.FieldBinlog{
|
|
|
|
FieldID: fieldID,
|
2021-12-19 20:00:42 +08:00
|
|
|
Binlogs: []*datapb.Binlog{},
|
2021-09-09 17:36:02 +08:00
|
|
|
},
|
2022-03-30 21:11:28 +08:00
|
|
|
indexInfo: &querypb.FieldIndexInfo{EnableIndex: true},
|
2021-09-09 17:36:02 +08:00
|
|
|
}
|
2022-03-30 21:11:28 +08:00
|
|
|
segment.setIndexedFieldInfo(fieldID, info)
|
2021-09-09 17:36:02 +08:00
|
|
|
fieldData := []*schemapb.FieldData{
|
|
|
|
{
|
|
|
|
Type: schemapb.DataType_FloatVector,
|
|
|
|
FieldName: fieldName,
|
|
|
|
FieldId: fieldID,
|
|
|
|
Field: &schemapb.FieldData_Vectors{
|
|
|
|
Vectors: &schemapb.VectorField{
|
|
|
|
Dim: defaultDim,
|
|
|
|
Data: &schemapb.VectorField_FloatVector{
|
|
|
|
FloatVector: &schemapb.FloatArray{
|
|
|
|
Data: []float32{1.1, 2.2, 3.3, 4.4},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
result := &segcorepb.RetrieveResults{
|
|
|
|
Ids: &schemapb.IDs{},
|
|
|
|
Offset: []int64{0},
|
|
|
|
FieldsData: fieldData,
|
|
|
|
}
|
2022-03-30 21:11:28 +08:00
|
|
|
err = segment.fillIndexedFieldsData(defaultCollectionID, vecCM, result)
|
2021-09-09 17:36:02 +08:00
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
}
|
2022-03-30 21:11:28 +08:00
|
|
|
|
|
|
|
func Test_getFieldDataPath(t *testing.T) {
|
|
|
|
indexedFieldInfo := &IndexedFieldInfo{
|
|
|
|
fieldBinlog: &datapb.FieldBinlog{
|
|
|
|
FieldID: 0,
|
|
|
|
Binlogs: []*datapb.Binlog{
|
|
|
|
{
|
|
|
|
LogPath: funcutil.GenRandomStr(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
LogPath: funcutil.GenRandomStr(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
s := &Segment{
|
|
|
|
idBinlogRowSizes: []int64{10, 15},
|
|
|
|
}
|
|
|
|
|
|
|
|
path, offsetInBinlog := s.getFieldDataPath(indexedFieldInfo, 4)
|
|
|
|
assert.Equal(t, indexedFieldInfo.fieldBinlog.Binlogs[0].LogPath, path)
|
|
|
|
assert.Equal(t, int64(4), offsetInBinlog)
|
|
|
|
|
|
|
|
path, offsetInBinlog = s.getFieldDataPath(indexedFieldInfo, 11)
|
|
|
|
assert.Equal(t, indexedFieldInfo.fieldBinlog.Binlogs[1].LogPath, path)
|
|
|
|
assert.Equal(t, int64(1), offsetInBinlog)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_fillBinVecFieldData(t *testing.T) {
|
|
|
|
var m storage.ChunkManager
|
|
|
|
|
|
|
|
m = newMockChunkManager(withDefaultReadAt())
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
f := newBinaryVectorFieldData(simpleBinVecField.fieldName, 1, 8)
|
2022-03-30 21:11:28 +08:00
|
|
|
|
|
|
|
path := funcutil.GenRandomStr()
|
|
|
|
index := 0
|
|
|
|
offset := int64(100)
|
|
|
|
endian := common.Endian
|
|
|
|
|
|
|
|
assert.NoError(t, fillBinVecFieldData(m, path, f, index, offset, endian))
|
|
|
|
|
|
|
|
m = newMockChunkManager(withReadAtErr())
|
|
|
|
assert.Error(t, fillBinVecFieldData(m, path, f, index, offset, endian))
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_fillFloatVecFieldData(t *testing.T) {
|
|
|
|
var m storage.ChunkManager
|
|
|
|
|
|
|
|
m = newMockChunkManager(withDefaultReadAt())
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
f := newFloatVectorFieldData(simpleFloatVecField.fieldName, 1, 8)
|
2022-03-30 21:11:28 +08:00
|
|
|
|
|
|
|
path := funcutil.GenRandomStr()
|
|
|
|
index := 0
|
|
|
|
offset := int64(100)
|
|
|
|
endian := common.Endian
|
|
|
|
|
|
|
|
assert.NoError(t, fillFloatVecFieldData(m, path, f, index, offset, endian))
|
|
|
|
|
|
|
|
m = newMockChunkManager(withReadAtErr())
|
|
|
|
assert.Error(t, fillFloatVecFieldData(m, path, f, index, offset, endian))
|
|
|
|
|
|
|
|
m = newMockChunkManager(withReadAtEmptyContent())
|
|
|
|
assert.Error(t, fillFloatVecFieldData(m, path, f, index, offset, endian))
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_fillBoolFieldData(t *testing.T) {
|
|
|
|
var m storage.ChunkManager
|
|
|
|
|
|
|
|
offset := int64(100)
|
|
|
|
m = newMockChunkManager(withReadBool(offset))
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
f := newScalarFieldData(schemapb.DataType_Bool, simpleBoolField.fieldName, 1)
|
2022-03-30 21:11:28 +08:00
|
|
|
|
|
|
|
path := funcutil.GenRandomStr()
|
|
|
|
index := 0
|
|
|
|
endian := common.Endian
|
|
|
|
|
|
|
|
assert.NoError(t, fillBoolFieldData(m, path, f, index, offset, endian))
|
|
|
|
|
|
|
|
m = newMockChunkManager(withReadErr())
|
|
|
|
assert.Error(t, fillBoolFieldData(m, path, f, index, offset, endian))
|
|
|
|
|
|
|
|
m = newMockChunkManager(withReadIllegalBool())
|
|
|
|
assert.Error(t, fillBoolFieldData(m, path, f, index, offset, endian))
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_fillStringFieldData(t *testing.T) {
|
|
|
|
var m storage.ChunkManager
|
|
|
|
|
|
|
|
offset := int64(100)
|
|
|
|
m = newMockChunkManager(withReadString(offset))
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
f := newScalarFieldData(schemapb.DataType_VarChar, simpleVarCharField.fieldName, 1)
|
2022-03-30 21:11:28 +08:00
|
|
|
|
|
|
|
path := funcutil.GenRandomStr()
|
|
|
|
index := 0
|
|
|
|
endian := common.Endian
|
|
|
|
|
|
|
|
assert.NoError(t, fillStringFieldData(m, path, f, index, offset, endian))
|
|
|
|
|
|
|
|
m = newMockChunkManager(withReadErr())
|
|
|
|
assert.Error(t, fillStringFieldData(m, path, f, index, offset, endian))
|
|
|
|
|
|
|
|
m = newMockChunkManager(withReadIllegalString())
|
|
|
|
assert.Error(t, fillStringFieldData(m, path, f, index, offset, endian))
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_fillInt8FieldData(t *testing.T) {
|
|
|
|
var m storage.ChunkManager
|
|
|
|
|
|
|
|
offset := int64(100)
|
|
|
|
m = newMockChunkManager(withDefaultReadAt())
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
f := newScalarFieldData(schemapb.DataType_Int8, simpleInt8Field.fieldName, 1)
|
2022-03-30 21:11:28 +08:00
|
|
|
|
|
|
|
path := funcutil.GenRandomStr()
|
|
|
|
index := 0
|
|
|
|
endian := common.Endian
|
|
|
|
|
|
|
|
assert.NoError(t, fillInt8FieldData(m, path, f, index, offset, endian))
|
|
|
|
|
|
|
|
m = newMockChunkManager(withReadAtErr())
|
|
|
|
assert.Error(t, fillInt8FieldData(m, path, f, index, offset, endian))
|
|
|
|
|
|
|
|
m = newMockChunkManager(withReadAtEmptyContent())
|
|
|
|
assert.Error(t, fillInt8FieldData(m, path, f, index, offset, endian))
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_fillInt16FieldData(t *testing.T) {
|
|
|
|
var m storage.ChunkManager
|
|
|
|
|
|
|
|
offset := int64(100)
|
|
|
|
m = newMockChunkManager(withDefaultReadAt())
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
f := newScalarFieldData(schemapb.DataType_Int16, simpleInt64Field.fieldName, 1)
|
2022-03-30 21:11:28 +08:00
|
|
|
|
|
|
|
path := funcutil.GenRandomStr()
|
|
|
|
index := 0
|
|
|
|
endian := common.Endian
|
|
|
|
|
|
|
|
assert.NoError(t, fillInt16FieldData(m, path, f, index, offset, endian))
|
|
|
|
|
|
|
|
m = newMockChunkManager(withReadAtErr())
|
|
|
|
assert.Error(t, fillInt16FieldData(m, path, f, index, offset, endian))
|
|
|
|
|
|
|
|
m = newMockChunkManager(withReadAtEmptyContent())
|
|
|
|
assert.Error(t, fillInt16FieldData(m, path, f, index, offset, endian))
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_fillInt32FieldData(t *testing.T) {
|
|
|
|
var m storage.ChunkManager
|
|
|
|
|
|
|
|
offset := int64(100)
|
|
|
|
m = newMockChunkManager(withDefaultReadAt())
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
f := newScalarFieldData(schemapb.DataType_Int32, simpleInt32Field.fieldName, 1)
|
2022-03-30 21:11:28 +08:00
|
|
|
|
|
|
|
path := funcutil.GenRandomStr()
|
|
|
|
index := 0
|
|
|
|
endian := common.Endian
|
|
|
|
|
|
|
|
assert.NoError(t, fillInt32FieldData(m, path, f, index, offset, endian))
|
|
|
|
|
|
|
|
m = newMockChunkManager(withReadAtErr())
|
|
|
|
assert.Error(t, fillInt32FieldData(m, path, f, index, offset, endian))
|
|
|
|
|
|
|
|
m = newMockChunkManager(withReadAtEmptyContent())
|
|
|
|
assert.Error(t, fillInt32FieldData(m, path, f, index, offset, endian))
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_fillInt64FieldData(t *testing.T) {
|
|
|
|
var m storage.ChunkManager
|
|
|
|
|
|
|
|
offset := int64(100)
|
|
|
|
m = newMockChunkManager(withDefaultReadAt())
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
f := newScalarFieldData(schemapb.DataType_Int64, simpleInt64Field.fieldName, 1)
|
2022-03-30 21:11:28 +08:00
|
|
|
|
|
|
|
path := funcutil.GenRandomStr()
|
|
|
|
index := 0
|
|
|
|
endian := common.Endian
|
|
|
|
|
|
|
|
assert.NoError(t, fillInt64FieldData(m, path, f, index, offset, endian))
|
|
|
|
|
|
|
|
m = newMockChunkManager(withReadAtErr())
|
|
|
|
assert.Error(t, fillInt64FieldData(m, path, f, index, offset, endian))
|
|
|
|
|
|
|
|
m = newMockChunkManager(withReadAtEmptyContent())
|
|
|
|
assert.Error(t, fillInt64FieldData(m, path, f, index, offset, endian))
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_fillFloatFieldData(t *testing.T) {
|
|
|
|
var m storage.ChunkManager
|
|
|
|
|
|
|
|
offset := int64(100)
|
|
|
|
m = newMockChunkManager(withDefaultReadAt())
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
f := newScalarFieldData(schemapb.DataType_Float, simpleFloatField.fieldName, 1)
|
2022-03-30 21:11:28 +08:00
|
|
|
|
|
|
|
path := funcutil.GenRandomStr()
|
|
|
|
index := 0
|
|
|
|
endian := common.Endian
|
|
|
|
|
|
|
|
assert.NoError(t, fillFloatFieldData(m, path, f, index, offset, endian))
|
|
|
|
|
|
|
|
m = newMockChunkManager(withReadAtErr())
|
|
|
|
assert.Error(t, fillFloatFieldData(m, path, f, index, offset, endian))
|
|
|
|
|
|
|
|
m = newMockChunkManager(withReadAtEmptyContent())
|
|
|
|
assert.Error(t, fillFloatFieldData(m, path, f, index, offset, endian))
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_fillDoubleFieldData(t *testing.T) {
|
|
|
|
var m storage.ChunkManager
|
|
|
|
|
|
|
|
offset := int64(100)
|
|
|
|
m = newMockChunkManager(withDefaultReadAt())
|
|
|
|
|
2022-04-29 13:35:49 +08:00
|
|
|
f := newScalarFieldData(schemapb.DataType_Double, simpleDoubleField.fieldName, 1)
|
2022-03-30 21:11:28 +08:00
|
|
|
|
|
|
|
path := funcutil.GenRandomStr()
|
|
|
|
index := 0
|
|
|
|
endian := common.Endian
|
|
|
|
|
|
|
|
assert.NoError(t, fillDoubleFieldData(m, path, f, index, offset, endian))
|
|
|
|
|
|
|
|
m = newMockChunkManager(withReadAtErr())
|
|
|
|
assert.Error(t, fillDoubleFieldData(m, path, f, index, offset, endian))
|
|
|
|
|
|
|
|
m = newMockChunkManager(withReadAtEmptyContent())
|
|
|
|
assert.Error(t, fillDoubleFieldData(m, path, f, index, offset, endian))
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_fillFieldData(t *testing.T) {
|
|
|
|
var m storage.ChunkManager
|
|
|
|
|
|
|
|
fs := []*schemapb.FieldData{
|
2022-04-29 13:35:49 +08:00
|
|
|
newBinaryVectorFieldData(simpleBinVecField.fieldName, 1, 8),
|
|
|
|
newFloatVectorFieldData(simpleFloatVecField.fieldName, 1, 8),
|
|
|
|
newScalarFieldData(schemapb.DataType_Bool, simpleBoolField.fieldName, 1),
|
|
|
|
newScalarFieldData(schemapb.DataType_VarChar, simpleVarCharField.fieldName, 1),
|
|
|
|
newScalarFieldData(schemapb.DataType_Int8, simpleInt8Field.fieldName, 1),
|
|
|
|
newScalarFieldData(schemapb.DataType_Int16, simpleInt16Field.fieldName, 1),
|
|
|
|
newScalarFieldData(schemapb.DataType_Int32, simpleInt32Field.fieldName, 1),
|
|
|
|
newScalarFieldData(schemapb.DataType_Int64, simpleInt64Field.fieldName, 1),
|
|
|
|
newScalarFieldData(schemapb.DataType_Float, simpleFloatField.fieldName, 1),
|
|
|
|
newScalarFieldData(schemapb.DataType_Double, simpleDoubleField.fieldName, 1),
|
2022-03-30 21:11:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
offset := int64(100)
|
|
|
|
path := funcutil.GenRandomStr()
|
|
|
|
index := 0
|
|
|
|
endian := common.Endian
|
|
|
|
|
|
|
|
for _, f := range fs {
|
|
|
|
if f.Type == schemapb.DataType_Bool {
|
|
|
|
m = newMockChunkManager(withReadBool(offset))
|
|
|
|
} else if funcutil.SliceContain([]schemapb.DataType{
|
|
|
|
schemapb.DataType_String,
|
|
|
|
schemapb.DataType_VarChar,
|
|
|
|
}, f.Type) {
|
|
|
|
m = newMockChunkManager(withReadString(offset))
|
|
|
|
} else {
|
|
|
|
m = newMockChunkManager(withDefaultReadAt())
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.NoError(t, fillFieldData(m, path, f, index, offset, endian))
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Error(t, fillFieldData(m, path, &schemapb.FieldData{Type: schemapb.DataType_None}, index, offset, endian))
|
|
|
|
}
|
2022-04-02 17:43:29 +08:00
|
|
|
|
|
|
|
func TestUpdateBloomFilter(t *testing.T) {
|
|
|
|
t.Run("test int64 pk", func(t *testing.T) {
|
|
|
|
historical, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = historical.addSegment(defaultSegmentID,
|
|
|
|
defaultPartitionID,
|
|
|
|
defaultCollectionID,
|
|
|
|
defaultDMLChannel,
|
|
|
|
segmentTypeSealed,
|
|
|
|
true)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
seg, err := historical.getSegmentByID(defaultSegmentID)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
pkValues := []int64{1, 2}
|
|
|
|
pks := make([]primaryKey, len(pkValues))
|
|
|
|
for index, v := range pkValues {
|
|
|
|
pks[index] = newInt64PrimaryKey(v)
|
|
|
|
}
|
|
|
|
seg.updateBloomFilter(pks)
|
|
|
|
buf := make([]byte, 8)
|
|
|
|
for _, v := range pkValues {
|
|
|
|
common.Endian.PutUint64(buf, uint64(v))
|
|
|
|
assert.True(t, seg.pkFilter.Test(buf))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("test string pk", func(t *testing.T) {
|
|
|
|
historical, err := genSimpleReplica()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = historical.addSegment(defaultSegmentID,
|
|
|
|
defaultPartitionID,
|
|
|
|
defaultCollectionID,
|
|
|
|
defaultDMLChannel,
|
|
|
|
segmentTypeSealed,
|
|
|
|
true)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
seg, err := historical.getSegmentByID(defaultSegmentID)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
pkValues := []string{"test1", "test2"}
|
|
|
|
pks := make([]primaryKey, len(pkValues))
|
|
|
|
for index, v := range pkValues {
|
|
|
|
pks[index] = newVarCharPrimaryKey(v)
|
|
|
|
}
|
|
|
|
seg.updateBloomFilter(pks)
|
|
|
|
for _, v := range pkValues {
|
|
|
|
assert.True(t, seg.pkFilter.TestString(v))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|