Compare commits

...

4 Commits

22 changed files with 366 additions and 78 deletions

View File

@@ -77,8 +77,11 @@ Output:
- retval = number of bytes actually read/written or negative error number
-EINVAL = invalid input parameters
-ENOENT = requested object/version does not exist for reads
-EEXIST = requested version to write already exists
-ENOSPC = no space left in the store for writes
-EDOM = checksum error.
-EAGAIN = temporary failure, operation should be retried (notably, writes may be retried
after stabilizing some journaled entries and freeing up journal space)
-EDOM = checksum error
- version = the version actually read or written
## BS_OP_DELETE
@@ -90,7 +93,7 @@ Input:
- version = requested version. Treated the same as with BS_OP_WRITE
Output:
- retval = 0 or negative error number (-EINVAL)
- retval = 0 or negative error number (-EINVAL, -EAGAIN)
- version = the version actually written (delete is initially written as an object version)
## BS_OP_SYNC
@@ -99,7 +102,7 @@ Make sure all previously issued modifications reach physical media.
Input: Nothing except opcode
Output:
- retval = 0 or negative error number (-EINVAL)
- retval = 0 or negative error number (-EINVAL, -EAGAIN)
## BS_OP_STABLE / BS_OP_ROLLBACK
@@ -129,7 +132,9 @@ Input:
- max_oid = max inode/stripe or 0 to list all objects
Output:
- retval = total obj_ver_id count
- retval = total obj_ver_id count or negative error number
-ENOMEM = could not allocate memory for the listing
-EAGAIN = pool sharding settings are incorrect, please reshard and retry
- version = stable obj_ver_id count
- buf = obj_ver_id array allocated by the blockstore. Stable versions come first.
You must free it yourself after usage with free().

View File

@@ -243,6 +243,12 @@ enospc:
uint64_t loc = !op->len ? 0 : heap->find_free_buffer_area(op->len);
if (loc == UINT64_MAX)
{
if (!heap->get_to_compact_count())
{
op->retval = -EAGAIN;
FINISH_OP(op);
return 2;
}
PRIV(op)->wait_for = WAIT_COMPACTION;
PRIV(op)->wait_detail = heap->get_compacted_count();
flusher->request_trim();

View File

@@ -76,6 +76,16 @@ size_t journal_flusher_t::get_queue_size()
return flush_queue.size();
}
bool journal_flusher_t::may_advance()
{
return flush_queue.size() || active_flushers > 0 || trim_possible;
}
bool journal_flusher_t::may_advance_except_one()
{
return flush_queue.size() || active_flushers > 1 || trim_possible;
}
void journal_flusher_t::loop()
{
target_flusher_count = bs->write_iodepth*2;
@@ -190,6 +200,7 @@ void journal_flusher_t::request_trim()
void journal_flusher_t::mark_trim_possible()
{
trim_possible = true;
if (trim_wanted > 0)
{
dequeuing = true;
@@ -652,9 +663,10 @@ resume_2:
flusher->sync_to_repeat.erase(repeat_it);
trim_journal:
// Clear unused part of the journal every <journal_trim_interval> flushes
if (bs->journal_trim_interval && !((++flusher->journal_trim_counter) % bs->journal_trim_interval) ||
flusher->trim_wanted > 0)
if ((bs->journal_trim_interval && !((++flusher->journal_trim_counter) % bs->journal_trim_interval) ||
flusher->trim_wanted > 0) && flusher->trim_possible)
{
flusher->trim_possible = false;
resume_30:
resume_31:
resume_32:
@@ -1496,10 +1508,19 @@ bool journal_flusher_co::trim_journal(int wait_base)
printf("Journal flushed\n");
exit(0);
}
bs->wakeup_wait_journal();
}
else if (!flusher->may_advance_except_one())
{
bs->wakeup_wait_journal();
}
flusher->journal_trim_counter = 0;
flusher->trimming = false;
}
else if (!flusher->may_advance_except_one())
{
bs->wakeup_wait_journal();
}
return true;
}

View File

@@ -94,6 +94,7 @@ public:
class journal_flusher_t
{
int trim_wanted = 0;
bool trim_possible = false;
bool dequeuing;
int min_flusher_count, max_flusher_count, cur_flusher_count, target_flusher_count;
int flusher_start_threshold;
@@ -117,12 +118,14 @@ class journal_flusher_t
bool try_find_older(std::map<obj_ver_id, dirty_entry>::iterator & dirty_end, obj_ver_id & cur);
bool try_find_other(std::map<obj_ver_id, dirty_entry>::iterator & dirty_end, obj_ver_id & cur);
bool may_advance_except_one();
public:
journal_flusher_t(blockstore_impl_t *bs);
~journal_flusher_t();
void loop();
bool is_trim_wanted() { return trim_wanted; }
bool may_advance();
bool is_active();
size_t get_queue_size();
void mark_trim_possible();

View File

@@ -212,10 +212,6 @@ void blockstore_impl_t::loop()
// ring is full, stop submission
break;
}
else if (PRIV(op)->wait_for == WAIT_JOURNAL)
{
PRIV(op)->wait_detail2 = (unstable_writes.size()+unstable_unsynced);
}
}
}
if (op_idx != new_idx)
@@ -280,6 +276,12 @@ bool blockstore_impl_t::is_safe_to_stop()
return true;
}
void blockstore_impl_t::wakeup_wait_journal()
{
wait_journal_counter++;
ringloop->wakeup();
}
void blockstore_impl_t::check_wait(blockstore_op_t *op)
{
if (PRIV(op)->wait_for == WAIT_SQE)
@@ -296,12 +298,11 @@ void blockstore_impl_t::check_wait(blockstore_op_t *op)
}
else if (PRIV(op)->wait_for == WAIT_JOURNAL)
{
if (journal.used_start == PRIV(op)->wait_detail &&
(unstable_writes.size()+unstable_unsynced) == PRIV(op)->wait_detail2)
if (wait_journal_counter == PRIV(op)->wait_detail)
{
// do not submit
#ifdef BLOCKSTORE_DEBUG
printf("Still waiting to flush journal offset %08jx\n", PRIV(op)->wait_detail);
printf("Still waiting for flush journal counter %ju\n", PRIV(op)->wait_detail);
#endif
return;
}

View File

@@ -93,7 +93,7 @@ struct blockstore_op_private_t
{
// Wait status
int wait_for;
uint64_t wait_detail, wait_detail2;
uint64_t wait_detail;
int pending_ops;
int op_state;
@@ -215,6 +215,8 @@ class blockstore_impl_t: public blockstore_i
blockstore_init_meta* metadata_init_reader;
blockstore_init_journal* journal_init_reader;
uint64_t wait_journal_counter = 0;
void wakeup_wait_journal();
void check_wait(blockstore_op_t *op);
void init_op(blockstore_op_t *op);

View File

@@ -1000,7 +1000,7 @@ int blockstore_init_journal::handle_journal_part(void *buf, uint64_t done_pos, u
memcpy((uint8_t*)dyn+sizeof(int), dyn_from, dyn_size);
}
bs->dirty_db.emplace(ov, (dirty_entry){
.state = (BS_ST_SMALL_WRITE | BS_ST_SYNCED),
.state = (BS_ST_SMALL_WRITE | BS_ST_SYNCED | (je->type == JE_SMALL_WRITE_INSTANT ? BS_ST_INSTANT : 0)),
.flags = 0,
.location = location,
.offset = je->small_write.offset,
@@ -1084,7 +1084,7 @@ int blockstore_init_journal::handle_journal_part(void *buf, uint64_t done_pos, u
memcpy((uint8_t*)dyn+sizeof(int), dyn_from, dyn_size);
}
auto dirty_it = bs->dirty_db.emplace(ov, (dirty_entry){
.state = (BS_ST_BIG_WRITE | BS_ST_SYNCED),
.state = (BS_ST_BIG_WRITE | BS_ST_SYNCED | (je->type == JE_BIG_WRITE_INSTANT ? BS_ST_INSTANT : 0)),
.flags = 0,
.location = je->big_write.location,
.offset = je->big_write.offset,

View File

@@ -15,6 +15,7 @@ blockstore_journal_check_t::blockstore_journal_check_t(blockstore_impl_t *bs)
first_sector = -1;
next_in_pos = bs->journal.in_sector_pos;
right_dir = next_pos >= bs->journal.used_start;
give_up = false;
}
// Check if we can write <required> entries of <size> bytes and <data_after> data bytes after them to the journal
@@ -119,13 +120,20 @@ int blockstore_journal_check_t::check_available(blockstore_op_t *op, int entries
if (bs->log_level > 5)
{
printf(
"Ran out of journal space (used_start=%08jx, next_free=%08jx, dirty_start=%08jx)\n",
bs->journal.used_start, bs->journal.next_free, bs->journal.dirty_start
"Ran out of journal space (used_start=%08jx, next_free=%08jx, dirty_start=%08jx, queued %zu)\n",
bs->journal.used_start, bs->journal.next_free, bs->journal.dirty_start, bs->flusher->get_queue_size()
);
}
PRIV(op)->wait_for = WAIT_JOURNAL;
bs->flusher->request_trim();
PRIV(op)->wait_detail = bs->journal.used_start;
if (!bs->flusher->may_advance())
{
give_up = true;
}
else
{
PRIV(op)->wait_for = WAIT_JOURNAL;
PRIV(op)->wait_detail = bs->wait_journal_counter;
bs->flusher->request_trim();
}
return 0;
}
return 1;

View File

@@ -70,6 +70,7 @@ struct blockstore_journal_check_t
uint64_t next_pos, next_sector, next_in_pos;
int sectors_to_write, first_sector;
bool right_dir; // writing to the end or the beginning of the ring buffer
bool give_up;
blockstore_journal_check_t(blockstore_impl_t *bs);
int check_available(blockstore_op_t *op, int required, int size, int data_after);

View File

@@ -63,6 +63,12 @@ int blockstore_impl_t::dequeue_rollback(blockstore_op_t *op)
blockstore_journal_check_t space_check(this);
if (!space_check.check_available(op, op->len, sizeof(journal_entry_rollback), 0))
{
if (space_check.give_up)
{
op->retval = -EAGAIN;
FINISH_OP(op);
return 2;
}
return 0;
}
// There is sufficient space. Check SQEs
@@ -162,7 +168,10 @@ void blockstore_impl_t::mark_rolled_back(const obj_ver_id & ov)
if (unstab_it != unstable_writes.end())
{
if (max_unstable == 0)
{
unstable_writes.erase(unstab_it);
wakeup_wait_journal();
}
else
unstab_it->second = max_unstable;
}

View File

@@ -362,6 +362,12 @@ int blockstore_impl_t::dequeue_stable(blockstore_op_t *op)
blockstore_journal_check_t space_check(this);
if (!space_check.check_available(op, op->len, sizeof(journal_entry_stable), 0))
{
if (space_check.give_up)
{
op->retval = -EAGAIN;
FINISH_OP(op);
return 2;
}
return 0;
}
// There is sufficient space. Check SQEs
@@ -557,6 +563,7 @@ void blockstore_impl_t::mark_stable(obj_ver_id v, bool forget_dirty)
unstab_it->second <= v.version)
{
unstable_writes.erase(unstab_it);
wakeup_wait_journal();
}
}

View File

@@ -79,6 +79,7 @@ int blockstore_impl_t::continue_sync(blockstore_op_t *op)
// 2nd step: Data device is synced, prepare & write journal entries
// Check space in the journal and journal memory buffers
blockstore_journal_check_t space_check(this);
bool space_ok = true;
if (dsk.csum_block_size)
{
// More complex check because all journal entries have different lengths
@@ -90,13 +91,34 @@ int blockstore_impl_t::continue_sync(blockstore_op_t *op)
uint64_t dyn_size = dsk.dirty_dyn_size(dirty_entry.offset, dirty_entry.len);
if (!space_check.check_available(op, 1, sizeof(journal_entry_big_write) + dyn_size, 0))
{
return 0;
space_ok = false;
break;
}
}
}
else if (!space_check.check_available(op, PRIV(op)->sync_big_writes.size(),
sizeof(journal_entry_big_write) + dsk.clean_entry_bitmap_size, 0))
{
space_ok = false;
}
if (!space_ok)
{
if (space_check.give_up)
{
// Return everything back
unsynced_big_write_count += PRIV(op)->sync_big_writes.size();
PRIV(op)->sync_big_writes.insert(PRIV(op)->sync_big_writes.end(),
unsynced_big_writes.begin(), unsynced_big_writes.end());
PRIV(op)->sync_big_writes.swap(unsynced_big_writes);
PRIV(op)->sync_big_writes.clear();
PRIV(op)->sync_small_writes.insert(PRIV(op)->sync_small_writes.end(),
unsynced_small_writes.begin(), unsynced_small_writes.end());
PRIV(op)->sync_small_writes.swap(unsynced_small_writes);
PRIV(op)->sync_small_writes.clear();
op->retval = -EAGAIN;
FINISH_OP(op);
return 2;
}
return 0;
}
// Check SQEs. Don't bother about merging, submit each journal sector as a separate request
@@ -193,6 +215,7 @@ void blockstore_impl_t::ack_sync(blockstore_op_t *op)
{
unstable_unsynced--;
assert(unstable_unsynced >= 0);
wakeup_wait_journal();
}
dirty_it++;
while (dirty_it != dirty_db.end() && dirty_it->first.oid == it->oid)
@@ -228,6 +251,7 @@ void blockstore_impl_t::ack_sync(blockstore_op_t *op)
{
unstable_unsynced--;
assert(unstable_unsynced >= 0);
wakeup_wait_journal();
}
}
}

View File

@@ -39,6 +39,11 @@ bool blockstore_impl_t::enqueue_write(blockstore_op_t *op)
dirty_it--; // segfaults when dirty_db is empty
if (dirty_it != dirty_db.end() && dirty_it->first.oid == op->oid)
{
if (op->opcode == BS_OP_WRITE_STABLE && !IS_INSTANT(dirty_it->second.state))
{
op->retval = -EINVAL;
return false;
}
found = true;
version = dirty_it->first.version + 1;
deleted = IS_DELETE(dirty_it->second.state);
@@ -312,6 +317,11 @@ int blockstore_impl_t::dequeue_write(blockstore_op_t *op)
sizeof(journal_entry_big_write) + dsk.clean_dyn_size,
(unstable_writes.size()+unstable_unsynced+((dirty_it->second.state & BS_ST_INSTANT) ? 0 : 1))*journal.block_size))
{
if (space_check.give_up)
{
cancel_all_writes(op, dirty_it, -EAGAIN);
return 2;
}
return 0;
}
// Big (redirect) write
@@ -404,6 +414,11 @@ int blockstore_impl_t::dequeue_write(blockstore_op_t *op)
sizeof(journal_entry_small_write) + dyn_size,
op->len + (unstable_writes.size()+unstable_unsynced+((dirty_it->second.state & BS_ST_INSTANT) ? 0 : 1))*journal.block_size))
{
if (space_check.give_up)
{
cancel_all_writes(op, dirty_it, -EAGAIN);
return 2;
}
return 0;
}
// There is sufficient space. Check SQE(s)
@@ -559,6 +574,25 @@ resume_2:
if (!space_check.check_available(op, 1, sizeof(journal_entry_big_write) + dyn_size,
(unstable_writes.size()+unstable_unsynced+((dirty_it->second.state & BS_ST_INSTANT) ? 0 : 1))*journal.block_size))
{
if (space_check.give_up)
{
auto uo_it = used_clean_objects.find(dirty_it->second.location);
if (uo_it != used_clean_objects.end())
uo_it->second.was_freed = true;
else
data_alloc->set(dirty_it->second.location / dsk.data_block_size, false);
if (!(dirty_it->second.state & BS_ST_INSTANT))
{
unstable_unsynced--;
assert(unstable_unsynced >= 0);
wakeup_wait_journal();
}
if (immediate_commit != IMMEDIATE_ALL)
unsynced_big_write_count--;
write_iodepth--;
cancel_all_writes(op, dirty_it, -EAGAIN);
return 2;
}
return 0;
}
BS_SUBMIT_CHECK_SQES(1);
@@ -622,6 +656,7 @@ resume_4:
{
unstable_unsynced--;
assert(unstable_unsynced >= 0);
wakeup_wait_journal();
}
}
dirty_it->second.state = (dirty_it->second.state & ~BS_ST_WORKFLOW_MASK)
@@ -774,6 +809,11 @@ int blockstore_impl_t::dequeue_del(blockstore_op_t *op)
blockstore_journal_check_t space_check(this);
if (!space_check.check_available(op, 1, sizeof(journal_entry_del), (unstable_writes.size()+unstable_unsynced)*journal.block_size))
{
if (space_check.give_up)
{
cancel_all_writes(op, dirty_it, -EAGAIN);
return 2;
}
return 0;
}
// Write current journal sector only if it's dirty and full, or in the immediate_commit mode

View File

@@ -1250,9 +1250,11 @@ resume_2:
return 1;
}
else if (op->retval != 0 && op->opcode != OSD_OP_SYNC && !(op->flags & OP_FLUSH_BUFFER) &&
op->retval != -EPIPE && (op->retval != -EIO || !client_eio_retry_interval) && (op->retval != -ENOSPC || !client_retry_enospc))
op->retval != -EPIPE && op->retval != -EAGAIN &&
(op->retval != -EIO || !client_eio_retry_interval) &&
(op->retval != -ENOSPC || !client_retry_enospc))
{
// Fatal error (neither -EPIPE, -EIO nor -ENOSPC)
// Fatal error (neither -EPIPE, -EAGAIN, -EIO nor -ENOSPC)
erase_op(op);
return 1;
}
@@ -1611,7 +1613,7 @@ resume_1:
if (op->retval != 0)
{
wb->fsync_error();
if (op->retval == -EPIPE || op->retval == -EIO || op->retval == -ENOSPC)
if (op->retval == -EPIPE || op->retval == -EAGAIN || op->retval == -EIO || op->retval == -ENOSPC)
{
// Retry later
op->parts.clear();
@@ -1662,9 +1664,6 @@ static inline void mem_or(void *res, const void *r2, unsigned int len)
}
}
// Error priority: others > EPERM > EIO > ENOSPC > ETIMEDOUT > EPIPE
#define ERR_PRIO(e) (((e) == -EPERM ? 5 : ((e) == -EIO ? 4 : ((e) == -ENOSPC ? 3 : ((e) == -ETIMEDOUT ? 2 : ((e) == -EPIPE ? 1 : (!(e) ? 0 : 10)))))))
void cluster_client_t::handle_op_part(cluster_op_part_t *part)
{
cluster_op_t *op = part->parent;
@@ -1676,7 +1675,7 @@ void cluster_client_t::handle_op_part(cluster_op_part_t *part)
if (ERR_PRIO(part->op.reply.hdr.retval) > ERR_PRIO(op->retval))
op->retval = part->op.reply.hdr.retval;
uint64_t stop_client_id = 0;
if (op->retval != -EINTR && op->retval != -EIO && op->retval != -ENOSPC && op->retval != -EPERM)
if (op->retval != -EINTR && op->retval != -EIO && op->retval != -ENOSPC && op->retval != -EPERM && op->retval != -EAGAIN)
{
stop_client_id = part->op.client_id;
if (op->retval != -EPIPE || log_level > 0)
@@ -1698,11 +1697,11 @@ void cluster_client_t::handle_op_part(cluster_op_part_t *part)
// So do all these things after modifying operation state, otherwise we may hit reenterability bugs
// FIXME postpone such things to set_immediate here to avoid bugs
// Set op->retry_after to retry operation after a short pause (not immediately)
if (!op->retry_after && (op->retval == -EPIPE ||
if (!op->retry_after && (op->retval == -EPIPE || op->retval == -EAGAIN ||
op->retval == -EIO && client_eio_retry_interval ||
op->retval == -ENOSPC && client_retry_enospc))
{
op->retry_after = op->retval != -EPIPE ? client_eio_retry_interval : client_retry_interval;
op->retry_after = op->retval != -EPIPE && op->retval != -EAGAIN ? client_eio_retry_interval : client_retry_interval;
}
reset_retry_timer(op->retry_after);
if (stop_client_id)

View File

@@ -370,8 +370,7 @@ void cluster_client_t::send_list(inode_list_osd_t *cur_list)
fprintf(stderr, "Failed to get PG %u/%u object list from OSD %ju (retval=%jd), skipping\n",
cur_list->pg->lst->pool_id, cur_list->pg->pg_num, cur_list->osd_num, op->reply.hdr.retval);
if (!cur_list->pg->errcode ||
cur_list->pg->errcode == -EPIPE ||
op->reply.hdr.retval != -EPIPE)
ERR_PRIO(op->reply.hdr.retval) > ERR_PRIO(cur_list->pg->errcode))
{
cur_list->pg->errcode = op->reply.hdr.retval;
}
@@ -434,7 +433,7 @@ void cluster_client_t::finish_list_pg(inode_list_pg_t *pg, bool retry_epipe)
auto lst = pg->lst;
if (pg->inflight_ops == 0)
{
if (pg->errcode == -EPIPE && retry_epipe)
if ((pg->errcode == -EPIPE || pg->errcode == -EAGAIN) && retry_epipe)
{
// Retry listing after <client_retry_interval> ms on EPIPE
pg->state = LIST_PG_WAIT_RETRY;

View File

@@ -111,4 +111,15 @@ namespace std
return seed;
}
};
template<> struct hash<pool_pg_num_t>
{
inline size_t operator()(const pool_pg_num_t &s) const
{
size_t seed = 0;
seed ^= ((size_t)s.pool_id + 0xc6a4a7935bd1e995 + (seed << 6) + (seed >> 2));
seed ^= ((size_t)s.pg_num + 0xc6a4a7935bd1e995 + (seed << 6) + (seed >> 2));
return seed;
}
};
}

View File

@@ -57,6 +57,9 @@
#define OSD_SEC_LOCK_PG 1
#define OSD_SEC_UNLOCK_PG 2
// Error priority: others > EPERM > EIO > EDOM > ENOSPC > EPIPE > EAGAIN
#define ERR_PRIO(e) (((e) == -EPERM ? 6 : ((e) == -EIO ? 5 : ((e) == -EDOM ? 4 : ((e) == -ENOSPC ? 3 : ((e) == -EPIPE ? 2 : ((e) == -EAGAIN ? 1 : (!(e) ? 0 : 10))))))))
// common request and reply headers
struct __attribute__((__packed__)) osd_op_header_t
{

View File

@@ -81,18 +81,9 @@ void osd_t::handle_flush_op(bool rollback, pool_id_t pool_id, pg_num_t pg_num, p
if (retval != 0)
{
fb->flush_errors++;
if (peer_osd == this->osd_num)
printf("Error while doing flush on OSD %ju: %d (%s)\n", peer_osd, retval, strerror(-retval));
if (peer_osd != this->osd_num && retval != -EAGAIN)
{
throw std::runtime_error(
std::string(rollback
? "Error while doing local rollback operation: "
: "Error while doing local stabilize operation: "
) + strerror(-retval)
);
}
else
{
printf("Error while doing flush on OSD %ju: %d (%s)\n", osd_num, retval, strerror(-retval));
auto peer_it = msgr.osd_peers.find(peer_osd);
if (peer_it != msgr.osd_peers.end())
{

View File

@@ -311,11 +311,10 @@ void osd_t::handle_primary_bs_subop(osd_op_t *subop)
blockstore_op_t *bs_op = subop->bs_op;
int64_t expected = bs_op->opcode == BS_OP_READ || bs_op->opcode == BS_OP_WRITE
|| bs_op->opcode == BS_OP_WRITE_STABLE ? bs_op->len : 0;
if (bs_op->retval != expected && bs_op->opcode != BS_OP_READ &&
(bs_op->opcode != BS_OP_WRITE && bs_op->opcode != BS_OP_WRITE_STABLE ||
bs_op->retval != -ENOSPC))
if (bs_op->retval != expected && bs_op->opcode != BS_OP_READ && bs_op->retval != -EAGAIN &&
(bs_op->opcode != BS_OP_WRITE && bs_op->opcode != BS_OP_WRITE_STABLE || bs_op->retval != -ENOSPC))
{
// die on any error except ENOSPC during write
// die on any error except ENOSPC or EAGAIN during write
if (bs_op->opcode == BS_OP_WRITE || bs_op->opcode == BS_OP_WRITE_STABLE)
{
printf(
@@ -428,7 +427,7 @@ void osd_t::handle_primary_subop(osd_op_t *subop, osd_op_t *cur_op)
#endif
if (!(op_data->flags & OP_DATA_SKIP_VER_CHECK))
{
if (op_data->fact_ver != version && (op_data->errors > 0 || op_data->done > 0) &&
if (op_data->fact_ver != version && op_data->done > 0 &&
(version != 0 && op_data->fact_ver != 0 || !(op_data->flags & OP_DATA_ENOENT_OK)))
{
fprintf(
@@ -473,16 +472,12 @@ void osd_t::handle_primary_subop(osd_op_t *subop, osd_op_t *cur_op)
);
}
subop->rmw_buf = NULL;
// Error priority: ENOSPC > others > EIO > EDOM > EPIPE
if (op_data->errcode == 0 ||
retval == -ENOSPC && op_data->errcode != -ENOSPC ||
retval == -EIO && (op_data->errcode == -EDOM || op_data->errcode == -EPIPE) ||
retval == -EDOM && (op_data->errcode == -EPIPE) ||
retval != -EIO && retval != -EDOM && retval != -EPIPE)
// Error priority: ENOSPC > others > EIO > EDOM > EPIPE > EAGAIN
if (op_data->errcode == 0 || ERR_PRIO(retval) > ERR_PRIO(op_data->errcode))
{
op_data->errcode = retval;
}
if (subop->client_id && retval != -EDOM && retval != -ERANGE &&
if (subop->client_id && retval != -EDOM && retval != -ERANGE && retval != -EAGAIN &&
(retval != -ENOSPC || opcode != OSD_OP_SEC_WRITE && opcode != OSD_OP_SEC_WRITE_STABLE) &&
(retval != -EIO || opcode != OSD_OP_SEC_READ))
{
@@ -490,6 +485,32 @@ void osd_t::handle_primary_subop(osd_op_t *subop, osd_op_t *cur_op)
msgr.stop_client(subop->client_id);
op_data->drops++;
}
else if (opcode == OSD_OP_SEC_STABILIZE || opcode == OSD_OP_SEC_ROLLBACK)
{
// STABILIZE/ROLLBACK should never fail, but if they do, we repeer the PGs
assert(subop->iov.count == 1);
obj_ver_id *vers = (obj_ver_id*)subop->iov.buf[0].iov_base;
size_t n = subop->iov.buf[0].iov_len/sizeof(obj_ver_id);
robin_hood::unordered_flat_set<pool_pg_num_t> to_repeer;
for (size_t i = 0; i < n; i++)
{
to_repeer.insert((pool_pg_num_t){
.pool_id = INODE_POOL(vers[n].oid.inode),
.pg_num = map_to_pg(vers[n].oid),
});
}
ringloop->set_immediate([this, to_repeer = std::move(to_repeer)]()
{
for (auto & ppg: to_repeer)
{
auto pg_it = pgs.find(ppg);
if (pg_it != pgs.end() && (pg_it->second.state & PG_ACTIVE))
{
repeer_pg(pg_it->second);
}
}
});
}
// Increase op_data->errors after stop_client to prevent >= n_subops running twice
op_data->errors++;
}
@@ -703,6 +724,7 @@ void osd_t::submit_primary_stab_subops(osd_op_t *cur_op)
{
clock_gettime(CLOCK_REALTIME, &subops[i].tv_begin);
subops[i].op_type = (uint64_t)cur_op;
subops[i].iov.push_back(op_data->unstable_writes + stab_osd.start, stab_osd.len * sizeof(obj_ver_id));
subops[i].bs_op = new blockstore_op_t((blockstore_op_t){
.opcode = BS_OP_STABLE,
.callback = [subop = &subops[i], this](blockstore_op_t *bs_subop)
@@ -724,7 +746,7 @@ void osd_t::submit_primary_stab_subops(osd_op_t *cur_op)
.magic = SECONDARY_OSD_OP_MAGIC,
.opcode = OSD_OP_SEC_STABILIZE,
},
.len = (uint64_t)(stab_osd.len * sizeof(obj_ver_id)),
.len = (uint64_t)stab_osd.len * sizeof(obj_ver_id),
.flags = cur_op->client_id == SELF_CLIENT && cur_op->req.hdr.opcode != OSD_OP_SCRUB ? OSD_OP_RECOVERY_RELATED : 0,
} };
subops[i].iov.push_back(op_data->unstable_writes + stab_osd.start, stab_osd.len * sizeof(obj_ver_id));
@@ -778,6 +800,7 @@ void osd_t::submit_primary_rollback_subops(osd_op_t *cur_op, const uint64_t* osd
{
clock_gettime(CLOCK_REALTIME, &subop->tv_begin);
subop->op_type = (uint64_t)cur_op;
subop->iov.push_back(op_data->unstable_writes + i, sizeof(obj_ver_id));
subop->bs_op = new blockstore_op_t((blockstore_op_t){
.opcode = BS_OP_ROLLBACK,
.callback = [subop, this](blockstore_op_t *bs_subop)

View File

@@ -258,9 +258,21 @@ resume_4:
return;
}
resume_5:
if (!(pg.state & PG_ACTIVE))
{
if (op_data->subops)
{
delete[] op_data->subops;
op_data->subops = NULL;
}
pg.ver_override.erase(op_data->oid);
deref_object_state(pg, &op_data->object_state, true);
pg_cancel_write_queue(pg, cur_op, op_data->oid, -EPIPE);
return;
}
if (op_data->errors > 0)
{
// Handle ENOSPC/EDOM/ERANGE/EIO. If some subops fail, but others succeed,
// Handle ENOSPC/EAGAIN/EDOM/ERANGE/EIO. If some subops fail, but others succeed,
// next writes to the same object will also fail because they'll try
// to overwrite the same version number which will result in EEXIST.
// To fix it, we should mark the object as degraded for replicas,
@@ -269,6 +281,11 @@ resume_5:
{
if (pg.scheme != POOL_SCHEME_REPLICATED)
{
if (op_data->subops)
{
delete[] op_data->subops;
op_data->subops = NULL;
}
submit_primary_rollback_subops(cur_op, pg.cur_set.data());
resume_11:
if (op_data->n_subops > 0)
@@ -277,21 +294,17 @@ resume_11:
return;
}
resume_12:
// Ignore ROLLBACK errors - submit_primary_subops will drop the connection if it fails
delete[] op_data->unstable_writes;
op_data->unstable_writes = NULL;
if (op_data->unstable_writes)
{
delete[] op_data->unstable_writes;
op_data->unstable_writes = NULL;
}
// Ignore ROLLBACK errors - submit_primary_subops will repeer the PG if it fails
}
else
{
pg.ver_override.erase(op_data->oid);
mark_partial_write(pg, cur_op);
if (op_data->subops)
{
delete[] op_data->subops;
op_data->subops = NULL;
}
pg_cancel_write_queue(pg, cur_op, op_data->oid, op_data->errcode);
return;
}
}
if (op_data->subops)
@@ -304,13 +317,6 @@ resume_12:
cur_op->reply.hdr.retval = op_data->errcode;
goto continue_others;
}
if (!(pg.state & PG_ACTIVE))
{
pg.ver_override.erase(op_data->oid);
deref_object_state(pg, &op_data->object_state, true);
pg_cancel_write_queue(pg, cur_op, op_data->oid, -EPIPE);
return;
}
if (pg.scheme != POOL_SCHEME_REPLICATED)
{
// Remove version override just after the write, but before stabilizing
@@ -555,6 +561,7 @@ resume_6:
return false;
}
resume_7:
// Ignore STABILIZE errors - submit_primary_subops will repeer the PG if it fails
// FIXME: Free those in the destructor?
delete op_data->unstable_write_osds;
delete[] op_data->unstable_writes;

View File

@@ -137,12 +137,13 @@ struct bs_test_t
}
}
void exec_op(blockstore_op_t *op)
void exec_op(blockstore_op_t *op, bool print = true)
{
bool done = false;
op->callback = [&](blockstore_op_t *op)
{
printf("op opcode=%ju completed retval=%jd\n", op->opcode, op->retval);
if (print)
printf("op opcode=%ju completed retval=%jd\n", op->opcode, op->retval);
done = true;
};
bs->enqueue_op(op);
@@ -976,6 +977,62 @@ static void test_list_limit()
free(op.buf);
}
static void test_write_no_space_eagain()
{
printf("\n-- test_write_no_space_eagain\n");
bs_test_t test;
test.default_cfg();
// 1 MB journal (data_offset 32 MB - journal_offset)
test.config["journal_offset"] = std::to_string(31*1024*1024);
test.init();
printf("blockstore initialized\n");
uint8_t *buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, 4096);
memset(buf, 0xAA, 4096);
// fill the journal with unstable writes
int i = 0, blocked_retval = 0;
auto do_write = [&]()
{
blockstore_op_t op;
op.opcode = BS_OP_WRITE;
op.oid = { .inode = 1, .stripe = (uint64_t)(i % 4) * 0x20000 };
op.version = 1 + i / 4;
op.offset = 0;
op.len = 4096;
op.buf = buf;
test.exec_op(&op, false);
if (op.retval != (int)op.len)
blocked_retval = op.retval;
};
for (i = 0; i < 100000 && !blocked_retval; i++)
do_write();
printf("write #%d refused with retval=%d\n", i, blocked_retval);
assert(blocked_retval == -EAGAIN);
// check that a stabilize operation and one more write can proceed
{
blockstore_op_t op;
op.opcode = BS_OP_STABLE;
op.len = 1;
op.buf = (uint8_t*)malloc_or_die(1 * sizeof(obj_ver_id));
((obj_ver_id*)op.buf)[0] = {
.oid = { .inode = 1, .stripe = 0 },
.version = 2,
};
test.exec_op(&op);
assert(op.retval == 0);
free(op.buf);
}
blocked_retval = 0;
do_write();
assert(!blocked_retval);
free(buf);
}
// FIXME Add a simple intent_write / big_intent test
int main(int narg, char *args[])
@@ -996,5 +1053,6 @@ int main(int narg, char *args[])
test_fsync_almost_batch_big();
test_fsync_batch_big();
test_list_limit();
test_write_no_space_eagain();
return 0;
}

View File

@@ -883,6 +883,75 @@ static void test_meta_tail_reload()
printf("blockstore re-initialized with an overflowing entry\n");
}
static void test_write_no_space_eagain()
{
printf("\n-- test_write_no_space_eagain\n");
bs_test_t test;
test.default_cfg();
// 1 MB journal (data_offset 32 MB - journal_offset), so it fills in a few hundred writes
test.config["journal_offset"] = std::to_string(31*1024*1024);
test.init();
printf("blockstore initialized\n");
uint8_t *buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, 4096);
memset(buf, 0xAA, 4096);
// fill the journal with unstable writes
int i = 0, blocked_retval = 0;
auto do_write = [&]()
{
blockstore_op_t op;
op.opcode = BS_OP_WRITE;
op.oid = { .inode = 1, .stripe = (uint64_t)(i % 4) * 0x20000 };
op.version = 1 + i / 4;
op.offset = 0;
op.len = 4096;
op.buf = buf;
test.exec_op(&op);
if (op.retval != (int)op.len)
blocked_retval = op.retval;
};
for (i = 0; i < 100000 && !blocked_retval; i++)
do_write();
printf("write #%d refused with retval=%d\n", i, blocked_retval);
assert(blocked_retval == -EAGAIN);
// check that a stabilize operation and one more write can proceed
// journal space_check is simplified so it requires slightly more space than actually needed
{
blockstore_op_t op;
op.opcode = BS_OP_STABLE;
op.len = 4;
op.buf = (uint8_t*)malloc_or_die(4 * sizeof(obj_ver_id));
((obj_ver_id*)op.buf)[0] = {
.oid = { .inode = 1, .stripe = 0 },
.version = 2,
};
((obj_ver_id*)op.buf)[1] = {
.oid = { .inode = 1, .stripe = 0x20000 },
.version = 2,
};
((obj_ver_id*)op.buf)[2] = {
.oid = { .inode = 1, .stripe = 0x40000 },
.version = 1,
};
((obj_ver_id*)op.buf)[3] = {
.oid = { .inode = 1, .stripe = 0x60000 },
.version = 1,
};
test.exec_op(&op);
assert(op.retval == 0);
free(op.buf);
}
blocked_retval = 0;
do_write();
assert(!blocked_retval);
free(buf);
}
// Check null dereference in read_bitmap over DELETE
static void test_read_bitmap_of_deleted_object()
{
@@ -1138,6 +1207,7 @@ int main(int narg, char *args[])
test_read_retry_on_ring_full_1M_csum4k_clean();
test_read_free_clean_loc_used();
test_meta_tail_reload();
test_write_no_space_eagain();
test_read_bitmap_of_deleted_object();
test_used_blocks_replay_stable_over_small_write();
test_used_blocks_replay_delete_over_unstable_big_write();