2 from tasks.cephfs.cephfs_test_case import CephFSTestCase
5 class TestBacktrace(CephFSTestCase):
6 def test_backtrace(self):
8 That the 'parent' and 'layout' xattrs on the head objects of files
12 old_data_pool_name = self.fs.get_data_pool_name()
13 old_pool_id = self.fs.get_data_pool_id()
15 # Create a file for subsequent checks
16 self.mount_a.run_shell(["mkdir", "parent_a"])
17 self.mount_a.run_shell(["touch", "parent_a/alpha"])
18 file_ino = self.mount_a.path_to_ino("parent_a/alpha")
20 # That backtrace and layout are written after initial flush
21 self.fs.mds_asok(["flush", "journal"])
22 backtrace = self.fs.read_backtrace(file_ino)
23 self.assertEqual(['alpha', 'parent_a'], [a['dname'] for a in backtrace['ancestors']])
24 layout = self.fs.read_layout(file_ino)
25 self.assertDictEqual(layout, {
26 "stripe_unit": 4194304,
28 "object_size": 4194304,
29 "pool_id": old_pool_id,
32 self.assertEqual(backtrace['pool'], old_pool_id)
34 # That backtrace is written after parentage changes
35 self.mount_a.run_shell(["mkdir", "parent_b"])
36 self.mount_a.run_shell(["mv", "parent_a/alpha", "parent_b/alpha"])
38 self.fs.mds_asok(["flush", "journal"])
39 backtrace = self.fs.read_backtrace(file_ino)
40 self.assertEqual(['alpha', 'parent_b'], [a['dname'] for a in backtrace['ancestors']])
42 # Create a new data pool
43 new_pool_name = "data_new"
44 new_pool_id = self.fs.add_data_pool(new_pool_name)
46 # That an object which has switched pools gets its backtrace updated
47 self.mount_a.setfattr("./parent_b/alpha",
48 "ceph.file.layout.pool", new_pool_name)
49 self.fs.mds_asok(["flush", "journal"])
50 backtrace_old_pool = self.fs.read_backtrace(file_ino, pool=old_data_pool_name)
51 self.assertEqual(backtrace_old_pool['pool'], new_pool_id)
52 backtrace_new_pool = self.fs.read_backtrace(file_ino, pool=new_pool_name)
53 self.assertEqual(backtrace_new_pool['pool'], new_pool_id)
54 new_pool_layout = self.fs.read_layout(file_ino, pool=new_pool_name)
55 self.assertEqual(new_pool_layout['pool_id'], new_pool_id)
56 self.assertEqual(new_pool_layout['pool_ns'], '')
58 # That subsequent linkage changes are only written to new pool backtrace
59 self.mount_a.run_shell(["mkdir", "parent_c"])
60 self.mount_a.run_shell(["mv", "parent_b/alpha", "parent_c/alpha"])
61 self.fs.mds_asok(["flush", "journal"])
62 backtrace_old_pool = self.fs.read_backtrace(file_ino, pool=old_data_pool_name)
63 self.assertEqual(['alpha', 'parent_b'], [a['dname'] for a in backtrace_old_pool['ancestors']])
64 backtrace_new_pool = self.fs.read_backtrace(file_ino, pool=new_pool_name)
65 self.assertEqual(['alpha', 'parent_c'], [a['dname'] for a in backtrace_new_pool['ancestors']])
67 # That layout is written to new pool after change to other field in layout
68 self.mount_a.setfattr("./parent_c/alpha",
69 "ceph.file.layout.object_size", "8388608")
71 self.fs.mds_asok(["flush", "journal"])
72 new_pool_layout = self.fs.read_layout(file_ino, pool=new_pool_name)
73 self.assertEqual(new_pool_layout['object_size'], 8388608)
75 # ...but not to the old pool: the old pool's backtrace points to the new pool, and that's enough,
76 # we don't update the layout in all the old pools whenever it changes
77 old_pool_layout = self.fs.read_layout(file_ino, pool=old_data_pool_name)
78 self.assertEqual(old_pool_layout['object_size'], 4194304)