Remove duplicate journal writing code (and fix it at the same time)
This commit is contained in:
+20
-49
@@ -36,52 +36,18 @@ int blockstore::dequeue_stable(blockstore_operation *op)
|
||||
op->callback(op);
|
||||
return 1;
|
||||
}
|
||||
// FIXME: Try to deduplicate journal entry submission code...
|
||||
// Check journal space
|
||||
uint64_t next_pos = journal.next_free;
|
||||
if (512 - journal.in_sector_pos < sizeof(struct journal_entry_stable))
|
||||
blockstore_journal_check_t space_check(this);
|
||||
if (!space_check.check_available(op, 1, sizeof(journal_entry_stable), 0))
|
||||
{
|
||||
next_pos = (next_pos+512) < journal.len ? next_pos+512 : 512;
|
||||
// Also check if we have an unused memory buffer for the journal sector
|
||||
if (journal.sector_info[((journal.cur_sector + 1) % journal.sector_count)].usage_count > 0)
|
||||
{
|
||||
// No memory buffer available. Wait for it.
|
||||
op->wait_for = WAIT_JOURNAL_BUFFER;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (next_pos >= journal.used_start)
|
||||
{
|
||||
// No space in the journal. Wait for it.
|
||||
op->wait_for = WAIT_JOURNAL;
|
||||
op->wait_detail = next_pos;
|
||||
return 0;
|
||||
}
|
||||
// There is sufficient space. Get SQE
|
||||
BS_SUBMIT_GET_SQE(sqe, data);
|
||||
// Got SQE. Prepare journal sector write
|
||||
if (512 - journal.in_sector_pos < sizeof(struct journal_entry_stable))
|
||||
{
|
||||
// Move to the next journal sector
|
||||
// Also select next sector buffer in memory
|
||||
journal.cur_sector = ((journal.cur_sector + 1) % journal.sector_count);
|
||||
journal.sector_info[journal.cur_sector].offset = journal.next_free;
|
||||
journal.in_sector_pos = 0;
|
||||
journal.next_free = (journal.next_free+512) < journal.len ? journal.next_free + 512 : 512;
|
||||
memset(journal.sector_buf + 512*journal.cur_sector, 0, 512);
|
||||
}
|
||||
journal_entry_stable *je = (journal_entry_stable*)(
|
||||
journal.sector_buf + 512*journal.cur_sector + journal.in_sector_pos
|
||||
);
|
||||
*je = {
|
||||
.crc32 = 0,
|
||||
.magic = JOURNAL_MAGIC,
|
||||
.type = JE_STABLE,
|
||||
.size = sizeof(struct journal_entry_stable),
|
||||
.crc32_prev = journal.crc32_last,
|
||||
.oid = op->oid,
|
||||
.version = op->version,
|
||||
};
|
||||
journal_entry_stable *je = (journal_entry_stable*)prefill_single_journal_entry(journal, JE_STABLE, sizeof(struct journal_entry_stable));
|
||||
je->oid = op->oid;
|
||||
je->version = op->version;
|
||||
je->crc32 = je_crc32((journal_entry*)je);
|
||||
journal.crc32_last = je->crc32;
|
||||
data->iov = (struct iovec){ journal.sector_buf + 512*journal.cur_sector, 512 };
|
||||
@@ -113,25 +79,30 @@ void blockstore::handle_stable_event(ring_data_t *data, blockstore_operation *op
|
||||
});
|
||||
if (dirty_it->second.state == ST_J_SYNCED)
|
||||
{
|
||||
dirty_it->second.state = ST_J_STABLE;
|
||||
// Copy data from the journal to the data device
|
||||
// -> increase version on the metadata device
|
||||
// -> advance clean_db entry's version and clear previous journal entries
|
||||
// This makes 1 4K small write look like:
|
||||
// 1) Copy data from the journal to the data device
|
||||
// 2) Increase version on the metadata device
|
||||
// 3) Advance clean_db entry's version, clear previous journal entries
|
||||
// This makes 1 4K small write+sync look like:
|
||||
// 512b+4K (journal) + sync + 512b (journal) + sync + 512b (metadata) + 4K (data) + sync.
|
||||
// WA = 2.375. It's not the best, SSD FTL-like redirect-write with defragmentation
|
||||
// could probably be lower even with defragmentation. But it's fixed and it's still
|
||||
// better than in Ceph. :)
|
||||
dirty_it->second.state = ST_J_STABLE;
|
||||
// Acknowledge op
|
||||
op->retval = 0;
|
||||
op->callback(op);
|
||||
}
|
||||
else if (dirty_it->second.state == ST_D_META_SYNCED)
|
||||
{
|
||||
dirty_it->second.state = ST_D_STABLE;
|
||||
// Copy metadata from the journal to the metadata device
|
||||
// -> move dirty_db entry to clean_db and clear previous journal entries
|
||||
// This makes 1 128K big write look like:
|
||||
// 1) Copy metadata from the journal to the metadata device
|
||||
// 2) Move dirty_db entry to clean_db and clear previous journal entries
|
||||
// This makes 1 128K big write+sync look like:
|
||||
// 128K (data) + sync + 512b (journal) + sync + 512b (journal) + sync + 512b (metadata) + sync.
|
||||
// WA = 1.012. Very good :)
|
||||
dirty_it->second.state = ST_D_STABLE;
|
||||
// Acknowledge op
|
||||
op->retval = 0;
|
||||
op->callback(op);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user