Fail the fio job instead of exiting the process on a client error #202

Open
koolkhel wants to merge 2 commits from koolkhel/vitastor:fio-no-exit-on-error into master
3 changed files with 64 additions and 0 deletions

View File

@@ -148,6 +148,14 @@ void cluster_client_t::fatal_error(int errcode, const std::string & error)
}
aborted = true;
abort_error = error;
if (!pgs_loaded)
{
// PGs may never load now, so fail the queued ops instead of leaving them hanging
auto ops = std::move(offline_ops);
offline_ops.clear();
for (auto op: ops)
execute(op);
}
}
cluster_op_t::~cluster_op_t()
@@ -803,6 +811,13 @@ void cluster_client_t::execute(cluster_op_t *op)
cb(op);
return;
}
if (aborted)
{
op->retval = -ECANCELED;
auto cb = std::move(op->callback);
cb(op);
return;
}
if (!pgs_loaded)
{
offline_ops.push_back(op);

View File

@@ -293,6 +293,8 @@ static int sec_setup(struct thread_data *td)
opt_push(options, "log_level", std::to_string(o->cluster_log).c_str());
// allow writeback caching if -direct is not set
opt_push(options, "client_writeback_allowed", td->o.odirect ? "0" : "1");
// fio crashes if an engine calls exit(), so report client errors to fio instead
opt_push(options, "client_exit_on_error", "0");
bsd->cli = o->no_io_uring ? NULL : vitastor_c_create_uring_json((const char**)options.data(), options.size());
bsd->epoll_based = false;
if (!bsd->cli)
@@ -330,6 +332,13 @@ static int sec_setup(struct thread_data *td)
vitastor_c_epoll_handle_events(bsd->cli, 1000);
}
}
char *err = NULL;
if (vitastor_c_is_failed(bsd->cli, &err))
{
td_verror(td, EIO, err);
free(err);
return 1;
}
td->files[0]->real_file_size = vitastor_c_inode_get_size(bsd->watch);
if (!vitastor_c_inode_get_num(bsd->watch) ||
!td->files[0]->real_file_size)
@@ -469,6 +478,15 @@ static enum fio_q_status sec_queue(struct thread_data *td, struct io_u *io)
return FIO_Q_QUEUED;
}
// Operations in flight never complete on a failed client
static bool sec_client_failed(sec_data *bsd)
{
char *err = NULL;
int failed = vitastor_c_is_failed(bsd->cli, &err);
free(err);
return failed;
}
static int sec_getevents(struct thread_data *td, unsigned int min, unsigned int max, const struct timespec *t)
{
sec_data *bsd = (sec_data*)td->io_ops_data;
@@ -479,6 +497,8 @@ static int sec_getevents(struct thread_data *td, unsigned int min, unsigned int
vitastor_c_uring_handle_events(bsd->cli);
if (bsd->completed.size() >= min)
break;
if (sec_client_failed(bsd))
return -EIO;
vitastor_c_uring_wait_events(bsd->cli);
}
}
@@ -488,6 +508,8 @@ static int sec_getevents(struct thread_data *td, unsigned int min, unsigned int
{
if (bsd->completed.size() >= min)
break;
if (sec_client_failed(bsd))
return -EIO;
vitastor_c_epoll_handle_events(bsd->cli, 1000);
}
}

View File

@@ -21,6 +21,11 @@ public:
}
static void test_vault();
static void fatal_error(cluster_client_t *cli)
{
cli->fatal_error(EINVAL, "test error");
}
};
void configure_single_pg_pool(etcd_state_client_mock_t *mock, const char *immediate_commit = "none")
@@ -1153,6 +1158,27 @@ void test_sync_released_during_continue_ops()
printf("[ok] test_sync_released_during_continue_ops\n");
}
void test_abort_before_ready()
{
json11::Json config = json11::Json::object { { "client_exit_on_error", false } };
timerfd_manager_t *tfd = new timerfd_manager_t([](int fd, bool wr, std::function<void(int, int)> callback){});
etcd_mock_t etcd_store;
etcd_state_client_mock_t *mock = new etcd_state_client_mock_t(etcd_store);
mock->pause();
cluster_client_t *cli = new cluster_client_t(NULL, tfd, config, std::unique_ptr<etcd_state_client_t>(mock));
// PGs are not loaded yet, so the write waits; a fatal error must fail it instead of leaving it hanging
int *r1 = test_write(cli, 0, 4096, 0x55);
can_complete(r1);
cluster_client_test_t::fatal_error(cli);
assert(*r1 == -ECANCELED);
delete r1;
delete cli;
delete tfd;
printf("[ok] test_abort_before_ready\n");
}
void test_snapshot_over_nonexistent_pool()
{
json11::Json config;
@@ -1421,5 +1447,6 @@ int main(int narg, char *args[])
test_pg_config_disappears();
test_sync_released_during_continue_ops();
test_snapshot_over_nonexistent_pool();
test_abort_before_ready();
return 0;
}