Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#306 - Compactor flush to backend based on buffer size #325

Merged
merged 3 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/tempo/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ func (c *Config) CheckConfig() {
level.Warn(util.Logger).Log("msg", "compactor.compaction.compacted_block_timeout < storage.trace.blocklist_poll",
"explan", "Queriers and Compactors may attempt to read a block that no longer exists")
}

if c.StorageConfig.Trace.Backend == "s3" && c.Compactor.Compactor.FlushSizeBytes < 5242880 {
level.Warn(util.Logger).Log("msg", "c.Compactor.Compactor.FlushSizeBytes < 5242880",
"explan", "Compaction flush size should be 5MB or higher for S3 backend")
}
}

// App is the root datastructure.
Expand Down
1 change: 1 addition & 0 deletions example/docker-compose/etc/tempo-s3-minio.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ compactor:
max_compaction_objects: 1000000 # maximum size of compacted blocks
block_retention: 1h
compacted_block_retention: 10m
flush_size_bytes: 5242880

storage:
trace:
Expand Down
5 changes: 3 additions & 2 deletions modules/compactor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ type Config struct {
OverrideRingKey string `yaml:"override_ring_key"`
}

// RegisterFlags registers the flags.
// RegisterFlagsAndApplyDefaults registers the flags.
func (cfg *Config) RegisterFlagsAndApplyDefaults(prefix string, f *flag.FlagSet) {
cfg.Compactor = tempodb.CompactorConfig{
ChunkSizeBytes: 10485760, // 10 MiB
ChunkSizeBytes: 10 * 1024 * 1024, // 10 MiB
FlushSizeBytes: 30 * 1024 * 1024, // 30 MiB
CompactedBlockRetention: time.Hour,
}

Expand Down
3 changes: 1 addition & 2 deletions tempodb/compactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const (
inputBlocks = 2
outputBlocks = 1

recordsPerBatch = 1000
compactionCycle = 30 * time.Second
)

Expand Down Expand Up @@ -182,7 +181,7 @@ func (rw *readerWriter) compact(blockMetas []*encoding.BlockMeta, tenantID strin
lowestBookmark.clear()

// write partial block
if currentBlock.Length()%recordsPerBatch == 0 {
if currentBlock.CurrentBufferLength() >= int(rw.compactorCfg.FlushSizeBytes) {
tracker, err = appendBlock(rw, tracker, currentBlock)
if err != nil {
return errors.Wrap(err, "error writing partial block")
Expand Down
1 change: 1 addition & 0 deletions tempodb/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Config struct {

type CompactorConfig struct {
ChunkSizeBytes uint32 `yaml:"chunk_size_bytes"` // todo: do we need this?
FlushSizeBytes uint32 `yaml:"flush_size_bytes"`
MaxCompactionRange time.Duration `yaml:"compaction_window"`
MaxCompactionObjects int `yaml:"max_compaction_objects"`
BlockRetention time.Duration `yaml:"block_retention"`
Expand Down
4 changes: 4 additions & 0 deletions tempodb/wal/compactor_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func (c *CompactorBlock) CurrentBuffer() []byte {
return c.appendBuffer.Bytes()
}

func (c *CompactorBlock) CurrentBufferLength() int {
return c.appendBuffer.Len()
}

func (c *CompactorBlock) ResetBuffer() {
c.appendBuffer.Reset()
}
Expand Down