2 Test our tools for recovering metadata from the data pool into an alternate pool
7 from collections
import namedtuple
9 from teuthology
.orchestra
.run
import CommandFailedError
10 from tasks
.cephfs
.cephfs_test_case
import CephFSTestCase
12 log
= logging
.getLogger(__name__
)
15 ValidationError
= namedtuple("ValidationError", ["exception", "backtrace"])
18 class OverlayWorkload(object):
19 def __init__(self
, orig_fs
, recovery_fs
, orig_mount
, recovery_mount
):
20 self
._orig
_fs
= orig_fs
21 self
._recovery
_fs
= recovery_fs
22 self
._orig
_mount
= orig_mount
23 self
._recovery
_mount
= recovery_mount
24 self
._initial
_state
= None
26 # Accumulate backtraces for every failed validation, and return them. Backtraces
27 # are rather verbose, but we only see them when something breaks, and they
28 # let us see which check failed without having to decorate each check with
32 def assert_equal(self
, a
, b
):
35 raise AssertionError("{0} != {1}".format(a
, b
))
36 except AssertionError as e
:
38 ValidationError(e
, traceback
.format_exc(3))
43 Write the workload files to the mount
45 raise NotImplementedError()
49 Read from the mount and validate that the workload files are present (i.e. have
50 survived or been reconstructed from the test scenario)
52 raise NotImplementedError()
56 Damage the filesystem pools in ways that will be interesting to recover from. By
57 default just wipe everything in the metadata pool
60 pool
= self
._orig
_fs
.get_metadata_pool_name()
61 self
._orig
_fs
.rados(["purge", pool
, '--yes-i-really-really-mean-it'])
65 Called after client unmount, after write: flush whatever you want
67 self
._orig
_fs
.mds_asok(["flush", "journal"])
68 self
._recovery
_fs
.mds_asok(["flush", "journal"])
71 class SimpleOverlayWorkload(OverlayWorkload
):
73 Single file, single directory, check that it gets recovered and so does its size
76 self
._orig
_mount
.run_shell(["mkdir", "subdir"])
77 self
._orig
_mount
.write_n_mb("subdir/sixmegs", 6)
78 self
._initial
_state
= self
._orig
_mount
.stat("subdir/sixmegs")
81 self
._recovery
_mount
.run_shell(["ls", "subdir"])
82 st
= self
._recovery
_mount
.stat("subdir/sixmegs")
83 self
.assert_equal(st
['st_size'], self
._initial
_state
['st_size'])
86 class TestRecoveryPool(CephFSTestCase
):
89 REQUIRE_RECOVERY_FILESYSTEM
= True
91 def is_marked_damaged(self
, rank
):
92 mds_map
= self
.fs
.get_mds_map()
93 return rank
in mds_map
['damaged']
95 def _rebuild_metadata(self
, workload
, other_pool
=None, workers
=1):
97 That when all objects in metadata pool are removed, we can rebuild a metadata pool
98 based on the contents of a data pool, and a client can see and read our files.
101 # First, inject some files
105 # Unmount the client and flush the journal: the tool should also cope with
106 # situations where there is dirty metadata, but we'll test that separately
107 self
.mount_a
.umount_wait()
108 self
.mount_b
.umount_wait()
111 # Create the alternate pool if requested
112 recovery_fs
= self
.recovery_fs
.name
113 recovery_pool
= self
.recovery_fs
.get_metadata_pool_name()
114 self
.recovery_fs
.data_scan(['init', '--force-init',
115 '--filesystem', recovery_fs
,
116 '--alternate-pool', recovery_pool
])
117 self
.recovery_fs
.mon_manager
.raw_cluster_cmd('-s')
118 self
.recovery_fs
.table_tool([recovery_fs
+ ":0", "reset", "session"])
119 self
.recovery_fs
.table_tool([recovery_fs
+ ":0", "reset", "snap"])
120 self
.recovery_fs
.table_tool([recovery_fs
+ ":0", "reset", "inode"])
123 self
.fs
.mds_stop() # otherwise MDS will join once the fs is reset
126 # After recovery, we need the MDS to not be strict about stats (in production these options
127 # are off by default, but in QA we need to explicitly disable them)
128 self
.fs
.set_ceph_conf('mds', 'mds verify scatter', False)
129 self
.fs
.set_ceph_conf('mds', 'mds debug scatterstat', False)
131 # Apply any data damage the workload wants
134 # Reset the MDS map in case multiple ranks were in play: recovery procedure
135 # only understands how to rebuild metadata under rank 0
138 self
.fs
.table_tool([self
.fs
.name
+ ":0", "reset", "session"])
139 self
.fs
.table_tool([self
.fs
.name
+ ":0", "reset", "snap"])
140 self
.fs
.table_tool([self
.fs
.name
+ ":0", "reset", "inode"])
142 # Run the recovery procedure
144 with self
.assertRaises(CommandFailedError
):
145 # Normal reset should fail when no objects are present, we'll use --force instead
146 self
.fs
.journal_tool(["journal", "reset"], 0)
148 self
.fs
.data_scan(['scan_extents', '--alternate-pool',
149 recovery_pool
, '--filesystem', self
.fs
.name
,
150 self
.fs
.get_data_pool_name()])
151 self
.fs
.data_scan(['scan_inodes', '--alternate-pool',
152 recovery_pool
, '--filesystem', self
.fs
.name
,
153 '--force-corrupt', '--force-init',
154 self
.fs
.get_data_pool_name()])
155 self
.fs
.journal_tool(['event', 'recover_dentries', 'list',
156 '--alternate-pool', recovery_pool
], 0)
158 self
.fs
.data_scan(['init', '--force-init', '--filesystem',
160 self
.fs
.data_scan(['scan_inodes', '--filesystem', self
.fs
.name
,
161 '--force-corrupt', '--force-init',
162 self
.fs
.get_data_pool_name()])
163 self
.fs
.journal_tool(['event', 'recover_dentries', 'list'], 0)
165 self
.recovery_fs
.journal_tool(['journal', 'reset', '--force'], 0)
166 self
.fs
.journal_tool(['journal', 'reset', '--force'], 0)
167 self
.fs
.mon_manager
.raw_cluster_cmd('mds', 'repaired',
170 # Mark the MDS repaired
171 self
.fs
.mon_manager
.raw_cluster_cmd('mds', 'repaired', '0')
174 self
.fs
.mds_restart()
175 self
.fs
.set_joinable()
176 self
.recovery_fs
.mds_restart()
177 self
.fs
.wait_for_daemons()
178 self
.recovery_fs
.wait_for_daemons()
179 status
= self
.recovery_fs
.status()
180 for rank
in self
.recovery_fs
.get_ranks(status
=status
):
181 self
.fs
.mon_manager
.raw_cluster_cmd('tell', "mds." + rank
['name'],
182 'injectargs', '--debug-mds=20')
183 self
.fs
.rank_tell(['scrub', 'start', '/', 'recursive', 'repair'], rank
=rank
['rank'], status
=status
)
184 log
.info(str(self
.mds_cluster
.status()))
187 self
.mount_a
.mount_wait()
188 self
.mount_b
.mount_wait(cephfs_name
=recovery_fs
)
190 # See that the files are present and correct
191 errors
= workload
.validate()
193 log
.error("Validation errors found: {0}".format(len(errors
)))
195 log
.error(e
.exception
)
196 log
.error(e
.backtrace
)
197 raise AssertionError("Validation failed, first error: {0}\n{1}".format(
198 errors
[0].exception
, errors
[0].backtrace
201 def test_rebuild_simple(self
):
202 self
._rebuild
_metadata
(SimpleOverlayWorkload(self
.fs
, self
.recovery_fs
,
203 self
.mount_a
, self
.mount_b
))