From 8bc5282eb39d8c2cf978a63e0bfe6e0d60d3c0c3 Mon Sep 17 00:00:00 2001 From: yah01 Date: Tue, 20 Jun 2023 16:40:42 +0800 Subject: [PATCH] Fix datanode always retries to load stats even file corrupted (#25012) Signed-off-by: yah01 --- internal/storage/stats.go | 11 +++++++++-- internal/storage/stats_test.go | 10 ++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/internal/storage/stats.go b/internal/storage/stats.go index 363ea6c882..3caee1b487 100644 --- a/internal/storage/stats.go +++ b/internal/storage/stats.go @@ -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 diff --git a/internal/storage/stats_test.go b/internal/storage/stats_test.go index 8fa7034ca2..610566828e 100644 --- a/internal/storage/stats_test.go +++ b/internal/storage/stats_test.go @@ -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) +}