2019-12-15 14:49:10 +03:00
|
|
|
#include "blockstore_impl.h"
|
2019-11-10 14:37:45 +03:00
|
|
|
|
2019-11-11 02:53:19 +03:00
|
|
|
// Stabilize small write:
|
|
|
|
// 1) Copy data from the journal to the data device
|
|
|
|
// 2) Increase version on the metadata device and sync it
|
|
|
|
// 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 + 4K (data) [+ sync?] + 512b (metadata) + sync.
|
2019-11-27 02:33:33 +03:00
|
|
|
// WA = 2.375. It's not the best, SSD FTL-like redirect-write could probably be lower
|
|
|
|
// even with defragmentation. But it's fixed and it's still better than in Ceph. :)
|
|
|
|
// except for HDD-only clusters, because each write results in 3 seeks.
|
2019-11-11 02:53:19 +03:00
|
|
|
|
|
|
|
// Stabilize big write:
|
|
|
|
// 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 :)
|
|
|
|
|
2019-12-01 17:25:59 +03:00
|
|
|
// Stabilize delete:
|
|
|
|
// 1) Remove metadata entry and sync it
|
|
|
|
// 2) Remove dirty_db entry and clear previous journal entries
|
2019-12-02 02:11:23 +03:00
|
|
|
// We have 2 problems here:
|
|
|
|
// - In the cluster environment, we must store the "tombstones" of deleted objects until
|
|
|
|
// all replicas (not just quorum) agrees about their deletion. That is, "stabilize" is
|
|
|
|
// not possible for deletes in degraded placement groups
|
|
|
|
// - With simple "fixed" metadata tables we can't just clear the metadata entry of the latest
|
|
|
|
// object version. We must clear all previous entries, too.
|
|
|
|
// FIXME Fix both problems - probably, by switching from "fixed" metadata tables to "dynamic"
|
2019-12-01 17:25:59 +03:00
|
|
|
|
2019-11-11 02:53:19 +03:00
|
|
|
// AND We must do it in batches, for the sake of reduced fsync call count
|
2019-11-11 14:10:23 +03:00
|
|
|
// AND We must know what we stabilize. Basic workflow is like:
|
|
|
|
// 1) primary OSD receives sync request
|
2019-11-25 01:16:34 +03:00
|
|
|
// 2) it submits syncs to blockstore and peers
|
|
|
|
// 3) after everyone acks sync it acks sync to the client
|
|
|
|
// 4) after a while it takes his synced object list and sends stabilize requests
|
|
|
|
// to peers and to its own blockstore, thus freeing the old version
|
2019-11-11 02:53:19 +03:00
|
|
|
|
2019-12-15 14:49:10 +03:00
|
|
|
int blockstore_impl_t::dequeue_stable(blockstore_op_t *op)
|
2019-11-10 14:37:45 +03:00
|
|
|
{
|
2019-11-11 14:10:23 +03:00
|
|
|
obj_ver_id* v;
|
|
|
|
int i, todo = 0;
|
|
|
|
for (i = 0, v = (obj_ver_id*)op->buf; i < op->len; i++, v++)
|
2019-11-10 14:37:45 +03:00
|
|
|
{
|
2019-11-11 14:10:23 +03:00
|
|
|
auto dirty_it = dirty_db.find(*v);
|
|
|
|
if (dirty_it == dirty_db.end())
|
2019-11-10 14:37:45 +03:00
|
|
|
{
|
2019-11-11 14:10:23 +03:00
|
|
|
auto clean_it = clean_db.find(v->oid);
|
|
|
|
if (clean_it == clean_db.end() || clean_it->second.version < v->version)
|
|
|
|
{
|
|
|
|
// No such object version
|
2019-11-21 02:09:12 +03:00
|
|
|
op->retval = -EINVAL;
|
2019-12-15 14:49:10 +03:00
|
|
|
FINISH_OP(op);
|
2019-11-11 14:10:23 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Already stable
|
|
|
|
}
|
2019-11-10 14:37:45 +03:00
|
|
|
}
|
2019-11-11 14:10:23 +03:00
|
|
|
else if (IS_UNSYNCED(dirty_it->second.state))
|
2019-11-10 14:37:45 +03:00
|
|
|
{
|
2019-11-11 14:10:23 +03:00
|
|
|
// Object not synced yet. Caller must sync it first
|
|
|
|
op->retval = EAGAIN;
|
2019-12-15 14:49:10 +03:00
|
|
|
FINISH_OP(op);
|
2019-11-11 14:10:23 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (!IS_STABLE(dirty_it->second.state))
|
|
|
|
{
|
|
|
|
todo++;
|
2019-11-10 14:37:45 +03:00
|
|
|
}
|
|
|
|
}
|
2019-11-11 14:10:23 +03:00
|
|
|
if (!todo)
|
2019-11-10 14:37:45 +03:00
|
|
|
{
|
|
|
|
// Already stable
|
|
|
|
op->retval = 0;
|
2019-12-15 14:49:10 +03:00
|
|
|
FINISH_OP(op);
|
2019-11-10 14:37:45 +03:00
|
|
|
return 1;
|
|
|
|
}
|
2019-11-10 15:00:01 +03:00
|
|
|
// Check journal space
|
2019-11-11 00:28:14 +03:00
|
|
|
blockstore_journal_check_t space_check(this);
|
2019-11-11 14:10:23 +03:00
|
|
|
if (!space_check.check_available(op, todo, sizeof(journal_entry_stable), 0))
|
2019-11-10 15:00:01 +03:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2019-11-11 14:10:23 +03:00
|
|
|
// There is sufficient space. Get SQEs
|
2019-11-11 18:24:04 +03:00
|
|
|
struct io_uring_sqe *sqe[space_check.sectors_required];
|
|
|
|
for (i = 0; i < space_check.sectors_required; i++)
|
2019-11-11 14:10:23 +03:00
|
|
|
{
|
|
|
|
BS_SUBMIT_GET_SQE_DECL(sqe[i]);
|
|
|
|
}
|
|
|
|
// Prepare and submit journal entries
|
2019-11-13 21:17:04 +03:00
|
|
|
auto cb = [this, op](ring_data_t *data) { handle_stable_event(data, op); };
|
2019-11-11 14:10:23 +03:00
|
|
|
int s = 0, cur_sector = -1;
|
2020-01-16 00:35:35 +03:00
|
|
|
if ((journal_block_size - journal.in_sector_pos) < sizeof(journal_entry_stable) &&
|
2020-01-15 01:55:30 +03:00
|
|
|
journal.sector_info[journal.cur_sector].dirty)
|
|
|
|
{
|
|
|
|
if (cur_sector == -1)
|
|
|
|
PRIV(op)->min_used_journal_sector = 1 + journal.cur_sector;
|
|
|
|
cur_sector = journal.cur_sector;
|
|
|
|
prepare_journal_sector_write(journal, cur_sector, sqe[s++], cb);
|
|
|
|
}
|
2019-11-11 14:10:23 +03:00
|
|
|
for (i = 0, v = (obj_ver_id*)op->buf; i < op->len; i++, v++)
|
|
|
|
{
|
2019-11-25 22:35:44 +03:00
|
|
|
auto unstab_it = unstable_writes.find(v->oid);
|
|
|
|
if (unstab_it != unstable_writes.end() &&
|
|
|
|
unstab_it->second <= v->version)
|
|
|
|
{
|
|
|
|
unstable_writes.erase(unstab_it);
|
|
|
|
}
|
2019-11-11 14:10:23 +03:00
|
|
|
journal_entry_stable *je = (journal_entry_stable*)
|
|
|
|
prefill_single_journal_entry(journal, JE_STABLE, sizeof(journal_entry_stable));
|
2020-01-15 01:55:30 +03:00
|
|
|
journal.sector_info[journal.cur_sector].dirty = false;
|
2019-11-11 14:10:23 +03:00
|
|
|
je->oid = v->oid;
|
|
|
|
je->version = v->version;
|
|
|
|
je->crc32 = je_crc32((journal_entry*)je);
|
|
|
|
journal.crc32_last = je->crc32;
|
|
|
|
if (cur_sector != journal.cur_sector)
|
|
|
|
{
|
2019-11-11 18:24:04 +03:00
|
|
|
if (cur_sector == -1)
|
2019-12-15 14:49:10 +03:00
|
|
|
PRIV(op)->min_used_journal_sector = 1 + journal.cur_sector;
|
2019-11-11 14:10:23 +03:00
|
|
|
cur_sector = journal.cur_sector;
|
2020-01-15 01:55:30 +03:00
|
|
|
prepare_journal_sector_write(journal, cur_sector, sqe[s++], cb);
|
2019-11-11 14:10:23 +03:00
|
|
|
}
|
|
|
|
}
|
2019-12-15 14:49:10 +03:00
|
|
|
PRIV(op)->max_used_journal_sector = 1 + journal.cur_sector;
|
|
|
|
PRIV(op)->pending_ops = s;
|
2019-11-10 15:00:01 +03:00
|
|
|
return 1;
|
2019-11-10 14:37:45 +03:00
|
|
|
}
|
|
|
|
|
2019-12-15 14:49:10 +03:00
|
|
|
void blockstore_impl_t::handle_stable_event(ring_data_t *data, blockstore_op_t *op)
|
2019-11-10 14:37:45 +03:00
|
|
|
{
|
2020-01-10 01:23:46 +03:00
|
|
|
live = true;
|
2019-11-17 22:27:29 +03:00
|
|
|
if (data->res != data->iov.iov_len)
|
2019-11-10 14:37:45 +03:00
|
|
|
{
|
2019-11-17 22:27:29 +03:00
|
|
|
throw std::runtime_error(
|
|
|
|
"write operation failed ("+std::to_string(data->res)+" != "+std::to_string(data->iov.iov_len)+
|
|
|
|
"). in-memory state is corrupted. AAAAAAAaaaaaaaaa!!!111"
|
|
|
|
);
|
2019-11-10 14:37:45 +03:00
|
|
|
}
|
2019-12-15 14:49:10 +03:00
|
|
|
PRIV(op)->pending_ops--;
|
|
|
|
if (PRIV(op)->pending_ops == 0)
|
2019-11-10 14:37:45 +03:00
|
|
|
{
|
2019-11-26 20:37:12 +03:00
|
|
|
// Release used journal sectors
|
2020-01-15 01:55:30 +03:00
|
|
|
release_journal_sectors(op);
|
2020-01-24 20:10:18 +03:00
|
|
|
// Mark dirty_db entries as stable, acknowledge op completion
|
2019-11-11 14:10:23 +03:00
|
|
|
obj_ver_id* v;
|
|
|
|
int i;
|
|
|
|
for (i = 0, v = (obj_ver_id*)op->buf; i < op->len; i++, v++)
|
2019-11-10 15:00:01 +03:00
|
|
|
{
|
2019-11-11 14:10:23 +03:00
|
|
|
// Mark all dirty_db entries up to op->version as stable
|
2019-11-12 13:52:27 +03:00
|
|
|
auto dirty_it = dirty_db.find(*v);
|
2019-11-11 14:10:23 +03:00
|
|
|
if (dirty_it != dirty_db.end())
|
|
|
|
{
|
2019-11-21 23:45:19 +03:00
|
|
|
while (1)
|
2019-11-11 14:10:23 +03:00
|
|
|
{
|
|
|
|
if (dirty_it->second.state == ST_J_SYNCED)
|
|
|
|
{
|
|
|
|
dirty_it->second.state = ST_J_STABLE;
|
|
|
|
}
|
|
|
|
else if (dirty_it->second.state == ST_D_META_SYNCED)
|
|
|
|
{
|
|
|
|
dirty_it->second.state = ST_D_STABLE;
|
|
|
|
}
|
2019-12-01 17:25:59 +03:00
|
|
|
else if (dirty_it->second.state == ST_DEL_SYNCED)
|
|
|
|
{
|
|
|
|
dirty_it->second.state = ST_DEL_STABLE;
|
|
|
|
}
|
2019-11-12 13:52:27 +03:00
|
|
|
else if (IS_STABLE(dirty_it->second.state))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2019-11-21 23:45:19 +03:00
|
|
|
if (dirty_it == dirty_db.begin())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2019-11-11 14:10:23 +03:00
|
|
|
dirty_it--;
|
2019-11-21 23:45:19 +03:00
|
|
|
if (dirty_it->first.oid != v->oid)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-11-27 18:07:08 +03:00
|
|
|
#ifdef BLOCKSTORE_DEBUG
|
|
|
|
printf("enqueue_flush %lu:%lu v%lu\n", v->oid.inode, v->oid.stripe, v->version);
|
|
|
|
#endif
|
2019-11-28 00:26:53 +03:00
|
|
|
flusher->enqueue_flush(*v);
|
2019-11-11 14:10:23 +03:00
|
|
|
}
|
2019-11-10 15:00:01 +03:00
|
|
|
}
|
2019-11-12 12:02:11 +03:00
|
|
|
// Acknowledge op
|
|
|
|
op->retval = 0;
|
2019-12-15 14:49:10 +03:00
|
|
|
FINISH_OP(op);
|
2019-11-12 12:02:11 +03:00
|
|
|
}
|
|
|
|
}
|