Fix rm-data waiting forever when PGs go inactive during deletion #203

Open
koolkhel wants to merge 2 commits from koolkhel/vitastor:delete-wait-up-timer into master
3 changed files with 74 additions and 0 deletions

View File

@@ -1223,6 +1223,7 @@ resume_1:
// Set "wait_up" timer
clock_gettime(CLOCK_REALTIME, &op->wait_up_until);
op->wait_up_until.tv_sec += client_wait_up_timeout;
reset_retry_timer(client_wait_up_timeout*1000);
}
else
{
@@ -1239,6 +1240,9 @@ resume_1:
op->retval = -ETIMEDOUT;
break;
}
// reset_retry_timer() keeps a shorter timer, which may have fired for another operation
reset_retry_timer(std::max(1l, (op->wait_up_until.tv_sec - tv.tv_sec)*1000 +
(op->wait_up_until.tv_nsec - tv.tv_nsec + 999999)/1000000));

Это какое-то смешение механизмов
Идея wait_up_until в том чтобы операция сдохла через это время
Ну то есть да, reset_retry_timer наверное правильно дёрнуть, но не тут а просто когда ставим // Set wait_up timer

Это какое-то смешение механизмов Идея wait_up_until в том чтобы операция сдохла через это время Ну то есть да, reset_retry_timer наверное правильно дёрнуть, но не тут а просто когда ставим // Set wait_up timer
}
}
if (op->parts[i].flags & PART_RETRY)

View File

@@ -109,6 +109,12 @@ struct rm_inode_t
fprintf(stderr, "Failed to remove object %jx:%jx from PG %u (retval=%d)\n",
op->inode, op->offset, cur_list->pg_num, op->retval);
error_count++;
if (op->retval == -ETIMEDOUT)
{
// The PG did not come up in time: don't wait for it again for each of its objects
inactive_pgs.insert(cur_list->pg_num);
cur_list->obj_pos = cur_list->objects.end();
}
}
else
{

View File

@@ -1345,6 +1345,69 @@ void test_sync_fail_dirty_state_loss()
// CAS write/delete over two objects must fail with -EINVAL before anything is
// sent: the OSD checks the version of one object only
// The deadline of an operation with OSD_OP_WAIT_UP_TIMEOUT is in real time, so the test sleeps.
// An operation that first found its PG inactive had no timer to see the deadline expire,
// and waited for an unrelated event instead of failing after client_wait_up_timeout.
// The second delete starts waiting 0.5 s later, so it needs the timer again after it
// fires for the first one
void test_wait_up_timeout_inactive_pg()
{
timerfd_manager_t *tfd = new timerfd_manager_t(nullptr);
tfd->set_fd_handler = [](int, bool, std::function<void(int, int)>) {};
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, json11::Json::object {
{ "client_wait_up_timeout", 1 },
}, std::unique_ptr<etcd_state_client_t>(mock));
configure_single_pg_pool(mock, "all");
mock->set("/vitastor/pg/state/1/1", json11::Json::object {
{ "peers", json11::Json::array { 1 } },
{ "primary", 1 },
{ "state", json11::Json::array { "incomplete" } },
});
mock->resume();
int r[2] = { 1, 1 };
timespec start;
clock_gettime(CLOCK_REALTIME, &start);
for (int i = 0; i < 2; i++)
{
if (i > 0)
usleep(500000);
cluster_op_t *op = new cluster_op_t;
op->opcode = OSD_OP_DELETE;
op->inode = 0x1000000000001;
op->offset = i*0x20000;
op->len = 0;
op->flags = OSD_OP_WAIT_UP_TIMEOUT;
op->callback = [&r, i](cluster_op_t *op)
{
r[i] = op->retval;
delete op;
};
cli->execute(op);
}
// Only the retry timer moves the deletes on from here. It follows the real time
// that passed, so a stall of the test can't fail it
timespec prev = start;
for (int i = 0; i < 50 && (r[0] == 1 || r[1] == 1); i++)
{
usleep(100000);
timespec now;
clock_gettime(CLOCK_REALTIME, &now);
long ns = (now.tv_sec - prev.tv_sec)*1000000000l + now.tv_nsec - prev.tv_nsec;
tfd->tick((timespec){ .tv_sec = ns / 1000000000, .tv_nsec = ns % 1000000000 });
prev = now;
}
assert(r[0] == -ETIMEDOUT && r[1] == -ETIMEDOUT);
delete cli;
delete tfd;
printf("[ok] test_wait_up_timeout_inactive_pg\n");
}
void test_cas_cross_object()
{
json11::Json config;
@@ -1417,6 +1480,7 @@ int main(int narg, char *args[])
test_primary_change_flush_loss();
test_sync_fail_dirty_state_loss();
test_cas_cross_object();
test_wait_up_timeout_inactive_pg();
cluster_client_test_t::test_vault();
test_pg_config_disappears();
test_sync_released_during_continue_ops();