dgraph-io/badger · error

Unsupported compression type

Error message

Unsupported compression type

What it means

Builder.compressData encodes a block according to the table's compression option. Only None (no compression), Snappy (s2), and ZSTD are implemented; any other options.Compression value causes compressData to return the 'Unsupported compression type' error, which fails the table build.

Source

Thrown at table/builder.go:523

func (b *Builder) shouldEncrypt() bool {
	return b.opts.DataKey != nil
}

// compressData compresses the given data.
func (b *Builder) compressData(data []byte) ([]byte, error) {
	switch b.opts.Compression {
	case options.None:
		return data, nil
	case options.Snappy:
		sz := s2.MaxEncodedLen(len(data))
		dst := b.alloc.Allocate(sz)
		return s2.EncodeSnappy(dst, data), nil
	case options.ZSTD:
		sz := y.ZSTDCompressBound(len(data))
		dst := b.alloc.Allocate(sz)
		return y.ZSTDCompress(dst, data, b.opts.ZSTDCompressionLevel)
	}
	return nil, errors.New("Unsupported compression type")
}

func (b *Builder) buildIndex(bloom []byte) ([]byte, uint32) {
	builder := fbs.NewBuilder(3 << 20)

	boList, dataSize := b.writeBlockOffsets(builder)
	// Write block offset vector the the idxBuilder.
	fb.TableIndexStartOffsetsVector(builder, len(boList))

	// Write individual block offsets in reverse order to work around how Flatbuffers expects it.
	for i := len(boList) - 1; i >= 0; i-- {
		builder.PrependUOffsetT(boList[i])
	}
	boEnd := builder.EndVector(len(boList))

	var bfoff fbs.UOffsetT
	// Write the bloom filter.
	if len(bloom) > 0 {

View on GitHub (pinned to 2a001d466f)

Solutions

  1. Set Options.Compression to options.None, options.Snappy, or options.ZSTD before opening/creating the DB
  2. If options were persisted, delete or fix the option/manifest so a supported compression id is loaded
  3. Check the options package of your Badger version for the exact enum constants; don't cast raw ints into options.Compression
  4. If high compression isn't required, fall back to options.None to guarantee compatibility

Example fix

// before
opts := badger.DefaultOptions(dir)
opts.Compression = options.Compression(7) // unknown type
// after
opts := badger.DefaultOptions(dir)
opts.Compression = options.ZSTD // or options.Snappy / options.None
Defensive patterns

Strategy: validation

Validate before calling

func compressionSupported(c options.Compression) bool {
	return c == options.None || c == options.Snappy || c == options.ZSTD
}
if !compressionSupported(opts.Compression) {
	return errors.New("unsupported compression type in options")
}

Type guard

func isKnownCompression(c options.Compression) bool {
	switch c {
	case options.None, options.Snappy, options.ZSTD:
		return true
	default:
		return false
	}
}

Try / catch

data, err := b.compressData(dst, block, blockOff)
if err != nil {
	if strings.Contains(err.Error(), "Unsupported compression type") {
		// fall back to a supported compression
		return b.compressData(dst, block, blockOff) // after correcting opts.Compression
	}
	return err
}

Prevention

When it happens

Trigger: Creating a table (via builder handleBlock) with opts.Compression set to a value other than options.None, options.Snappy, or options.ZSTD — e.g. a value from a different/older options enum, a custom integer cast, or an options file that persisted an unknown compression id.

Common situations: Migrating options across Badger versions where the compression enum changed; constructing Options programmatically with an invalid compression constant; restoring a DB whose option metadata references an algorithm this build doesn't support (e.g. a build without ZSTD support in older versions).

Related errors


AI-assisted analysis of dgraph-io/badger@2a001d466f (2026-09-05). Data as JSON: /api/errors/935cc1b79a0305af. Report an issue: GitHub.