Skip to content

Commit 648078e

Browse files
authored
fix: [2.4] Fix 0 read count during import (#38696)
issue: #38693 pr: #38694 Signed-off-by: bigsheeper <[email protected]>
1 parent 5fd69a0 commit 648078e

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

internal/util/importutilv2/common/util.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,15 @@ func EstimateReadCountPerBatch(bufferSize int, schema *schemapb.CollectionSchema
8484
if err != nil {
8585
return 0, err
8686
}
87+
if sizePerRecord <= 0 || bufferSize <= 0 {
88+
return 0, fmt.Errorf("invalid size, sizePerRecord=%d, bufferSize=%d", sizePerRecord, bufferSize)
89+
}
8790
if 1000*sizePerRecord <= bufferSize {
8891
return 1000, nil
8992
}
90-
return int64(bufferSize) / int64(sizePerRecord), nil
93+
ret := int64(bufferSize) / int64(sizePerRecord)
94+
if ret <= 0 {
95+
return 1, nil
96+
}
97+
return ret, nil
9198
}

internal/util/importutilv2/common/util_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,43 @@ func TestUtil_EstimateReadCountPerBatch(t *testing.T) {
6666
_, err = EstimateReadCountPerBatch(16*1024*1024, schema)
6767
assert.Error(t, err)
6868
}
69+
70+
func TestUtil_EstimateReadCountPerBatch_InvalidBufferSize(t *testing.T) {
71+
schema := &schemapb.CollectionSchema{}
72+
count, err := EstimateReadCountPerBatch(16*1024*1024, schema)
73+
assert.Error(t, err)
74+
assert.Equal(t, int64(0), count)
75+
t.Logf("err=%v", err)
76+
77+
schema = &schemapb.CollectionSchema{
78+
Fields: []*schemapb.FieldSchema{
79+
{
80+
FieldID: 100,
81+
DataType: schemapb.DataType_Int64,
82+
},
83+
},
84+
}
85+
count, err = EstimateReadCountPerBatch(0, schema)
86+
assert.Error(t, err)
87+
assert.Equal(t, int64(0), count)
88+
t.Logf("err=%v", err)
89+
}
90+
91+
func TestUtil_EstimateReadCountPerBatch_LargeSchema(t *testing.T) {
92+
schema := &schemapb.CollectionSchema{}
93+
for i := 0; i < 100; i++ {
94+
schema.Fields = append(schema.Fields, &schemapb.FieldSchema{
95+
FieldID: int64(i),
96+
DataType: schemapb.DataType_VarChar,
97+
TypeParams: []*commonpb.KeyValuePair{
98+
{
99+
Key: common.MaxLengthKey,
100+
Value: "10000000",
101+
},
102+
},
103+
})
104+
}
105+
count, err := EstimateReadCountPerBatch(16*1024*1024, schema)
106+
assert.NoError(t, err)
107+
assert.Equal(t, int64(1), count)
108+
}

0 commit comments

Comments
 (0)