Client: Check CAS writes for multiple stripes after slicing them #175

Merged
vitalif merged 1 commits from koolkhel/vitastor:cas-multi-stripe into master 2026-11-25 20:33:56 +03:00
2 changed files with 72 additions and 10 deletions

View File

@@ -925,14 +925,6 @@ void cluster_client_t::execute_cas(cluster_op_t *op, bool nosync)
cb(op);
return;
}
if ((op->opcode == OSD_OP_WRITE || op->opcode == OSD_OP_DELETE) && op->version && op->parts.size() > 1)
{
// Atomic writes to multiple stripes are unsupported
op->retval = -EINVAL;
auto cb = std::move(op->callback);
cb(op);
return;
}
if (!(op->flags & OP_IMMEDIATE_COMMIT) && !nosync &&
wb->has_dirty(op->inode, op->offset, op->len))
{
@@ -961,6 +953,14 @@ void cluster_client_t::execute_cas(cluster_op_t *op, bool nosync)
cb(op);
return;
}
if ((op->opcode == OSD_OP_WRITE || op->opcode == OSD_OP_DELETE) && op->version && op->parts.size() > 1)
{
// Atomic writes to multiple stripes are unsupported
op->retval = -EINVAL;
auto cb = std::move(op->callback);
cb(op);
return;
}
op->needs_reslice = false;
int res = try_send(op, 0, [this, op](osd_op_t *part)
{

View File

@@ -23,7 +23,7 @@ public:
static void test_vault();
};
void configure_single_pg_pool(etcd_state_client_mock_t *mock)
void configure_single_pg_pool(etcd_state_client_mock_t *mock, const char *immediate_commit = "none")
{
mock->set("/vitastor/config/pools", json11::Json::object {
{ "1", json11::Json::object {
@@ -33,7 +33,7 @@ void configure_single_pg_pool(etcd_state_client_mock_t *mock)
{ "pg_minsize", 1 },
{ "pg_count", 1 },
{ "failure_domain", "osd" },
{ "immediate_commit", "none" },
{ "immediate_commit", immediate_commit },
} }
});
mock->set("/vitastor/pg/config", json11::Json::object {
@@ -1343,6 +1343,67 @@ 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
void test_cas_cross_object()
{
json11::Json config;
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));
configure_single_pg_pool(mock, "all");
mock->resume();
pretend_connected(cli, 1);
cluster_client_test_t::continue_ops(cli);
const uint64_t obj_size = 128*1024; // default block_size
struct { uint64_t opcode, offset, len; int64_t expected; } cases[] = {
{ OSD_OP_WRITE, obj_size-0x1000, 0x2000, -EINVAL },
{ OSD_OP_DELETE, obj_size-0x1000, 0x2000, -EINVAL },
// ends exactly at the object boundary: one part, must be sent whole
{ OSD_OP_WRITE, obj_size-0x2000, 0x2000, 0x2000 },
};
int fails = 0;
for (auto & c: cases)
{
const char *name = c.opcode == OSD_OP_WRITE ? "write" : "delete";
int64_t r = -1000;
cluster_op_t *op = new cluster_op_t();
op->opcode = c.opcode;
op->inode = 0x1000000000001;
op->offset = c.offset;
op->len = c.len;
op->version = 2;
if (c.opcode == OSD_OP_WRITE)
{
op->iov.push_back(malloc_or_die(c.len), c.len);
memset(op->iov.buf[0].iov_base, 0x5a, c.len);
}
op->callback = [&r](cluster_op_t *op) { r = op->retval; };
cli->execute(op);
osd_client_t *cl = cli->msgr->osd_peers.at(1);
for (auto it = cl->sent_ops.begin(); r == -1000 && it != cl->sent_ops.end(); it = cl->sent_ops.begin())
{
osd_op_t *part = it->second;
printf("CAS %s %jx+%jx: sent %jx+%x to OSD 1\n", name, c.offset, c.len, part->req.rw.offset, part->req.rw.len);
pretend_op_completed(cli, part, 0);
}
printf("CAS %s %jx+%jx version 2: retval %jd, expected %jd\n", name, c.offset, c.len, r, c.expected);
if (r != c.expected || cl->sent_ops.size())
fails++;
if (c.opcode == OSD_OP_WRITE)
free(op->iov.buf[0].iov_base);
delete op;
}
assert(!fails);
delete cli;
delete tfd;
printf("[ok] CAS over two objects test\n");
}
int main(int narg, char *args[])
{
test1();
@@ -1355,6 +1416,7 @@ int main(int narg, char *args[])
test_msgr_decrypt_chain();
test_primary_change_flush_loss();
test_sync_fail_dirty_state_loss();
test_cas_cross_object();
cluster_client_test_t::test_vault();
test_pg_config_disappears();
test_sync_released_during_continue_ops();