Skip to content

Commit

Permalink
cgo zstd
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-elliott committed Sep 10, 2021
1 parent 9ef685e commit 04bae4a
Show file tree
Hide file tree
Showing 98 changed files with 64,679 additions and 48 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ALL_DOC := $(shell find . \( -name "*.md" -o -name "*.yaml" \) \
# ALL_PKGS is used with 'go cover'
ALL_PKGS := $(shell go list $(sort $(dir $(ALL_SRC))))

GO_OPT= -mod vendor -ldflags "-X main.Branch=$(GIT_BRANCH) -X main.Revision=$(GIT_REVISION) -X main.Version=$(VERSION)"
GO_OPT= -mod vendor -tags 'netgo osusergo nethttpomithttp2' -ldflags "-X main.Branch=$(GIT_BRANCH) -X main.Revision=$(GIT_REVISION) -X main.Version=$(VERSION) -s -w -extldflags '-static'"
GOTEST_OPT?= -race -timeout 10m -count=1
GOTEST_OPT_WITH_COVERAGE = $(GOTEST_OPT) -cover
GOTEST=go test
Expand All @@ -40,7 +40,7 @@ FILES_TO_FMT=$(shell find . -type d \( -path ./vendor -o -path ./opentelemetry-p

.PHONY: tempo
tempo:
GO111MODULE=on CGO_ENABLED=0 go build $(GO_OPT) -o ./bin/$(GOOS)/tempo-$(GOARCH) $(BUILD_INFO) ./cmd/tempo
GO111MODULE=on CGO_ENABLED=1 go build $(GO_OPT) -o ./bin/$(GOOS)/tempo-$(GOARCH) $(BUILD_INFO) ./cmd/tempo

.PHONY: tempo-query
tempo-query:
Expand Down
3 changes: 3 additions & 0 deletions cmd/tempo/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM alpine:3.9 as certs
RUN apk --update add ca-certificates
# RUN apk add --no-cache git make build-base zstd-dev
ARG TARGETARCH
COPY bin/linux/tempo-${TARGETARCH} /tempo
ENTRYPOINT ["/tempo"]


1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
contrib.go.opencensus.io/exporter/prometheus v0.3.0
github.com/Azure/azure-pipeline-go v0.2.2
github.com/Azure/azure-storage-blob-go v0.8.0
github.com/DataDog/zstd v1.4.8
github.com/alecthomas/kong v0.2.11
github.com/aws/aws-sdk-go v1.38.68
github.com/cespare/xxhash v1.1.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ github.com/DataDog/datadog-go v2.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/zstd v1.3.6-0.20190409195224-796139022798/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/DataDog/zstd v1.4.4/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/DataDog/zstd v1.4.8 h1:Rpmta4xZ/MgZnriKNd24iZMhGpP5dvUcs/uqfBapKZY=
github.com/DataDog/zstd v1.4.8/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/HdrHistogram/hdrhistogram-go v0.9.0/go.mod h1:nxrse8/Tzg2tg3DZcZjm6qEclQKK70g0KxO61gFFZD4=
github.com/HdrHistogram/hdrhistogram-go v1.0.1/go.mod h1:BWJ+nMSHY3L41Zj7CA3uXnloDp7xxV0YvstAE7nKTaM=
github.com/HdrHistogram/hdrhistogram-go v1.1.0 h1:6dpdDPTRoo78HxAJ6T1HfMiKSnqhgRRqzCuPshRkQ7I=
Expand Down
27 changes: 4 additions & 23 deletions tempodb/encoding/v2/data_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ import (
tempo_io "github.com/grafana/tempo/pkg/io"
"github.com/grafana/tempo/tempodb/backend"
"github.com/grafana/tempo/tempodb/encoding/common"
"github.com/klauspost/compress/zstd"
)

type dataReader struct {
contextReader backend.ContextReader

pageBuffer []byte

encoding backend.Encoding
pool ReaderPool
compressedReader io.Reader
}
Expand All @@ -35,7 +33,6 @@ func NewDataReader(r backend.ContextReader, encoding backend.Encoding) (common.D
}

return &dataReader{
encoding: encoding,
contextReader: r,
pool: pool,
}, nil
Expand Down Expand Up @@ -108,12 +105,7 @@ func (r *dataReader) Read(ctx context.Context, records []common.Record, pagesBuf
return nil, nil, err
}

decoder, ok := reader.(*zstd.Decoder)
if ok {
pagesBuffer[i], err = decoder.DecodeAll(page, pagesBuffer[i][:0])
} else {
pagesBuffer[i], err = tempo_io.ReadAllWithBuffer(reader, len(page), pagesBuffer[i])
}
pagesBuffer[i], err = tempo_io.ReadAllWithBuffer(reader, len(page), pagesBuffer[i])
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -146,13 +138,7 @@ func (r *dataReader) NextPage(buffer []byte) ([]byte, uint32, error) {
return nil, 0, err
}

decoder, ok := compressedReader.(*zstd.Decoder)
if ok {
buffer, err = decoder.DecodeAll(page.data, buffer[:0])
} else {
buffer, err = tempo_io.ReadAllWithBuffer(compressedReader, len(page.data), buffer)
}

buffer, err = tempo_io.ReadAllWithBuffer(compressedReader, len(page.data), buffer)
if err != nil {
return nil, 0, err
}
Expand All @@ -162,15 +148,10 @@ func (r *dataReader) NextPage(buffer []byte) ([]byte, uint32, error) {

func (r *dataReader) getCompressedReader(page []byte) (io.Reader, error) {
var err error
var reader io.Reader
if r.encoding != backend.EncZstd {
reader = bytes.NewReader(page)
}

if r.compressedReader == nil {
r.compressedReader, err = r.pool.GetReader(reader)
r.compressedReader, err = r.pool.GetReader(bytes.NewReader(page))
} else {
r.compressedReader, err = r.pool.ResetReader(reader, r.compressedReader)
r.compressedReader, err = r.pool.ResetReader(bytes.NewReader(page), r.compressedReader)
}
return r.compressedReader, err
}
34 changes: 11 additions & 23 deletions tempodb/encoding/v2/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"io"
"sync"

"github.com/DataDog/zstd"
"github.com/golang/snappy"
"github.com/grafana/tempo/tempodb/backend"
"github.com/klauspost/compress/gzip"
"github.com/klauspost/compress/zstd"
"github.com/pierrec/lz4/v4"
"github.com/prometheus/prometheus/pkg/pool"
)
Expand Down Expand Up @@ -350,47 +350,35 @@ func (pool *ZstdPool) Encoding() backend.Encoding {

// GetReader gets or creates a new CompressionReader and reset it to read from src
func (pool *ZstdPool) GetReader(src io.Reader) (io.Reader, error) {
reader, err := zstd.NewReader(src)
if err != nil {
return nil, err
}
return reader, nil
return zstd.NewReader(src), nil
}

// PutReader places back in the pool a CompressionReader
func (pool *ZstdPool) PutReader(reader io.Reader) {
r := reader.(*zstd.Decoder)
r := reader.(io.ReadCloser)
r.Close()
}

// ResetReader implements ReaderPool
func (pool *ZstdPool) ResetReader(src io.Reader, resetReader io.Reader) (io.Reader, error) {
reader := resetReader.(*zstd.Decoder)
err := reader.Reset(src)
if err != nil {
return nil, err
}
return reader, nil
pool.PutReader(resetReader)
// there is no reset - jpe
return pool.GetReader(src)
}

// GetWriter gets or creates a new CompressionWriter and reset it to write to dst
func (pool *ZstdPool) GetWriter(dst io.Writer) (io.WriteCloser, error) {
w, err := zstd.NewWriter(dst)
if err != nil {
return nil, err
}
return w, nil
return zstd.NewWriter(dst), nil
}

// PutWriter places back in the pool a CompressionWriter
func (pool *ZstdPool) PutWriter(writer io.WriteCloser) {
w := writer.(*zstd.Encoder)
w.Close()
// writer.(*zstd.Writer).Flush()
// writer.Close()
}

// ResetWriter implements WriterPool
func (pool *ZstdPool) ResetWriter(dst io.Writer, resetWriter io.WriteCloser) (io.WriteCloser, error) {
writer := resetWriter.(*zstd.Encoder)
writer.Reset(dst)
return writer, nil
pool.PutWriter(resetWriter)
return pool.GetWriter(dst)
}
27 changes: 27 additions & 0 deletions vendor/github.com/DataDog/zstd/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

127 changes: 127 additions & 0 deletions vendor/github.com/DataDog/zstd/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions vendor/github.com/DataDog/zstd/ZSTD_LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 04bae4a

Please sign in to comment.