| ### Handling Database Updates When a master or slave replica receives updates, it applies the updates to its database in virtual memory, and saves a copy of each update in a log file that is stored on disk. Updates accumulate in the log file in sequenced numerical order. If a server restarts unexpectedly, the log file ensures that no updates are lost. Periodically, the replica writes the database in virtual memory to disk, thus bringing the disk copy up-to-date. Then, if the replica is a slave, it clears the log file of all updates. If the replica is the master, it clears the log file of all updates that have been propagated to the slave replicas. Updates that have not been propagated to the slaves are retained and used to reconstruct the propagation queue, if necessary. Only the master replica maintains a propagation queue, which is used to hold changes to be propagated to the slave replicas, as described in Propagating Database Changes . When the master replica receives an update, it adds it to the propagation queue in addition to its virtual memory database and its log file. Each update in a propagation queue is identified by a sequence number and a timestamp. The sequence number is used internally to track the propagation of updates to slave replicas. The timestamp is provided to show users the date and time of updates. When a master or slave replica restarts, it initializes its database in virtual memory and then applies any outstanding updates in the log file to its database. If the replica is the master replica, it also recreates the propagation queue from the log file so that any outstanding slave updates can be propagated. This mechanism ensures that no updates are lost when a server is shut down. ###