From 0c3eb68f4865d67630af813080ac23d7c6b46072 Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Wed, 16 Sep 2020 13:45:31 -0400 Subject: [PATCH] Clean-up Badger's trace-not-found check (#2481) --- plugin/storage/badger/spanstore/read_write_test.go | 2 +- plugin/storage/badger/spanstore/reader.go | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/plugin/storage/badger/spanstore/read_write_test.go b/plugin/storage/badger/spanstore/read_write_test.go index 0c5f921dd76..91796387c0a 100644 --- a/plugin/storage/badger/spanstore/read_write_test.go +++ b/plugin/storage/badger/spanstore/read_write_test.go @@ -303,7 +303,7 @@ func TestFindNothing(t *testing.T) { trs, err := sr.FindTraces(context.Background(), params) assert.NoError(t, err) - assert.Equal(t, 0, len(trs)) + assert.Len(t, trs, 0) tr, err := sr.GetTrace(context.Background(), model.TraceID{High: 0, Low: 0}) assert.Equal(t, spanstore.ErrTraceNotFound, err) diff --git a/plugin/storage/badger/spanstore/reader.go b/plugin/storage/badger/spanstore/reader.go index c5d2ccf848f..b89020382b5 100644 --- a/plugin/storage/badger/spanstore/reader.go +++ b/plugin/storage/badger/spanstore/reader.go @@ -54,6 +54,9 @@ var ( // ErrNotSupported during development, don't support every option - yet ErrNotSupported = errors.New("this query parameter is not supported yet") + + // ErrInternalConsistencyError indicates internal data consistency issue + ErrInternalConsistencyError = errors.New("internal data consistency issue") ) const ( @@ -160,11 +163,14 @@ func (r *TraceReader) GetTrace(ctx context.Context, traceID model.TraceID) (*mod if err != nil { return nil, err } + if len(traces) == 0 { + return nil, spanstore.ErrTraceNotFound + } if len(traces) == 1 { return traces[0], nil } - return nil, spanstore.ErrTraceNotFound + return nil, ErrInternalConsistencyError } // scanTimeRange returns all the Traces found between startTs and endTs