Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
a0a3a889
M
milvus
项目概览
milvus
/
milvus
12 个月 前同步成功
通知
261
Star
22476
Fork
2472
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
milvus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
a0a3a889
编写于
11月 02, 2021
作者:
G
godchen
提交者:
GitHub
11月 02, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add common endian for global use (#11092)
Signed-off-by:
N
godchen
<
qingxiang.chen@zilliz.com
>
上级
82e5d213
变更
38
隐藏空白更改
内联
并排
Showing
38 changed file
with
173 addition
and
155 deletion
+173
-155
internal/common/common.go
internal/common/common.go
+5
-0
internal/datanode/data_sync_service_test.go
internal/datanode/data_sync_service_test.go
+8
-7
internal/datanode/flow_graph_delete_node.go
internal/datanode/flow_graph_delete_node.go
+1
-2
internal/datanode/flow_graph_delete_node_test.go
internal/datanode/flow_graph_delete_node_test.go
+3
-3
internal/datanode/flow_graph_insert_buffer_node.go
internal/datanode/flow_graph_insert_buffer_node.go
+2
-1
internal/datanode/mock_test.go
internal/datanode/mock_test.go
+9
-8
internal/datanode/segment_replica.go
internal/datanode/segment_replica.go
+1
-2
internal/datanode/segment_replica_test.go
internal/datanode/segment_replica_test.go
+2
-3
internal/proxy/proxy_test.go
internal/proxy/proxy_test.go
+3
-1
internal/proxy/task.go
internal/proxy/task.go
+1
-1
internal/proxy/task_test.go
internal/proxy/task_test.go
+1
-1
internal/querynode/data_sync_service_test.go
internal/querynode/data_sync_service_test.go
+3
-3
internal/querynode/flow_graph_insert_node.go
internal/querynode/flow_graph_insert_node.go
+3
-2
internal/querynode/flow_graph_insert_node_test.go
internal/querynode/flow_graph_insert_node_test.go
+2
-3
internal/querynode/load_service_test.go
internal/querynode/load_service_test.go
+8
-8
internal/querynode/mock_test.go
internal/querynode/mock_test.go
+5
-5
internal/querynode/plan_test.go
internal/querynode/plan_test.go
+3
-3
internal/querynode/query_collection.go
internal/querynode/query_collection.go
+6
-6
internal/querynode/query_collection_test.go
internal/querynode/query_collection_test.go
+9
-9
internal/querynode/query_service_test.go
internal/querynode/query_service_test.go
+3
-3
internal/querynode/reduce_test.go
internal/querynode/reduce_test.go
+3
-3
internal/querynode/segment.go
internal/querynode/segment.go
+4
-2
internal/querynode/segment_test.go
internal/querynode/segment_test.go
+20
-20
internal/storage/binlog_test.go
internal/storage/binlog_test.go
+3
-2
internal/storage/binlog_writer.go
internal/storage/binlog_writer.go
+2
-1
internal/storage/event_data.go
internal/storage/event_data.go
+23
-22
internal/storage/event_header.go
internal/storage/event_header.go
+4
-3
internal/storage/event_test.go
internal/storage/event_test.go
+3
-2
internal/storage/event_writer.go
internal/storage/event_writer.go
+3
-2
internal/storage/event_writer_test.go
internal/storage/event_writer_test.go
+4
-3
internal/storage/stats.go
internal/storage/stats.go
+2
-2
internal/storage/stats_test.go
internal/storage/stats_test.go
+1
-2
internal/storage/utils_test.go
internal/storage/utils_test.go
+5
-4
internal/storage/vector_chunk_manager.go
internal/storage/vector_chunk_manager.go
+2
-1
internal/util/mqclient/pulsar_client_test.go
internal/util/mqclient/pulsar_client_test.go
+3
-2
internal/util/mqclient/rmq_id.go
internal/util/mqclient/rmq_id.go
+3
-4
internal/util/typeutil/convension.go
internal/util/typeutil/convension.go
+8
-7
internal/util/typeutil/hash.go
internal/util/typeutil/hash.go
+2
-2
未找到文件。
internal/common/common.go
浏览文件 @
a0a3a889
...
...
@@ -16,6 +16,8 @@
package
common
import
"encoding/binary"
// system filed id:
// 0: unique row id
// 1: timestamp
...
...
@@ -48,3 +50,6 @@ const (
// InvalidFieldID indicates that the field does not exist . It will be set when the field is not found.
InvalidFieldID
=
int64
(
-
1
)
)
// Common implementation of ByteOrder for whole milvus
var
Endian
=
binary
.
LittleEndian
internal/datanode/data_sync_service_test.go
浏览文件 @
a0a3a889
...
...
@@ -27,6 +27,7 @@ import (
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/log"
"github.com/milvus-io/milvus/internal/msgstream"
"github.com/milvus-io/milvus/internal/proto/commonpb"
...
...
@@ -302,7 +303,7 @@ func genBytes() (rawData []byte) {
var
fvector
=
[
DIM
]
float32
{
1
,
2
}
for
_
,
ele
:=
range
fvector
{
buf
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
common
.
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
rawData
=
append
(
rawData
,
buf
...
)
}
...
...
@@ -315,7 +316,7 @@ func genBytes() (rawData []byte) {
// Bool
var
fieldBool
=
true
buf
:=
new
(
bytes
.
Buffer
)
if
err
:=
binary
.
Write
(
buf
,
binary
.
Little
Endian
,
fieldBool
);
err
!=
nil
{
if
err
:=
binary
.
Write
(
buf
,
common
.
Endian
,
fieldBool
);
err
!=
nil
{
panic
(
err
)
}
...
...
@@ -324,7 +325,7 @@ func genBytes() (rawData []byte) {
// int8
var
dataInt8
int8
=
100
bint8
:=
new
(
bytes
.
Buffer
)
if
err
:=
binary
.
Write
(
bint8
,
binary
.
Little
Endian
,
dataInt8
);
err
!=
nil
{
if
err
:=
binary
.
Write
(
bint8
,
common
.
Endian
,
dataInt8
);
err
!=
nil
{
panic
(
err
)
}
rawData
=
append
(
rawData
,
bint8
.
Bytes
()
...
)
...
...
@@ -339,22 +340,22 @@ func TestBytesReader(t *testing.T) {
rawDataReader
:=
bytes
.
NewReader
(
rawData
)
var
fvector
[]
float32
=
make
([]
float32
,
2
)
err
:=
binary
.
Read
(
rawDataReader
,
binary
.
Little
Endian
,
&
fvector
)
err
:=
binary
.
Read
(
rawDataReader
,
common
.
Endian
,
&
fvector
)
assert
.
Nil
(
t
,
err
)
assert
.
ElementsMatch
(
t
,
fvector
,
[]
float32
{
1
,
2
})
var
bvector
[]
byte
=
make
([]
byte
,
4
)
err
=
binary
.
Read
(
rawDataReader
,
binary
.
Little
Endian
,
&
bvector
)
err
=
binary
.
Read
(
rawDataReader
,
common
.
Endian
,
&
bvector
)
assert
.
Nil
(
t
,
err
)
assert
.
ElementsMatch
(
t
,
bvector
,
[]
byte
{
255
,
255
,
255
,
0
})
var
fieldBool
bool
err
=
binary
.
Read
(
rawDataReader
,
binary
.
Little
Endian
,
&
fieldBool
)
err
=
binary
.
Read
(
rawDataReader
,
common
.
Endian
,
&
fieldBool
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
true
,
fieldBool
)
var
dataInt8
int8
err
=
binary
.
Read
(
rawDataReader
,
binary
.
Little
Endian
,
&
dataInt8
)
err
=
binary
.
Read
(
rawDataReader
,
common
.
Endian
,
&
dataInt8
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
int8
(
100
),
dataInt8
)
}
internal/datanode/flow_graph_delete_node.go
浏览文件 @
a0a3a889
...
...
@@ -18,7 +18,6 @@ package datanode
import
(
"context"
"encoding/binary"
"math"
"sync"
...
...
@@ -223,7 +222,7 @@ func (dn *deleteNode) filterSegmentByPK(partID UniqueID, pks []int64) map[int64]
segments
:=
dn
.
replica
.
filterSegments
(
dn
.
channelName
,
partID
)
for
_
,
pk
:=
range
pks
{
for
_
,
segment
:=
range
segments
{
binary
.
Big
Endian
.
PutUint64
(
buf
,
uint64
(
pk
))
common
.
Endian
.
PutUint64
(
buf
,
uint64
(
pk
))
exist
:=
segment
.
pkFilter
.
Test
(
buf
)
if
exist
{
result
[
pk
]
=
append
(
result
[
pk
],
segment
.
segmentID
)
...
...
internal/datanode/flow_graph_delete_node_test.go
浏览文件 @
a0a3a889
...
...
@@ -18,12 +18,12 @@ package datanode
import
(
"context"
"encoding/binary"
"errors"
"testing"
"time"
"github.com/bits-and-blooms/bloom/v3"
"github.com/milvus-io/milvus/internal/common"
memkv
"github.com/milvus-io/milvus/internal/kv/mem"
"github.com/milvus-io/milvus/internal/msgstream"
"github.com/milvus-io/milvus/internal/proto/schemapb"
...
...
@@ -121,13 +121,13 @@ func genMockReplica(segIDs []int64, pks []int64, chanName string) *mockReplica {
buf
:=
make
([]
byte
,
8
)
filter0
:=
bloom
.
NewWithEstimates
(
1000000
,
0.01
)
for
i
:=
0
;
i
<
3
;
i
++
{
binary
.
Big
Endian
.
PutUint64
(
buf
,
uint64
(
pks
[
i
]))
common
.
Endian
.
PutUint64
(
buf
,
uint64
(
pks
[
i
]))
filter0
.
Add
(
buf
)
}
filter1
:=
bloom
.
NewWithEstimates
(
1000000
,
0.01
)
for
i
:=
3
;
i
<
5
;
i
++
{
binary
.
Big
Endian
.
PutUint64
(
buf
,
uint64
(
pks
[
i
]))
common
.
Endian
.
PutUint64
(
buf
,
uint64
(
pks
[
i
]))
filter1
.
Add
(
buf
)
}
...
...
internal/datanode/flow_graph_insert_buffer_node.go
浏览文件 @
a0a3a889
...
...
@@ -35,6 +35,7 @@ import (
"github.com/milvus-io/milvus/internal/storage"
"github.com/milvus-io/milvus/internal/util/trace"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/proto/commonpb"
"github.com/milvus-io/milvus/internal/proto/datapb"
"github.com/milvus-io/milvus/internal/proto/etcdpb"
...
...
@@ -630,7 +631,7 @@ func (ibNode *insertBufferNode) bufferInsertMsg(msg *msgstream.InsertMsg, endPos
// The receiver can be any type in int8, int16, int32, int64, float32, float64 and bool
// readBinary uses LittleEndian ByteOrder.
func
readBinary
(
reader
io
.
Reader
,
receiver
interface
{},
dataType
schemapb
.
DataType
)
{
err
:=
binary
.
Read
(
reader
,
binary
.
Little
Endian
,
receiver
)
err
:=
binary
.
Read
(
reader
,
common
.
Endian
,
receiver
)
if
err
!=
nil
{
log
.
Error
(
"binary.Read failed"
,
zap
.
Any
(
"data type"
,
dataType
),
zap
.
Error
(
err
))
}
...
...
internal/datanode/mock_test.go
浏览文件 @
a0a3a889
...
...
@@ -36,6 +36,7 @@ import (
s
"github.com/milvus-io/milvus/internal/storage"
"github.com/milvus-io/milvus/internal/types"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/proto/commonpb"
"github.com/milvus-io/milvus/internal/proto/datapb"
"github.com/milvus-io/milvus/internal/proto/etcdpb"
...
...
@@ -313,7 +314,7 @@ func GenRowData() (rawData []byte) {
var
fvector
=
[
DIM
]
float32
{
1
,
2
}
for
_
,
ele
:=
range
fvector
{
buf
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
common
.
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
rawData
=
append
(
rawData
,
buf
...
)
}
...
...
@@ -326,7 +327,7 @@ func GenRowData() (rawData []byte) {
// Bool
var
fieldBool
=
true
buf
:=
new
(
bytes
.
Buffer
)
if
err
:=
binary
.
Write
(
buf
,
binary
.
Little
Endian
,
fieldBool
);
err
!=
nil
{
if
err
:=
binary
.
Write
(
buf
,
common
.
Endian
,
fieldBool
);
err
!=
nil
{
panic
(
err
)
}
...
...
@@ -335,7 +336,7 @@ func GenRowData() (rawData []byte) {
// int8
var
dataInt8
int8
=
100
bint8
:=
new
(
bytes
.
Buffer
)
if
err
:=
binary
.
Write
(
bint8
,
binary
.
Little
Endian
,
dataInt8
);
err
!=
nil
{
if
err
:=
binary
.
Write
(
bint8
,
common
.
Endian
,
dataInt8
);
err
!=
nil
{
panic
(
err
)
}
rawData
=
append
(
rawData
,
bint8
.
Bytes
()
...
)
...
...
@@ -343,7 +344,7 @@ func GenRowData() (rawData []byte) {
// int16
var
dataInt16
int16
=
200
bint16
:=
new
(
bytes
.
Buffer
)
if
err
:=
binary
.
Write
(
bint16
,
binary
.
Little
Endian
,
dataInt16
);
err
!=
nil
{
if
err
:=
binary
.
Write
(
bint16
,
common
.
Endian
,
dataInt16
);
err
!=
nil
{
panic
(
err
)
}
rawData
=
append
(
rawData
,
bint16
.
Bytes
()
...
)
...
...
@@ -351,7 +352,7 @@ func GenRowData() (rawData []byte) {
// int32
var
dataInt32
int32
=
300
bint32
:=
new
(
bytes
.
Buffer
)
if
err
:=
binary
.
Write
(
bint32
,
binary
.
Little
Endian
,
dataInt32
);
err
!=
nil
{
if
err
:=
binary
.
Write
(
bint32
,
common
.
Endian
,
dataInt32
);
err
!=
nil
{
panic
(
err
)
}
rawData
=
append
(
rawData
,
bint32
.
Bytes
()
...
)
...
...
@@ -359,7 +360,7 @@ func GenRowData() (rawData []byte) {
// int64
var
dataInt64
int64
=
400
bint64
:=
new
(
bytes
.
Buffer
)
if
err
:=
binary
.
Write
(
bint64
,
binary
.
Little
Endian
,
dataInt64
);
err
!=
nil
{
if
err
:=
binary
.
Write
(
bint64
,
common
.
Endian
,
dataInt64
);
err
!=
nil
{
panic
(
err
)
}
rawData
=
append
(
rawData
,
bint64
.
Bytes
()
...
)
...
...
@@ -367,7 +368,7 @@ func GenRowData() (rawData []byte) {
// float32
var
datafloat
float32
=
1.1
bfloat32
:=
new
(
bytes
.
Buffer
)
if
err
:=
binary
.
Write
(
bfloat32
,
binary
.
Little
Endian
,
datafloat
);
err
!=
nil
{
if
err
:=
binary
.
Write
(
bfloat32
,
common
.
Endian
,
datafloat
);
err
!=
nil
{
panic
(
err
)
}
rawData
=
append
(
rawData
,
bfloat32
.
Bytes
()
...
)
...
...
@@ -375,7 +376,7 @@ func GenRowData() (rawData []byte) {
// float64
var
datafloat64
=
2.2
bfloat64
:=
new
(
bytes
.
Buffer
)
if
err
:=
binary
.
Write
(
bfloat64
,
binary
.
Little
Endian
,
datafloat64
);
err
!=
nil
{
if
err
:=
binary
.
Write
(
bfloat64
,
common
.
Endian
,
datafloat64
);
err
!=
nil
{
panic
(
err
)
}
rawData
=
append
(
rawData
,
bfloat64
.
Bytes
()
...
)
...
...
internal/datanode/segment_replica.go
浏览文件 @
a0a3a889
...
...
@@ -18,7 +18,6 @@ package datanode
import
(
"context"
"encoding/binary"
"fmt"
"math"
"sync"
...
...
@@ -108,7 +107,7 @@ type SegmentReplica struct {
func
(
s
*
Segment
)
updatePKRange
(
pks
[]
int64
)
{
buf
:=
make
([]
byte
,
8
)
for
_
,
pk
:=
range
pks
{
binary
.
Big
Endian
.
PutUint64
(
buf
,
uint64
(
pk
))
common
.
Endian
.
PutUint64
(
buf
,
uint64
(
pk
))
s
.
pkFilter
.
Add
(
buf
)
if
pk
>
s
.
maxPK
{
s
.
maxPK
=
pk
...
...
internal/datanode/segment_replica_test.go
浏览文件 @
a0a3a889
...
...
@@ -18,7 +18,6 @@ package datanode
import
(
"context"
"encoding/binary"
"encoding/json"
"fmt"
"math"
...
...
@@ -725,7 +724,7 @@ func TestSegmentReplica_UpdatePKRange(t *testing.T) {
assert
.
LessOrEqual
(
t
,
seg
.
minPK
,
c
)
assert
.
GreaterOrEqual
(
t
,
seg
.
maxPK
,
c
)
binary
.
Big
Endian
.
PutUint64
(
buf
,
uint64
(
c
))
common
.
Endian
.
PutUint64
(
buf
,
uint64
(
c
))
assert
.
True
(
t
,
seg
.
pkFilter
.
Test
(
buf
))
}
}
...
...
@@ -767,7 +766,7 @@ func TestReplica_UpdatePKRange(t *testing.T) {
assert
.
LessOrEqual
(
t
,
segNormal
.
minPK
,
c
)
assert
.
GreaterOrEqual
(
t
,
segNormal
.
maxPK
,
c
)
binary
.
Big
Endian
.
PutUint64
(
buf
,
uint64
(
c
))
common
.
Endian
.
PutUint64
(
buf
,
uint64
(
c
))
assert
.
True
(
t
,
segNew
.
pkFilter
.
Test
(
buf
))
assert
.
True
(
t
,
segNormal
.
pkFilter
.
Test
(
buf
))
...
...
internal/proxy/proxy_test.go
浏览文件 @
a0a3a889
...
...
@@ -15,6 +15,8 @@ import (
"go.uber.org/zap"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/util/metricsinfo"
"github.com/milvus-io/milvus/internal/util/distance"
...
...
@@ -591,7 +593,7 @@ func TestProxy(t *testing.T) {
for
j
:=
0
;
j
<
dim
;
j
++
{
var
buffer
bytes
.
Buffer
f
:=
rand
.
Float32
()
err
:=
binary
.
Write
(
&
buffer
,
binary
.
Little
Endian
,
f
)
err
:=
binary
.
Write
(
&
buffer
,
common
.
Endian
,
f
)
assert
.
NoError
(
t
,
err
)
bs
=
append
(
bs
,
buffer
.
Bytes
()
...
)
}
...
...
internal/proxy/task.go
浏览文件 @
a0a3a889
...
...
@@ -496,7 +496,7 @@ func (it *insertTask) transferColumnBasedRequestToRowBasedData() error {
it
.
RowData
=
make
([]
*
commonpb
.
Blob
,
0
,
rowNum
)
l
:=
len
(
dTypes
)
// TODO(dragondriver): big endian or little endian?
endian
:=
binary
.
Little
Endian
endian
:=
common
.
Endian
printed
:=
false
for
i
:=
0
;
i
<
rowNum
;
i
++
{
blob
:=
&
commonpb
.
Blob
{
...
...
internal/proxy/task_test.go
浏览文件 @
a0a3a889
...
...
@@ -187,7 +187,7 @@ func constructPlaceholderGroup(
for
j
:=
0
;
j
<
dim
;
j
++
{
var
buffer
bytes
.
Buffer
f
:=
rand
.
Float32
()
err
:=
binary
.
Write
(
&
buffer
,
binary
.
Little
Endian
,
f
)
err
:=
binary
.
Write
(
&
buffer
,
common
.
Endian
,
f
)
if
err
!=
nil
{
panic
(
err
)
}
...
...
internal/querynode/data_sync_service_test.go
浏览文件 @
a0a3a889
...
...
@@ -13,12 +13,12 @@ package querynode
import
(
"context"
"encoding/binary"
"math"
"testing"
"github.com/stretchr/testify/assert"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/msgstream"
"github.com/milvus-io/milvus/internal/proto/commonpb"
"github.com/milvus-io/milvus/internal/proto/internalpb"
...
...
@@ -39,11 +39,11 @@ func TestDataSyncService_Start(t *testing.T) {
var
rawData
[]
byte
for
_
,
ele
:=
range
vec
{
buf
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
common
.
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
rawData
=
append
(
rawData
,
buf
...
)
}
bs
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
bs
,
1
)
common
.
Endian
.
PutUint32
(
bs
,
1
)
rawData
=
append
(
rawData
,
bs
...
)
var
records
[]
*
commonpb
.
Blob
for
i
:=
0
;
i
<
N
;
i
++
{
...
...
internal/querynode/flow_graph_insert_node.go
浏览文件 @
a0a3a889
...
...
@@ -22,6 +22,7 @@ import (
"github.com/opentracing/opentracing-go"
"go.uber.org/zap"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/log"
"github.com/milvus-io/milvus/internal/msgstream"
"github.com/milvus-io/milvus/internal/proto/commonpb"
...
...
@@ -229,7 +230,7 @@ func filterSegmentsByPKs(pks []int64, segment *Segment) ([]int64, error) {
buf
:=
make
([]
byte
,
8
)
res
:=
make
([]
int64
,
0
)
for
_
,
pk
:=
range
pks
{
binary
.
Big
Endian
.
PutUint64
(
buf
,
uint64
(
pk
))
common
.
Endian
.
PutUint64
(
buf
,
uint64
(
pk
))
exist
:=
segment
.
pkFilter
.
Test
(
buf
)
if
exist
{
res
=
append
(
res
,
pk
)
...
...
@@ -393,7 +394,7 @@ func (iNode *insertNode) getPrimaryKeys(msg *msgstream.InsertMsg) []int64 {
pks
:=
make
([]
int64
,
len
(
blobReaders
))
for
i
,
reader
:=
range
blobReaders
{
err
:=
binary
.
Read
(
reader
,
binary
.
Little
Endian
,
&
pks
[
i
])
err
:=
binary
.
Read
(
reader
,
common
.
Endian
,
&
pks
[
i
])
if
err
!=
nil
{
log
.
Warn
(
"binary read blob value failed"
,
zap
.
Error
(
err
))
}
...
...
internal/querynode/flow_graph_insert_node_test.go
浏览文件 @
a0a3a889
...
...
@@ -12,7 +12,6 @@
package
querynode
import
(
"encoding/binary"
"sync"
"testing"
...
...
@@ -267,7 +266,7 @@ func TestFlowGraphInsertNode_operate(t *testing.T) {
assert
.
Nil
(
t
,
err
)
buf
:=
make
([]
byte
,
8
)
for
i
:=
0
;
i
<
defaultMsgLength
;
i
++
{
binary
.
Big
Endian
.
PutUint64
(
buf
,
uint64
(
i
))
common
.
Endian
.
PutUint64
(
buf
,
uint64
(
i
))
assert
.
True
(
t
,
s
.
pkFilter
.
Test
(
buf
))
}
...
...
@@ -392,7 +391,7 @@ func TestGetSegmentsByPKs(t *testing.T) {
buf
:=
make
([]
byte
,
8
)
filter
:=
bloom
.
NewWithEstimates
(
1000000
,
0.01
)
for
i
:=
0
;
i
<
3
;
i
++
{
binary
.
Big
Endian
.
PutUint64
(
buf
,
uint64
(
i
))
common
.
Endian
.
PutUint64
(
buf
,
uint64
(
i
))
filter
.
Add
(
buf
)
}
segment
:=
&
Segment
{
...
...
internal/querynode/load_service_test.go
浏览文件 @
a0a3a889
...
...
@@ -13,13 +13,13 @@ package querynode
import
(
"context"
"encoding/binary"
"fmt"
"math"
"math/rand"
"path"
"strconv"
"github.com/milvus-io/milvus/internal/common"
minioKV
"github.com/milvus-io/milvus/internal/kv/minio"
"github.com/milvus-io/milvus/internal/msgstream"
"github.com/milvus-io/milvus/internal/proto/commonpb"
...
...
@@ -66,11 +66,11 @@ import (
// rowData := make([]byte, 0)
// for i := 0; i < DIM; i++ {
// vec := make([]byte, 4)
//
binary.Little
Endian.PutUint32(vec, math.Float32bits(float32(n*i)))
//
common.
Endian.PutUint32(vec, math.Float32bits(float32(n*i)))
// rowData = append(rowData, vec...)
// }
// age := make([]byte, 4)
//
binary.Little
Endian.PutUint32(age, 1)
//
common.
Endian.PutUint32(age, 1)
// rowData = append(rowData, age...)
// blob := &commonpb.Blob{
// Value: rowData,
...
...
@@ -161,7 +161,7 @@ import (
// var searchRowByteData []byte
// for i := range searchRowData {
// vec := make([]byte, 4)
//
binary.Little
Endian.PutUint32(vec, math.Float32bits(searchRowData[i]))
//
common.
Endian.PutUint32(vec, math.Float32bits(searchRowData[i]))
// searchRowByteData = append(searchRowByteData, vec...)
// }
// placeholderValue := milvuspb.PlaceholderValue{
...
...
@@ -404,7 +404,7 @@ import (
// rowData = append(rowData, indexRowData[offset:offset+(DIM/8)]...)
// offset += DIM / 8
// age := make([]byte, 4)
//
binary.Little
Endian.PutUint32(age, 1)
//
common.
Endian.PutUint32(age, 1)
// rowData = append(rowData, age...)
// blob := &commonpb.Blob{
// Value: rowData,
...
...
@@ -859,11 +859,11 @@ func doInsert(ctx context.Context, collectionID UniqueID, partitionID UniqueID,
var
rawData
[]
byte
for
_
,
ele
:=
range
vec
{
buf
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
common
.
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
rawData
=
append
(
rawData
,
buf
...
)
}
bs
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
bs
,
1
)
common
.
Endian
.
PutUint32
(
bs
,
1
)
rawData
=
append
(
rawData
,
bs
...
)
// messages generate
...
...
@@ -990,7 +990,7 @@ func doInsert(ctx context.Context, collectionID UniqueID, partitionID UniqueID,
// var vec = [DIM]float32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
// for _, ele := range vec {
// buf := make([]byte, 4)
//
binary.Little
Endian.PutUint32(buf, math.Float32bits(ele))
//
common.
Endian.PutUint32(buf, math.Float32bits(ele))
// searchRawData = append(searchRawData, buf...)
// }
// placeholderValue := milvuspb.PlaceholderValue{
...
...
internal/querynode/mock_test.go
浏览文件 @
a0a3a889
...
...
@@ -13,7 +13,6 @@ package querynode
import
(
"context"
"encoding/binary"
"errors"
"math"
"math/rand"
...
...
@@ -23,6 +22,7 @@ import (
"github.com/golang/protobuf/proto"
"go.uber.org/zap"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/indexnode"
etcdkv
"github.com/milvus-io/milvus/internal/kv/etcd"
minioKV
"github.com/milvus-io/milvus/internal/kv/minio"
...
...
@@ -597,11 +597,11 @@ func genCommonBlob(msgLength int, schema *schemapb.CollectionSchema) ([]*commonp
switch
f
.
DataType
{
case
schemapb
.
DataType_Int32
:
bs
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
bs
,
uint32
(
i
))
common
.
Endian
.
PutUint32
(
bs
,
uint32
(
i
))
rawData
=
append
(
rawData
,
bs
...
)
case
schemapb
.
DataType_Int64
:
bs
:=
make
([]
byte
,
8
)
binary
.
Little
Endian
.
PutUint32
(
bs
,
uint32
(
i
))
common
.
Endian
.
PutUint32
(
bs
,
uint32
(
i
))
rawData
=
append
(
rawData
,
bs
...
)
case
schemapb
.
DataType_FloatVector
:
dim
:=
simpleVecField
.
dim
// if no dim specified, use simpleVecField's dim
...
...
@@ -617,7 +617,7 @@ func genCommonBlob(msgLength int, schema *schemapb.CollectionSchema) ([]*commonp
for
j
:=
0
;
j
<
dim
;
j
++
{
f
:=
float32
(
i
*
j
)
*
0.1
buf
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
f
))
common
.
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
f
))
rawData
=
append
(
rawData
,
buf
...
)
}
default
:
...
...
@@ -1002,7 +1002,7 @@ func genSimplePlaceHolderGroup() ([]byte, error) {
var
rawData
[]
byte
for
k
,
ele
:=
range
vec
{
buf
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
+
float32
(
k
*
2
)))
common
.
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
+
float32
(
k
*
2
)))
rawData
=
append
(
rawData
,
buf
...
)
}
placeholderValue
.
Values
=
append
(
placeholderValue
.
Values
,
rawData
)
...
...
internal/querynode/plan_test.go
浏览文件 @
a0a3a889
...
...
@@ -13,13 +13,13 @@ package querynode
import
(
"context"
"encoding/binary"
"math"
"testing"
"github.com/golang/protobuf/proto"
"github.com/stretchr/testify/assert"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/proto/milvuspb"
"github.com/milvus-io/milvus/internal/proto/planpb"
)
...
...
@@ -92,12 +92,12 @@ func TestPlan_PlaceholderGroup(t *testing.T) {
var
vec
=
[
DIM
]
float32
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
16
}
for
i
,
ele
:=
range
vec
{
buf
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
+
float32
(
i
*
2
)))
common
.
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
+
float32
(
i
*
2
)))
searchRawData1
=
append
(
searchRawData1
,
buf
...
)
}
for
i
,
ele
:=
range
vec
{
buf
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
+
float32
(
i
*
4
)))
common
.
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
+
float32
(
i
*
4
)))
searchRawData2
=
append
(
searchRawData2
,
buf
...
)
}
placeholderValue
:=
milvuspb
.
PlaceholderValue
{
...
...
internal/querynode/query_collection.go
浏览文件 @
a0a3a889
...
...
@@ -13,7 +13,6 @@ package querynode
import
(
"context"
"encoding/binary"
"errors"
"fmt"
"math"
...
...
@@ -24,6 +23,7 @@ import (
oplog
"github.com/opentracing/opentracing-go/log"
"go.uber.org/zap"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/log"
"github.com/milvus-io/milvus/internal/msgstream"
"github.com/milvus-io/milvus/internal/proto/commonpb"
...
...
@@ -677,7 +677,7 @@ func translateHits(schema *typeutil.SchemaHelper, fieldIDs []int64, rawHits [][]
for
_
,
hit
:=
range
hits
{
for
_
,
row
:=
range
hit
.
RowData
{
dataBlob
:=
row
[
blobOffset
:
blobOffset
+
blobLen
]
data
:=
int32
(
int16
(
binary
.
Little
Endian
.
Uint16
(
dataBlob
)))
data
:=
int32
(
int16
(
common
.
Endian
.
Uint16
(
dataBlob
)))
colData
=
append
(
colData
,
data
)
}
}
...
...
@@ -700,7 +700,7 @@ func translateHits(schema *typeutil.SchemaHelper, fieldIDs []int64, rawHits [][]
for
_
,
hit
:=
range
hits
{
for
_
,
row
:=
range
hit
.
RowData
{
dataBlob
:=
row
[
blobOffset
:
blobOffset
+
blobLen
]
data
:=
int32
(
binary
.
Little
Endian
.
Uint32
(
dataBlob
))
data
:=
int32
(
common
.
Endian
.
Uint32
(
dataBlob
))
colData
=
append
(
colData
,
data
)
}
}
...
...
@@ -723,7 +723,7 @@ func translateHits(schema *typeutil.SchemaHelper, fieldIDs []int64, rawHits [][]
for
_
,
hit
:=
range
hits
{
for
_
,
row
:=
range
hit
.
RowData
{
dataBlob
:=
row
[
blobOffset
:
blobOffset
+
blobLen
]
data
:=
int64
(
binary
.
Little
Endian
.
Uint64
(
dataBlob
))
data
:=
int64
(
common
.
Endian
.
Uint64
(
dataBlob
))
colData
=
append
(
colData
,
data
)
}
}
...
...
@@ -746,7 +746,7 @@ func translateHits(schema *typeutil.SchemaHelper, fieldIDs []int64, rawHits [][]
for
_
,
hit
:=
range
hits
{
for
_
,
row
:=
range
hit
.
RowData
{
dataBlob
:=
row
[
blobOffset
:
blobOffset
+
blobLen
]
data
:=
math
.
Float32frombits
(
binary
.
Little
Endian
.
Uint32
(
dataBlob
))
data
:=
math
.
Float32frombits
(
common
.
Endian
.
Uint32
(
dataBlob
))
colData
=
append
(
colData
,
data
)
}
}
...
...
@@ -769,7 +769,7 @@ func translateHits(schema *typeutil.SchemaHelper, fieldIDs []int64, rawHits [][]
for
_
,
hit
:=
range
hits
{
for
_
,
row
:=
range
hit
.
RowData
{
dataBlob
:=
row
[
blobOffset
:
blobOffset
+
blobLen
]
data
:=
math
.
Float64frombits
(
binary
.
Little
Endian
.
Uint64
(
dataBlob
))
data
:=
math
.
Float64frombits
(
common
.
Endian
.
Uint64
(
dataBlob
))
colData
=
append
(
colData
,
data
)
}
}
...
...
internal/querynode/query_collection_test.go
浏览文件 @
a0a3a889
...
...
@@ -174,12 +174,12 @@ func TestQueryCollection_withoutVChannel(t *testing.T) {
var
searchRawData2
[]
byte
for
i
,
ele
:=
range
vec
{
buf
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
+
float32
(
i
*
2
)))
common
.
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
+
float32
(
i
*
2
)))
searchRawData1
=
append
(
searchRawData1
,
buf
...
)
}
for
i
,
ele
:=
range
vec
{
buf
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
+
float32
(
i
*
4
)))
common
.
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
+
float32
(
i
*
4
)))
searchRawData2
=
append
(
searchRawData2
,
buf
...
)
}
...
...
@@ -331,49 +331,49 @@ func TestQueryCollection_TranslateHits(t *testing.T) {
case
schemapb
.
DataType_Bool
:
var
buf
bytes
.
Buffer
for
i
:=
0
;
i
<
defaultMsgLength
;
i
++
{
err
:=
binary
.
Write
(
&
buf
,
binary
.
Little
Endian
,
true
)
err
:=
binary
.
Write
(
&
buf
,
common
.
Endian
,
true
)
assert
.
NoError
(
t
,
err
)
}
rawData
=
append
(
rawData
,
buf
.
Bytes
())
case
schemapb
.
DataType_Int8
:
var
buf
bytes
.
Buffer
for
i
:=
0
;
i
<
defaultMsgLength
;
i
++
{
err
:=
binary
.
Write
(
&
buf
,
binary
.
Little
Endian
,
int8
(
i
))
err
:=
binary
.
Write
(
&
buf
,
common
.
Endian
,
int8
(
i
))
assert
.
NoError
(
t
,
err
)
}
rawData
=
append
(
rawData
,
buf
.
Bytes
())
case
schemapb
.
DataType_Int16
:
var
buf
bytes
.
Buffer
for
i
:=
0
;
i
<
defaultMsgLength
;
i
++
{
err
:=
binary
.
Write
(
&
buf
,
binary
.
Little
Endian
,
int16
(
i
))
err
:=
binary
.
Write
(
&
buf
,
common
.
Endian
,
int16
(
i
))
assert
.
NoError
(
t
,
err
)
}
rawData
=
append
(
rawData
,
buf
.
Bytes
())
case
schemapb
.
DataType_Int32
:
var
buf
bytes
.
Buffer
for
i
:=
0
;
i
<
defaultMsgLength
;
i
++
{
err
:=
binary
.
Write
(
&
buf
,
binary
.
Little
Endian
,
int32
(
i
))
err
:=
binary
.
Write
(
&
buf
,
common
.
Endian
,
int32
(
i
))
assert
.
NoError
(
t
,
err
)
}
rawData
=
append
(
rawData
,
buf
.
Bytes
())
case
schemapb
.
DataType_Int64
:
var
buf
bytes
.
Buffer
for
i
:=
0
;
i
<
defaultMsgLength
;
i
++
{
err
:=
binary
.
Write
(
&
buf
,
binary
.
Little
Endian
,
int64
(
i
))
err
:=
binary
.
Write
(
&
buf
,
common
.
Endian
,
int64
(
i
))
assert
.
NoError
(
t
,
err
)
}
rawData
=
append
(
rawData
,
buf
.
Bytes
())
case
schemapb
.
DataType_Float
:
var
buf
bytes
.
Buffer
for
i
:=
0
;
i
<
defaultMsgLength
;
i
++
{
err
:=
binary
.
Write
(
&
buf
,
binary
.
Little
Endian
,
float32
(
i
))
err
:=
binary
.
Write
(
&
buf
,
common
.
Endian
,
float32
(
i
))
assert
.
NoError
(
t
,
err
)
}
rawData
=
append
(
rawData
,
buf
.
Bytes
())
case
schemapb
.
DataType_Double
:
var
buf
bytes
.
Buffer
for
i
:=
0
;
i
<
defaultMsgLength
;
i
++
{
err
:=
binary
.
Write
(
&
buf
,
binary
.
Little
Endian
,
float64
(
i
))
err
:=
binary
.
Write
(
&
buf
,
common
.
Endian
,
float64
(
i
))
assert
.
NoError
(
t
,
err
)
}
rawData
=
append
(
rawData
,
buf
.
Bytes
())
...
...
internal/querynode/query_service_test.go
浏览文件 @
a0a3a889
...
...
@@ -13,7 +13,6 @@ package querynode
import
(
"context"
"encoding/binary"
"math"
"math/rand"
"testing"
...
...
@@ -22,6 +21,7 @@ import (
"github.com/golang/protobuf/proto"
"github.com/stretchr/testify/assert"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/msgstream"
"github.com/milvus-io/milvus/internal/proto/commonpb"
"github.com/milvus-io/milvus/internal/proto/internalpb"
...
...
@@ -78,12 +78,12 @@ func sendSearchRequest(ctx context.Context, DIM int) error {
var
searchRawData2
[]
byte
for
i
,
ele
:=
range
vec
{
buf
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
+
float32
(
i
*
2
)))
common
.
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
+
float32
(
i
*
2
)))
searchRawData1
=
append
(
searchRawData1
,
buf
...
)
}
for
i
,
ele
:=
range
vec
{
buf
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
+
float32
(
i
*
4
)))
common
.
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
+
float32
(
i
*
4
)))
searchRawData2
=
append
(
searchRawData2
,
buf
...
)
}
...
...
internal/querynode/reduce_test.go
浏览文件 @
a0a3a889
...
...
@@ -12,7 +12,6 @@
package
querynode
import
(
"encoding/binary"
"log"
"math"
"testing"
...
...
@@ -20,6 +19,7 @@ import (
"github.com/golang/protobuf/proto"
"github.com/stretchr/testify/assert"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/proto/milvuspb"
)
...
...
@@ -40,12 +40,12 @@ func TestReduce_AllFunc(t *testing.T) {
var
searchRawData2
[]
byte
for
i
,
ele
:=
range
vec
{
buf
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
+
float32
(
i
*
2
)))
common
.
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
+
float32
(
i
*
2
)))
searchRawData1
=
append
(
searchRawData1
,
buf
...
)
}
for
i
,
ele
:=
range
vec
{
buf
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
+
float32
(
i
*
4
)))
common
.
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
+
float32
(
i
*
4
)))
searchRawData2
=
append
(
searchRawData2
,
buf
...
)
}
placeholderValue
:=
milvuspb
.
PlaceholderValue
{
...
...
internal/querynode/segment.go
浏览文件 @
a0a3a889
...
...
@@ -33,6 +33,7 @@ import (
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/log"
"github.com/milvus-io/milvus/internal/proto/commonpb"
"github.com/milvus-io/milvus/internal/proto/datapb"
...
...
@@ -384,7 +385,7 @@ func (s *Segment) fillVectorFieldsData(collectionID UniqueID,
}
floatResult
:=
make
([]
float32
,
dim
)
buf
:=
bytes
.
NewReader
(
content
)
err
=
binary
.
Read
(
buf
,
binary
.
Little
Endian
,
&
floatResult
)
err
=
binary
.
Read
(
buf
,
common
.
Endian
,
&
floatResult
)
if
err
!=
nil
{
return
err
}
...
...
@@ -542,9 +543,10 @@ func (s *Segment) checkIndexReady(fieldID int64) bool {
}
func
(
s
*
Segment
)
updateBloomFilter
(
pks
[]
int64
)
{
log
.
Debug
(
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx updateBloom Filter"
,
zap
.
Any
(
"pks"
,
pks
))
buf
:=
make
([]
byte
,
8
)
for
_
,
pk
:=
range
pks
{
binary
.
Big
Endian
.
PutUint64
(
buf
,
uint64
(
pk
))
common
.
Endian
.
PutUint64
(
buf
,
uint64
(
pk
))
s
.
pkFilter
.
Add
(
buf
)
}
}
...
...
internal/querynode/segment_test.go
浏览文件 @
a0a3a889
...
...
@@ -13,7 +13,6 @@ package querynode
import
(
"context"
"encoding/binary"
"log"
"math"
"sync"
...
...
@@ -22,6 +21,7 @@ import (
"github.com/golang/protobuf/proto"
"github.com/stretchr/testify/assert"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/proto/commonpb"
"github.com/milvus-io/milvus/internal/proto/datapb"
"github.com/milvus-io/milvus/internal/proto/milvuspb"
...
...
@@ -101,11 +101,11 @@ func TestSegment_getRowCount(t *testing.T) {
var
rawData
[]
byte
for
_
,
ele
:=
range
vec
{
buf
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
common
.
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
rawData
=
append
(
rawData
,
buf
...
)
}
bs
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
bs
,
1
)
common
.
Endian
.
PutUint32
(
bs
,
1
)
rawData
=
append
(
rawData
,
bs
...
)
var
records
[]
*
commonpb
.
Blob
for
i
:=
0
;
i
<
N
;
i
++
{
...
...
@@ -160,11 +160,11 @@ func TestSegment_retrieve(t *testing.T) {
var
rawData
[]
byte
for
_
,
ele
:=
range
vec
{
buf
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
+
float32
(
i
)
*
float32
(
N
)))
common
.
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
+
float32
(
i
)
*
float32
(
N
)))
rawData
=
append
(
rawData
,
buf
...
)
}
bs
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
bs
,
uint32
(
i
+
1
))
common
.
Endian
.
PutUint32
(
bs
,
uint32
(
i
+
1
))
rawData
=
append
(
rawData
,
bs
...
)
blob
:=
&
commonpb
.
Blob
{
Value
:
rawData
,
...
...
@@ -251,11 +251,11 @@ func TestSegment_getDeletedCount(t *testing.T) {
var
rawData
[]
byte
for
_
,
ele
:=
range
vec
{
buf
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
common
.
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
rawData
=
append
(
rawData
,
buf
...
)
}
bs
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
bs
,
1
)
common
.
Endian
.
PutUint32
(
bs
,
1
)
rawData
=
append
(
rawData
,
bs
...
)
var
records
[]
*
commonpb
.
Blob
for
i
:=
0
;
i
<
N
;
i
++
{
...
...
@@ -313,11 +313,11 @@ func TestSegment_getMemSize(t *testing.T) {
var
rawData
[]
byte
for
_
,
ele
:=
range
vec
{
buf
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
common
.
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
rawData
=
append
(
rawData
,
buf
...
)
}
bs
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
bs
,
1
)
common
.
Endian
.
PutUint32
(
bs
,
1
)
rawData
=
append
(
rawData
,
bs
...
)
var
records
[]
*
commonpb
.
Blob
for
i
:=
0
;
i
<
N
;
i
++
{
...
...
@@ -361,11 +361,11 @@ func TestSegment_segmentInsert(t *testing.T) {
var
rawData
[]
byte
for
_
,
ele
:=
range
vec
{
buf
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
common
.
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
rawData
=
append
(
rawData
,
buf
...
)
}
bs
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
bs
,
1
)
common
.
Endian
.
PutUint32
(
bs
,
1
)
rawData
=
append
(
rawData
,
bs
...
)
var
records
[]
*
commonpb
.
Blob
for
i
:=
0
;
i
<
N
;
i
++
{
...
...
@@ -421,11 +421,11 @@ func TestSegment_segmentDelete(t *testing.T) {
var
rawData
[]
byte
for
_
,
ele
:=
range
vec
{
buf
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
common
.
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
rawData
=
append
(
rawData
,
buf
...
)
}
bs
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
bs
,
1
)
common
.
Endian
.
PutUint32
(
bs
,
1
)
rawData
=
append
(
rawData
,
bs
...
)
var
records
[]
*
commonpb
.
Blob
for
i
:=
0
;
i
<
N
;
i
++
{
...
...
@@ -471,11 +471,11 @@ func TestSegment_segmentSearch(t *testing.T) {
var
rawData
[]
byte
for
_
,
ele
:=
range
vec
{
buf
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
common
.
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
rawData
=
append
(
rawData
,
buf
...
)
}
bs
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
bs
,
1
)
common
.
Endian
.
PutUint32
(
bs
,
1
)
rawData
=
append
(
rawData
,
bs
...
)
var
records
[]
*
commonpb
.
Blob
for
i
:=
0
;
i
<
N
;
i
++
{
...
...
@@ -495,7 +495,7 @@ func TestSegment_segmentSearch(t *testing.T) {
var
searchRawData
[]
byte
for
_
,
ele
:=
range
vec
{
buf
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
common
.
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
searchRawData
=
append
(
searchRawData
,
buf
...
)
}
placeholderValue
:=
milvuspb
.
PlaceholderValue
{
...
...
@@ -574,11 +574,11 @@ func TestSegment_segmentPreInsert(t *testing.T) {
var
rawData
[]
byte
for
_
,
ele
:=
range
vec
{
buf
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
common
.
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
rawData
=
append
(
rawData
,
buf
...
)
}
bs
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
bs
,
1
)
common
.
Endian
.
PutUint32
(
bs
,
1
)
rawData
=
append
(
rawData
,
bs
...
)
var
records
[]
*
commonpb
.
Blob
for
i
:=
0
;
i
<
N
;
i
++
{
...
...
@@ -616,11 +616,11 @@ func TestSegment_segmentPreDelete(t *testing.T) {
var
rawData
[]
byte
for
_
,
ele
:=
range
vec
{
buf
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
common
.
Endian
.
PutUint32
(
buf
,
math
.
Float32bits
(
ele
))
rawData
=
append
(
rawData
,
buf
...
)
}
bs
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
bs
,
1
)
common
.
Endian
.
PutUint32
(
bs
,
1
)
rawData
=
append
(
rawData
,
bs
...
)
var
records
[]
*
commonpb
.
Blob
for
i
:=
0
;
i
<
N
;
i
++
{
...
...
internal/storage/binlog_test.go
浏览文件 @
a0a3a889
...
...
@@ -24,6 +24,7 @@ import (
"github.com/milvus-io/milvus/internal/util/uniquegenerator"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/proto/schemapb"
"github.com/milvus-io/milvus/internal/util/tsoutil"
"github.com/stretchr/testify/assert"
...
...
@@ -1156,7 +1157,7 @@ func TestNewBinlogReaderError(t *testing.T) {
assert
.
NotNil
(
t
,
err
)
buffer
:=
new
(
bytes
.
Buffer
)
err
=
binary
.
Write
(
buffer
,
binary
.
Little
Endian
,
int32
(
MagicNumber
))
err
=
binary
.
Write
(
buffer
,
common
.
Endian
,
int32
(
MagicNumber
))
assert
.
Nil
(
t
,
err
)
data
=
buffer
.
Bytes
()
...
...
@@ -1164,7 +1165,7 @@ func TestNewBinlogReaderError(t *testing.T) {
assert
.
Nil
(
t
,
reader
)
assert
.
NotNil
(
t
,
err
)
err
=
binary
.
Write
(
buffer
,
binary
.
Little
Endian
,
int32
(
555
))
err
=
binary
.
Write
(
buffer
,
common
.
Endian
,
int32
(
555
))
assert
.
Nil
(
t
,
err
)
data
=
buffer
.
Bytes
()
...
...
internal/storage/binlog_writer.go
浏览文件 @
a0a3a889
...
...
@@ -16,6 +16,7 @@ import (
"encoding/binary"
"fmt"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/proto/schemapb"
)
...
...
@@ -94,7 +95,7 @@ func (writer *baseBinlogWriter) Close() error {
var
offset
int32
=
0
writer
.
buffer
=
new
(
bytes
.
Buffer
)
if
err
:=
binary
.
Write
(
writer
.
buffer
,
binary
.
Little
Endian
,
int32
(
MagicNumber
));
err
!=
nil
{
if
err
:=
binary
.
Write
(
writer
.
buffer
,
common
.
Endian
,
int32
(
MagicNumber
));
err
!=
nil
{
return
err
}
offset
+=
int32
(
binary
.
Size
(
MagicNumber
))
...
...
internal/storage/event_data.go
浏览文件 @
a0a3a889
...
...
@@ -19,6 +19,7 @@ import (
"io"
"strconv"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/proto/schemapb"
"github.com/milvus-io/milvus/internal/util/typeutil"
)
...
...
@@ -97,16 +98,16 @@ func (data *descriptorEventData) FinishExtra() error {
// Write transfer DescriptorEventDataFixPart to binary buffer.
func
(
data
*
descriptorEventData
)
Write
(
buffer
io
.
Writer
)
error
{
if
err
:=
binary
.
Write
(
buffer
,
binary
.
Little
Endian
,
data
.
DescriptorEventDataFixPart
);
err
!=
nil
{
if
err
:=
binary
.
Write
(
buffer
,
common
.
Endian
,
data
.
DescriptorEventDataFixPart
);
err
!=
nil
{
return
err
}
if
err
:=
binary
.
Write
(
buffer
,
binary
.
Little
Endian
,
data
.
PostHeaderLengths
);
err
!=
nil
{
if
err
:=
binary
.
Write
(
buffer
,
common
.
Endian
,
data
.
PostHeaderLengths
);
err
!=
nil
{
return
err
}
if
err
:=
binary
.
Write
(
buffer
,
binary
.
Little
Endian
,
data
.
ExtraLength
);
err
!=
nil
{
if
err
:=
binary
.
Write
(
buffer
,
common
.
Endian
,
data
.
ExtraLength
);
err
!=
nil
{
return
err
}
if
err
:=
binary
.
Write
(
buffer
,
binary
.
Little
Endian
,
data
.
ExtraBytes
);
err
!=
nil
{
if
err
:=
binary
.
Write
(
buffer
,
common
.
Endian
,
data
.
ExtraBytes
);
err
!=
nil
{
return
err
}
...
...
@@ -115,18 +116,18 @@ func (data *descriptorEventData) Write(buffer io.Writer) error {
func
readDescriptorEventData
(
buffer
io
.
Reader
)
(
*
descriptorEventData
,
error
)
{
event
:=
newDescriptorEventData
()
if
err
:=
binary
.
Read
(
buffer
,
binary
.
Little
Endian
,
&
event
.
DescriptorEventDataFixPart
);
err
!=
nil
{
if
err
:=
binary
.
Read
(
buffer
,
common
.
Endian
,
&
event
.
DescriptorEventDataFixPart
);
err
!=
nil
{
return
nil
,
err
}
if
err
:=
binary
.
Read
(
buffer
,
binary
.
Little
Endian
,
&
event
.
PostHeaderLengths
);
err
!=
nil
{
if
err
:=
binary
.
Read
(
buffer
,
common
.
Endian
,
&
event
.
PostHeaderLengths
);
err
!=
nil
{
return
nil
,
err
}
if
err
:=
binary
.
Read
(
buffer
,
binary
.
Little
Endian
,
&
event
.
ExtraLength
);
err
!=
nil
{
if
err
:=
binary
.
Read
(
buffer
,
common
.
Endian
,
&
event
.
ExtraLength
);
err
!=
nil
{
return
nil
,
err
}
event
.
ExtraBytes
=
make
([]
byte
,
event
.
ExtraLength
)
if
err
:=
binary
.
Read
(
buffer
,
binary
.
Little
Endian
,
&
event
.
ExtraBytes
);
err
!=
nil
{
if
err
:=
binary
.
Read
(
buffer
,
common
.
Endian
,
&
event
.
ExtraBytes
);
err
!=
nil
{
return
nil
,
err
}
if
err
:=
json
.
Unmarshal
(
event
.
ExtraBytes
,
&
event
.
Extras
);
err
!=
nil
{
...
...
@@ -164,7 +165,7 @@ func (data *insertEventData) WriteEventData(buffer io.Writer) error {
if
data
.
EndTimestamp
==
0
{
return
errors
.
New
(
"hasn't set end time stamp"
)
}
return
binary
.
Write
(
buffer
,
binary
.
Little
Endian
,
data
)
return
binary
.
Write
(
buffer
,
common
.
Endian
,
data
)
}
type
deleteEventData
struct
{
...
...
@@ -188,7 +189,7 @@ func (data *deleteEventData) WriteEventData(buffer io.Writer) error {
if
data
.
EndTimestamp
==
0
{
return
errors
.
New
(
"hasn't set end time stamp"
)
}
return
binary
.
Write
(
buffer
,
binary
.
Little
Endian
,
data
)
return
binary
.
Write
(
buffer
,
common
.
Endian
,
data
)
}
type
createCollectionEventData
struct
{
...
...
@@ -212,7 +213,7 @@ func (data *createCollectionEventData) WriteEventData(buffer io.Writer) error {
if
data
.
EndTimestamp
==
0
{
return
errors
.
New
(
"hasn't set end time stamp"
)
}
return
binary
.
Write
(
buffer
,
binary
.
Little
Endian
,
data
)
return
binary
.
Write
(
buffer
,
common
.
Endian
,
data
)
}
type
dropCollectionEventData
struct
{
...
...
@@ -236,7 +237,7 @@ func (data *dropCollectionEventData) WriteEventData(buffer io.Writer) error {
if
data
.
EndTimestamp
==
0
{
return
errors
.
New
(
"hasn't set end time stamp"
)
}
return
binary
.
Write
(
buffer
,
binary
.
Little
Endian
,
data
)
return
binary
.
Write
(
buffer
,
common
.
Endian
,
data
)
}
type
createPartitionEventData
struct
{
...
...
@@ -260,7 +261,7 @@ func (data *createPartitionEventData) WriteEventData(buffer io.Writer) error {
if
data
.
EndTimestamp
==
0
{
return
errors
.
New
(
"hasn't set end time stamp"
)
}
return
binary
.
Write
(
buffer
,
binary
.
Little
Endian
,
data
)
return
binary
.
Write
(
buffer
,
common
.
Endian
,
data
)
}
type
dropPartitionEventData
struct
{
...
...
@@ -284,7 +285,7 @@ func (data *dropPartitionEventData) WriteEventData(buffer io.Writer) error {
if
data
.
EndTimestamp
==
0
{
return
errors
.
New
(
"hasn't set end time stamp"
)
}
return
binary
.
Write
(
buffer
,
binary
.
Little
Endian
,
data
)
return
binary
.
Write
(
buffer
,
common
.
Endian
,
data
)
}
type
indexFileEventData
struct
{
...
...
@@ -308,7 +309,7 @@ func (data *indexFileEventData) WriteEventData(buffer io.Writer) error {
if
data
.
EndTimestamp
==
0
{
return
errors
.
New
(
"hasn't set end time stamp"
)
}
return
binary
.
Write
(
buffer
,
binary
.
Little
Endian
,
data
)
return
binary
.
Write
(
buffer
,
common
.
Endian
,
data
)
}
func
getEventFixPartSize
(
code
EventTypeCode
)
int32
{
...
...
@@ -400,7 +401,7 @@ func newIndexFileEventData() *indexFileEventData {
func
readInsertEventDataFixPart
(
buffer
io
.
Reader
)
(
*
insertEventData
,
error
)
{
data
:=
&
insertEventData
{}
if
err
:=
binary
.
Read
(
buffer
,
binary
.
Little
Endian
,
data
);
err
!=
nil
{
if
err
:=
binary
.
Read
(
buffer
,
common
.
Endian
,
data
);
err
!=
nil
{
return
nil
,
err
}
return
data
,
nil
...
...
@@ -408,7 +409,7 @@ func readInsertEventDataFixPart(buffer io.Reader) (*insertEventData, error) {
func
readDeleteEventDataFixPart
(
buffer
io
.
Reader
)
(
*
deleteEventData
,
error
)
{
data
:=
&
deleteEventData
{}
if
err
:=
binary
.
Read
(
buffer
,
binary
.
Little
Endian
,
data
);
err
!=
nil
{
if
err
:=
binary
.
Read
(
buffer
,
common
.
Endian
,
data
);
err
!=
nil
{
return
nil
,
err
}
return
data
,
nil
...
...
@@ -416,7 +417,7 @@ func readDeleteEventDataFixPart(buffer io.Reader) (*deleteEventData, error) {
func
readCreateCollectionEventDataFixPart
(
buffer
io
.
Reader
)
(
*
createCollectionEventData
,
error
)
{
data
:=
&
createCollectionEventData
{}
if
err
:=
binary
.
Read
(
buffer
,
binary
.
Little
Endian
,
data
);
err
!=
nil
{
if
err
:=
binary
.
Read
(
buffer
,
common
.
Endian
,
data
);
err
!=
nil
{
return
nil
,
err
}
return
data
,
nil
...
...
@@ -424,7 +425,7 @@ func readCreateCollectionEventDataFixPart(buffer io.Reader) (*createCollectionEv
func
readDropCollectionEventDataFixPart
(
buffer
io
.
Reader
)
(
*
dropCollectionEventData
,
error
)
{
data
:=
&
dropCollectionEventData
{}
if
err
:=
binary
.
Read
(
buffer
,
binary
.
Little
Endian
,
data
);
err
!=
nil
{
if
err
:=
binary
.
Read
(
buffer
,
common
.
Endian
,
data
);
err
!=
nil
{
return
nil
,
err
}
return
data
,
nil
...
...
@@ -432,7 +433,7 @@ func readDropCollectionEventDataFixPart(buffer io.Reader) (*dropCollectionEventD
func
readCreatePartitionEventDataFixPart
(
buffer
io
.
Reader
)
(
*
createPartitionEventData
,
error
)
{
data
:=
&
createPartitionEventData
{}
if
err
:=
binary
.
Read
(
buffer
,
binary
.
Little
Endian
,
data
);
err
!=
nil
{
if
err
:=
binary
.
Read
(
buffer
,
common
.
Endian
,
data
);
err
!=
nil
{
return
nil
,
err
}
return
data
,
nil
...
...
@@ -440,7 +441,7 @@ func readCreatePartitionEventDataFixPart(buffer io.Reader) (*createPartitionEven
func
readDropPartitionEventDataFixPart
(
buffer
io
.
Reader
)
(
*
dropPartitionEventData
,
error
)
{
data
:=
&
dropPartitionEventData
{}
if
err
:=
binary
.
Read
(
buffer
,
binary
.
Little
Endian
,
data
);
err
!=
nil
{
if
err
:=
binary
.
Read
(
buffer
,
common
.
Endian
,
data
);
err
!=
nil
{
return
nil
,
err
}
return
data
,
nil
...
...
@@ -448,7 +449,7 @@ func readDropPartitionEventDataFixPart(buffer io.Reader) (*dropPartitionEventDat
func
readIndexFileEventDataFixPart
(
buffer
io
.
Reader
)
(
*
indexFileEventData
,
error
)
{
data
:=
&
indexFileEventData
{}
if
err
:=
binary
.
Read
(
buffer
,
binary
.
Little
Endian
,
data
);
err
!=
nil
{
if
err
:=
binary
.
Read
(
buffer
,
common
.
Endian
,
data
);
err
!=
nil
{
return
nil
,
err
}
return
data
,
nil
...
...
internal/storage/event_header.go
浏览文件 @
a0a3a889
...
...
@@ -16,6 +16,7 @@ import (
"io"
"time"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/util/tsoutil"
"github.com/milvus-io/milvus/internal/util/typeutil"
)
...
...
@@ -32,7 +33,7 @@ func (header *baseEventHeader) GetMemoryUsageInBytes() int32 {
}
func
(
header
*
baseEventHeader
)
Write
(
buffer
io
.
Writer
)
error
{
return
binary
.
Write
(
buffer
,
binary
.
Little
Endian
,
header
)
return
binary
.
Write
(
buffer
,
common
.
Endian
,
header
)
}
type
descriptorEventHeader
=
baseEventHeader
...
...
@@ -43,7 +44,7 @@ type eventHeader struct {
func
readEventHeader
(
buffer
io
.
Reader
)
(
*
eventHeader
,
error
)
{
header
:=
&
eventHeader
{}
if
err
:=
binary
.
Read
(
buffer
,
binary
.
Little
Endian
,
header
);
err
!=
nil
{
if
err
:=
binary
.
Read
(
buffer
,
common
.
Endian
,
header
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -52,7 +53,7 @@ func readEventHeader(buffer io.Reader) (*eventHeader, error) {
func
readDescriptorEventHeader
(
buffer
io
.
Reader
)
(
*
descriptorEventHeader
,
error
)
{
header
:=
&
descriptorEventHeader
{}
if
err
:=
binary
.
Read
(
buffer
,
binary
.
Little
Endian
,
header
);
err
!=
nil
{
if
err
:=
binary
.
Read
(
buffer
,
common
.
Endian
,
header
);
err
!=
nil
{
return
nil
,
err
}
return
header
,
nil
...
...
internal/storage/event_test.go
浏览文件 @
a0a3a889
...
...
@@ -19,6 +19,7 @@ import (
"time"
"unsafe"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/proto/schemapb"
"github.com/milvus-io/milvus/internal/util/tsoutil"
"github.com/stretchr/testify/assert"
...
...
@@ -1242,7 +1243,7 @@ func TestReadFixPartError(t *testing.T) {
assert
.
NotNil
(
t
,
err
)
event
:=
newDescriptorEventData
()
err
=
binary
.
Write
(
buf
,
binary
.
Little
Endian
,
event
.
DescriptorEventDataFixPart
)
err
=
binary
.
Write
(
buf
,
common
.
Endian
,
event
.
DescriptorEventDataFixPart
)
assert
.
Nil
(
t
,
err
)
_
,
err
=
readDescriptorEventData
(
buf
)
assert
.
NotNil
(
t
,
err
)
...
...
@@ -1284,7 +1285,7 @@ func TestEventReaderError(t *testing.T) {
StartTimestamp
:
1000
,
EndTimestamp
:
2000
,
}
err
=
binary
.
Write
(
buf
,
binary
.
Little
Endian
,
insertData
)
err
=
binary
.
Write
(
buf
,
common
.
Endian
,
insertData
)
assert
.
Nil
(
t
,
err
)
r
,
err
=
newEventReader
(
schemapb
.
DataType_Int64
,
buf
)
...
...
internal/storage/event_writer.go
浏览文件 @
a0a3a889
...
...
@@ -19,6 +19,7 @@ import (
"io"
"strconv"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/proto/schemapb"
)
...
...
@@ -81,7 +82,7 @@ func (event *descriptorEvent) Write(buffer io.Writer) error {
func
readMagicNumber
(
buffer
io
.
Reader
)
(
int32
,
error
)
{
var
magicNumber
int32
if
err
:=
binary
.
Read
(
buffer
,
binary
.
Little
Endian
,
&
magicNumber
);
err
!=
nil
{
if
err
:=
binary
.
Read
(
buffer
,
common
.
Endian
,
&
magicNumber
);
err
!=
nil
{
return
-
1
,
err
}
if
magicNumber
!=
MagicNumber
{
...
...
@@ -148,7 +149,7 @@ func (writer *baseEventWriter) Write(buffer *bytes.Buffer) error {
if
err
!=
nil
{
return
err
}
if
err
:=
binary
.
Write
(
buffer
,
binary
.
Little
Endian
,
data
);
err
!=
nil
{
if
err
:=
binary
.
Write
(
buffer
,
common
.
Endian
,
data
);
err
!=
nil
{
return
err
}
return
nil
...
...
internal/storage/event_writer_test.go
浏览文件 @
a0a3a889
...
...
@@ -16,6 +16,7 @@ import (
"encoding/binary"
"testing"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/proto/schemapb"
"github.com/stretchr/testify/assert"
)
...
...
@@ -32,7 +33,7 @@ func TestEventTypeCode_String(t *testing.T) {
func
TestSizeofStruct
(
t
*
testing
.
T
)
{
var
buf
bytes
.
Buffer
err
:=
binary
.
Write
(
&
buf
,
binary
.
Little
Endian
,
baseEventHeader
{})
err
:=
binary
.
Write
(
&
buf
,
common
.
Endian
,
baseEventHeader
{})
assert
.
Nil
(
t
,
err
)
s1
:=
binary
.
Size
(
baseEventHeader
{})
s2
:=
binary
.
Size
(
&
baseEventHeader
{})
...
...
@@ -95,12 +96,12 @@ func TestReadMagicNumber(t *testing.T) {
assert
.
Error
(
t
,
err
)
// not a magic number
_
=
binary
.
Write
(
&
buf
,
binary
.
Little
Endian
,
MagicNumber
+
1
)
_
=
binary
.
Write
(
&
buf
,
common
.
Endian
,
MagicNumber
+
1
)
_
,
err
=
readMagicNumber
(
&
buf
)
assert
.
Error
(
t
,
err
)
// normal case
_
=
binary
.
Write
(
&
buf
,
binary
.
Little
Endian
,
MagicNumber
)
_
=
binary
.
Write
(
&
buf
,
common
.
Endian
,
MagicNumber
)
num
,
err
:=
readMagicNumber
(
&
buf
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
MagicNumber
,
num
)
...
...
internal/storage/stats.go
浏览文件 @
a0a3a889
...
...
@@ -12,10 +12,10 @@
package
storage
import
(
"encoding/binary"
"encoding/json"
"github.com/bits-and-blooms/bloom/v3"
"github.com/milvus-io/milvus/internal/common"
)
const
(
...
...
@@ -57,7 +57,7 @@ func (sw *StatsWriter) StatsInt64(fieldID int64, isPrimaryKey bool, msgs []int64
stats
.
BF
=
bloom
.
NewWithEstimates
(
bloomFilterSize
,
maxBloomFalsePositive
)
b
:=
make
([]
byte
,
8
)
for
_
,
msg
:=
range
msgs
{
binary
.
Little
Endian
.
PutUint64
(
b
,
uint64
(
msg
))
common
.
Endian
.
PutUint64
(
b
,
uint64
(
msg
))
stats
.
BF
.
Add
(
b
)
}
}
...
...
internal/storage/stats_test.go
浏览文件 @
a0a3a889
...
...
@@ -12,7 +12,6 @@
package
storage
import
(
"encoding/binary"
"testing"
"github.com/milvus-io/milvus/internal/common"
...
...
@@ -35,7 +34,7 @@ func TestStatsWriter_StatsInt64(t *testing.T) {
assert
.
Equal
(
t
,
stats
.
Min
,
int64
(
1
))
buffer
:=
make
([]
byte
,
8
)
for
_
,
id
:=
range
data
{
binary
.
Little
Endian
.
PutUint64
(
buffer
,
uint64
(
id
))
common
.
Endian
.
PutUint64
(
buffer
,
uint64
(
id
))
assert
.
True
(
t
,
stats
.
BF
.
Test
(
buffer
))
}
...
...
internal/storage/utils_test.go
浏览文件 @
a0a3a889
...
...
@@ -20,6 +20,7 @@ import (
"fmt"
"testing"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/util/funcutil"
"github.com/milvus-io/milvus/internal/util/uniquegenerator"
...
...
@@ -64,7 +65,7 @@ func (kv *mockWrongHeaderDataKV) LoadPartial(key string, start, end int64) ([]by
header
.
NextPosition
=
-
1
buffer
:=
bytes
.
Buffer
{}
_
=
binary
.
Write
(
&
buffer
,
binary
.
Little
Endian
,
header
)
_
=
binary
.
Write
(
&
buffer
,
common
.
Endian
,
header
)
return
buffer
.
Bytes
(),
nil
}
...
...
@@ -247,7 +248,7 @@ func (kv *mockFailedToGetDescDataKV) LoadPartial(key string, start, end int64) (
}
buf
:=
bytes
.
Buffer
{}
_
=
binary
.
Write
(
&
buf
,
binary
.
Little
Endian
,
header
)
_
=
binary
.
Write
(
&
buf
,
common
.
Endian
,
header
)
return
buf
.
Bytes
(),
nil
}
...
...
@@ -278,7 +279,7 @@ func (kv *mockLessDescDataKV) LoadPartial(key string, start, end int64) ([]byte,
header
.
EventLength
=
20
buffer
:=
bytes
.
Buffer
{}
_
=
binary
.
Write
(
&
buffer
,
binary
.
Little
Endian
,
header
)
_
=
binary
.
Write
(
&
buffer
,
common
.
Endian
,
header
)
// no event data
return
buffer
.
Bytes
(),
nil
...
...
@@ -288,7 +289,7 @@ func (kv *mockLessDescDataKV) LoadPartial(key string, start, end int64) ([]byte,
desc.ExtraLength = 2
desc.ExtraBytes = []byte{1, 2}
buffer := bytes.Buffer{}
_ = binary.Write(&buffer,
binary.Little
Endian, desc)
_ = binary.Write(&buffer,
common.
Endian, desc)
// extra not in json format
return buffer.Bytes(), nil
*/
...
...
internal/storage/vector_chunk_manager.go
浏览文件 @
a0a3a889
...
...
@@ -17,6 +17,7 @@ import (
"errors"
"io"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/proto/etcdpb"
)
...
...
@@ -73,7 +74,7 @@ func (vcm *VectorChunkManager) downloadVectorFile(key string) ([]byte, error) {
floatVector
,
ok
:=
singleData
.
(
*
FloatVectorFieldData
)
if
ok
{
buf
:=
new
(
bytes
.
Buffer
)
err
:=
binary
.
Write
(
buf
,
binary
.
Little
Endian
,
floatVector
.
Data
)
err
:=
binary
.
Write
(
buf
,
common
.
Endian
,
floatVector
.
Data
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
internal/util/mqclient/pulsar_client_test.go
浏览文件 @
a0a3a889
...
...
@@ -23,6 +23,7 @@ import (
"go.uber.org/zap"
"github.com/apache/pulsar-client-go/pulsar"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/log"
"github.com/stretchr/testify/assert"
)
...
...
@@ -30,14 +31,14 @@ import (
func
IntToBytes
(
n
int
)
[]
byte
{
tmp
:=
int32
(
n
)
bytesBuffer
:=
bytes
.
NewBuffer
([]
byte
{})
binary
.
Write
(
bytesBuffer
,
binary
.
Big
Endian
,
tmp
)
binary
.
Write
(
bytesBuffer
,
common
.
Endian
,
tmp
)
return
bytesBuffer
.
Bytes
()
}
func
BytesToInt
(
b
[]
byte
)
int
{
bytesBuffer
:=
bytes
.
NewBuffer
(
b
)
var
tmp
int32
binary
.
Read
(
bytesBuffer
,
binary
.
Big
Endian
,
&
tmp
)
binary
.
Read
(
bytesBuffer
,
common
.
Endian
,
&
tmp
)
return
int
(
tmp
)
}
...
...
internal/util/mqclient/rmq_id.go
浏览文件 @
a0a3a889
...
...
@@ -12,8 +12,7 @@
package
mqclient
import
(
"encoding/binary"
"github.com/milvus-io/milvus/internal/common"
"github.com/milvus-io/milvus/internal/util/rocksmq/server/rocksmq"
)
...
...
@@ -52,11 +51,11 @@ func (rid *rmqID) PartitionIdx() int32 {
// SerializeRmqID is used to serialize a message ID to byte array
func
SerializeRmqID
(
messageID
int64
)
[]
byte
{
b
:=
make
([]
byte
,
8
)
binary
.
Little
Endian
.
PutUint64
(
b
,
uint64
(
messageID
))
common
.
Endian
.
PutUint64
(
b
,
uint64
(
messageID
))
return
b
}
// DeserializeRmqID is used to deserialize a message ID from byte array
func
DeserializeRmqID
(
messageID
[]
byte
)
(
int64
,
error
)
{
return
int64
(
binary
.
Little
Endian
.
Uint64
(
messageID
)),
nil
return
int64
(
common
.
Endian
.
Uint64
(
messageID
)),
nil
}
internal/util/typeutil/convension.go
浏览文件 @
a0a3a889
...
...
@@ -12,24 +12,25 @@
package
typeutil
import
(
"encoding/binary"
"fmt"
"math"
"reflect"
"github.com/milvus-io/milvus/internal/common"
)
// Float32ToBytes converts a float to byte slice.
func
Float32ToBytes
(
float
float32
)
[]
byte
{
bits
:=
math
.
Float32bits
(
float
)
bytes
:=
make
([]
byte
,
4
)
binary
.
Little
Endian
.
PutUint32
(
bytes
,
bits
)
common
.
Endian
.
PutUint32
(
bytes
,
bits
)
return
bytes
}
// BytesToFloat32 converts a byte slice to float32.
func
BytesToFloat32
(
bytes
[]
byte
)
float32
{
bits
:=
binary
.
Little
Endian
.
Uint32
(
bytes
)
bits
:=
common
.
Endian
.
Uint32
(
bytes
)
return
math
.
Float32frombits
(
bits
)
}
...
...
@@ -40,13 +41,13 @@ func BytesToInt64(b []byte) (int64, error) {
return
0
,
fmt
.
Errorf
(
"Failed to convert []byte to int64: invalid data, must 8 bytes, but %d"
,
len
(
b
))
}
return
int64
(
binary
.
Big
Endian
.
Uint64
(
b
)),
nil
return
int64
(
common
.
Endian
.
Uint64
(
b
)),
nil
}
// Int64ToBytes converts uint64 to a byte slice.
func
Int64ToBytes
(
v
int64
)
[]
byte
{
b
:=
make
([]
byte
,
8
)
binary
.
Big
Endian
.
PutUint64
(
b
,
uint64
(
v
))
common
.
Endian
.
PutUint64
(
b
,
uint64
(
v
))
return
b
}
...
...
@@ -56,13 +57,13 @@ func BytesToUint64(b []byte) (uint64, error) {
return
0
,
fmt
.
Errorf
(
"Failed to convert []byte to uint64: invalid data, must 8 bytes, but %d"
,
len
(
b
))
}
return
binary
.
Big
Endian
.
Uint64
(
b
),
nil
return
common
.
Endian
.
Uint64
(
b
),
nil
}
// Uint64ToBytes converts uint64 to a byte slice.
func
Uint64ToBytes
(
v
uint64
)
[]
byte
{
b
:=
make
([]
byte
,
8
)
binary
.
Big
Endian
.
PutUint64
(
b
,
v
)
common
.
Endian
.
PutUint64
(
b
,
v
)
return
b
}
...
...
internal/util/typeutil/hash.go
浏览文件 @
a0a3a889
...
...
@@ -12,9 +12,9 @@
package
typeutil
import
(
"encoding/binary"
"unsafe"
"github.com/milvus-io/milvus/internal/common"
"github.com/spaolacci/murmur3"
)
...
...
@@ -32,7 +32,7 @@ func Hash32Uint64(v uint64) (uint32, error) {
// need unsafe package to get element byte size
/* #nosec G103 */
b
:=
make
([]
byte
,
unsafe
.
Sizeof
(
v
))
binary
.
Little
Endian
.
PutUint64
(
b
,
v
)
common
.
Endian
.
PutUint64
(
b
,
v
)
return
Hash32Bytes
(
b
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录