Fix datanode always retries to load stats even file corrupted (#25012)

Signed-off-by: yah01 <yang.cen@zilliz.com>
This commit is contained in:
yah01 2023-06-20 16:40:42 +08:00 committed by GitHub
parent 73b7cf5df4
commit 8bc5282eb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -24,6 +24,7 @@ import (
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
"github.com/milvus-io/milvus/pkg/common"
"github.com/milvus-io/milvus/pkg/log"
"github.com/milvus-io/milvus/pkg/util/merr"
)
const (
@ -254,7 +255,10 @@ func (sr *StatsReader) GetPrimaryKeyStats() (*PrimaryKeyStats, error) {
stats := &PrimaryKeyStats{}
err := json.Unmarshal(sr.buffer, &stats)
if err != nil {
return nil, err
return nil, merr.WrapErrParameterInvalid(
"valid JSON",
string(sr.buffer),
err.Error())
}
return stats, nil
@ -265,7 +269,10 @@ func (sr *StatsReader) GetPrimaryKeyStatsList() ([]*PrimaryKeyStats, error) {
stats := []*PrimaryKeyStats{}
err := json.Unmarshal(sr.buffer, &stats)
if err != nil {
return nil, err
return nil, merr.WrapErrParameterInvalid(
"valid JSON",
string(sr.buffer),
err.Error())
}
return stats, nil

View File

@ -25,6 +25,7 @@ import (
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
"github.com/milvus-io/milvus/pkg/common"
"github.com/milvus-io/milvus/pkg/util/merr"
)
func TestStatsWriter_Int64PrimaryKey(t *testing.T) {
@ -155,3 +156,12 @@ func TestStatsWriter_UpgradePrimaryKey(t *testing.T) {
assert.True(t, unmarshaledStats.BF.Test(buffer))
}
}
func TestDeserializeStatsFailed(t *testing.T) {
blob := &Blob{
Value: []byte("abc"),
}
_, err := DeserializeStatsList(blob)
assert.ErrorIs(t, err, merr.ErrParameterInvalid)
}