2021-10-25 20:13:51 +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 datanode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-03-23 19:43:57 +08:00
|
|
|
"fmt"
|
2021-10-25 20:13:51 +08:00
|
|
|
"path"
|
|
|
|
"testing"
|
2021-11-26 17:43:17 +08:00
|
|
|
"time"
|
2021-10-25 20:13:51 +08:00
|
|
|
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/cockroachdb/errors"
|
2023-03-23 19:43:57 +08:00
|
|
|
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/schemapb"
|
2023-03-23 19:43:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/datanode/allocator"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/storage"
|
|
|
|
"github.com/milvus-io/milvus/pkg/common"
|
|
|
|
"github.com/milvus-io/milvus/pkg/log"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/typeutil"
|
2021-10-25 20:13:51 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2023-03-23 19:43:57 +08:00
|
|
|
"github.com/stretchr/testify/mock"
|
2021-10-25 20:13:51 +08:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2022-03-17 18:03:23 +08:00
|
|
|
var binlogTestDir = "/tmp/milvus_test/test_binlog_io"
|
|
|
|
|
2023-03-23 19:43:57 +08:00
|
|
|
var validGeneratorFn = func(count int, done <-chan struct{}) <-chan UniqueID {
|
|
|
|
ret := make(chan UniqueID, count)
|
|
|
|
for i := 0; i < count; i++ {
|
|
|
|
ret <- int64(100 + i)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2021-10-25 20:13:51 +08:00
|
|
|
func TestBinlogIOInterfaceMethods(t *testing.T) {
|
2022-09-29 16:18:56 +08:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2022-03-17 18:03:23 +08:00
|
|
|
cm := storage.NewLocalChunkManager(storage.RootPath(binlogTestDir))
|
2022-11-21 10:19:10 +08:00
|
|
|
defer cm.RemoveWithPrefix(ctx, cm.RootPath())
|
2021-10-25 20:13:51 +08:00
|
|
|
|
|
|
|
t.Run("Test upload", func(t *testing.T) {
|
|
|
|
f := &MetaFactory{}
|
2022-03-25 14:27:25 +08:00
|
|
|
meta := f.GetCollectionMeta(UniqueID(10001), "uploads", schemapb.DataType_Int64)
|
2021-10-25 20:13:51 +08:00
|
|
|
|
2022-09-25 20:12:52 +08:00
|
|
|
//pkFieldID := int64(106)
|
2021-10-25 20:13:51 +08:00
|
|
|
iData := genInsertData()
|
2022-04-02 17:43:29 +08:00
|
|
|
pk := newInt64PrimaryKey(888)
|
2021-10-25 20:13:51 +08:00
|
|
|
dData := &DeleteData{
|
2021-12-19 20:00:42 +08:00
|
|
|
RowCount: 1,
|
2022-04-02 17:43:29 +08:00
|
|
|
Pks: []primaryKey{pk},
|
2021-12-19 20:00:42 +08:00
|
|
|
Tss: []uint64{666666},
|
2021-10-25 20:13:51 +08:00
|
|
|
}
|
2023-03-23 19:43:57 +08:00
|
|
|
t.Run("Test upload one iData", func(t *testing.T) {
|
|
|
|
alloc := allocator.NewMockAllocator(t)
|
|
|
|
alloc.EXPECT().GetGenerator(mock.Anything, mock.Anything).Call.Return(validGeneratorFn, nil)
|
|
|
|
alloc.EXPECT().AllocOne().Call.Return(int64(11111), nil)
|
|
|
|
|
|
|
|
b := &binlogIO{cm, alloc}
|
|
|
|
p, err := b.upload(context.TODO(), 1, 10, []*InsertData{iData}, dData, meta)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 12, len(p.inPaths))
|
|
|
|
assert.Equal(t, 1, len(p.statsPaths))
|
|
|
|
assert.Equal(t, 1, len(p.inPaths[0].GetBinlogs()))
|
|
|
|
assert.Equal(t, 1, len(p.statsPaths[0].GetBinlogs()))
|
|
|
|
assert.NotNil(t, p.deltaInfo)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test upload two iData", func(t *testing.T) {
|
|
|
|
alloc := allocator.NewMockAllocator(t)
|
|
|
|
alloc.EXPECT().GetGenerator(mock.Anything, mock.Anything).Call.Return(validGeneratorFn, nil)
|
|
|
|
alloc.EXPECT().AllocOne().Call.Return(int64(11111), nil)
|
|
|
|
|
|
|
|
b := &binlogIO{cm, alloc}
|
|
|
|
p, err := b.upload(context.TODO(), 1, 10, []*InsertData{iData, iData}, dData, meta)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 12, len(p.inPaths))
|
|
|
|
assert.Equal(t, 1, len(p.statsPaths))
|
|
|
|
assert.Equal(t, 2, len(p.inPaths[0].GetBinlogs()))
|
|
|
|
assert.Equal(t, 2, len(p.statsPaths[0].GetBinlogs()))
|
|
|
|
assert.NotNil(t, p.deltaInfo)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test uploadInsertLog", func(t *testing.T) {
|
|
|
|
alloc := allocator.NewMockAllocator(t)
|
|
|
|
alloc.EXPECT().GetGenerator(mock.Anything, mock.Anything).Call.Return(validGeneratorFn, nil)
|
|
|
|
|
|
|
|
b := &binlogIO{cm, alloc}
|
|
|
|
|
|
|
|
in, stats, err := b.uploadInsertLog(ctx, 1, 10, iData, meta)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 12, len(in))
|
|
|
|
assert.Equal(t, 1, len(in[0].GetBinlogs()))
|
|
|
|
assert.Equal(t, 1, len(stats))
|
|
|
|
})
|
|
|
|
t.Run("Test uploadDeltaLog", func(t *testing.T) {
|
|
|
|
alloc := allocator.NewMockAllocator(t)
|
|
|
|
alloc.EXPECT().AllocOne().Call.Return(int64(11111), nil)
|
|
|
|
|
|
|
|
b := &binlogIO{cm, alloc}
|
|
|
|
deltas, err := b.uploadDeltaLog(ctx, 1, 10, dData, meta)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, deltas)
|
|
|
|
assert.Equal(t, 1, len(deltas[0].GetBinlogs()))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test context Done", func(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
cancel()
|
|
|
|
|
|
|
|
alloc := allocator.NewMockAllocator(t)
|
|
|
|
alloc.EXPECT().GetGenerator(mock.Anything, mock.Anything).Call.Return(validGeneratorFn, nil)
|
|
|
|
alloc.EXPECT().AllocOne().Call.Return(int64(11111), nil)
|
|
|
|
|
|
|
|
b := &binlogIO{cm, alloc}
|
|
|
|
|
|
|
|
p, err := b.upload(ctx, 1, 10, []*InsertData{iData}, dData, meta)
|
|
|
|
assert.EqualError(t, err, errUploadToBlobStorage.Error())
|
|
|
|
assert.Nil(t, p)
|
|
|
|
|
|
|
|
in, _, err := b.uploadInsertLog(ctx, 1, 10, iData, meta)
|
|
|
|
assert.EqualError(t, err, errUploadToBlobStorage.Error())
|
|
|
|
assert.Nil(t, in)
|
|
|
|
|
|
|
|
deltas, err := b.uploadDeltaLog(ctx, 1, 10, dData, meta)
|
|
|
|
assert.EqualError(t, err, errUploadToBlobStorage.Error())
|
|
|
|
assert.Nil(t, deltas)
|
|
|
|
})
|
2021-10-25 20:13:51 +08:00
|
|
|
})
|
|
|
|
|
2021-11-26 17:43:17 +08:00
|
|
|
t.Run("Test upload error", func(t *testing.T) {
|
|
|
|
f := &MetaFactory{}
|
2022-03-25 14:27:25 +08:00
|
|
|
meta := f.GetCollectionMeta(UniqueID(10001), "uploads", schemapb.DataType_Int64)
|
2021-11-26 17:43:17 +08:00
|
|
|
dData := &DeleteData{
|
2022-04-02 17:43:29 +08:00
|
|
|
Pks: []primaryKey{},
|
2021-11-26 17:43:17 +08:00
|
|
|
Tss: []uint64{},
|
|
|
|
}
|
|
|
|
|
2023-03-23 19:43:57 +08:00
|
|
|
t.Run("Test upload empty insertData", func(t *testing.T) {
|
|
|
|
alloc := allocator.NewMockAllocator(t)
|
|
|
|
b := &binlogIO{cm, alloc}
|
|
|
|
|
|
|
|
iData := genEmptyInsertData()
|
|
|
|
p, err := b.upload(context.TODO(), 1, 10, []*InsertData{iData}, dData, meta)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Empty(t, p.inPaths)
|
|
|
|
assert.Empty(t, p.statsPaths)
|
|
|
|
assert.Empty(t, p.deltaInfo)
|
|
|
|
|
|
|
|
iData = &InsertData{Data: make(map[int64]storage.FieldData)}
|
|
|
|
p, err = b.upload(context.TODO(), 1, 10, []*InsertData{iData}, dData, meta)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Empty(t, p.inPaths)
|
|
|
|
assert.Empty(t, p.statsPaths)
|
|
|
|
assert.Empty(t, p.deltaInfo)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test deleta data not match", func(t *testing.T) {
|
|
|
|
alloc := allocator.NewMockAllocator(t)
|
|
|
|
alloc.EXPECT().GetGenerator(mock.Anything, mock.Anything).Call.Return(validGeneratorFn, nil)
|
|
|
|
b := &binlogIO{cm, alloc}
|
|
|
|
iData := genInsertData()
|
|
|
|
dData := &DeleteData{
|
|
|
|
Pks: []primaryKey{},
|
|
|
|
Tss: []uint64{1},
|
|
|
|
RowCount: 1,
|
|
|
|
}
|
|
|
|
p, err := b.upload(context.TODO(), 1, 10, []*InsertData{iData}, dData, meta)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Empty(t, p)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test multisave error", func(t *testing.T) {
|
|
|
|
mkc := &mockCm{errMultiSave: true}
|
|
|
|
alloc := allocator.NewMockAllocator(t)
|
|
|
|
alloc.EXPECT().GetGenerator(mock.Anything, mock.Anything).Call.Return(validGeneratorFn, nil)
|
|
|
|
alloc.EXPECT().AllocOne().Call.Return(int64(11111), nil)
|
|
|
|
var (
|
|
|
|
b = &binlogIO{mkc, alloc}
|
|
|
|
iData = genInsertData()
|
|
|
|
pk = newInt64PrimaryKey(1)
|
|
|
|
dData = &DeleteData{
|
|
|
|
Pks: []primaryKey{pk},
|
|
|
|
Tss: []uint64{1},
|
|
|
|
RowCount: 1,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
ctx, cancel := context.WithTimeout(context.TODO(), 20*time.Millisecond)
|
|
|
|
p, err := b.upload(ctx, 1, 10, []*InsertData{iData}, dData, meta)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Empty(t, p)
|
|
|
|
|
|
|
|
in, _, err := b.uploadInsertLog(ctx, 1, 10, iData, meta)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Empty(t, in)
|
|
|
|
|
|
|
|
deltas, err := b.uploadDeltaLog(ctx, 1, 10, dData, meta)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Empty(t, deltas)
|
|
|
|
cancel()
|
|
|
|
})
|
2021-11-26 17:43:17 +08:00
|
|
|
})
|
|
|
|
|
2021-10-25 20:13:51 +08:00
|
|
|
t.Run("Test download", func(t *testing.T) {
|
2023-03-23 19:43:57 +08:00
|
|
|
alloc := allocator.NewMockAllocator(t)
|
|
|
|
b := &binlogIO{cm, alloc}
|
2021-10-25 20:13:51 +08:00
|
|
|
tests := []struct {
|
|
|
|
isvalid bool
|
|
|
|
ks []string // for preparation
|
|
|
|
|
|
|
|
inctx context.Context
|
|
|
|
|
|
|
|
description string
|
|
|
|
}{
|
|
|
|
{true, []string{"a", "b", "c"}, context.TODO(), "valid input"},
|
|
|
|
{false, nil, context.Background(), "cancel by context"},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.description, func(t *testing.T) {
|
|
|
|
if test.isvalid {
|
|
|
|
inkeys := []string{}
|
|
|
|
for _, k := range test.ks {
|
2022-03-17 18:03:23 +08:00
|
|
|
blob, key, err := prepareBlob(cm, k)
|
2021-10-25 20:13:51 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.NotEmpty(t, blob)
|
|
|
|
inkeys = append(inkeys, key)
|
|
|
|
|
|
|
|
loaded, err := b.download(test.inctx, []string{key})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.ElementsMatch(t, blob, loaded[0].GetValue())
|
|
|
|
}
|
|
|
|
|
|
|
|
loaded, err := b.download(test.inctx, inkeys)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, len(test.ks), len(loaded))
|
|
|
|
} else {
|
|
|
|
ctx, cancel := context.WithCancel(test.inctx)
|
|
|
|
cancel()
|
|
|
|
|
|
|
|
_, err := b.download(ctx, nil)
|
|
|
|
assert.EqualError(t, err, errDownloadFromBlobStorage.Error())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2021-11-26 17:43:17 +08:00
|
|
|
})
|
2021-10-25 20:13:51 +08:00
|
|
|
|
2021-11-26 17:43:17 +08:00
|
|
|
t.Run("Test download twice", func(t *testing.T) {
|
2022-03-17 18:03:23 +08:00
|
|
|
mkc := &mockCm{errMultiLoad: true}
|
2023-03-23 19:43:57 +08:00
|
|
|
alloc := allocator.NewMockAllocator(t)
|
2022-03-17 18:03:23 +08:00
|
|
|
b := &binlogIO{mkc, alloc}
|
2021-11-26 17:43:17 +08:00
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.TODO(), time.Millisecond*20)
|
|
|
|
blobs, err := b.download(ctx, []string{"a"})
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Empty(t, blobs)
|
|
|
|
cancel()
|
2021-10-25 20:13:51 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-03-17 18:03:23 +08:00
|
|
|
func prepareBlob(cm storage.ChunkManager, key string) ([]byte, string, error) {
|
2022-09-29 16:18:56 +08:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2022-11-21 10:19:10 +08:00
|
|
|
k := path.Join(cm.RootPath(), "test_prepare_blob", key)
|
2021-10-25 20:13:51 +08:00
|
|
|
blob := []byte{1, 2, 3, 255, 188}
|
|
|
|
|
2022-09-29 16:18:56 +08:00
|
|
|
err := cm.Write(ctx, k, blob[:])
|
2021-10-25 20:13:51 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, "", err
|
|
|
|
}
|
|
|
|
return blob, k, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBinlogIOInnerMethods(t *testing.T) {
|
2022-09-29 16:18:56 +08:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2022-03-17 18:03:23 +08:00
|
|
|
cm := storage.NewLocalChunkManager(storage.RootPath(binlogTestDir))
|
2022-11-21 10:19:10 +08:00
|
|
|
defer cm.RemoveWithPrefix(ctx, cm.RootPath())
|
2021-10-25 20:13:51 +08:00
|
|
|
|
|
|
|
t.Run("Test genDeltaBlobs", func(t *testing.T) {
|
2023-03-23 19:43:57 +08:00
|
|
|
alloc := allocator.NewMockAllocator(t)
|
|
|
|
alloc.EXPECT().AllocOne().Call.Return(int64(11111), nil)
|
|
|
|
|
|
|
|
b := &binlogIO{cm, alloc}
|
2021-10-25 20:13:51 +08:00
|
|
|
f := &MetaFactory{}
|
2022-03-25 14:27:25 +08:00
|
|
|
meta := f.GetCollectionMeta(UniqueID(10002), "test_gen_blobs", schemapb.DataType_Int64)
|
2021-10-25 20:13:51 +08:00
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
isvalid bool
|
2022-04-02 17:43:29 +08:00
|
|
|
deletepk primaryKey
|
2021-11-09 15:01:17 +08:00
|
|
|
ts uint64
|
2021-10-25 20:13:51 +08:00
|
|
|
|
|
|
|
description string
|
|
|
|
}{
|
2022-04-02 17:43:29 +08:00
|
|
|
{true, newInt64PrimaryKey(1), 1111111, "valid input"},
|
2021-10-25 20:13:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.description, func(t *testing.T) {
|
|
|
|
if test.isvalid {
|
|
|
|
|
|
|
|
k, v, err := b.genDeltaBlobs(&DeleteData{
|
2022-04-02 17:43:29 +08:00
|
|
|
Pks: []primaryKey{test.deletepk},
|
2021-11-09 15:01:17 +08:00
|
|
|
Tss: []uint64{test.ts},
|
2021-10-25 20:13:51 +08:00
|
|
|
}, meta.GetID(), 10, 1)
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEmpty(t, k)
|
|
|
|
assert.NotEmpty(t, v)
|
|
|
|
|
|
|
|
log.Debug("genDeltaBlobs returns", zap.String("key", k))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2021-11-26 17:43:17 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test genDeltaBlobs error", func(t *testing.T) {
|
2022-04-02 17:43:29 +08:00
|
|
|
pk := newInt64PrimaryKey(1)
|
2021-10-25 20:13:51 +08:00
|
|
|
|
2023-03-23 19:43:57 +08:00
|
|
|
t.Run("Test serialize error", func(t *testing.T) {
|
|
|
|
alloc := allocator.NewMockAllocator(t)
|
|
|
|
b := &binlogIO{cm, alloc}
|
|
|
|
k, v, err := b.genDeltaBlobs(&DeleteData{Pks: []primaryKey{pk}, Tss: []uint64{}}, 1, 1, 1)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Empty(t, k)
|
|
|
|
assert.Empty(t, v)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test AllocOne error", func(t *testing.T) {
|
|
|
|
alloc := allocator.NewMockAllocator(t)
|
|
|
|
alloc.EXPECT().AllocOne().Call.Return(int64(0), fmt.Errorf("mock AllocOne error"))
|
|
|
|
bin := binlogIO{cm, alloc}
|
|
|
|
k, v, err := bin.genDeltaBlobs(&DeleteData{Pks: []primaryKey{pk}, Tss: []uint64{1}}, 1, 1, 1)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Empty(t, k)
|
|
|
|
assert.Empty(t, v)
|
|
|
|
|
|
|
|
})
|
2021-10-25 20:13:51 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test genInsertBlobs", func(t *testing.T) {
|
|
|
|
f := &MetaFactory{}
|
2023-03-23 19:43:57 +08:00
|
|
|
alloc := allocator.NewMockAllocator(t)
|
|
|
|
alloc.EXPECT().GetGenerator(mock.Anything, mock.Anything).Call.Return(validGeneratorFn, nil)
|
|
|
|
b := binlogIO{cm, alloc}
|
|
|
|
|
2022-03-25 14:27:25 +08:00
|
|
|
tests := []struct {
|
|
|
|
pkType schemapb.DataType
|
|
|
|
description string
|
2022-09-02 10:34:59 +08:00
|
|
|
expectError bool
|
2022-03-25 14:27:25 +08:00
|
|
|
}{
|
2022-09-02 10:34:59 +08:00
|
|
|
{schemapb.DataType_Int64, "int64PrimaryField", false},
|
|
|
|
{schemapb.DataType_VarChar, "varCharPrimaryField", false},
|
2022-03-25 14:27:25 +08:00
|
|
|
}
|
2021-10-25 20:13:51 +08:00
|
|
|
|
2022-03-25 14:27:25 +08:00
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.description, func(t *testing.T) {
|
|
|
|
meta := f.GetCollectionMeta(UniqueID(10001), "test_gen_blobs", test.pkType)
|
2022-10-31 17:41:34 +08:00
|
|
|
helper, err := typeutil.CreateSchemaHelper(meta.Schema)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
primaryKeyFieldSchema, err := helper.GetPrimaryKeyField()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
primaryKeyFieldID := primaryKeyFieldSchema.GetFieldID()
|
2022-03-25 14:27:25 +08:00
|
|
|
|
2022-10-31 17:41:34 +08:00
|
|
|
kvs, pin, pstats, err := b.genInsertBlobs(genInsertData(), 10, 1, meta)
|
2022-03-25 14:27:25 +08:00
|
|
|
|
|
|
|
assert.NoError(t, err)
|
2022-10-31 17:41:34 +08:00
|
|
|
assert.Equal(t, 1, len(pstats))
|
2022-03-25 14:27:25 +08:00
|
|
|
assert.Equal(t, 12, len(pin))
|
2022-10-31 17:41:34 +08:00
|
|
|
assert.Equal(t, 13, len(kvs))
|
2022-03-25 14:27:25 +08:00
|
|
|
|
|
|
|
log.Debug("test paths",
|
|
|
|
zap.Any("kvs no.", len(kvs)),
|
2022-10-31 17:41:34 +08:00
|
|
|
zap.String("insert paths field0", pin[common.TimeStampField].GetBinlogs()[0].GetLogPath()),
|
|
|
|
zap.String("stats paths field0", pstats[primaryKeyFieldID].GetBinlogs()[0].GetLogPath()))
|
2022-03-25 14:27:25 +08:00
|
|
|
})
|
|
|
|
}
|
2021-10-25 20:13:51 +08:00
|
|
|
})
|
|
|
|
|
2021-11-26 17:43:17 +08:00
|
|
|
t.Run("Test genInsertBlobs error", func(t *testing.T) {
|
2023-03-23 19:43:57 +08:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
cm := storage.NewLocalChunkManager(storage.RootPath(binlogTestDir))
|
|
|
|
defer cm.RemoveWithPrefix(ctx, cm.RootPath())
|
|
|
|
|
|
|
|
t.Run("serialize error", func(t *testing.T) {
|
|
|
|
bin := &binlogIO{cm, allocator.NewMockAllocator(t)}
|
|
|
|
kvs, pin, pstats, err := bin.genInsertBlobs(genEmptyInsertData(), 10, 1, nil)
|
|
|
|
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Empty(t, kvs)
|
|
|
|
assert.Empty(t, pin)
|
|
|
|
assert.Empty(t, pstats)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("GetGenerator error", func(t *testing.T) {
|
|
|
|
f := &MetaFactory{}
|
|
|
|
meta := f.GetCollectionMeta(UniqueID(10001), "test_gen_blobs", schemapb.DataType_Int64)
|
|
|
|
|
|
|
|
alloc := allocator.NewMockAllocator(t)
|
|
|
|
alloc.EXPECT().GetGenerator(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("mock GetGenerator error"))
|
|
|
|
bin := &binlogIO{cm, alloc}
|
|
|
|
kvs, pin, pstats, err := bin.genInsertBlobs(genInsertData(), 10, 1, meta)
|
|
|
|
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Empty(t, kvs)
|
|
|
|
assert.Empty(t, pin)
|
|
|
|
assert.Empty(t, pstats)
|
|
|
|
})
|
2021-10-25 20:13:51 +08:00
|
|
|
})
|
|
|
|
}
|
2021-11-26 17:43:17 +08:00
|
|
|
|
2022-03-17 18:03:23 +08:00
|
|
|
type mockCm struct {
|
|
|
|
storage.ChunkManager
|
2021-11-26 17:43:17 +08:00
|
|
|
errMultiLoad bool
|
|
|
|
errMultiSave bool
|
|
|
|
}
|
|
|
|
|
2022-03-17 18:03:23 +08:00
|
|
|
var _ storage.ChunkManager = (*mockCm)(nil)
|
2021-11-26 17:43:17 +08:00
|
|
|
|
2022-08-25 19:32:53 +08:00
|
|
|
func (mk *mockCm) RootPath() string {
|
|
|
|
return "mock_test"
|
|
|
|
}
|
|
|
|
|
2022-09-29 16:18:56 +08:00
|
|
|
func (mk *mockCm) Write(ctx context.Context, filePath string, content []byte) error {
|
2022-03-17 18:03:23 +08:00
|
|
|
return nil
|
2021-11-26 17:43:17 +08:00
|
|
|
}
|
|
|
|
|
2022-09-29 16:18:56 +08:00
|
|
|
func (mk *mockCm) MultiWrite(ctx context.Context, contents map[string][]byte) error {
|
2021-11-26 17:43:17 +08:00
|
|
|
if mk.errMultiSave {
|
|
|
|
return errors.New("mockKv multisave error")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2022-03-17 18:03:23 +08:00
|
|
|
|
2022-09-29 16:18:56 +08:00
|
|
|
func (mk *mockCm) Read(ctx context.Context, filePath string) ([]byte, error) {
|
2022-03-17 18:03:23 +08:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2022-09-29 16:18:56 +08:00
|
|
|
func (mk *mockCm) MultiRead(ctx context.Context, filePaths []string) ([][]byte, error) {
|
2022-03-17 18:03:23 +08:00
|
|
|
if mk.errMultiLoad {
|
|
|
|
return nil, errors.New("mockKv multiload error")
|
|
|
|
}
|
|
|
|
return [][]byte{[]byte("a")}, nil
|
|
|
|
}
|
|
|
|
|
2022-09-29 16:18:56 +08:00
|
|
|
func (mk *mockCm) ReadWithPrefix(ctx context.Context, prefix string) ([]string, [][]byte, error) {
|
2022-03-17 18:03:23 +08:00
|
|
|
return nil, nil, nil
|
|
|
|
}
|
|
|
|
|
2022-09-29 16:18:56 +08:00
|
|
|
func (mk *mockCm) Remove(ctx context.Context, key string) error { return nil }
|
|
|
|
func (mk *mockCm) MultiRemove(ctx context.Context, keys []string) error { return nil }
|
|
|
|
func (mk *mockCm) RemoveWithPrefix(ctx context.Context, key string) error { return nil }
|
|
|
|
func (mk *mockCm) Close() {}
|