]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
seastore: recover header's variable correctly without storing it
authormyoungwon oh <ohmyoungwon@gmail.com>
Mon, 11 Apr 2022 06:24:37 +0000 (15:24 +0900)
committermyoungwon oh <ohmyoungwon@gmail.com>
Thu, 19 May 2022 00:31:39 +0000 (09:31 +0900)
Signed-off-by: Myoungwon Oh <myoungwon.oh@samsung.com>
src/crimson/os/seastore/journal/circular_bounded_journal.cc
src/crimson/os/seastore/journal/circular_bounded_journal.h
src/test/crimson/seastore/test_cbjournal.cc

index 5d4bcf961a02e99af45bc5f0e73fa121498fd0d0..5047353de07d82c2312dc19d53251bec5b03e6e5 100644 (file)
@@ -153,6 +153,7 @@ CircularBoundedJournal::open_for_write(rbm_abs_addr start)
       paddr_t paddr = convert_abs_addr_to_paddr(
        get_written_to(),
        header.device_id);
+      header.size = header.end - header.start - get_block_size();
       init = true;
       return open_for_write_ret(
        open_for_write_ertr::ready_future_marker{},
@@ -360,9 +361,6 @@ Journal::replay_ret CircularBoundedJournal::replay(
   LOG_PREFIX(CircularBoundedJournal::replay);
   auto fut = open_for_write(CBJOURNAL_START_ADDRESS);
   return fut.safe_then([this, FNAME, delta_handler=std::move(delta_handler)] (auto addr) {
-    if (get_used_size() == 0) {
-      return replay_ertr::now();
-    }
     return seastar::do_with(
       rbm_abs_addr(get_applied_to()),
       std::move(delta_handler),
@@ -409,6 +407,7 @@ Journal::replay_ret CircularBoundedJournal::replay(
          cursor_addr += bl.length();
          set_written_to(cursor_addr);
          last_seq = r_header.committed_to.segment_seq;
+         set_used_size(get_used_size() + bl.length());
          return seastar::do_with(
            std::move(*maybe_record_deltas_list),
            [write_result,
index 71282d412042f124b6e40cbf786f50f6dde5d415..b76ee86d5b5555d552485bfaa65bc28235a425a0 100644 (file)
@@ -211,8 +211,6 @@ public:
       denc(v.magic, p);
       denc(v.uuid, p);
       denc(v.block_size, p);
-      denc(v.size, p);
-      denc(v.used_size, p);
       denc(v.error, p);
 
       denc(v.start_offset, p);
index 107e0c9ab62898149d57bb0330253c9eb7f550fe..0ec2cae4cecb500e6d8767b8c5f4372d9956e5fc 100644 (file)
@@ -254,6 +254,9 @@ struct cbjournal_test_t : public seastar_test_suite_t
   auto get_applied_to() {
     return cbj->get_applied_to();
   }
+  auto get_used_size() {
+    return cbj->get_used_size();
+  }
   void update_applied_to(rbm_abs_addr addr, uint32_t len) {
     cbj->update_applied_to(addr, len);
   }
@@ -263,6 +266,9 @@ struct cbjournal_test_t : public seastar_test_suite_t
   void set_written_to(rbm_abs_addr addr) {
     cbj->set_written_to(addr);
   }
+  void set_used_size(size_t size) {
+    cbj->set_used_size(size);
+  }
 };
 
 TEST_F(cbjournal_test_t, submit_one_record)
@@ -397,20 +403,20 @@ TEST_F(cbjournal_test_t, update_header)
     auto record_total_size = r_size.get_encoded_length();
     submit_record(std::move(rec));
 
-    cbj->write_header().unsafe_get0();
-    auto [update_header, update_buf] = *(cbj->read_header(0).unsafe_get0());
-
-    ASSERT_EQ(header.size, update_header.size);
-    ASSERT_EQ(header.used_size + record_total_size, update_header.used_size);
-
     update_applied_to(entries.front().addr, record_total_size);
     cbj->write_header().unsafe_get0();
-    auto [update_header2, update_buf2] = *(cbj->read_header(0).unsafe_get0());
+    auto [update_header, update_buf2] = *(cbj->read_header(0).unsafe_get0());
+    replay();
 
-    ASSERT_EQ(header.used_size, update_header2.used_size);
-    ASSERT_EQ(header.written_to + record_total_size, update_header2.written_to);
+    ASSERT_EQ(update_header.applied_to, update_header.applied_to);
+    ASSERT_EQ(header.block_size, update_header.block_size);
+    ASSERT_EQ(header.start, update_header.start);
+    ASSERT_EQ(header.end, update_header.end);
+    ASSERT_EQ(header.size, update_header.size);
+    ASSERT_EQ(header.used_size, update_header.used_size);
+    ASSERT_EQ(header.written_to + record_total_size, update_header.written_to);
     ASSERT_EQ(header.last_committed_record_base + block_size,
-             update_header2.last_committed_record_base);
+             update_header.last_committed_record_base);
   });
 }
 
@@ -470,11 +476,15 @@ TEST_F(cbjournal_test_t, replay_after_reset)
     }
     auto old_written_to = get_written_to();
     auto old_last_committed_record_base = get_last_committed_record_base();
+    auto old_used_size = get_used_size();
     set_written_to(4096);
     set_last_committed_record_base(4096);
+    set_used_size(0);
     replay();
     ASSERT_EQ(old_written_to, get_written_to());
     ASSERT_EQ(old_last_committed_record_base,
       get_last_committed_record_base());
+    ASSERT_EQ(old_used_size,
+      get_used_size());
   });
 }