databendlabs/databend · error

internal error: entered unreachable code

Error message

internal error: entered unreachable code

What it means

Compression::from_u8 maps a serialized u8 tag (from segment/snapshot metadata) back to a Compression enum. It panics with unreachable! when the stored byte is not one of the known tags 0..=5. This means the metadata on disk was written by an incompatible (newer) format version or is corrupted.

Solutions

  1. Upgrade Databend to a version at least as new as the one that wrote the metadata
  2. Check the compression byte in the offending segment/snapshot file for corruption
  3. Restore the table metadata from a backup taken with a compatible version
  4. If you added a new Compression variant, add a matching arm to from_u8 (ideally returning an error instead of panicking)

Example fix

// before
_ => unreachable!(),
// after
v => Err(ErrorCode::StorageOther(format!(
    "unknown compression tag {v} in metadata; table may be from a newer version"
))),
Defensive patterns

Strategy: fallback

Validate before calling

// rust: validate compression byte before decoding
fn valid_compression_tag(b: u8) -> bool { b <= 5 }

Type guard

fn is_known_compression(b: u8) -> bool { b <= 5 }

Try / catch

// expect a panic from from_u8 on unknown tags; wrap meta load
let compression = std::panic::catch_unwind(|| Compression::from_u8(tag))
    .map_err(|_| "unknown compression tag; metadata may be from a newer version")?;

Prevention

When it happens

Trigger: Reading a segment/snapshot whose serialized compression byte exceeds 5 — e.g. metadata produced by a newer Databend that added a Compression variant, then read by an older binary; or corrupted meta files.

Common situations: Downgrade scenarios (new cluster data read by old release); manually edited or damaged table metadata; snapshot/segment files copied between incompatible versions.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of databendlabs/databend@288d84d76e (2026-09-11). Data as JSON: /api/errors/86c14331f0e427e0. Report an issue: GitHub.

Appendix: source

Thrown at src/query/storages/common/table_meta/src/meta/compression.rs:53

        match self {
            Compression::Lz4 => 0,
            Compression::Lz4Raw => 1,
            Compression::Snappy => 2,
            Compression::Zstd => 3,
            Compression::Gzip => 4,
            Compression::None => 5,
        }
    }

    pub fn from_u8(value: u8) -> Self {
        match value {
            0 => Compression::Lz4,
            1 => Compression::Lz4Raw,
            2 => Compression::Snappy,
            3 => Compression::Zstd,
            4 => Compression::Gzip,
            5 => Compression::None,
            _ => unreachable!(),
        }
    }
}

View on GitHub (pinned to 288d84d76e)