Skip to content

Commit

Permalink
Fix device manager load of chunks.
Browse files Browse the repository at this point in the history
Chunks getting duplciate start offset while recovery. Add or cleanup
logs for debugging. Add test case. Add more logdev for logstore test.
Enable logstore test. Move rollback test to new logdev test.
  • Loading branch information
sanebay committed Feb 26, 2024
1 parent 2f5f94d commit f7e577f
Show file tree
Hide file tree
Showing 21 changed files with 522 additions and 260 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/build_dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ on:
jobs:
BuildHomestoreDeps:
runs-on: ${{ inputs.platform }}
timeout-minutes: 24000
steps:
- name: Retrieve Code
uses: actions/checkout@v3
Expand Down Expand Up @@ -206,18 +207,18 @@ jobs:
fail_on_cache_miss: true
if: ${{ inputs.testing == 'True' && github.event_name != 'pull_request' && steps.restore-cache.outputs.cache-hit != 'true' }}

- uses: actions/checkout@v3
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
with:
limit-access-to-actor: true
detached: true

- name: Create and Test Package
run: |
sanitize=$([[ "${{ inputs.tooling }}" == "Sanitize" ]] && echo "True" || echo "False")
pre=$([[ "${{ inputs.build-type }}" != "Debug" ]] && echo "-o sisl:prerelease=${{ inputs.prerelease }}" || echo "")
conan create \
${pre} \
-o sisl:malloc_impl=${{ inputs.malloc-impl }} \
-o iomgr:testing=off \
-o homestore:sanitize=${sanitize} \
-s build_type=${{ inputs.build-type }} \
--build missing \
.
sleep 10000000
if: ${{ inputs.testing == 'True' && inputs.tooling != 'Coverage' }}

- name: Code Coverage Run
Expand Down
2 changes: 2 additions & 0 deletions src/include/homestore/logstore/log_store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ class HomeLogStore : public std::enable_shared_from_this< HomeLogStore > {
return (ts == std::numeric_limits< logstore_seq_num_t >::max()) ? -1 : ts;
}

sisl::StreamTracker< logstore_record >& mrecords() { return m_records; }

/**
* @brief iterator to get all the log buffers;
*
Expand Down
1 change: 1 addition & 0 deletions src/lib/device/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class DeviceManager {

std::vector< PhysicalDev* > get_pdevs_by_dev_type(HSDevType dtype) const;
std::vector< shared< VirtualDev > > get_vdevs() const;
std::vector< shared< Chunk > > get_chunks() const;

uint64_t total_capacity() const;
uint64_t total_capacity(HSDevType dtype) const;
Expand Down
10 changes: 10 additions & 0 deletions src/lib/device/device_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,16 @@ std::vector< shared< VirtualDev > > DeviceManager::get_vdevs() const {
return ret_v;
}

std::vector< shared< Chunk > > DeviceManager::get_chunks() const {
std::unique_lock lg{m_vdev_mutex};
std::vector< shared< Chunk > > res;
res.reserve(m_chunks.size());
for (auto& chunk : m_chunks) {
if (chunk) res.push_back(chunk);
}
return res;
}

// Some of the hs_super_blk details
uint64_t hs_super_blk::vdev_super_block_size() { return (hs_super_blk::MAX_VDEVS_IN_SYSTEM * vdev_info::size); }

Expand Down
25 changes: 17 additions & 8 deletions src/lib/device/journal_vdev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ off_t JournalVirtualDev::Descriptor::alloc_next_append_blk(size_t sz) {

// assert that returnning logical offset is in good range
HS_DBG_ASSERT_LE(tail_off, m_end_offset);
LOGDEBUGMOD(journalvdev, "returned tail_off 0x{} desc {}", to_hex(tail_off), to_string());
LOGDEBUGMOD(journalvdev, "returned tail_off 0x{} size {} desc {}", to_hex(tail_off), sz, to_string());
return tail_off;
}

Expand Down Expand Up @@ -443,6 +443,14 @@ off_t JournalVirtualDev::Descriptor::dev_offset(off_t nbytes) const {
return vdev_offset;
}

void JournalVirtualDev::Descriptor::update_data_start_offset(off_t offset) {
m_data_start_offset = offset;
auto data_start_offset_aligned = sisl::round_down(m_data_start_offset, m_vdev.info().chunk_size);
m_end_offset = data_start_offset_aligned + m_journal_chunks.size() * m_vdev.info().chunk_size;
LOGTRACEMOD(journalvdev, "Updated data start offset off 0x{} {}", to_hex(offset), to_string());
RELEASE_ASSERT_EQ(m_end_offset - data_start_offset_aligned, m_total_size, "offset size mismatch {}", to_string());
}

off_t JournalVirtualDev::Descriptor::tail_offset(bool reserve_space_include) const {
off_t tail = static_cast< off_t >(data_start_offset() + m_write_sz_in_total.load(std::memory_order_relaxed));
if (reserve_space_include) { tail += m_reserved_sz; }
Expand All @@ -461,7 +469,7 @@ void JournalVirtualDev::Descriptor::update_tail_offset(off_t tail) {
}
lseek(tail);

LOGDEBUGMOD(journalvdev, "tail arg 0x{} desc {} ", to_hex(tail), to_string());
LOGDEBUGMOD(journalvdev, "Updated tail offset arg 0x{} desc {} ", to_hex(tail), to_string());
HS_REL_ASSERT(tail_offset() == tail, "tail offset mismatch after calculation 0x{} : {}", tail_offset(), tail);
}

Expand Down Expand Up @@ -598,7 +606,7 @@ bool JournalVirtualDev::Descriptor::is_alloc_accross_chunk(size_t size) const {

nlohmann::json JournalVirtualDev::Descriptor::get_status(int log_level) const {
nlohmann::json j;
j["logdev_id"] = m_logdev_id;
j["logdev"] = m_logdev_id;
j["seek_cursor"] = m_seek_cursor;
j["data_start_offset"] = m_data_start_offset;
j["end_offset"] = m_end_offset;
Expand All @@ -613,7 +621,7 @@ nlohmann::json JournalVirtualDev::Descriptor::get_status(int log_level) const {
nlohmann::json c;
auto* private_data = r_cast< JournalChunkPrivate* >(const_cast< uint8_t* >(chunk->user_private()));
c["chunk_id"] = chunk->chunk_id();
c["logdev_id"] = private_data->logdev_id;
c["logdev"] = private_data->logdev_id;
c["is_head"] = private_data->is_head;
c["end_of_chunk"] = private_data->end_of_chunk;
c["next_chunk"] = private_data->next_chunk;
Expand All @@ -627,12 +635,13 @@ nlohmann::json JournalVirtualDev::Descriptor::get_status(int log_level) const {
}

std::string JournalVirtualDev::Descriptor::to_string() const {
std::string str{fmt::format("id={};ds=0x{};end=0x{};writesz={};tail=0x{};"
off_t tail =
static_cast< off_t >(data_start_offset() + m_write_sz_in_total.load(std::memory_order_relaxed)) + m_reserved_sz;
std::string str{fmt::format("log_dev={};ds=0x{};end=0x{};writesz={};tail=0x{};"
"rsvdsz={};chunks={};trunc={};total={};seek=0x{} ",
m_logdev_id, to_hex(m_data_start_offset), to_hex(m_end_offset),
m_write_sz_in_total.load(std::memory_order_relaxed), to_hex(tail_offset()),
m_reserved_sz, m_journal_chunks.size(), m_truncate_done, m_total_size,
to_hex(m_seek_cursor))};
m_write_sz_in_total.load(std::memory_order_relaxed), to_hex(tail), m_reserved_sz,
m_journal_chunks.size(), m_truncate_done, m_total_size, to_hex(m_seek_cursor))};
return str;
}

Expand Down
9 changes: 3 additions & 6 deletions src/lib/device/journal_vdev.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,7 @@ class JournalVirtualDev : public VirtualDev {
*
* @param offset : the start logical offset to be persisted
*/
void update_data_start_offset(off_t offset) {
m_data_start_offset = offset;
auto data_start_offset_aligned = sisl::round_down(m_data_start_offset, m_vdev.info().chunk_size);
m_end_offset = data_start_offset_aligned + m_journal_chunks.size() * m_vdev.info().chunk_size;
RELEASE_ASSERT_EQ(m_end_offset - data_start_offset_aligned, m_total_size, "offset size mismatch");
}
void update_data_start_offset(off_t offset);

/**
* @brief : get the logical tail offset;
Expand Down Expand Up @@ -309,6 +304,8 @@ class JournalVirtualDev : public VirtualDev {
*/
nlohmann::json get_status(int log_level) const;

logdev_id_t logdev_id() const { return m_logdev_id; }

std::string to_string() const;

private:
Expand Down
8 changes: 7 additions & 1 deletion src/lib/device/physical_dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,13 @@ std::vector< shared< Chunk > > PhysicalDev::create_chunks(const std::vector< uin
auto chunk = std::make_shared< Chunk >(this, *cinfo, cslot);
ret_chunks.push_back(chunk);
get_stream(chunk).m_chunks_map.insert(std::pair{chunk_ids[cit], std::move(chunk)});

HS_LOG(DEBUG, device, "Creating chunk {}", chunk->to_string());
cinfo->~chunk_info();
}

m_chunk_info_slots->set_bits(b.start_bit, b.nbits);
write_super_block(buf, chunk_info::size * b.nbits, chunk_info_offset_nth(b.start_bit));

hs_utils::iobuf_free(buf, sisl::buftag::superblk);

chunks_remaining -= b.nbits;
Expand Down Expand Up @@ -296,6 +297,7 @@ shared< Chunk > PhysicalDev::create_chunk(uint32_t chunk_id, uint32_t vdev_id, u

auto bitmap_mem = m_chunk_info_slots->serialize(m_pdev_info.dev_attr.align_size);
write_super_block(bitmap_mem->cbytes(), bitmap_mem->size(), hs_super_blk::chunk_sb_offset());
HS_LOG(TRACE, device, "Created chunk {}", chunk->to_string());

cinfo->~chunk_info();
hs_utils::iobuf_free(buf, sisl::buftag::superblk);
Expand Down Expand Up @@ -397,6 +399,7 @@ void PhysicalDev::do_remove_chunk(cshared< Chunk >& chunk) {
get_stream(chunk).m_chunks_map.erase(chunk->chunk_id());
cinfo->~chunk_info();
hs_utils::iobuf_free(buf, sisl::buftag::superblk);
HS_LOG(TRACE, device, "Removed chunk {}", chunk->to_string());
}

uint64_t PhysicalDev::chunk_info_offset_nth(uint32_t slot) const {
Expand All @@ -418,11 +421,14 @@ void PhysicalDev::populate_chunk_info(chunk_info* cinfo, uint32_t vdev_id, uint6
cinfo->set_allocated();
cinfo->set_user_private(private_data);
cinfo->compute_checksum();
auto [_, inserted] = m_chunk_start.insert(cinfo->chunk_start_offset);
RELEASE_ASSERT(inserted, "Duplicate start offset {} for chunk {}", cinfo->chunk_start_offset, cinfo->chunk_id);
}

void PhysicalDev::free_chunk_info(chunk_info* cinfo) {
auto ival = ChunkInterval::right_open(cinfo->chunk_start_offset, cinfo->chunk_start_offset + cinfo->chunk_size);
m_chunk_data_area.erase(ival);
m_chunk_start.erase(cinfo->chunk_start_offset);

cinfo->set_free();
cinfo->checksum = 0;
Expand Down
1 change: 1 addition & 0 deletions src/lib/device/physical_dev.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class PhysicalDev {
ChunkIntervalSet m_chunk_data_area; // Range of chunks data area created
std::unique_ptr< sisl::Bitset > m_chunk_info_slots; // Slots to write the chunk info
uint32_t m_chunk_sb_size{0}; // Total size of the chunk sb at present
std::unordered_set< uint64_t > m_chunk_start; // Store and verify start offset of all chunks for debugging.

public:
PhysicalDev(const dev_info& dinfo, int oflags, const pdev_info_header& pinfo);
Expand Down
Loading

0 comments on commit f7e577f

Please sign in to comment.