Database / Mnesia basics Interview questions
What happens to a disc_copies table when its node restarts?
On restart, Mnesia reads the table's data back from the disk files in the Mnesia directory before the node rejoins the cluster and is considered ready — the in-memory copy is rebuilt from what was durably written to disk, plus replaying any transaction log entries recorded since the last full checkpoint.
sequenceDiagram
participant Node
participant Disk
Node->>Disk: read schema + table files
Disk-->>Node: table data loaded into memory
Node->>Node: replay transaction log since last checkpoint
Node-->>Node: table marked as loaded, ready for use
If this is the only node holding a copy of that table, code trying to use it must wait (typically via
mnesia:wait_for_tables/2) until loading finishes. If other nodes in the cluster already have the
table loaded and running, the restarting node can instead copy the current state from one of them, which is
often faster than reading its own potentially-stale disk copy from scratch.
More Related questions...