2021-12-03 19:29:33 +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-09-10 17:11:09 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-12-03 19:29:33 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-09-10 17:11:09 +08:00
|
|
|
//
|
2021-12-03 19:29:33 +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-09-10 17:11:09 +08:00
|
|
|
|
|
|
|
package querynode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIndexLoader_setIndexInfo(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
t.Run("test setIndexInfo", func(t *testing.T) {
|
2021-11-12 18:27:10 +08:00
|
|
|
node, err := genSimpleQueryNode(ctx)
|
2021-09-10 17:11:09 +08:00
|
|
|
assert.NoError(t, err)
|
2021-11-12 18:27:10 +08:00
|
|
|
loader := node.loader
|
|
|
|
assert.NotNil(t, loader)
|
2021-09-10 17:11:09 +08:00
|
|
|
|
|
|
|
segment, err := genSimpleSealedSegment()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-11-12 18:27:10 +08:00
|
|
|
loader.indexLoader.rootCoord = newMockRootCoord()
|
|
|
|
loader.indexLoader.indexCoord = newMockIndexCoord()
|
2021-09-10 17:11:09 +08:00
|
|
|
|
2021-12-03 11:29:33 +08:00
|
|
|
info, err := loader.indexLoader.getIndexInfo(defaultCollectionID, segment)
|
2021-09-10 17:11:09 +08:00
|
|
|
assert.NoError(t, err)
|
2021-12-03 11:29:33 +08:00
|
|
|
loader.indexLoader.setIndexInfo(segment, info)
|
2021-09-10 17:11:09 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test nil root and index", func(t *testing.T) {
|
2021-11-12 18:27:10 +08:00
|
|
|
node, err := genSimpleQueryNode(ctx)
|
2021-09-10 17:11:09 +08:00
|
|
|
assert.NoError(t, err)
|
2021-11-12 18:27:10 +08:00
|
|
|
loader := node.loader
|
|
|
|
assert.NotNil(t, loader)
|
2021-09-10 17:11:09 +08:00
|
|
|
|
|
|
|
segment, err := genSimpleSealedSegment()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-12-03 11:29:33 +08:00
|
|
|
info, err := loader.indexLoader.getIndexInfo(defaultCollectionID, segment)
|
2021-09-14 10:24:48 +08:00
|
|
|
assert.NoError(t, err)
|
2021-12-03 11:29:33 +08:00
|
|
|
loader.indexLoader.setIndexInfo(segment, info)
|
2021-09-10 17:11:09 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIndexLoader_getIndexBinlog(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
t.Run("test getIndexBinlog", func(t *testing.T) {
|
2021-11-12 18:27:10 +08:00
|
|
|
node, err := genSimpleQueryNode(ctx)
|
2021-09-10 17:11:09 +08:00
|
|
|
assert.NoError(t, err)
|
2021-11-12 18:27:10 +08:00
|
|
|
loader := node.loader
|
|
|
|
assert.NotNil(t, loader)
|
2021-09-10 17:11:09 +08:00
|
|
|
|
|
|
|
paths, err := generateIndex(defaultSegmentID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-11-12 18:27:10 +08:00
|
|
|
_, _, _, err = loader.indexLoader.getIndexBinlog(paths)
|
2021-09-10 17:11:09 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test invalid path", func(t *testing.T) {
|
2021-11-12 18:27:10 +08:00
|
|
|
node, err := genSimpleQueryNode(ctx)
|
2021-09-10 17:11:09 +08:00
|
|
|
assert.NoError(t, err)
|
2021-11-12 18:27:10 +08:00
|
|
|
loader := node.loader
|
|
|
|
assert.NotNil(t, loader)
|
2021-09-10 17:11:09 +08:00
|
|
|
|
2021-11-12 18:27:10 +08:00
|
|
|
_, _, _, err = loader.indexLoader.getIndexBinlog([]string{""})
|
2021-09-10 17:11:09 +08:00
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIndexLoader_printIndexParams(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2021-11-12 18:27:10 +08:00
|
|
|
node, err := genSimpleQueryNode(ctx)
|
2021-09-10 17:11:09 +08:00
|
|
|
assert.NoError(t, err)
|
2021-11-12 18:27:10 +08:00
|
|
|
loader := node.loader
|
|
|
|
assert.NotNil(t, loader)
|
2021-09-10 17:11:09 +08:00
|
|
|
|
|
|
|
indexKV := []*commonpb.KeyValuePair{
|
|
|
|
{
|
|
|
|
Key: "test-key-0",
|
|
|
|
Value: "test-value-0",
|
|
|
|
},
|
|
|
|
}
|
2021-11-12 18:27:10 +08:00
|
|
|
loader.indexLoader.printIndexParams(indexKV)
|
2021-09-10 17:11:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestIndexLoader_loadIndex(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
t.Run("test loadIndex", func(t *testing.T) {
|
2021-11-12 18:27:10 +08:00
|
|
|
node, err := genSimpleQueryNode(ctx)
|
2021-09-10 17:11:09 +08:00
|
|
|
assert.NoError(t, err)
|
2021-11-12 18:27:10 +08:00
|
|
|
loader := node.loader
|
|
|
|
assert.NotNil(t, loader)
|
2021-09-10 17:11:09 +08:00
|
|
|
|
|
|
|
segment, err := genSimpleSealedSegment()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-11-12 18:27:10 +08:00
|
|
|
loader.indexLoader.rootCoord = newMockRootCoord()
|
|
|
|
loader.indexLoader.indexCoord = newMockIndexCoord()
|
2021-09-10 17:11:09 +08:00
|
|
|
|
2021-12-03 11:29:33 +08:00
|
|
|
info, err := loader.indexLoader.getIndexInfo(defaultCollectionID, segment)
|
2021-09-10 17:11:09 +08:00
|
|
|
assert.NoError(t, err)
|
2021-12-03 11:29:33 +08:00
|
|
|
loader.indexLoader.setIndexInfo(segment, info)
|
2021-09-10 17:11:09 +08:00
|
|
|
|
2021-11-12 18:27:10 +08:00
|
|
|
err = loader.indexLoader.loadIndex(segment, simpleVecField.id)
|
2021-09-14 10:21:08 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-10 17:11:09 +08:00
|
|
|
})
|
|
|
|
|
2021-12-03 11:29:33 +08:00
|
|
|
t.Run("test get indexinfo with empty indexFilePath", func(t *testing.T) {
|
2021-11-12 18:27:10 +08:00
|
|
|
node, err := genSimpleQueryNode(ctx)
|
2021-10-27 17:12:30 +08:00
|
|
|
assert.NoError(t, err)
|
2021-11-12 18:27:10 +08:00
|
|
|
loader := node.loader
|
|
|
|
assert.NotNil(t, loader)
|
2021-10-27 17:12:30 +08:00
|
|
|
|
|
|
|
segment, err := genSimpleSealedSegment()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-11-12 18:27:10 +08:00
|
|
|
loader.indexLoader.rootCoord = newMockRootCoord()
|
2021-10-27 17:12:30 +08:00
|
|
|
ic := newMockIndexCoord()
|
|
|
|
ic.idxFileInfo.IndexFilePaths = []string{}
|
|
|
|
|
2021-11-12 18:27:10 +08:00
|
|
|
loader.indexLoader.indexCoord = ic
|
2021-10-27 17:12:30 +08:00
|
|
|
|
2021-12-03 11:29:33 +08:00
|
|
|
_, err = loader.indexLoader.getIndexInfo(defaultCollectionID, segment)
|
2021-10-27 17:12:30 +08:00
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
|
2021-09-13 16:37:01 +08:00
|
|
|
//t.Run("test get index failed", func(t *testing.T) {
|
|
|
|
// historical, err := genSimpleHistorical(ctx)
|
|
|
|
// assert.NoError(t, err)
|
|
|
|
//
|
|
|
|
// segment, err := genSimpleSealedSegment()
|
|
|
|
// assert.NoError(t, err)
|
|
|
|
//
|
|
|
|
// historical.loader.indexLoader.rootCoord = newMockRootCoord()
|
|
|
|
// historical.loader.indexLoader.indexCoord = newMockIndexCoord()
|
|
|
|
//
|
|
|
|
// err = historical.loader.indexLoader.loadIndex(segment, rowIDFieldID)
|
|
|
|
// assert.Error(t, err)
|
|
|
|
//})
|
2021-09-10 17:11:09 +08:00
|
|
|
|
|
|
|
t.Run("test checkIndexReady failed", func(t *testing.T) {
|
2021-11-12 18:27:10 +08:00
|
|
|
node, err := genSimpleQueryNode(ctx)
|
2021-09-10 17:11:09 +08:00
|
|
|
assert.NoError(t, err)
|
2021-11-12 18:27:10 +08:00
|
|
|
loader := node.loader
|
|
|
|
assert.NotNil(t, loader)
|
2021-09-10 17:11:09 +08:00
|
|
|
|
|
|
|
segment, err := genSimpleSealedSegment()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-11-12 18:27:10 +08:00
|
|
|
loader.indexLoader.rootCoord = newMockRootCoord()
|
|
|
|
loader.indexLoader.indexCoord = newMockIndexCoord()
|
2021-09-10 17:11:09 +08:00
|
|
|
|
2021-12-03 11:29:33 +08:00
|
|
|
info, err := loader.indexLoader.getIndexInfo(defaultCollectionID, segment)
|
2021-09-10 17:11:09 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-12-03 11:29:33 +08:00
|
|
|
vecFieldID := UniqueID(101)
|
|
|
|
info.setFieldID(vecFieldID)
|
|
|
|
loader.indexLoader.setIndexInfo(segment, info)
|
2021-09-10 17:11:09 +08:00
|
|
|
|
2021-12-03 11:29:33 +08:00
|
|
|
segment.indexInfos[vecFieldID].setReadyLoad(false)
|
|
|
|
err = loader.indexLoader.loadIndex(segment, vecFieldID)
|
2021-09-10 17:11:09 +08:00
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
}
|