Limitations
slate wraps Erlang's DETS. DETS is simple because it does less than a database, and slate keeps most of its limits. Each section below describes one limit and what to do when you reach it. Use them to decide whether slate fits your storage needs.
File size limit
Section titled “File size limit”DETS limits each table file to 2 GB. You cannot configure this limit.
A write that would exceed it returns Error(FileSizeLimitExceeded(context)).
No ordered_set table type
Section titled “No ordered_set table type”Unlike Erlang's ETS (in-memory storage), DETS does not support ordered_set tables. Only set, bag, and duplicate_bag are available. Keys are stored in an unspecified order, so to_list and fold visit entries in an unspecified order too. To process keys in order, collect them and sort the result.
Disk-backed performance
Section titled “Disk-backed performance”DETS stores data on disk, so performance depends on disk I/O, buffering, and
your workload. Buffering also means that a successful insert is not
necessarily on disk yet. Use sync to flush pending writes and close when
you finish with a table. Handle errors from both operations.
Disk access is the cost of persistence. For frequent reads with low latency, load data into ETS at startup and use DETS only for persistence.
Tables must be closed properly
Section titled “Tables must be closed properly”DETS keeps recent writes in memory and saves them later, at the latest when the table closes. VM or node termination and power loss can prevent a DETS table from closing properly. Then pending writes may be lost, and the file may need repair on the next open. Thus a file on disk does not guarantee that all writes survive a crash.
An individual Erlang process exit is less severe. DETS tracks processes that
open a table and normally closes it when the last user exits.
with_table also attempts to close the table after
its callback returns or raises. The helper cannot run cleanup after a forced
kill of the owning process. For longer-lived tables, call close yourself.
If a file does need repair, the repair policy selects what happens on open.
slate's default AutoRepair policy attempts repair when needed. ForceRepair
repairs even a properly closed file. NoRepair returns NeedsRepair when
repair is required. None of these policies guarantees full data recovery.
For this reason, back up a closed file before attempting repair. Keep primary data files on persistent storage and maintain backups. Deleting or replacing a DETS file loses the data in that file.
Erlang target only
Section titled “Erlang target only”DETS is a BEAM feature. slate supports only Gleam's Erlang target. It does not support the JavaScript target.
Bounded table-name pool
Section titled “Bounded table-name pool”slate names each open DETS table with an atom. The BEAM does not free atoms,
so a new atom for each path would grow the atom table without a limit.
Instead, slate reuses a pool of 4096 DETS table names. Thus up to 4096
distinct normalized paths can be open at once.
Closing a table releases its slot for reuse. If all slots are in use,
new opens for other paths return TableNamePoolExhausted.
Serialized access from multiple OS processes
Section titled “Serialized access from multiple OS processes”Multiple Erlang processes within one BEAM node can share an unlocked table.
Independent VMs cannot. Unlocked open* and with_table APIs do not
coordinate with other OS processes, and simultaneous unlocked access can lose
writes or damage the file.
For this reason, independent VMs must use
with_exclusive_table for every access to a
shared DETS file, including reads. The helper opens the current file under an
OS lock and closes DETS before releasing ownership. Competing commands take
turns; their DETS handles do not remain open between sessions.
The lock has its own requirements. Exclusive sessions require supported native code and an allowed local filesystem. Network, FUSE, and overlay mounts are unsupported. Keep the directory namespace trusted and stable. Slate rejects hard-linked data and unsafe sidecars. Do not delete or replace the persistent sidecar while clients can start sessions.
The lock makes sessions take turns, but it adds no other guarantee. The
acquisition wait does not limit an acquired callback. Callback errors do not
undo writes, and locks add no power-loss guarantee. Unsafe cleanup can retain
ownership until VM exit; report CleanupFailed rather than deleting a lock
file.
Validating DETS files
Section titled “Validating DETS files”A DETS file needs no special name or extension, so a filename does not tell
you what a file contains. Use slate.is_dets_file to identify a DETS file
before opening it:
import slate
let assert Ok(True) = slate.is_dets_file("data/cache.dets")let assert Ok(False) = slate.is_dets_file("README.md")Use this when scanning a directory for DETS files. A result of Ok(True)
does not guarantee file integrity, successful decoding, or safe access to
a user-provided path. Apply your application's path and access rules separately.
Comparison with alternatives
Section titled “Comparison with alternatives”If one of these limits rules out DETS, another BEAM storage option can fit better. This table compares them:
| Feature | DETS (slate) | ETS | SQLite | Mnesia |
|---|---|---|---|---|
| Persistence | Disk | Memory only | Disk | Memory or disk, depending on table configuration |
| Maximum size | 2 GB per file | RAM | Depends on configuration and storage | Depends on table type, configuration, and storage |
| Query capability | Key lookup, fold | Key lookup, match specs | Full SQL | Match specs, QLC |
| Ordered keys | No | Yes (ordered_set) |
Yes | Yes |
| Storage engine | Included in OTP | Included in OTP | Separate library | Included in OTP |
| Performance | Depends on disk I/O and workload | In-memory reads | Depends on workload | Depends on configuration and workload |
| Concurrent processes | Serialized exclusive sessions on one host | Single node | Multiple | Distributed |
