From 35a6ed728d461fb5027acb61a7861eb2eb30f012 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Thu, 28 Nov 2019 00:26:53 +0300 Subject: [PATCH] Fix another stall due to bad unstable_writes tracking, do not try to write beyond the end of the journal --- blockstore.cpp | 2 +- blockstore_flush.cpp | 2 +- blockstore_flush.h | 2 +- blockstore_init.cpp | 11 +++++++---- blockstore_stable.cpp | 2 +- blockstore_write.cpp | 2 ++ 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/blockstore.cpp b/blockstore.cpp index 4c5b4d846..0371f7705 100644 --- a/blockstore.cpp +++ b/blockstore.cpp @@ -114,7 +114,7 @@ void blockstore::loop() auto op_ptr = cur; auto op = *(cur++); // FIXME: This needs some simplification - // Writes should not block reads if the ring is not null and if reads don't depend on them + // Writes should not block reads if the ring is not full and if reads don't depend on them // In all other cases we should stop submission if (op->wait_for) { diff --git a/blockstore_flush.cpp b/blockstore_flush.cpp index 95ea9bd4c..cec3df25f 100644 --- a/blockstore_flush.cpp +++ b/blockstore_flush.cpp @@ -58,7 +58,7 @@ void journal_flusher_t::loop() } } -void journal_flusher_t::queue_flush(obj_ver_id ov) +void journal_flusher_t::enqueue_flush(obj_ver_id ov) { auto it = flush_versions.find(ov.oid); if (it != flush_versions.end()) diff --git a/blockstore_flush.h b/blockstore_flush.h index e20b78c28..aa6f86efb 100644 --- a/blockstore_flush.h +++ b/blockstore_flush.h @@ -70,6 +70,6 @@ public: ~journal_flusher_t(); void loop(); bool is_active(); - void queue_flush(obj_ver_id oid); + void enqueue_flush(obj_ver_id oid); void unshift_flush(obj_ver_id oid); }; diff --git a/blockstore_init.cpp b/blockstore_init.cpp index 2c493a3ea..e95b456c7 100644 --- a/blockstore_init.cpp +++ b/blockstore_init.cpp @@ -86,7 +86,7 @@ void blockstore_init_meta::handle_entries(struct clean_disk_entry* entries, int { auto clean_it = bs->clean_db.find(entries[i].oid); #ifdef BLOCKSTORE_DEBUG - printf("Clean entry %lu: %lu:%lu v%lu\n", done_cnt+i, entries[i].oid.inode, entries[i].oid.stripe, entries[i].version); + printf("Clean entry %u: %lu:%lu v%lu\n", done_cnt+i, entries[i].oid.inode, entries[i].oid.stripe, entries[i].version); #endif if (clean_it == bs->clean_db.end() || clean_it->second.version < entries[i].version) { @@ -359,8 +359,11 @@ int blockstore_init_journal::handle_journal_part(void *buf, uint64_t len) .journal_sector = proc_pos, }); bs->journal.used_sectors[proc_pos]++; +#ifdef BLOCKSTORE_DEBUG + printf("journal offset %lu is used by %lu:%lu v%lu\n", proc_pos, ov.oid.inode, ov.oid.stripe, ov.version); +#endif auto & unstab = bs->unstable_writes[ov.oid]; - unstab = !unstab || unstab > ov.version ? ov.version : unstab; + unstab = unstab < ov.version ? ov.version : unstab; } else if (je->type == JE_BIG_WRITE) { @@ -380,7 +383,7 @@ int blockstore_init_journal::handle_journal_part(void *buf, uint64_t len) }); bs->journal.used_sectors[proc_pos]++; auto & unstab = bs->unstable_writes[ov.oid]; - unstab = !unstab || unstab > ov.version ? ov.version : unstab; + unstab = unstab < ov.version ? ov.version : unstab; } else if (je->type == JE_STABLE) { @@ -410,7 +413,7 @@ int blockstore_init_journal::handle_journal_part(void *buf, uint64_t len) if (it->first.oid != ov.oid || IS_STABLE(it->second.state)) break; } - bs->flusher->queue_flush(ov); + bs->flusher->enqueue_flush(ov); } auto unstab_it = bs->unstable_writes.find(ov.oid); if (unstab_it != bs->unstable_writes.end() && unstab_it->second <= ov.version) diff --git a/blockstore_stable.cpp b/blockstore_stable.cpp index deb765e5d..6d039e944 100644 --- a/blockstore_stable.cpp +++ b/blockstore_stable.cpp @@ -171,7 +171,7 @@ void blockstore::handle_stable_event(ring_data_t *data, blockstore_operation *op #ifdef BLOCKSTORE_DEBUG printf("enqueue_flush %lu:%lu v%lu\n", v->oid.inode, v->oid.stripe, v->version); #endif - flusher->queue_flush(*v); + flusher->enqueue_flush(*v); } } // Acknowledge op diff --git a/blockstore_write.cpp b/blockstore_write.cpp index b383e131b..5134ed9a0 100644 --- a/blockstore_write.cpp +++ b/blockstore_write.cpp @@ -146,6 +146,8 @@ int blockstore::dequeue_write(blockstore_operation *op) dirty_it->second.location = journal.next_free; dirty_it->second.state = ST_J_SUBMITTED; journal.next_free += op->len; + if (journal.next_free >= journal.len) + journal.next_free = 512; op->pending_ops = 2; // Remember small write as unsynced unsynced_small_writes.push_back((obj_ver_id){