2021-12-29 22:42:14 +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-07-20 15:06:09 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-12-29 22:42:14 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-07-20 15:06:09 +08:00
|
|
|
//
|
2021-12-29 22:42:14 +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-07-20 15:06:09 +08:00
|
|
|
|
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-02-24 23:53:53 +08:00
|
|
|
"errors"
|
2021-07-20 15:06:09 +08:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2022-04-12 22:19:34 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2022-09-16 16:56:49 +08:00
|
|
|
"github.com/milvus-io/milvus/api/schemapb"
|
2021-07-20 15:06:09 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/etcdpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/paramtable"
|
2021-07-24 09:25:22 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/typeutil"
|
2021-07-20 15:06:09 +08:00
|
|
|
)
|
|
|
|
|
2021-08-14 11:18:10 +08:00
|
|
|
func initMeta() *etcdpb.CollectionMeta {
|
|
|
|
meta := &etcdpb.CollectionMeta{
|
2021-07-20 15:06:09 +08:00
|
|
|
ID: 1,
|
|
|
|
CreateTime: 1,
|
|
|
|
SegmentIDs: []int64{0, 1},
|
|
|
|
PartitionTags: []string{"partition_0", "partition_1"},
|
|
|
|
Schema: &schemapb.CollectionSchema{
|
|
|
|
Name: "schema",
|
|
|
|
Description: "schema",
|
|
|
|
AutoID: true,
|
|
|
|
Fields: []*schemapb.FieldSchema{
|
|
|
|
{
|
|
|
|
FieldID: 0,
|
|
|
|
Name: "row_id",
|
|
|
|
IsPrimaryKey: false,
|
|
|
|
Description: "row_id",
|
|
|
|
DataType: schemapb.DataType_Int64,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
FieldID: 1,
|
|
|
|
Name: "Ts",
|
|
|
|
IsPrimaryKey: false,
|
|
|
|
Description: "Ts",
|
|
|
|
DataType: schemapb.DataType_Int64,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
FieldID: 101,
|
|
|
|
Name: "field_int8",
|
|
|
|
IsPrimaryKey: false,
|
|
|
|
Description: "description_3",
|
|
|
|
DataType: schemapb.DataType_Int8,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
FieldID: 108,
|
|
|
|
Name: "field_binary_vector",
|
|
|
|
IsPrimaryKey: false,
|
|
|
|
Description: "description_10",
|
|
|
|
DataType: schemapb.DataType_BinaryVector,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
FieldID: 109,
|
|
|
|
Name: "field_float_vector",
|
|
|
|
IsPrimaryKey: false,
|
|
|
|
Description: "description_11",
|
|
|
|
DataType: schemapb.DataType_FloatVector,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-08-14 11:18:10 +08:00
|
|
|
return meta
|
2021-07-20 15:06:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func initBinlogFile(schema *etcdpb.CollectionMeta) []*Blob {
|
|
|
|
insertCodec := NewInsertCodec(schema)
|
|
|
|
insertData := &InsertData{
|
|
|
|
Data: map[int64]FieldData{
|
|
|
|
0: &Int64FieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2021-07-20 15:06:09 +08:00
|
|
|
Data: []int64{3, 4},
|
|
|
|
},
|
|
|
|
1: &Int64FieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2021-07-20 15:06:09 +08:00
|
|
|
Data: []int64{3, 4},
|
|
|
|
},
|
|
|
|
101: &Int8FieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2021-07-20 15:06:09 +08:00
|
|
|
Data: []int8{3, 4},
|
|
|
|
},
|
|
|
|
108: &BinaryVectorFieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2021-07-20 15:06:09 +08:00
|
|
|
Data: []byte{0, 255},
|
|
|
|
Dim: 8,
|
|
|
|
},
|
|
|
|
109: &FloatVectorFieldData{
|
2021-07-24 09:25:22 +08:00
|
|
|
NumRows: []int64{2},
|
2021-07-20 15:06:09 +08:00
|
|
|
Data: []float32{0, 1, 2, 3, 4, 5, 6, 7, 0, 111, 222, 333, 444, 555, 777, 666},
|
|
|
|
Dim: 8,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
blobs, _, err := insertCodec.Serialize(1, 1, insertData)
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return blobs
|
|
|
|
}
|
2021-09-09 14:34:00 +08:00
|
|
|
|
2022-02-24 23:53:53 +08:00
|
|
|
func buildVectorChunkManager(localPath string, localCacheEnable bool) (*VectorChunkManager, context.CancelFunc, error) {
|
2021-09-09 14:34:00 +08:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
|
|
|
|
bucketName := "vector-chunk-manager"
|
|
|
|
|
2022-08-25 19:32:53 +08:00
|
|
|
rcm, err := newMinIOChunkManager(ctx, bucketName, "")
|
2022-02-24 23:53:53 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, cancel, err
|
|
|
|
}
|
|
|
|
lcm := NewLocalChunkManager(RootPath(localPath))
|
2021-09-09 14:34:00 +08:00
|
|
|
|
|
|
|
meta := initMeta()
|
2022-03-26 22:05:26 +08:00
|
|
|
vcm, err := NewVectorChunkManager(lcm, rcm, meta, 16, localCacheEnable)
|
|
|
|
if err != nil {
|
|
|
|
return nil, cancel, err
|
|
|
|
}
|
2021-09-09 14:34:00 +08:00
|
|
|
|
2022-02-24 23:53:53 +08:00
|
|
|
return vcm, cancel, nil
|
2021-09-09 14:34:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var Params paramtable.BaseTable
|
2022-02-24 23:53:53 +08:00
|
|
|
var localPath = "/tmp/milvus/test_data/"
|
2021-09-09 14:34:00 +08:00
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
Params.Init()
|
|
|
|
exitCode := m.Run()
|
2021-09-28 20:46:04 +08:00
|
|
|
err := os.RemoveAll(localPath)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2021-09-09 14:34:00 +08:00
|
|
|
os.Exit(exitCode)
|
|
|
|
}
|
|
|
|
|
2022-03-26 22:05:26 +08:00
|
|
|
func TestNewVectorChunkManager(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
bucketName := "vector-chunk-manager"
|
2021-09-09 14:34:00 +08:00
|
|
|
|
2022-08-25 19:32:53 +08:00
|
|
|
rcm, err := newMinIOChunkManager(ctx, bucketName, "")
|
2021-09-09 14:34:00 +08:00
|
|
|
assert.Nil(t, err)
|
2022-03-26 22:05:26 +08:00
|
|
|
assert.NotNil(t, rcm)
|
|
|
|
lcm := NewLocalChunkManager(RootPath(localPath))
|
2021-09-09 14:34:00 +08:00
|
|
|
|
2022-03-26 22:05:26 +08:00
|
|
|
meta := initMeta()
|
|
|
|
vcm, err := NewVectorChunkManager(lcm, rcm, meta, 16, true)
|
2022-08-25 19:32:53 +08:00
|
|
|
assert.Equal(t, "", vcm.RootPath())
|
2021-09-09 14:34:00 +08:00
|
|
|
assert.Nil(t, err)
|
2022-03-26 22:05:26 +08:00
|
|
|
assert.NotNil(t, vcm)
|
2022-02-24 23:53:53 +08:00
|
|
|
|
2022-03-26 22:05:26 +08:00
|
|
|
vcm, err = NewVectorChunkManager(lcm, rcm, meta, -1, true)
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
assert.Nil(t, vcm)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestVectorChunkManager_GetPath(t *testing.T) {
|
|
|
|
localCaches := []bool{true, false}
|
|
|
|
for _, localCache := range localCaches {
|
|
|
|
vcm, cancel, err := buildVectorChunkManager(localPath, localCache)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, vcm)
|
|
|
|
|
|
|
|
key := "1"
|
|
|
|
err = vcm.Write(key, []byte{1})
|
|
|
|
assert.Nil(t, err)
|
2022-04-12 22:19:34 +08:00
|
|
|
pathGet, err := vcm.Path(key)
|
2022-03-26 22:05:26 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, pathGet, key)
|
|
|
|
|
|
|
|
err = vcm.cacheStorage.Write(key, []byte{1})
|
|
|
|
assert.Nil(t, err)
|
2022-04-12 22:19:34 +08:00
|
|
|
pathGet, err = vcm.Path(key)
|
2022-03-26 22:05:26 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, pathGet, key)
|
|
|
|
|
|
|
|
err = vcm.RemoveWithPrefix(localPath)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
cancel()
|
|
|
|
vcm.Close()
|
|
|
|
}
|
2022-02-24 23:53:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestVectorChunkManager_GetSize(t *testing.T) {
|
2022-03-26 22:05:26 +08:00
|
|
|
localCaches := []bool{true, false}
|
|
|
|
for _, localCache := range localCaches {
|
|
|
|
vcm, cancel, err := buildVectorChunkManager(localPath, localCache)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, vcm)
|
2022-02-24 23:53:53 +08:00
|
|
|
|
2022-03-26 22:05:26 +08:00
|
|
|
key := "1"
|
|
|
|
err = vcm.Write(key, []byte{1})
|
|
|
|
assert.Nil(t, err)
|
2022-04-12 22:19:34 +08:00
|
|
|
sizeGet, err := vcm.Size(key)
|
2022-03-26 22:05:26 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.EqualValues(t, sizeGet, 1)
|
2022-02-24 23:53:53 +08:00
|
|
|
|
2022-03-26 22:05:26 +08:00
|
|
|
err = vcm.cacheStorage.Write(key, []byte{1})
|
|
|
|
assert.Nil(t, err)
|
2022-04-12 22:19:34 +08:00
|
|
|
sizeGet, err = vcm.Size(key)
|
2022-03-26 22:05:26 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.EqualValues(t, sizeGet, 1)
|
2022-02-24 23:53:53 +08:00
|
|
|
|
2022-03-26 22:05:26 +08:00
|
|
|
err = vcm.RemoveWithPrefix(localPath)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
cancel()
|
|
|
|
vcm.Close()
|
|
|
|
}
|
2021-09-09 14:34:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestVectorChunkManager_Write(t *testing.T) {
|
2022-03-26 22:05:26 +08:00
|
|
|
localCaches := []bool{true, false}
|
|
|
|
for _, localCache := range localCaches {
|
|
|
|
vcm, cancel, err := buildVectorChunkManager(localPath, localCache)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, vcm)
|
2021-09-09 14:34:00 +08:00
|
|
|
|
2022-03-26 22:05:26 +08:00
|
|
|
key := "1"
|
|
|
|
err = vcm.Write(key, []byte{1})
|
|
|
|
assert.Nil(t, err)
|
2021-09-09 14:34:00 +08:00
|
|
|
|
2022-05-16 19:25:55 +08:00
|
|
|
exist, err := vcm.Exist(key)
|
2022-03-26 22:05:26 +08:00
|
|
|
assert.True(t, exist)
|
2022-05-16 19:25:55 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-09 14:34:00 +08:00
|
|
|
|
2022-03-26 22:05:26 +08:00
|
|
|
contents := map[string][]byte{
|
|
|
|
"key_1": {111},
|
|
|
|
"key_2": {222},
|
|
|
|
}
|
|
|
|
err = vcm.MultiWrite(contents)
|
|
|
|
assert.NoError(t, err)
|
2021-09-09 14:34:00 +08:00
|
|
|
|
2022-05-16 19:25:55 +08:00
|
|
|
exist, err = vcm.Exist("key_1")
|
2022-03-26 22:05:26 +08:00
|
|
|
assert.True(t, exist)
|
2022-05-16 19:25:55 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
exist, err = vcm.Exist("key_2")
|
2022-03-26 22:05:26 +08:00
|
|
|
assert.True(t, exist)
|
2022-05-16 19:25:55 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-09 14:34:00 +08:00
|
|
|
|
2022-03-26 22:05:26 +08:00
|
|
|
err = vcm.RemoveWithPrefix(localPath)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
cancel()
|
|
|
|
vcm.Close()
|
|
|
|
}
|
2022-02-24 23:53:53 +08:00
|
|
|
}
|
2021-09-09 14:34:00 +08:00
|
|
|
|
2022-02-24 23:53:53 +08:00
|
|
|
func TestVectorChunkManager_Remove(t *testing.T) {
|
|
|
|
localCaches := []bool{true, false}
|
|
|
|
for _, localCache := range localCaches {
|
|
|
|
vcm, cancel, err := buildVectorChunkManager(localPath, localCache)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, vcm)
|
2021-09-09 14:34:00 +08:00
|
|
|
|
2022-02-24 23:53:53 +08:00
|
|
|
key := "1"
|
2022-03-26 22:05:26 +08:00
|
|
|
err = vcm.cacheStorage.Write(key, []byte{1})
|
2021-09-28 20:46:04 +08:00
|
|
|
assert.Nil(t, err)
|
2022-02-24 23:53:53 +08:00
|
|
|
|
|
|
|
err = vcm.Remove(key)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2022-05-16 19:25:55 +08:00
|
|
|
exist, err := vcm.Exist(key)
|
2022-02-24 23:53:53 +08:00
|
|
|
assert.False(t, exist)
|
2022-05-16 19:25:55 +08:00
|
|
|
assert.NoError(t, err)
|
2022-02-24 23:53:53 +08:00
|
|
|
|
|
|
|
contents := map[string][]byte{
|
|
|
|
"key_1": {111},
|
|
|
|
"key_2": {222},
|
|
|
|
}
|
2022-03-26 22:05:26 +08:00
|
|
|
err = vcm.cacheStorage.MultiWrite(contents)
|
2022-02-24 23:53:53 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = vcm.MultiRemove([]string{"key_1", "key_2"})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-05-16 19:25:55 +08:00
|
|
|
exist, err = vcm.Exist("key_1")
|
2022-02-24 23:53:53 +08:00
|
|
|
assert.False(t, exist)
|
2022-05-16 19:25:55 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
exist, err = vcm.Exist("key_2")
|
2022-02-24 23:53:53 +08:00
|
|
|
assert.False(t, exist)
|
2022-05-16 19:25:55 +08:00
|
|
|
assert.NoError(t, err)
|
2022-02-24 23:53:53 +08:00
|
|
|
|
|
|
|
err = vcm.RemoveWithPrefix(localPath)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
cancel()
|
2022-03-26 22:05:26 +08:00
|
|
|
vcm.Close()
|
2021-09-09 14:34:00 +08:00
|
|
|
}
|
2022-02-24 23:53:53 +08:00
|
|
|
}
|
2021-09-09 14:34:00 +08:00
|
|
|
|
2022-02-24 23:53:53 +08:00
|
|
|
type mockFailedChunkManager struct {
|
|
|
|
fail bool
|
|
|
|
ChunkManager
|
|
|
|
}
|
2021-09-09 14:34:00 +08:00
|
|
|
|
2022-02-24 23:53:53 +08:00
|
|
|
func (m *mockFailedChunkManager) Remove(key string) error {
|
|
|
|
if m.fail {
|
|
|
|
return errors.New("remove error")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2021-09-09 14:34:00 +08:00
|
|
|
|
2022-02-24 23:53:53 +08:00
|
|
|
func (m *mockFailedChunkManager) RemoveWithPrefix(prefix string) error {
|
|
|
|
if m.fail {
|
|
|
|
return errors.New("remove with prefix error")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
func (m *mockFailedChunkManager) MultiRemove(key []string) error {
|
|
|
|
if m.fail {
|
|
|
|
return errors.New("multi remove error")
|
2021-09-09 14:34:00 +08:00
|
|
|
}
|
2022-02-24 23:53:53 +08:00
|
|
|
return nil
|
|
|
|
}
|
2021-09-09 14:34:00 +08:00
|
|
|
|
2022-02-24 23:53:53 +08:00
|
|
|
func TestVectorChunkManager_Remove_Fail(t *testing.T) {
|
|
|
|
vcm := &VectorChunkManager{
|
2022-03-26 22:05:26 +08:00
|
|
|
vectorStorage: &mockFailedChunkManager{fail: true},
|
|
|
|
cacheStorage: &mockFailedChunkManager{fail: true},
|
2021-09-09 14:34:00 +08:00
|
|
|
}
|
2022-02-24 23:53:53 +08:00
|
|
|
assert.Error(t, vcm.Remove("test"))
|
|
|
|
assert.Error(t, vcm.MultiRemove([]string{"test"}))
|
|
|
|
assert.Error(t, vcm.RemoveWithPrefix("test"))
|
|
|
|
}
|
2021-09-09 14:34:00 +08:00
|
|
|
|
2022-02-24 23:53:53 +08:00
|
|
|
func TestVectorChunkManager_Read(t *testing.T) {
|
|
|
|
localCaches := []bool{true, false}
|
|
|
|
for _, localCache := range localCaches {
|
|
|
|
vcm, cancel, err := buildVectorChunkManager(localPath, localCache)
|
|
|
|
assert.NotNil(t, vcm)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
content, err := vcm.Read("9999")
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Nil(t, content)
|
|
|
|
|
|
|
|
meta := initMeta()
|
|
|
|
binlogs := initBinlogFile(meta)
|
|
|
|
assert.NotNil(t, binlogs)
|
|
|
|
for _, binlog := range binlogs {
|
2022-03-26 22:05:26 +08:00
|
|
|
err := vcm.vectorStorage.Write(binlog.Key, binlog.Value)
|
2022-02-24 23:53:53 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
content, err = vcm.Read("108")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, []byte{0, 255}, content)
|
2021-09-09 14:34:00 +08:00
|
|
|
|
2022-02-24 23:53:53 +08:00
|
|
|
content, err = vcm.Read("109")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
floatResult := make([]float32, 0)
|
|
|
|
for i := 0; i < len(content)/4; i++ {
|
|
|
|
singleData := typeutil.BytesToFloat32(content[i*4 : i*4+4])
|
|
|
|
floatResult = append(floatResult, singleData)
|
|
|
|
}
|
|
|
|
assert.Equal(t, []float32{0, 1, 2, 3, 4, 5, 6, 7, 0, 111, 222, 333, 444, 555, 777, 666}, floatResult)
|
|
|
|
|
|
|
|
contents, err := vcm.MultiRead([]string{"108", "109"})
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, []byte{0, 255}, contents[0])
|
|
|
|
|
|
|
|
floatResult = make([]float32, 0)
|
|
|
|
for i := 0; i < len(content)/4; i++ {
|
|
|
|
singleData := typeutil.BytesToFloat32(contents[1][i*4 : i*4+4])
|
|
|
|
floatResult = append(floatResult, singleData)
|
|
|
|
}
|
|
|
|
assert.Equal(t, []float32{0, 1, 2, 3, 4, 5, 6, 7, 0, 111, 222, 333, 444, 555, 777, 666}, floatResult)
|
|
|
|
|
2022-03-26 22:05:26 +08:00
|
|
|
keys, contents, err := vcm.ReadWithPrefix("10")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, "101", keys[0])
|
|
|
|
assert.Equal(t, []byte{3, 4}, contents[0])
|
|
|
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, "108", keys[1])
|
|
|
|
assert.Equal(t, []byte{0, 255}, contents[1])
|
|
|
|
|
2022-02-24 23:53:53 +08:00
|
|
|
floatResult = make([]float32, 0)
|
|
|
|
for i := 0; i < len(content)/4; i++ {
|
2022-03-26 22:05:26 +08:00
|
|
|
singleData := typeutil.BytesToFloat32(contents[2][i*4 : i*4+4])
|
2022-02-24 23:53:53 +08:00
|
|
|
floatResult = append(floatResult, singleData)
|
|
|
|
}
|
2022-03-26 22:05:26 +08:00
|
|
|
assert.Equal(t, "109", keys[2])
|
2022-02-24 23:53:53 +08:00
|
|
|
assert.Equal(t, []float32{0, 1, 2, 3, 4, 5, 6, 7, 0, 111, 222, 333, 444, 555, 777, 666}, floatResult)
|
|
|
|
|
|
|
|
content, err = vcm.ReadAt("109", 8*4, 8*4)
|
|
|
|
assert.Nil(t, err)
|
2021-09-09 14:34:00 +08:00
|
|
|
|
2022-02-24 23:53:53 +08:00
|
|
|
floatResult = make([]float32, 0)
|
|
|
|
for i := 0; i < len(content)/4; i++ {
|
|
|
|
singleData := typeutil.BytesToFloat32(content[i*4 : i*4+4])
|
|
|
|
floatResult = append(floatResult, singleData)
|
|
|
|
}
|
|
|
|
assert.Equal(t, []float32{0, 111, 222, 333, 444, 555, 777, 666}, floatResult)
|
2021-09-09 14:34:00 +08:00
|
|
|
|
2022-02-24 23:53:53 +08:00
|
|
|
content, err = vcm.ReadAt("9999", 0, 8*4)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Nil(t, content)
|
|
|
|
|
|
|
|
content, err = vcm.ReadAt("109", 8*4, 8*4)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, 32, len(content))
|
|
|
|
|
2022-03-26 22:05:26 +08:00
|
|
|
if localCache {
|
|
|
|
r, err := vcm.Mmap("109")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
p := make([]byte, 32)
|
|
|
|
n, err := r.ReadAt(p, 32)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, n, 32)
|
|
|
|
|
|
|
|
r, err = vcm.Mmap("not exist")
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Nil(t, nil)
|
|
|
|
}
|
|
|
|
|
2022-02-24 23:53:53 +08:00
|
|
|
content, err = vcm.ReadAt("109", 9999, 8*4)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Nil(t, content)
|
|
|
|
|
|
|
|
content, err = vcm.ReadAt("9999", 0, 8*4)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Nil(t, content)
|
|
|
|
|
|
|
|
err = vcm.RemoveWithPrefix(localPath)
|
|
|
|
assert.NoError(t, err)
|
2022-03-26 22:05:26 +08:00
|
|
|
|
2022-02-24 23:53:53 +08:00
|
|
|
cancel()
|
2022-03-26 22:05:26 +08:00
|
|
|
vcm.Close()
|
2022-02-24 23:53:53 +08:00
|
|
|
}
|
2021-09-09 14:34:00 +08:00
|
|
|
}
|