234: Filesystem: Journaling Keeps Your Filesystem Intact.

Take Up Code - A podcast by Take Up Code: build your own computer games, apps, and robotics with podcasts and live classes

Categories:

Journaling records extra information in case there are problems. If your computer loses power or maybe you’re saving your files to a removable drive and you eject the drive without notice, then you might lose your work. In order to prevent larger problems like this, filesystems go through checks to make sure they’re in good shape before you can use them. This check is sometimes called fsck in Linux or Mac and chkdsk in Windows. Journaling can help prevent this check and help the filesystem recover in case there are problems. But it might not help restore your data. Listen to the full episode or read the full transcript below to learn about different types of journals such as a meta-data journal, a data journal, and a write-on-copy journal. Transcript We normally think of our filesystems as a safe place to write information. After working on a document for hours, you want to be able to press save and feel good that your work will still be around when you need it. But the real story is this isn’t always what happens. If your computer loses power or maybe you’re saving your files to a removable drive and you eject the drive without notice, then you might lose your work. If that’s not bad enough, the initial problem if left uncorrected could lead to your entire filesystem becoming corrupt. This could cause you to lose information in other files completely unrelated to your recent work. In order to prevent larger problems like this, filesystems go through checks to make sure they’re in good shape before you can use them. One thing to understand is that the filesystem has different priorities than you might think. It wants to keep everything organized. Having two different files both think they own the same storage area on a disk is bad. It’s bad for your data too. But the filesystem is more concerned with the fact that the files are mixed up. This is what the system check is looking for. Some problems can be corrected easy if they’re discovered right away. Other problems might require you to make some decisions about what to keep and what to throw away. Journaling can help prevent this and help the filesystem recover in case there are problems. But it might not help restore your data. Journaling can help eliminate the need for a full check and find problems sooner. Think of it like this. Let’s say that you’re renting a house when some natural disaster happens. Maybe string winds tear the roof off the house. Or heavy rains cause flooding. Now the owner of the house has insurance which should help fix the house. You can think of this insurance like a journal. But what about your furniture and clothes? Your pictures and electronics? You need a different kind of insurance for these things. The journal won’t help you. This may not be the best example. Because it really depends on the type of journal. Some might be able to take care of everything. The point is, just like in real life where you have to pay attention to details of your insurance, you should also pay attention to the details of your filesystem journal. The first thing to find out is if you have a journal at all. Without a journal, if there are any problems, the operating system will need to do a full scan of the filesystem to check for errors when it starts back up. This could take a long time. It’s not like you can just look up and see a big hole in your roof. A large filesystem can have problems anywhere and it all has to be scanned. This can take minutes or even hours to complete. During this time, your computer is waiting and can’t finish mounting that filesystem. This could keep the entire startup sequence delayed. For your own personal computer, that’s bad enough. A server computer that your company relies on is worse if it can’t start up right away. The reason this process takes so long is that your filesystem has no idea what it was doing before it crashed. There could be one