2021-04-19 13:47:10 +08:00
|
|
|
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
|
|
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
// or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
|
|
|
2021-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 (
|
|
|
|
"encoding/binary"
|
2020-11-17 10:07:42 +08:00
|
|
|
"log"
|
2020-11-12 12:04:12 +08:00
|
|
|
"math"
|
|
|
|
"testing"
|
|
|
|
|
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-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/milvuspb"
|
2021-06-04 10:38:34 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/schemapb"
|
2021-06-15 14:43:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/segcorepb"
|
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)
|
2021-02-03 11:52:19 +08:00
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
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)
|
2021-06-15 12:41:40 +08:00
|
|
|
segment := newSegment(collection, segmentID, defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
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)
|
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)
|
2021-02-03 11:52:19 +08:00
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
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)
|
2021-06-15 12:41:40 +08:00
|
|
|
segment := newSegment(collection, segmentID, defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.Equal(t, segmentID, segment.segmentID)
|
|
|
|
|
|
|
|
deleteSegment(segment)
|
2020-11-24 20:14:51 +08:00
|
|
|
deleteCollection(collection)
|
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)
|
2021-02-03 11:52:19 +08:00
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
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)
|
2021-06-15 12:41:40 +08:00
|
|
|
segment := newSegment(collection, segmentID, defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.Equal(t, segmentID, segment.segmentID)
|
|
|
|
|
|
|
|
ids := []int64{1, 2, 3}
|
|
|
|
timestamps := []uint64{0, 0, 0}
|
|
|
|
|
|
|
|
const DIM = 16
|
|
|
|
const N = 3
|
|
|
|
var vec = [DIM]float32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
|
|
|
|
var rawData []byte
|
|
|
|
for _, ele := range vec {
|
|
|
|
buf := make([]byte, 4)
|
|
|
|
binary.LittleEndian.PutUint32(buf, math.Float32bits(ele))
|
|
|
|
rawData = append(rawData, buf...)
|
|
|
|
}
|
|
|
|
bs := make([]byte, 4)
|
|
|
|
binary.LittleEndian.PutUint32(bs, 1)
|
|
|
|
rawData = append(rawData, bs...)
|
|
|
|
var records []*commonpb.Blob
|
|
|
|
for i := 0; i < N; i++ {
|
|
|
|
blob := &commonpb.Blob{
|
|
|
|
Value: rawData,
|
|
|
|
}
|
|
|
|
records = append(records, blob)
|
|
|
|
}
|
|
|
|
|
2021-03-12 19:23:06 +08:00
|
|
|
offset, err := segment.segmentPreInsert(N)
|
|
|
|
assert.Nil(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.GreaterOrEqual(t, offset, int64(0))
|
|
|
|
|
2021-03-12 19:23:06 +08:00
|
|
|
err = segment.segmentInsert(offset, &ids, ×tamps, &records)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
rowCount := segment.getRowCount()
|
|
|
|
assert.Equal(t, int64(N), rowCount)
|
2020-11-24 20:14:51 +08:00
|
|
|
|
|
|
|
deleteSegment(segment)
|
|
|
|
deleteCollection(collection)
|
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)
|
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
|
|
|
|
|
|
|
collection := newCollection(collectionMeta.ID, collectionMeta.Schema)
|
|
|
|
assert.Equal(t, collection.ID(), collectionID)
|
|
|
|
|
|
|
|
segmentID := UniqueID(0)
|
2021-06-15 12:41:40 +08:00
|
|
|
segment := newSegment(collection, segmentID, defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2021-06-04 10:38:34 +08:00
|
|
|
assert.Equal(t, segmentID, segment.segmentID)
|
|
|
|
|
|
|
|
ids := []int64{}
|
|
|
|
timestamps := []Timestamp{}
|
|
|
|
const DIM = 16
|
|
|
|
const N = 100
|
|
|
|
var records []*commonpb.Blob
|
|
|
|
for i := 0; i < N; i++ {
|
|
|
|
ids = append(ids, int64(i))
|
|
|
|
timestamps = append(timestamps, 0)
|
|
|
|
var vec = [DIM]float32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
|
|
|
|
var rawData []byte
|
|
|
|
for _, ele := range vec {
|
|
|
|
buf := make([]byte, 4)
|
|
|
|
binary.LittleEndian.PutUint32(buf, math.Float32bits(ele+float32(i)*float32(N)))
|
|
|
|
rawData = append(rawData, buf...)
|
|
|
|
}
|
|
|
|
bs := make([]byte, 4)
|
|
|
|
binary.LittleEndian.PutUint32(bs, 1)
|
|
|
|
rawData = append(rawData, bs...)
|
|
|
|
blob := &commonpb.Blob{
|
|
|
|
Value: rawData,
|
|
|
|
}
|
|
|
|
records = append(records, blob)
|
|
|
|
}
|
|
|
|
offset, err := segment.segmentPreInsert(N)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, offset, int64(0))
|
|
|
|
err = segment.segmentInsert(offset, &ids, ×tamps, &records)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-06-15 14:43:57 +08:00
|
|
|
reqIds := &segcorepb.RetrieveRequest{
|
2021-06-04 10:38:34 +08:00
|
|
|
Ids: &schemapb.IDs{
|
|
|
|
IdField: &schemapb.IDs_IntId{
|
|
|
|
IntId: &schemapb.LongArray{
|
|
|
|
Data: []int64{2, 3, 1},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
OutputFields: []string{"vec"},
|
|
|
|
}
|
|
|
|
plan, err := createRetrievePlan(collection, reqIds, 100)
|
|
|
|
defer plan.delete()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
res, err := segment.segmentGetEntityByIds(plan)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, res.Ids.GetIntId().Data, []int64{2, 3, 1})
|
|
|
|
}
|
|
|
|
|
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)
|
2021-02-03 11:52:19 +08:00
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
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)
|
2021-06-15 12:41:40 +08:00
|
|
|
segment := newSegment(collection, segmentID, defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.Equal(t, segmentID, segment.segmentID)
|
|
|
|
|
|
|
|
ids := []int64{1, 2, 3}
|
|
|
|
timestamps := []uint64{0, 0, 0}
|
|
|
|
|
|
|
|
const DIM = 16
|
|
|
|
const N = 3
|
|
|
|
var vec = [DIM]float32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
|
|
|
|
var rawData []byte
|
|
|
|
for _, ele := range vec {
|
|
|
|
buf := make([]byte, 4)
|
|
|
|
binary.LittleEndian.PutUint32(buf, math.Float32bits(ele))
|
|
|
|
rawData = append(rawData, buf...)
|
|
|
|
}
|
|
|
|
bs := make([]byte, 4)
|
|
|
|
binary.LittleEndian.PutUint32(bs, 1)
|
|
|
|
rawData = append(rawData, bs...)
|
|
|
|
var records []*commonpb.Blob
|
|
|
|
for i := 0; i < N; i++ {
|
|
|
|
blob := &commonpb.Blob{
|
|
|
|
Value: rawData,
|
|
|
|
}
|
|
|
|
records = append(records, blob)
|
|
|
|
}
|
|
|
|
|
2021-03-12 19:23:06 +08:00
|
|
|
offsetInsert, err := segment.segmentPreInsert(N)
|
|
|
|
assert.Nil(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.GreaterOrEqual(t, offsetInsert, int64(0))
|
|
|
|
|
2021-03-12 19:23:06 +08:00
|
|
|
err = segment.segmentInsert(offsetInsert, &ids, ×tamps, &records)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
var offsetDelete = segment.segmentPreDelete(10)
|
|
|
|
assert.GreaterOrEqual(t, offsetDelete, int64(0))
|
|
|
|
|
|
|
|
err = segment.segmentDelete(offsetDelete, &ids, ×tamps)
|
|
|
|
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)
|
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)
|
2021-02-03 11:52:19 +08:00
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
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)
|
2021-06-15 12:41:40 +08:00
|
|
|
segment := newSegment(collection, segmentID, defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.Equal(t, segmentID, segment.segmentID)
|
|
|
|
|
|
|
|
ids := []int64{1, 2, 3}
|
|
|
|
timestamps := []uint64{0, 0, 0}
|
|
|
|
|
|
|
|
const DIM = 16
|
|
|
|
const N = 3
|
|
|
|
var vec = [DIM]float32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
|
|
|
|
var rawData []byte
|
|
|
|
for _, ele := range vec {
|
|
|
|
buf := make([]byte, 4)
|
|
|
|
binary.LittleEndian.PutUint32(buf, math.Float32bits(ele))
|
|
|
|
rawData = append(rawData, buf...)
|
|
|
|
}
|
|
|
|
bs := make([]byte, 4)
|
|
|
|
binary.LittleEndian.PutUint32(bs, 1)
|
|
|
|
rawData = append(rawData, bs...)
|
|
|
|
var records []*commonpb.Blob
|
|
|
|
for i := 0; i < N; i++ {
|
|
|
|
blob := &commonpb.Blob{
|
|
|
|
Value: rawData,
|
|
|
|
}
|
|
|
|
records = append(records, blob)
|
|
|
|
}
|
|
|
|
|
2021-03-12 19:23:06 +08:00
|
|
|
offset, err := segment.segmentPreInsert(N)
|
|
|
|
assert.Nil(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.GreaterOrEqual(t, offset, int64(0))
|
|
|
|
|
2021-03-12 19:23:06 +08:00
|
|
|
err = segment.segmentInsert(offset, &ids, ×tamps, &records)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
var memSize = segment.getMemSize()
|
|
|
|
assert.Equal(t, memSize, int64(2785280))
|
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)
|
2021-02-03 11:52:19 +08:00
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
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)
|
2021-06-15 12:41:40 +08:00
|
|
|
segment := newSegment(collection, segmentID, defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.Equal(t, segmentID, segment.segmentID)
|
|
|
|
|
|
|
|
ids := []int64{1, 2, 3}
|
|
|
|
timestamps := []uint64{0, 0, 0}
|
|
|
|
|
|
|
|
const DIM = 16
|
|
|
|
const N = 3
|
|
|
|
var vec = [DIM]float32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
|
|
|
|
var rawData []byte
|
|
|
|
for _, ele := range vec {
|
|
|
|
buf := make([]byte, 4)
|
|
|
|
binary.LittleEndian.PutUint32(buf, math.Float32bits(ele))
|
|
|
|
rawData = append(rawData, buf...)
|
|
|
|
}
|
|
|
|
bs := make([]byte, 4)
|
|
|
|
binary.LittleEndian.PutUint32(bs, 1)
|
|
|
|
rawData = append(rawData, bs...)
|
|
|
|
var records []*commonpb.Blob
|
|
|
|
for i := 0; i < N; i++ {
|
|
|
|
blob := &commonpb.Blob{
|
|
|
|
Value: rawData,
|
|
|
|
}
|
|
|
|
records = append(records, blob)
|
|
|
|
}
|
|
|
|
|
2021-03-12 19:23:06 +08:00
|
|
|
offset, err := segment.segmentPreInsert(N)
|
|
|
|
assert.Nil(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.GreaterOrEqual(t, offset, int64(0))
|
|
|
|
|
2021-03-12 19:23:06 +08:00
|
|
|
err = segment.segmentInsert(offset, &ids, ×tamps, &records)
|
2020-11-25 16:24:57 +08:00
|
|
|
assert.NoError(t, err)
|
2020-11-24 20:14:51 +08:00
|
|
|
deleteSegment(segment)
|
|
|
|
deleteCollection(collection)
|
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)
|
2021-02-03 11:52:19 +08:00
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
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)
|
2021-06-15 12:41:40 +08:00
|
|
|
segment := newSegment(collection, segmentID, defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.Equal(t, segmentID, segment.segmentID)
|
|
|
|
|
|
|
|
ids := []int64{1, 2, 3}
|
|
|
|
timestamps := []uint64{0, 0, 0}
|
|
|
|
|
|
|
|
const DIM = 16
|
|
|
|
const N = 3
|
|
|
|
var vec = [DIM]float32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
|
|
|
|
var rawData []byte
|
|
|
|
for _, ele := range vec {
|
|
|
|
buf := make([]byte, 4)
|
|
|
|
binary.LittleEndian.PutUint32(buf, math.Float32bits(ele))
|
|
|
|
rawData = append(rawData, buf...)
|
|
|
|
}
|
|
|
|
bs := make([]byte, 4)
|
|
|
|
binary.LittleEndian.PutUint32(bs, 1)
|
|
|
|
rawData = append(rawData, bs...)
|
|
|
|
var records []*commonpb.Blob
|
|
|
|
for i := 0; i < N; i++ {
|
|
|
|
blob := &commonpb.Blob{
|
|
|
|
Value: rawData,
|
|
|
|
}
|
|
|
|
records = append(records, blob)
|
|
|
|
}
|
|
|
|
|
2021-03-12 19:23:06 +08:00
|
|
|
offsetInsert, err := segment.segmentPreInsert(N)
|
|
|
|
assert.Nil(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.GreaterOrEqual(t, offsetInsert, int64(0))
|
|
|
|
|
2021-03-12 19:23:06 +08:00
|
|
|
err = segment.segmentInsert(offsetInsert, &ids, ×tamps, &records)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
var offsetDelete = segment.segmentPreDelete(10)
|
|
|
|
assert.GreaterOrEqual(t, offsetDelete, int64(0))
|
|
|
|
|
|
|
|
err = segment.segmentDelete(offsetDelete, &ids, ×tamps)
|
|
|
|
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) {
|
2020-12-08 14:41:04 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
2020-11-17 10:07:42 +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-17 10:07:42 +08:00
|
|
|
|
|
|
|
segmentID := UniqueID(0)
|
2021-06-15 12:41:40 +08:00
|
|
|
segment := newSegment(collection, segmentID, defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-17 10:07:42 +08:00
|
|
|
assert.Equal(t, segmentID, segment.segmentID)
|
|
|
|
|
|
|
|
ids := []int64{1, 2, 3}
|
|
|
|
timestamps := []uint64{0, 0, 0}
|
|
|
|
|
|
|
|
const DIM = 16
|
|
|
|
const N = 3
|
|
|
|
var vec = [DIM]float32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
|
|
|
|
var rawData []byte
|
|
|
|
for _, ele := range vec {
|
|
|
|
buf := make([]byte, 4)
|
|
|
|
binary.LittleEndian.PutUint32(buf, math.Float32bits(ele))
|
|
|
|
rawData = append(rawData, buf...)
|
|
|
|
}
|
|
|
|
bs := make([]byte, 4)
|
|
|
|
binary.LittleEndian.PutUint32(bs, 1)
|
|
|
|
rawData = append(rawData, bs...)
|
|
|
|
var records []*commonpb.Blob
|
|
|
|
for i := 0; i < N; i++ {
|
|
|
|
blob := &commonpb.Blob{
|
|
|
|
Value: rawData,
|
|
|
|
}
|
|
|
|
records = append(records, blob)
|
|
|
|
}
|
|
|
|
|
2021-03-12 19:23:06 +08:00
|
|
|
offset, err := segment.segmentPreInsert(N)
|
|
|
|
assert.Nil(t, err)
|
2020-11-17 10:07:42 +08:00
|
|
|
assert.GreaterOrEqual(t, offset, int64(0))
|
|
|
|
|
2021-03-12 19:23:06 +08:00
|
|
|
err = segment.segmentInsert(offset, &ids, ×tamps, &records)
|
2020-11-17 10:07:42 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
dslString := "{\"bool\": { \n\"vector\": {\n \"vec\": {\n \"metric_type\": \"L2\", \n \"params\": {\n \"nprobe\": 10 \n},\n \"query\": \"$0\",\"topk\": 10 \n } \n } \n } \n }"
|
|
|
|
|
|
|
|
var searchRawData []byte
|
|
|
|
for _, ele := range vec {
|
|
|
|
buf := make([]byte, 4)
|
|
|
|
binary.LittleEndian.PutUint32(buf, math.Float32bits(ele))
|
|
|
|
searchRawData = append(searchRawData, buf...)
|
|
|
|
}
|
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,
|
2020-11-17 10:07:42 +08:00
|
|
|
Values: [][]byte{searchRawData},
|
|
|
|
}
|
|
|
|
|
2021-01-22 09:36:18 +08:00
|
|
|
placeholderGroup := milvuspb.PlaceholderGroup{
|
|
|
|
Placeholders: []*milvuspb.PlaceholderValue{&placeholderValue},
|
2020-11-17 10:07:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
placeHolderGroupBlob, err := proto.Marshal(&placeholderGroup)
|
|
|
|
if err != nil {
|
|
|
|
log.Print("marshal placeholderGroup failed")
|
|
|
|
}
|
|
|
|
|
2021-06-30 21:02:13 +08:00
|
|
|
travelTimestamp := Timestamp(1020)
|
2021-06-15 12:41:40 +08:00
|
|
|
plan, err := createPlan(collection, dslString)
|
2020-11-30 17:58:23 +08:00
|
|
|
assert.NoError(t, err)
|
2021-03-30 22:16:58 +08:00
|
|
|
holder, err := parseSearchRequest(plan, placeHolderGroupBlob)
|
2020-11-30 17:58:23 +08:00
|
|
|
assert.NoError(t, err)
|
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
|
|
|
|
2021-02-20 10:14:03 +08:00
|
|
|
searchResults := make([]*SearchResult, 0)
|
|
|
|
matchedSegments := make([]*Segment, 0)
|
|
|
|
|
2021-06-30 21:02:13 +08:00
|
|
|
searchResult, err := segment.segmentSearch(plan, placeholderGroups, []Timestamp{travelTimestamp})
|
2020-11-26 16:01:31 +08:00
|
|
|
assert.Nil(t, err)
|
2020-11-24 20:14:51 +08:00
|
|
|
|
2021-02-20 10:14:03 +08:00
|
|
|
searchResults = append(searchResults, searchResult)
|
|
|
|
matchedSegments = append(matchedSegments, segment)
|
|
|
|
|
|
|
|
///////////////////////////////////
|
|
|
|
inReduced := make([]bool, len(searchResults))
|
|
|
|
numSegment := int64(len(searchResults))
|
|
|
|
err2 := reduceSearchResults(searchResults, numSegment, inReduced)
|
|
|
|
assert.NoError(t, err2)
|
|
|
|
err = fillTargetEntry(plan, searchResults, matchedSegments, inReduced)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
marshaledHits, err := reorganizeQueryResults(plan, placeholderGroups, searchResults, numSegment, inReduced)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
hitsBlob, err := marshaledHits.getHitsBlob()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
var placeHolderOffset int64 = 0
|
|
|
|
for index := range placeholderGroups {
|
|
|
|
hitBlobSizePeerQuery, err := marshaledHits.hitBlobSizeInGroup(int64(index))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
hits := make([][]byte, 0)
|
|
|
|
for _, len := range hitBlobSizePeerQuery {
|
|
|
|
hits = append(hits, hitsBlob[placeHolderOffset:placeHolderOffset+len])
|
|
|
|
placeHolderOffset += len
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteSearchResults(searchResults)
|
|
|
|
deleteMarshaledHits(marshaledHits)
|
|
|
|
///////////////////////////////////
|
|
|
|
|
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)
|
2021-02-03 11:52:19 +08:00
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
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)
|
2021-06-15 12:41:40 +08:00
|
|
|
segment := newSegment(collection, segmentID, defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.Equal(t, segmentID, segment.segmentID)
|
|
|
|
|
|
|
|
const DIM = 16
|
|
|
|
const N = 3
|
|
|
|
var vec = [DIM]float32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
|
|
|
|
var rawData []byte
|
|
|
|
for _, ele := range vec {
|
|
|
|
buf := make([]byte, 4)
|
|
|
|
binary.LittleEndian.PutUint32(buf, math.Float32bits(ele))
|
|
|
|
rawData = append(rawData, buf...)
|
|
|
|
}
|
|
|
|
bs := make([]byte, 4)
|
|
|
|
binary.LittleEndian.PutUint32(bs, 1)
|
|
|
|
rawData = append(rawData, bs...)
|
|
|
|
var records []*commonpb.Blob
|
|
|
|
for i := 0; i < N; i++ {
|
|
|
|
blob := &commonpb.Blob{
|
|
|
|
Value: rawData,
|
|
|
|
}
|
|
|
|
records = append(records, blob)
|
|
|
|
}
|
|
|
|
|
2021-03-12 19:23:06 +08:00
|
|
|
offset, err := segment.segmentPreInsert(N)
|
|
|
|
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)
|
2021-02-03 11:52:19 +08:00
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
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)
|
2021-06-15 12:41:40 +08:00
|
|
|
segment := newSegment(collection, segmentID, defaultPartitionID, collectionID, "", segmentTypeGrowing, true)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.Equal(t, segmentID, segment.segmentID)
|
|
|
|
|
|
|
|
ids := []int64{1, 2, 3}
|
|
|
|
timestamps := []uint64{0, 0, 0}
|
|
|
|
|
|
|
|
const DIM = 16
|
|
|
|
const N = 3
|
|
|
|
var vec = [DIM]float32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
|
|
|
|
var rawData []byte
|
|
|
|
for _, ele := range vec {
|
|
|
|
buf := make([]byte, 4)
|
|
|
|
binary.LittleEndian.PutUint32(buf, math.Float32bits(ele))
|
|
|
|
rawData = append(rawData, buf...)
|
|
|
|
}
|
|
|
|
bs := make([]byte, 4)
|
|
|
|
binary.LittleEndian.PutUint32(bs, 1)
|
|
|
|
rawData = append(rawData, bs...)
|
|
|
|
var records []*commonpb.Blob
|
|
|
|
for i := 0; i < N; i++ {
|
|
|
|
blob := &commonpb.Blob{
|
|
|
|
Value: rawData,
|
|
|
|
}
|
|
|
|
records = append(records, blob)
|
|
|
|
}
|
|
|
|
|
2021-03-12 19:23:06 +08:00
|
|
|
offsetInsert, err := segment.segmentPreInsert(N)
|
|
|
|
assert.Nil(t, err)
|
2020-11-12 11:18:23 +08:00
|
|
|
assert.GreaterOrEqual(t, offsetInsert, int64(0))
|
|
|
|
|
2021-03-12 19:23:06 +08:00
|
|
|
err = segment.segmentInsert(offsetInsert, &ids, ×tamps, &records)
|
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
|
|
|
|
|
|
|
func TestSegment_segmentLoadFieldData(t *testing.T) {
|
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
2021-01-21 15:20:23 +08:00
|
|
|
|
|
|
|
collection := newCollection(collectionMeta.ID, collectionMeta.Schema)
|
|
|
|
assert.Equal(t, collection.ID(), collectionID)
|
|
|
|
|
|
|
|
segmentID := UniqueID(0)
|
|
|
|
partitionID := UniqueID(0)
|
2021-06-15 12:41:40 +08:00
|
|
|
segment := newSegment(collection, segmentID, partitionID, collectionID, "", segmentTypeSealed, true)
|
2021-01-21 15:20:23 +08:00
|
|
|
assert.Equal(t, segmentID, segment.segmentID)
|
|
|
|
assert.Equal(t, partitionID, segment.partitionID)
|
|
|
|
|
|
|
|
const N = 16
|
|
|
|
var ages = []int32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
|
|
|
|
err := segment.segmentLoadFieldData(101, N, ages)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
deleteSegment(segment)
|
|
|
|
deleteCollection(collection)
|
|
|
|
}
|