Store v1: Roll back over a stable deletion instead of returning EBUSY #220
@@ -42,6 +42,9 @@ int blockstore_impl_t::dequeue_rollback(blockstore_op_t *op)
|
||||
}
|
||||
else if (IS_STABLE(dirty_it->second.state))
|
||||
{
|
||||
// LIST shows a stable delete as no version, so stop at it like mark_rolled_back() does
|
||||
if (IS_DELETE(dirty_it->second.state))
|
||||
break;
|
||||
// Can't jump back over a stable version
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
@@ -2823,6 +2823,113 @@ static void test_rollback_over_stable_write()
|
||||
free(buf);
|
||||
}
|
||||
|
||||
// LIST hides a stable deletion, so peering sees only the unstable write above it and rolls the
|
||||
// object back to 0. That has to succeed, while a stable write above the target is still refused
|
||||
static void test_rollback_over_stable_delete()
|
||||
{
|
||||
printf("\n-- test_rollback_over_stable_delete\n");
|
||||
|
||||
bs_test_t test;
|
||||
test.default_cfg();
|
||||
test.init();
|
||||
|
||||
object_id oid = { .inode = 1, .stripe = 0 };
|
||||
uint32_t block_size = test.dsk().data_block_size;
|
||||
blockstore_op_t op;
|
||||
op.oid = oid;
|
||||
op.offset = 0;
|
||||
op.buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, block_size);
|
||||
memset(op.buf, 0xAA, block_size);
|
||||
|
||||
printf("write v1 and flush it\n");
|
||||
op.opcode = BS_OP_WRITE_STABLE;
|
||||
op.version = 1;
|
||||
op.len = block_size;
|
||||
test.exec_op(&op);
|
||||
assert(op.retval == (int)op.len);
|
||||
test.force_compaction();
|
||||
|
||||
printf("delete v2 - stable at once, not flushed\n");
|
||||
op.opcode = BS_OP_DELETE;
|
||||
op.version = 2;
|
||||
test.exec_op(&op);
|
||||
assert(op.retval == 0);
|
||||
assert(test.find_dirty_entry(oid, 2) && IS_STABLE(test.find_dirty_entry(oid, 2)->state));
|
||||
|
||||
printf("write v3, left unstable\n");
|
||||
op.opcode = BS_OP_WRITE;
|
||||
op.version = 3;
|
||||
op.len = block_size;
|
||||
test.exec_op(&op);
|
||||
assert(op.retval == (int)op.len);
|
||||
|
||||
blockstore_op_t ls = {};
|
||||
ls.opcode = BS_OP_LIST;
|
||||
test.exec_op(&ls);
|
||||
printf("list: %jd versions, %ju stable\n", ls.retval, ls.version);
|
||||
assert(ls.retval == 1 && ls.version == 0);
|
||||
assert((((obj_ver_id*)ls.buf)[0] == (obj_ver_id){ .oid = oid, .version = 3 }));
|
||||
free(ls.buf);
|
||||
|
||||
printf("roll back to v0\n");
|
||||
blockstore_op_t rb;
|
||||
rb.opcode = BS_OP_ROLLBACK;
|
||||
rb.len = 1;
|
||||
rb.buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, sizeof(obj_ver_id));
|
||||
*((obj_ver_id*)rb.buf) = (obj_ver_id){ .oid = oid, .version = 0 };
|
||||
test.exec_op(&rb);
|
||||
printf("rollback: %jd\n", rb.retval);
|
||||
assert(rb.retval == 0);
|
||||
|
||||
blockstore_op_t rd;
|
||||
rd.opcode = BS_OP_READ;
|
||||
rd.oid = oid;
|
||||
rd.offset = 0;
|
||||
rd.len = block_size;
|
||||
rd.buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, block_size);
|
||||
for (int pass = 0; pass < 2; pass++)
|
||||
{
|
||||
printf("%s: v3 is gone, the object is deleted\n", pass ? "after restart" : "before restart");
|
||||
assert(!test.find_dirty_entry(oid, 3));
|
||||
assert(test.find_dirty_entry(oid, 2) && IS_STABLE(test.find_dirty_entry(oid, 2)->state));
|
||||
ls = {};
|
||||
ls.opcode = BS_OP_LIST;
|
||||
test.exec_op(&ls);
|
||||
assert(ls.retval == 0);
|
||||
free(ls.buf);
|
||||
rd.version = UINT64_MAX;
|
||||
test.exec_op(&rd);
|
||||
assert(rd.retval == -ENOENT);
|
||||
if (!pass)
|
||||
{
|
||||
test.destroy_bs();
|
||||
test.init();
|
||||
}
|
||||
}
|
||||
|
||||
printf("stable write v4 over the deletion: rollback to v0 must fail with EBUSY\n");
|
||||
op.opcode = BS_OP_WRITE;
|
||||
op.version = 4;
|
||||
test.exec_op(&op);
|
||||
assert(op.retval == (int)op.len);
|
||||
rb.opcode = BS_OP_STABLE;
|
||||
*((obj_ver_id*)rb.buf) = (obj_ver_id){ .oid = oid, .version = 4 };
|
||||
test.exec_op(&rb);
|
||||
assert(rb.retval == 0);
|
||||
rb.opcode = BS_OP_ROLLBACK;
|
||||
*((obj_ver_id*)rb.buf) = (obj_ver_id){ .oid = oid, .version = 0 };
|
||||
test.exec_op(&rb);
|
||||
assert(rb.retval == -EBUSY);
|
||||
rd.version = UINT64_MAX;
|
||||
test.exec_op(&rd);
|
||||
assert(rd.retval == (int)rd.len && rd.version == 4);
|
||||
assert(memcheck(rd.buf, 0xAA, rd.len));
|
||||
|
||||
free(rd.buf);
|
||||
free(rb.buf);
|
||||
free(op.buf);
|
||||
}
|
||||
|
||||
// A deletion takes the preceding unsynced writes of the object over: it drops them from the
|
||||
// unsynced lists and erases them from the journal, because from that moment the only thing on
|
||||
// the disk accounting for them is the deletion itself. A sync submitted while the deletion is
|
||||
@@ -3394,6 +3501,7 @@ int main(int narg, char *args[])
|
||||
test_no_double_submit_of_journal_sector();
|
||||
test_recovered_state_is_made_durable();
|
||||
test_rollback_over_stable_write();
|
||||
test_rollback_over_stable_delete();
|
||||
test_sync_waits_for_delete_taking_over_unsynced();
|
||||
test_zero_write_over_rollback_to_zero();
|
||||
test_small_write_waits_for_its_own_big_write();
|
||||
|
||||
Reference in New Issue
Block a user