opensi·si

A Shard is a serialized object containing file reconstruction information and xorb metadata for deduplication purposes.

Shard Format

A Shard is a serialized object containing file reconstruction information and xorb metadata for deduplication purposes.

The Shard format is the vehicle for uploading the file reconstruction upload and communicating information about xorbs and chunks that clients can deduplicate their data against.

Overview

The MDB (Merkle Database) shard file format is a binary format used to store file metadata and content-addressable storage (CAS) information for efficient deduplication and retrieval. This document describes the binary layout and deserialization process for the shard format. Implementors of the xet protocol MUST use the shard format when implementing the upload protocol. The shard format is used on the shard upload (record files) and global deduplication APIs.

Use As API Request and Response Bodies

The shard format is used in the shard upload API as the request payload and in the global deduplication/chunk query API as the response payload.

Shard Upload

The shard in this case is a serialization format that allows clients to denote the files that they are uploading. Each file reconstruction maps to a File Info block in the File Info section. Additionally, the listing of all new xorbs that the client created are mapped to items (CAS Info blocks) in the CAS Info section so that they may be deduplicated against in the future.

When uploading a shard the footer section MUST be omitted.

An example of a shard that can be used for file upload can be found in Xet reference files. A version of this shard that also contains the footer in Xet reference files too, see the README for the reference files dataset for more context.

Global Deduplication

Shards returned by the Global Deduplication API have an empty File Info Section, and only contain relevant information in the CAS Info section. The CAS Info section returned by this API contains xorbs, where a xorb described in the CAS Info section contains the chunk that was queried. Clients can deduplicate their content against any of the other xorbs described in any CAS Info block in the CAS Info section of the returned shard. Other xorb descriptions returned in a shard are possibly more likely to reference content that the client has.

An example of a shard that can be returned for a global deduplication query can be found in Xet reference files.

File Structure

A shard file consists of the following sections in order:

┌─────────────────────┐
│ Header              │
├─────────────────────┤
│ File Info Section   │
├─────────────────────┤
│ CAS Info Section    │
├─────────────────────┤
│ Footer              │
└─────────────────────┘

Overall File Layout with Byte Offsets

Offset 0:
┌───────────────────────────────────────────────────────┐
│                 Header (48 bytes)                     │ ← Fixed size
└───────────────────────────────────────────────────────┘

Offset footer.file_info_offset:
┌───────────────────────────────────────────────────────┐
│                                                       │
│              File Info Section                        │ ← Variable size
│            (Multiple file blocks +                    │
│               bookend entry)                          │
│                                                       │
└───────────────────────────────────────────────────────┘

Offset footer.cas_info_offset:
┌───────────────────────────────────────────────────────┐
│                                                       │
│               CAS Info Section                        │ ← Variable size
│            (Multiple CAS blocks +                     │
│               bookend entry)                          │
│                                                       │
└───────────────────────────────────────────────────────┘

Offset footer.footer_offset:
┌───────────────────────────────────────────────────────┐
│         Footer (200 bytes, sometimes omitted)         │ ← Fixed size
└───────────────────────────────────────────────────────┘

Constants

  • MDB_SHARD_HEADER_VERSION: 2
  • MDB_SHARD_FOOTER_VERSION: 1
  • MDB_FILE_INFO_ENTRY_SIZE: 48 bytes (size of each file info structure)
  • MDB_CAS_INFO_ENTRY_SIZE: 48 bytes (size of each CAS info structure)
  • MDB_SHARD_HEADER_TAG: 32-byte magic identifier

Data Types

All multi-byte integers are stored in little-endian format.

  • u8: 8-bit unsigned integer
  • u32: 32-bit unsigned integer
  • u64: 64-bit unsigned integer
  • Byte Array types are denoted like in rust as [u8; N] where N is the number of bytes in the array.
  • Hash: 32-byte hash value, a special [u8; 32]

1. Header (MDBShardFileHeader)

Location: Start of file (offset 0) Size: 48 bytes

struct MDBShardFileHeader {
    tag: [u8; 32],           // Magic number identifier
    version: u64,            // Header version (must be 2)
    footer_size: u64,        // Size of footer in bytes, set to 0 if footer is omitted
}

Memory Layout:

┌────────────────────────────────────────────────────────────────┬───────────┬───────────┐
│                          tag (32 bytes)                        │  version  │ footer_sz │
│                    Magic Number Identifier                     │ (8 bytes) │ (8 bytes) │
└────────────────────────────────────────────────────────────────┴───────────┴───────────┘
0                                                               32          40         48

Deserialization steps:

  1. Read 32 bytes for the magic tag
  2. Verify tag matches MDB_SHARD_HEADER_TAG
  3. Read 8 bytes for version (u64)
  4. Verify version equals 2
  5. Read 8 bytes for footer_size (u64)

Note When serializing, footer_size MUST be the number of bytes that make up the footer, or 0 if the footer is omitted.