Let's learn how GFS implements garbage collection.
Garbage collection through lazy deletion
When a file is deleted, GFS does not immediately reclaim the physical space used by that file. Instead, it follows a lazy garbage collection strategy. When the client issues a delete file operation, GFS does two things:
- The master logs the deletion operation just like other changes.
- The deleted file is renamed to a hidden name that also includes a deletion timestamp.
The file can still be read under the new, special name and can also be undeleted by renaming it back to normal