How does the database guarantee reliability using write-ahead logging?