From 71a9c4027e4ca3836e6330db72fc470240eb06ba Mon Sep 17 00:00:00 2001 From: Piotr Wolski Date: Wed, 13 Oct 2021 19:49:39 +0200 Subject: [PATCH 1/2] ddsketch/store: Compact buffer paginated store before encoding --- ddsketch/store/buffered_paginated.go | 1 + 1 file changed, 1 insertion(+) diff --git a/ddsketch/store/buffered_paginated.go b/ddsketch/store/buffered_paginated.go index f08bf55..7484fa3 100644 --- a/ddsketch/store/buffered_paginated.go +++ b/ddsketch/store/buffered_paginated.go @@ -571,6 +571,7 @@ func (s *BufferedPaginatedStore) Reweight(w float64) error { func (s *BufferedPaginatedStore) Encode(b *[]byte, t enc.FlagType) { if len(s.buffer) > 0 { + s.compact() enc.EncodeFlag(b, enc.NewFlag(t, enc.BinEncodingIndexDeltas)) enc.EncodeUvarint64(b, uint64(len(s.buffer))) previousIndex := 0 From 47d600901f2c7dcada77be5f4e680133e6e379ae Mon Sep 17 00:00:00 2001 From: Charles Masson Date: Thu, 6 Jan 2022 11:26:35 +0100 Subject: [PATCH 2/2] Compact before checking buffer length Compacting may cause the buffer to become empty, in which case there is no need to encode the buffer. --- ddsketch/store/buffered_paginated.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ddsketch/store/buffered_paginated.go b/ddsketch/store/buffered_paginated.go index 7484fa3..7ec5fb8 100644 --- a/ddsketch/store/buffered_paginated.go +++ b/ddsketch/store/buffered_paginated.go @@ -570,8 +570,8 @@ func (s *BufferedPaginatedStore) Reweight(w float64) error { } func (s *BufferedPaginatedStore) Encode(b *[]byte, t enc.FlagType) { + s.compact() if len(s.buffer) > 0 { - s.compact() enc.EncodeFlag(b, enc.NewFlag(t, enc.BinEncodingIndexDeltas)) enc.EncodeUvarint64(b, uint64(len(s.buffer))) previousIndex := 0