zpool checkpoints

In March, to FreeBSD landed a very interesting feature called 'zpool checkpoints'. Before we jump straight into the topic, let's take a step back and look at another ZFS feature called ‘snapshot’. Snapshot allows us to create an image of our single file systems. This gives us the option to modify data on the dataset without the fear of losing some data.



A very good example of how to use ZFS snapshot is during an upgrade of database schema. Let us consider a situation where we have a few scripts which change our schema. Sometimes we are unable to upgrade in one transaction (for example, when we attempt to alter a table and then update it in single transaction). If our database is on dataset, we can just snapshot it, and if something goes wrong, simply rollback the file system to its previous state.



The problem with snapshot is that it works only on a single dataset. If we added some dataset, we wouldn't then be able to create the snapshot which would rollback that operation. The same with changing the attributes of a dataset. If we change the compression on the dataset, we cannot rollback it. We would need to change that manually.



Another interesting problem involves upgrading the whole operating system when we upgrade system with a new ZFS version. What if we start upgrading our dataset and our kernel begins to crash? (If you use FreeBSD, I doubt you will ever have had that experience but still...). If we rollback to the old kernel, there is a chance the dataset will stop working because the new kernel doesn’t know how to use the new features.



Zpool checkpoints is the solution to all those problems. Instead of taking a single snapshot of the dataset, we can now take a snapshot of the whole pool. That means we will not only rollback the data but also all the metadata. If we rewind to the checkpoint, all our ZFS properties will be rolled back; the upgrade will be rolledback, and even the creation/deletion of the dataset, and the snapshot, will be rolledback.



Zpool Checkpoint has introduced a few simple functions:

- For a creating checkpoint:

zpool checkpoint <pool>

- Rollbacks state to checkpoint and remove the checkpoint:

zpool import -- rewind-to-checkpoint <pool>



- Mount the pool read only - this does not rollback the data:

zpool import --read-only=on --rewind-to-checkpoint

- Remove the checkpoint

zpool checkpoint --discard <pool> or zpool checkpoint -d <pool>

With this powerful feature we need to remember some safety rules:

- Scrub will work only on data that isn't in checkpoint.

- You can't remove vdev if you have a checkpoint.

- You can't split mirror.

- Reguid will not work either.

- Create a checkpoint when one of the disks is removed..

For me, this feature is incredibly useful, especially when upgrading an operating system, or when I need to experiment with additional data sets. If you speak Polish, I have some additional information for you. During the first Polish BSD user group meeting, I had the opportunity to give a short talk about this feature. Here you find the video of that talk, and here is the slideshow.

I would like to offer my thanks to Serapheim Dimitropoulos for developing this feature, and for being so kind in sharing with me so many of its intricacies. If you are interested in knowing more about the technical details of this feature, you should check out Serapheim’s blog, and his video about checkpoints.