icechunk-format 2.0.0-alpha.6

Binary format types and serialization for the Icechunk storage engine
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
> [!WARNING]
> These schematics were generated by Claude Code and have received minimal review
> They are useful to get a high-level overview, but may be wrong.


# Icechunk Flatbuffer File Format Schema

This document describes the flatbuffer metadata files used by Icechunk for
storing repository state, snapshots, manifests, and transaction logs.

## Storage Layout

```
<repository-root>/
|
+-- repo                    # Repository info file (Repo flatbuffer)
|
+-- config.yaml             # Configuration file (YAML)
|
+-- snapshots/              # Snapshot files
|   +-- <snapshot-id>       # Individual snapshot (Snapshot flatbuffer)
|   +-- ...
|
+-- manifests/              # Manifest files
|   +-- <manifest-id>       # Individual manifest (Manifest flatbuffer)
|   +-- ...
|
+-- chunks/                 # Chunk data files
|   +-- <chunk-id>          # Raw chunk data (compressed bytes)
|   +-- ...
|
+-- transactions/           # Transaction log files
    +-- <snapshot-id>       # Transaction log (TransactionLog flatbuffer)
    +-- ...
```

## File Header Format (39 bytes)

All flatbuffer files (except chunks) have a 39-byte header:

```
+---+---+---+---+---+---+---+---+---+---+---+---+---  ...  ---+---+---+---+
| I | C | E |  ice cube (4B)| C | H | U | N | K | impl (24B)  | V | F | C |
+---+---+---+---+---+---+---+---+---+---+---+---+---  ...  ---+---+---+---+
  0   1   2   3   4   5   6   7   8   9  10  11  12        35  36  37  38

Bytes 0-11:  Magic bytes "ICE🧊CHUNK" (12 bytes: "ICE"=3, 🧊=4 UTF-8, "CHUNK"=5)
Bytes 12-35: Implementation name, padded to 24 bytes (e.g., "ic-0.1.0")
Byte 36:     Spec version (1=V1.0, 2=V2.0)
Byte 37:     File type (1=Snapshot, 2=Manifest, 3=Attributes,
                        4=TransactionLog, 5=Chunk, 6=RepoInfo)
Byte 38:     Compression (0=None, 1=Zstd)
```

## Object ID Types

```
ObjectId12 (12 bytes)                ObjectId8 (8 bytes)
+-------------------------+          +------------------+
|     bytes[12]           |          |    bytes[8]      |
+-------------------------+          +------------------+
Used for: SnapshotId,                Used for: NodeId
          ManifestId,                  (arrays, groups)
          ChunkId,
          AttributesId
```

IDs are encoded as Crockford Base32 strings for display/paths.

## Repo File (Root Repository State)

The `repo` file is the entry point to an Icechunk repository.
It contains all branches, tags, and a summary of all snapshots.

```
+==================================================================+
|                           REPO                                   |
+==================================================================+
| spec_version: u8              # Format version (1 or 2)          |
+------------------------------------------------------------------+
| tags: [Ref]                   # Named tag references             |
|   +-- name: string                                               |
|   +-- snapshot_index: u32     # Index into snapshots[]           |
+------------------------------------------------------------------+
| branches: [Ref]               # Named branch references          |
|   +-- name: string                                               |
|   +-- snapshot_index: u32     # Index into snapshots[]           |
+------------------------------------------------------------------+
| deleted_tags: [string]        # Names of deleted tags            |
+------------------------------------------------------------------+
| snapshots: [SnapshotInfo]     # All snapshots in repo            |
|   +-- id: ObjectId12                                             |
|   +-- parent_offset: i32      # Offset to parent in this array   |
|   +-- flushed_at: u64         # Microseconds since Unix epoch    |
|   +-- message: string         # Commit message                   |
|   +-- metadata: [MetadataItem]?                                  |
+------------------------------------------------------------------+
| status: RepoStatus            # Repository availability          |
|   +-- availability: enum      # Online/ReadOnly/Offline          |
|   +-- set_at: u64             # When status was set              |
|   +-- limited_availability_reason: string?                       |
+------------------------------------------------------------------+
| metadata: [MetadataItem]?     # Repository-level metadata        |
+------------------------------------------------------------------+
| latest_updates: [Update]      # Recent update history            |
+------------------------------------------------------------------+
| repo_before_updates: string?  # Path to previous repo state      |
+==================================================================+
```

### Ref (Branch/Tag Reference)

```
+--------------------------+
| name: string             |
| snapshot_index: u32      |---> Index into Repo.snapshots[]
+--------------------------+
```

## Snapshot File

Snapshot files contain the complete state of a repository version,
including all groups and arrays with their metadata and manifest refs.

```
+==================================================================+
|                         SNAPSHOT                                 |
+==================================================================+
| id: ObjectId12                # Unique snapshot identifier       |
+------------------------------------------------------------------+
| parent_id: ObjectId12?        # Previous snapshot (if any)       |
|                               # DEPRECATED: v2.0 uses Repo file  |
+------------------------------------------------------------------+
| nodes: [NodeSnapshot]         # All groups and arrays            |
+------------------------------------------------------------------+
| flushed_at: u64               # Microseconds since Unix epoch    |
+------------------------------------------------------------------+
| message: string               # Commit message                   |
+------------------------------------------------------------------+
| metadata: [MetadataItem]      # Snapshot metadata                |
+------------------------------------------------------------------+
| manifest_files: [ManifestFileInfo]  # Summary of manifests       |
|   +-- id: ObjectId12                                             |
|   +-- size_bytes: u64                                            |
|   +-- num_chunk_refs: u32                                        |
+==================================================================+
```

### NodeSnapshot (Array or Group)

```
+====================================+
| id: ObjectId8                      |
| path: string        # "/group/arr" |
| user_data: [u8]     # Zarr attrs   |
| node_data: NodeData (union)        |
|   +-- ArrayNodeData                |
|   +-- GroupNodeData                |
+====================================+
```

Note: Flatbuffers automatically generates a `node_data_type` discriminator field
(NONE=0, Array=1, Group=2) to identify which union variant is stored.

### ArrayNodeData and GroupNodeData

```
ArrayNodeData:                      GroupNodeData:
+-------------------------------+   +----------------+
| shape: [DimensionShape]       |   | (empty table)  |
|   +-- array_length: u64       |   +----------------+
|   +-- chunk_length: u64       |
+-------------------------------+
| dimension_names: [DimensionName]?
+-------------------------------+
| manifests: [ManifestRef]      |
|   +-- object_id: ObjectId12 --|---> manifests/<id>
|   +-- extents: [ChunkIndexRange]
+-------------------------------+
```

## Manifest File

Manifest files map chunk coordinates to chunk locations.
Each manifest contains chunk references for one or more arrays.

```
+==================================================================+
|                         MANIFEST                                 |
+==================================================================+
| id: ObjectId12                # Manifest file identifier         |
+------------------------------------------------------------------+
| arrays: [ArrayManifest]       # Per-array chunk mappings         |
+==================================================================+
```

### ArrayManifest

```
+=========================================+
| node_id: ObjectId8  # Which array       |
+-----------------------------------------+
| refs: [ChunkRef]    # Chunk references  |
+=========================================+
```

### ChunkRef (Chunk Reference)

```
+==================================================+
| index: [u32]              # Chunk coordinates    |
|                           # e.g., [0,5,12]       |
+--------------------------------------------------+
| inline: [u8]?             # Inline chunk data    |
|                           # (small chunks)       |
+--------------------------------------------------+
| offset: u64               # Byte offset in file  |
+--------------------------------------------------+
| length: u64               # Chunk size in bytes  |
+--------------------------------------------------+
| chunk_id: ObjectId12?     # --> chunks/<id>      |
+--------------------------------------------------+
| location: string?         # Virtual chunk URL    |
|                           # (external reference) |
+--------------------------------------------------+
| checksum_etag: string?    # S3 ETag for verify   |
+--------------------------------------------------+
| checksum_last_modified: u32  # Last modified     |
+==================================================+
```

ChunkRef has three mutually exclusive storage modes:
1. **inline** - Data embedded directly in manifest
2. **chunk_id** - Reference to `chunks/<id>` file
3. **location** - URL to external virtual chunk (HDF5, NetCDF, etc.)

## Transaction Log File

Transaction logs record the delta between snapshots for conflict
detection and efficient change tracking.

```
+==================================================================+
|                      TRANSACTION LOG                             |
+==================================================================+
| id: ObjectId12                # Same as snapshot id              |
+------------------------------------------------------------------+
| new_groups: [ObjectId8]       # Created groups                   |
+------------------------------------------------------------------+
| new_arrays: [ObjectId8]       # Created arrays                   |
+------------------------------------------------------------------+
| deleted_groups: [ObjectId8]   # Deleted groups                   |
+------------------------------------------------------------------+
| deleted_arrays: [ObjectId8]   # Deleted arrays                   |
+------------------------------------------------------------------+
| updated_arrays: [ObjectId8]   # Metadata-modified arrays         |
+------------------------------------------------------------------+
| updated_groups: [ObjectId8]   # Metadata-modified groups         |
+------------------------------------------------------------------+
| updated_chunks: [ArrayUpdatedChunks]  # Per-array chunk deltas   |
|   +-- node_id: ObjectId8                                         |
|   +-- chunks: [ChunkIndices]  # List of modified chunk coords    |
+------------------------------------------------------------------+
| moved_nodes: [MoveOperation]? # Renamed/moved nodes (v2.0+)      |
|   +-- from: string            # Source path                      |
|   +-- to: string              # Destination path                 |
+==================================================================+
```

## Relationships Diagram

```
                              +--------+
                              |  REPO  |
                              +--------+
                                  |
           +----------------------+----------------------+
           |                      |                      |
       branches[]              tags[]              snapshots[]
           |                      |                      |
           v                      v                      |
      +----------+          +----------+                 |
      | Ref      |          | Ref      |                 |
      | name     |          | name     |                 |
      | snap_idx-|--------->| snap_idx-|---------------->|
      +----------+          +----------+                 |
                                                         v
                                                  +--------------+
                                                  | SnapshotInfo |
                                                  | id, message  |
                                                  | parent_off   |
                                                  +--------------+
                                                         |
                                                         | (id lookup)
                                                         v
+-------------------------------------------------------------------------+
|                                                                         |
|  snapshots/<id>                                                         |
|  +====================================================================+ |
|  |                           SNAPSHOT                                 | |
|  +====================================================================+ |
|  | id, parent_id, message, flushed_at                                 | |
|  +--------------------------------------------------------------------+ |
|  | nodes: [NodeSnapshot]                                              | |
|  |   +-- id: ObjectId8                                                | |
|  |   +-- path: "/group/array"                                         | |
|  |   +-- ArrayNodeData                                                | |
|  |       +-- manifests: [ManifestRef]                                 | |
|  |           +-- object_id -------------------------------------------|----+
|  +--------------------------------------------------------------------+ |   |
|  | manifest_files: [ManifestFileInfo]                                 | |   |
|  |   +-- id, size_bytes, num_chunk_refs                               | |   |
|  +====================================================================+ |   |
|                                                                         |   |
+---------+---------------------------------------------------------------+   |
          |                                                                   |
          |                         +----------------------------------------+
          |                         |
          |                         v
+---------+--------------------+    manifests/<id>
|                              |    +==========================================+
| transactions/<snapshot-id>   |    |                   MANIFEST               |
| +==========================+ |    +==========================================+
| |    TRANSACTION LOG       | |    | id: ObjectId12                           |
| +==========================+ |    +------------------------------------------+
| | new_groups, new_arrays   | |    | arrays: [ArrayManifest]                  |
| | deleted_*, updated_*     | |    |   +-- node_id: ObjectId8                 |
| | updated_chunks           | |    |   +-- refs: [ChunkRef]                   |
| |   +-- node_id            | |    |       +-- index: [0, 5, 12]              |
| |   +-- chunk coords       | |    |       +-- chunk_id ----------------------|----+
| | moved_nodes              | |    |       +-- offset, length                 |    |
| |   +-- from, to           | |    |       +-- inline, location               |    |
| +==========================+ |    +==========================================+    |
+------------------------------+                                                    |
                                                                                    |
                                                                                    v
                                                                         chunks/<chunk-id>
                                                                         +================+
                                                                         | Raw chunk data |
                                                                         | (compressed)   |
                                                                         +================+
```

## Data Flow on Write

1. Session modifies arrays and chunks
2. Changed chunks written to `chunks/<chunk-id>`
3. New Manifest files created with updated ChunkRefs
4. New Snapshot created pointing to Manifests
5. TransactionLog created recording the delta
6. Repo file atomically updated with new SnapshotInfo

```
+----------+      +----------+      +------------+      +------+
| Session  | ---> | Chunks   | ---> | Manifests  | ---> | Snap | ---> Repo
| (writes) |      | (new)    |      | (new/copy) |      | shot |     update
+----------+      +----------+      +------------+      +------+
```

## Data Flow on Read

1. Read Repo file to get branch/tag -> snapshot mapping
2. Fetch Snapshot file by id
3. For each array, read ManifestRefs
4. Fetch Manifest files, find ChunkRefs by coordinates
5. Fetch chunk data from `chunks/<id>` or inline

```
Repo --> SnapshotInfo --> Snapshot --> ManifestRef --> Manifest --> ChunkRef --> Chunk
```

## Supporting Types

### MetadataItem

```
+--------------------+
| name: string       |
| value: [u8]        |  # Arbitrary bytes (often JSON)
+--------------------+
```

### DimensionShape (16 bytes, packed struct)

```
+----------------------+
| array_length: u64    |  # Size of array in this dimension
| chunk_length: u64    |  # Size of chunks in this dimension
+----------------------+
```

### ManifestFileInfo (32 bytes, packed struct)

```
+--------------------+
| id: ObjectId12     |  # bytes 0-11
| (padding)          |  # bytes 12-15
| size_bytes: u64    |  # bytes 16-23
| num_chunk_refs: u32|  # bytes 24-27
| (padding)          |  # bytes 28-31
+--------------------+
```

### ChunkIndices

```
+--------------------+
| coords: [u32]      |  # N-dimensional chunk coordinates
+--------------------+
```

### ChunkIndexRange (8 bytes, packed struct)

```
+--------------------+
| from: u32          |  # Start of chunk index range (inclusive)
| to: u32            |  # End of chunk index range (exclusive)
+--------------------+
```

### MoveOperation

```
+--------------------+
| from: string       |  # Source path (e.g., "/old/path")
| to: string         |  # Destination path (e.g., "/new/path")
+--------------------+
```

### ArrayUpdatedChunks

```
+-----------------------------+
| node_id: ObjectId8          |  # Which array was modified
| chunks: [ChunkIndices]      |  # List of modified chunk coords
+-----------------------------+
```

### DimensionName

```
+--------------------+
| name: string?      |  # Optional dimension name
+--------------------+
```

## Update Types (in Repo)

Update union type for tracking recent repository changes:

| Type | Description |
|------|-------------|
| `RepoInitializedUpdate` | Repository created |
| `RepoMigratedUpdate` | Format migration |
| `ConfigChangedUpdate` | Config modified |
| `MetadataChangedUpdate` | Repo metadata changed |
| `TagCreatedUpdate` | New tag |
| `TagDeletedUpdate` | Tag removed |
| `BranchCreatedUpdate` | New branch |
| `BranchDeletedUpdate` | Branch removed |
| `BranchResetUpdate` | Branch pointer moved |
| `NewCommitUpdate` | New snapshot committed |
| `CommitAmendedUpdate` | Snapshot amended |
| `NewDetachedSnapshotUpdate` | Detached snapshot |
| `GCRanUpdate` | Garbage collection ran |
| `ExpirationRanUpdate` | Expiration policy ran |

## Notes

- ObjectIds are content-addressed (typically random or hash-based)
- Snapshot `parent_id` is deprecated in v2.0; use `Repo.snapshots[].parent_offset` instead
- Manifests can be shared across snapshots (copy-on-write)
- Chunks are immutable and deduplicated by id
- Transaction logs enable conflict detection for concurrent writes
- Virtual chunks (`location` field) reference external data (HDF5, NetCDF)
- Inline chunks store small data directly in manifest (no separate file)
- All numeric values are little-endian in flatbuffers
- All timestamps (`flushed_at`, `set_at`, etc.) are microseconds since Unix epoch
- Files are typically zstd-compressed after the 39-byte header