Store v1: Fix writes over a deletion hanging with immediate_commit=all #165

Merged
vitalif merged 1 commits from koolkhel/vitastor:blockstore-v1-wait-big-after-delete into master 2026-11-24 03:49:04 +03:00
2 changed files with 92 additions and 3 deletions

View File

@@ -842,15 +842,19 @@ resume_4:
}
if (imm && (dirty_it->second.state & BS_ST_TYPE_MASK) == BS_ST_BIG_WRITE)
{
// Unblock small writes. The ones after the next big write wait for that one
// Unblock small writes and the next big write (erase_dirty() makes big writes over a
// deletion wait too). The ones after the next big write wait for that one
dirty_it++;
while (dirty_it != dirty_db.end() && dirty_it->first.oid == op->oid &&
!IS_BIG_WRITE(dirty_it->second.state))
while (dirty_it != dirty_db.end() && dirty_it->first.oid == op->oid)
{
if ((dirty_it->second.state & BS_ST_WORKFLOW_MASK) == BS_ST_WAIT_BIG)
{
dirty_it->second.state = (dirty_it->second.state & ~BS_ST_WORKFLOW_MASK) | BS_ST_IN_FLIGHT;
}
if (IS_BIG_WRITE(dirty_it->second.state))
{
break;
}
dirty_it++;
}
}

View File

@@ -3204,6 +3204,90 @@ static void test_small_write_waits_for_its_own_big_write_imm()
free(buf1);
}
// Writes over a deletion wait until it is flushed, and then erase_dirty() puts every one of them
// after the first big write - big writes too - into WAIT_BIG. With immediate_commit=all only the
// ack of the previous big write lets them go, so it must release the next big write as well
static void test_writes_over_delete_released_imm()
{
printf("\n-- test_writes_over_delete_released_imm\n");
bs_test_t test;
test.default_cfg();
test.init();
printf("blockstore initialized\n");
object_id oid = { .inode = 1, .stripe = 0 };
const uint32_t bs_size = 128*1024;
uint8_t *buf1 = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, bs_size);
uint8_t *buf2 = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, bs_size);
uint8_t *buf3 = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, 4096);
memset(buf1, 0xAA, bs_size);
memset(buf2, 0xBB, bs_size);
memset(buf3, 0xCC, 4096);
printf("write v1 (big)\n");
blockstore_op_t wr;
wr.opcode = BS_OP_WRITE_STABLE;
wr.oid = oid;
wr.version = 1;
wr.offset = 0;
wr.len = bs_size;
wr.buf = buf1;
test.exec_op(&wr);
assert(wr.retval == (int)wr.len);
// All of them have to reach the queue before the event loop runs, so that the writes find
// the deletion still unflushed and wait for it
printf("delete v2, then write v1 (big), v2 (big) and v3 (small) over it at once\n");
blockstore_op_t del;
bool del_done = false;
del.opcode = BS_OP_DELETE;
del.oid = oid;
del.version = 2;
del.offset = 0;
del.len = 0;
del.buf = NULL;
del.callback = [&](blockstore_op_t *op) { del_done = true; };
test.bs->enqueue_op(&del);
blockstore_op_t op[3];
bool done[3] = {};
uint8_t *bufs[3] = { buf1, buf2, buf3 };
for (int i = 0; i < 3; i++)
{
op[i].opcode = BS_OP_WRITE_STABLE;
op[i].oid = oid;
op[i].version = i+1;
op[i].offset = 0;
op[i].len = i < 2 ? bs_size : 4096;
op[i].buf = bufs[i];
op[i].callback = [&done, i](blockstore_op_t *op) { done[i] = true; };
test.bs->enqueue_op(&op[i]);
}
for (int i = 0; i < 200 && !(del_done && done[0] && done[1] && done[2]); i++)
test.ringloop->loop();
printf("done: del=%d v1=%d v2=%d v3=%d\n", del_done, done[0], done[1], done[2]);
assert(del_done && del.retval == 0);
for (int i = 0; i < 3; i++)
assert(done[i] && op[i].retval == (int)op[i].len && op[i].version == (uint64_t)i+1);
printf("the object must read as v3 written over v2\n");
blockstore_op_t rd;
rd.opcode = BS_OP_READ;
rd.oid = oid;
rd.version = UINT64_MAX;
rd.offset = 0;
rd.len = bs_size;
rd.buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, rd.len);
test.exec_op(&rd);
assert(rd.retval == (int)rd.len);
assert(memcheck(rd.buf, 0xCC, 4096) && memcheck(rd.buf+4096, 0xBB, bs_size-4096));
free(rd.buf);
free(buf3);
free(buf2);
free(buf1);
}
// Tombstones are a heap-store (meta_format 3) feature, the v1 store must refuse them
static void test_tombstone_unsupported()
{
@@ -3261,6 +3345,7 @@ int main(int narg, char *args[])
test_zero_write_over_rollback_to_zero();
test_small_write_waits_for_its_own_big_write();
test_small_write_waits_for_its_own_big_write_imm();
test_writes_over_delete_released_imm();
test_tombstone_unsupported();
return 0;
}