From 0dea6d8379165c2f38125f8bb308733f1e4cb4ec Mon Sep 17 00:00:00 2001 From: Matthew Ahrens Date: Tue, 26 Jul 2022 11:05:58 -0700 Subject: [PATCH] fix import/discovery panic (#523) When starting the agent and discovering zettacaches, if there's an old zettacache (with an older on-disk format) present, the agent crashes. We should instead ignore this old cache. Bonus cleanup: document recommended relationship between tunables. --- cmd/zfs_object_agent/zettacache/src/open.rs | 17 ++++++++--------- .../zettacache/src/slab_allocator.rs | 1 + .../zettacache/src/zettacache/mod.rs | 3 ++- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cmd/zfs_object_agent/zettacache/src/open.rs b/cmd/zfs_object_agent/zettacache/src/open.rs index d738d28960d7..8a2791d9a70c 100644 --- a/cmd/zfs_object_agent/zettacache/src/open.rs +++ b/cmd/zfs_object_agent/zettacache/src/open.rs @@ -183,15 +183,14 @@ fn is_valid_cache( match primary { Some(disk) => { - let disks_from_primary = disk - .superblock - .primary - .as_ref() - .unwrap() - .disks - .iter() - .map(|(k, v)| (*k, v.guid)) - .collect::>(); + let disks_from_primary = match &disk.superblock.primary { + Some(primary) => primary + .disks + .iter() + .map(|(k, v)| (*k, v.guid)) + .collect::>(), + None => return false, + }; // Only retain disks with IDs that are part of the primary block disks.retain( diff --git a/cmd/zfs_object_agent/zettacache/src/slab_allocator.rs b/cmd/zfs_object_agent/zettacache/src/slab_allocator.rs index b895720cf95c..cfb33d07734c 100644 --- a/cmd/zfs_object_agent/zettacache/src/slab_allocator.rs +++ b/cmd/zfs_object_agent/zettacache/src/slab_allocator.rs @@ -53,6 +53,7 @@ tunable! { // Try to keep this amount of slabs available for normal (i.e. BlockAllocator) use. Ideally // this will be enough space to absorb all the writes that can occur between index merges. + // This should be less than TARGET_FREE_BLOCKS_PCT. static ref TARGET_AVAILABLE_SLABS_PCT: Percent = Percent::new(2.0); } diff --git a/cmd/zfs_object_agent/zettacache/src/zettacache/mod.rs b/cmd/zfs_object_agent/zettacache/src/zettacache/mod.rs index f09994227a42..f780fc100ce1 100644 --- a/cmd/zfs_object_agent/zettacache/src/zettacache/mod.rs +++ b/cmd/zfs_object_agent/zettacache/src/zettacache/mod.rs @@ -113,7 +113,8 @@ tunable! { // keep at least 5% of the cache "free". We need to have slop for the rebalance code to be // able to consolidate slabs (to create empty slabs) to accomodate block size changes in the // workload. This target includes both free blocks within the BlockAllocator, and free slabs - // within the SlabAllocator which are available to the BlockAllocator. + // within the SlabAllocator which are available to the BlockAllocator. This should be more + // than TARGET_AVAILABLE_SLABS_PCT. static ref TARGET_FREE_BLOCKS_PCT: Percent = Percent::new(5.0); // Keep the total footprint for the pending changes and index cache data at about 12% of