Compare commits

..

4 Commits

44 changed files with 627 additions and 1843 deletions

View File

@@ -75,6 +75,9 @@ Vitastor поддерживает QEMU-драйвер, протоколы UBLK,
- [NFS](docs/usage/nfs.ru.md) кластерная файловая система и псевдо-ФС прокси
- [Безопасность](docs/usage/security.ru.md)
- [Администрирование](docs/usage/admin.ru.md)
- Тесты
- [Хаос тест хранилища](docs/tests/blockstore-chaos.ru.md)
- [Хаос тест PG](docs/tests/pg-chaos.ru.md)
- Производительность
- [Понимание сути производительности](docs/performance/understanding.ru.md)
- [Теоретический максимум](docs/performance/theoretical.ru.md)

View File

@@ -34,8 +34,7 @@
#define BS_OP_DELETE 6
#define BS_OP_LIST 7
#define BS_OP_ROLLBACK 8
#define BS_OP_TOMBSTONE 9
#define BS_OP_MAX 9
#define BS_OP_MAX 8
#define BS_OP_PRIVATE_DATA_SIZE 256
@@ -91,37 +90,12 @@ Delete an object.
Input:
- oid = requested object
- version = requested version. Treated the same as with BS_OP_WRITE, except that a delete
is guarded: if the object's current head version is greater than `version`, the object
was recreated above this delete and it's skipped (retval = 0). version = 0 means an
unconditional delete
- version = requested version. Treated the same as with BS_OP_WRITE
Output:
- retval = 0 or negative error number (-EINVAL, -EAGAIN)
- version = the version actually written (delete is initially written as an object version)
## BS_OP_TOMBSTONE
Write a versioned deletion marker (tombstone): an object version that records the object
as DELETED as of `version`. Unlike BS_OP_DELETE, which is physically removed from the
index once all older versions are garbage, a tombstone persists and is reported by
BS_OP_LIST in a dedicated tombstone section, so that "deleted" can be told apart from
"lost" after peering. Like a delete, a tombstone is stable immediately, it erases all
older versions of the object (they become garbage), and reads over it return -ENOENT.
A versioned tombstone is never removed by compaction; it is only erased by a newer
write or a newer tombstone over the same object.
Input:
- oid = requested object
- version = tombstone version. 0 = assign head_version + 1 automatically.
A tombstone may only be written over a version strictly lower than itself; writing
over an absent object (already deleted) is a no-op success, writing version <= the
version already present returns -EEXIST for data heads.
Output:
- retval = 0, -EEXIST or negative error number (-EINVAL, -EAGAIN, -ENOSPC)
- version = the tombstone version actually written
## BS_OP_SYNC
Make sure all previously issued modifications reach physical media.
@@ -164,10 +138,6 @@ Output:
- version = stable obj_ver_id count
- buf = obj_ver_id array allocated by the blockstore. Stable versions come first.
You must free it yourself after usage with free().
- tombstone_count = number of trailing obj_ver_id entries which are versioned tombstones
(deleted markers). The reply layout is [stable][unstable][tombstones]: entries in
buf[retval-tombstone_count .. retval) are tombstones, and tombstones are always
reported even when list_stable_limit truncates the stable section.
Output includes all objects for which (((inode + stripe / <PG alignment>) % <PG count>) == <PG number>).
*/
@@ -199,8 +169,6 @@ struct __attribute__ ((visibility("default"))) blockstore_op_t
uint32_t list_stable_limit;
};
};
// BS_OP_LIST output: count of trailing tombstone entries (see BS_OP_LIST docs)
uint64_t tombstone_count = 0;
uint8_t *buf = NULL;
uint8_t *bitmap = NULL;
int64_t retval = 0;
@@ -270,7 +238,4 @@ public:
virtual uint64_t get_live_memory() = 0;
virtual uint64_t get_garbage_entries() = 0;
virtual uint64_t get_garbage_memory() = 0;
// Whether this store persists tombstones (BS_OP_TOMBSTONE), enabling two-phase deletes
virtual bool supports_tombstones() { return false; }
};

View File

@@ -2199,15 +2199,6 @@ int blockstore_heap_t::add_delete(heap_entry_t *obj, uint32_t *modified_block)
return add_simple(obj, 0, modified_block, BS_HEAP_DELETE|BS_HEAP_STABLE, false);
}
// Write a versioned tombstone: a stable deletion record at version `version`.
// It erases the chain below it (is_overwrite) but, unlike a versionless delete marker,
// it survives GC and compaction until it's overwritten by a new write or tombstone
int blockstore_heap_t::add_tombstone(heap_entry_t *obj, uint64_t version, uint32_t *modified_block)
{
assert(obj && version);
return add_simple(obj, version, modified_block, BS_HEAP_DELETE|BS_HEAP_STABLE, false);
}
// 2nd step: mark the block as being written (to prevent further in-memory updates to it),
// then mark it as written, then mark LSN as fsynced, then compact objects
@@ -2514,16 +2505,6 @@ heap_compact_t blockstore_heap_t::iterate_compaction(heap_entry_t *obj, uint64_t
{
// Object is deleted
assert(!has_small && stable); // unstable deletes are not supported
if (wr->version != 0)
{
// A versioned tombstone must survive compaction. Entries below it were
// already marked as garbage by the tombstone write itself, there's
// nothing to merge and nothing to sweep
res.do_delete = false;
res.compact_lsn = 0;
res.compact_version = 0;
return res;
}
if (!res.do_delete && res.compact_lsn)
{
// A COMMIT above the delete reset do_delete, but all writes between
@@ -2581,14 +2562,12 @@ void blockstore_heap_t::iterate_objects(std::function<void(heap_entry_t*, uint32
}
int blockstore_heap_t::list_objects(uint32_t pg_num, object_id min_oid, object_id max_oid,
obj_ver_id **result_list, size_t *stable_count, size_t *unstable_count, size_t *tombstone_count)
obj_ver_id **result_list, size_t *stable_count, size_t *unstable_count)
{
obj_ver_id *res = NULL;
size_t res_size = 0, res_alloc = 0;
obj_ver_id *unstable = NULL;
size_t unstable_size = 0, unstable_alloc = 0;
obj_ver_id *tombstone = NULL;
size_t tombstone_size = 0, tombstone_alloc = 0;
uint64_t pool_id = (min_oid.inode >> (64-POOL_ID_BITS));
if (pool_id == 0 || pool_id != (max_oid.inode >> (64-POOL_ID_BITS)))
{
@@ -2622,19 +2601,7 @@ int blockstore_heap_t::list_objects(uint32_t pg_num, object_id min_oid, object_i
{
if (stable)
{
if (wr->type() == BS_HEAP_DELETE && wr->version != 0)
{
// Versioned tombstone: a deleted stable version, reported
// in a separate trailing section
if (tombstone_size >= tombstone_alloc)
{
tombstone_alloc = (!tombstone_alloc ? 128 : tombstone_alloc*2);
tombstone = (obj_ver_id*)realloc_or_die(tombstone, sizeof(obj_ver_id) * tombstone_alloc);
}
tombstone[tombstone_size++] = (obj_ver_id){ .oid = oid, .version = wr->version };
}
else
stable_version = wr->version;
stable_version = wr->version;
return false;
}
if (unstable_size >= unstable_alloc)
@@ -2656,22 +2623,20 @@ int blockstore_heap_t::list_objects(uint32_t pg_num, object_id min_oid, object_i
}
});
}
if (unstable_size || tombstone_size)
if (unstable_size)
{
if (res_size+unstable_size+tombstone_size > res_alloc)
if (res_size+unstable_size > res_alloc)
{
res_alloc = res_size+unstable_size+tombstone_size;
res_alloc = res_size+unstable_size;
res = (obj_ver_id*)realloc_or_die(res, sizeof(obj_ver_id) * res_alloc);
}
memcpy(res + res_size, unstable, sizeof(obj_ver_id) * unstable_size);
memcpy(res + res_size+unstable_size, tombstone, sizeof(obj_ver_id) * tombstone_size);
free(unstable);
free(tombstone);
unstable = NULL;
}
*result_list = res;
*stable_count = res_size;
*unstable_count = unstable_size;
*tombstone_count = tombstone_size;
return 0;
}
@@ -2962,12 +2927,9 @@ void blockstore_heap_t::apply_inflight(heap_inflight_lsn_t & inflight)
assert(!li->prev);
assert((li->entry.entry_type & ~BS_HEAP_GARBAGE) == (BS_HEAP_DELETE|BS_HEAP_STABLE));
}
else if (!li->prev && li->next->entry.entry_type == (BS_HEAP_DELETE|BS_HEAP_STABLE) &&
li->next->entry.version == 0)
else if (!li->prev && li->next->entry.entry_type == (BS_HEAP_DELETE|BS_HEAP_STABLE))
{
// Free versionless BS_HEAP_DELETE markers when all previous entries are also
// freed. A versioned tombstone is never garbage-collected this way: it's the
// only record that the object was deleted and must survive as a chain head
// free BS_HEAP_DELETEs when all previous entries are also freed
mark_garbage(li->next->block_num, &li->next->entry, UINT32_MAX, UINT32_MAX);
}
unlink_list_item(li);

View File

@@ -334,9 +334,6 @@ public:
// forget an object
// return error code
int add_delete(heap_entry_t *obj, uint32_t *modified_block);
// write a versioned tombstone (stable deleted marker at version)
// return error code
int add_tombstone(heap_entry_t *obj, uint64_t version, uint32_t *modified_block);
// get the next object to compact
// guaranteed to return objects in min lsn order
// returns 0 if OK, ENOENT if nothing to compact
@@ -348,9 +345,8 @@ public:
// iterate all objects
void iterate_objects(std::function<void(heap_entry_t*, uint32_t block_num)> cb);
// retrieve object listing from a PG
// result layout is [stable][unstable][tombstones], tombstone_count is the tail length
int list_objects(uint32_t pg_num, object_id min_oid, object_id max_oid,
obj_ver_id **result_list, size_t *stable_count, size_t *unstable_count, size_t *tombstone_count);
obj_ver_id **result_list, size_t *stable_count, size_t *unstable_count);
// inflight write tracking
void start_block_write(uint32_t block_num);

View File

@@ -149,8 +149,7 @@ void blockstore_impl_t::loop()
{
wr_st = dequeue_read(op);
}
else if (op->opcode == BS_OP_WRITE || op->opcode == BS_OP_WRITE_STABLE ||
op->opcode == BS_OP_DELETE || op->opcode == BS_OP_TOMBSTONE)
else if (op->opcode == BS_OP_WRITE || op->opcode == BS_OP_WRITE_STABLE || op->opcode == BS_OP_DELETE)
{
wr_st = dequeue_write(op);
has_unfinished_writes = has_unfinished_writes || (wr_st != 2);
@@ -322,8 +321,7 @@ void blockstore_impl_t::enqueue_op(blockstore_op_t *op)
ringloop->set_immediate([op]() { std::function<void (blockstore_op_t*)>(op->callback)(op); });
return;
}
if ((op->opcode == BS_OP_WRITE || op->opcode == BS_OP_WRITE_STABLE ||
op->opcode == BS_OP_DELETE || op->opcode == BS_OP_TOMBSTONE) && !enqueue_write(op))
if ((op->opcode == BS_OP_WRITE || op->opcode == BS_OP_WRITE_STABLE || op->opcode == BS_OP_DELETE) && !enqueue_write(op))
{
ringloop->set_immediate([op]() { std::function<void (blockstore_op_t*)>(op->callback)(op); });
return;
@@ -369,8 +367,8 @@ void blockstore_impl_t::process_list(blockstore_op_t *op)
return;
}
obj_ver_id *result = NULL;
size_t stable_count = 0, unstable_count = 0, tombstone_count = 0;
int res = heap->list_objects(list_pg, op->min_oid, op->max_oid, &result, &stable_count, &unstable_count, &tombstone_count);
size_t stable_count = 0, unstable_count = 0;
int res = heap->list_objects(list_pg, op->min_oid, op->max_oid, &result, &stable_count, &unstable_count);
if (op->list_stable_limit)
{
// Ordered result is expected - used by scrub
@@ -378,16 +376,12 @@ void blockstore_impl_t::process_list(blockstore_op_t *op)
std::sort(result, result + stable_count);
if (stable_count > op->list_stable_limit)
{
// Layout is [stable][unstable][tombstones] - unstable+tombstones are moved together,
// tombstones are never truncated away
memmove(result + op->list_stable_limit, result + stable_count,
(unstable_count+tombstone_count)*sizeof(obj_ver_id));
memmove(result + op->list_stable_limit, result + stable_count, unstable_count*sizeof(obj_ver_id));
stable_count = op->list_stable_limit;
}
}
op->version = stable_count;
op->tombstone_count = tombstone_count;
op->retval = res == 0 ? stable_count+unstable_count+tombstone_count : -res;
op->retval = res == 0 ? stable_count+unstable_count : -res;
op->buf = (uint8_t*)result;
FINISH_OP(op);
}

View File

@@ -71,8 +71,6 @@ class blockstore_impl_t: public blockstore_i
public:
blockstore_disk_t dsk;
virtual bool supports_tombstones() { return true; }
/******* OPTIONS *******/
bool readonly = false;
// Enable if you want every operation to be executed with an "implicit fsync"

View File

@@ -98,9 +98,7 @@ undo_wait:
{
// May happen if there are entries but all of them are > requested version
heap->unlock_entry(op->oid);
// A versioned tombstone is the head of the chain: it's reported as the version
// even over -ENOENT, so that recreations are written above the recorded deletion
op->version = obj->type() == BS_HEAP_DELETE && obj->version != 0 ? obj->version : 0;
op->version = 0;
op->retval = -ENOENT;
FINISH_OP(op);
return 2;

View File

@@ -124,56 +124,20 @@ int blockstore_impl_t::dequeue_write(blockstore_op_t *op)
PRIV(op)->modified_block = UINT32_MAX;
PRIV(op)->write_type = 0;
heap_entry_t *obj = heap->read_entry(op->oid);
if (op->opcode == BS_OP_DELETE || op->opcode == BS_OP_TOMBSTONE)
if (op->opcode == BS_OP_DELETE)
{
// Delete, tombstone or tombstone sweep
// Delete
// An absent chain (deleted or fully rolled back) is already "not there"
if (!obj || heap->is_absent(obj))
{
if (op->opcode == BS_OP_TOMBSTONE)
{
// Already deleted - the absence is already recorded
op->retval = 0;
op->version = obj ? obj->version : 0;
FINISH_OP(op);
return 2;
}
// A DELETE over a versioned tombstone sweeps it (phase 2 of deletion).
// Over anything else absent it's a no-op
if (!obj || !(obj->type() == BS_HEAP_DELETE && obj->version != 0))
{
// Already deleted
op->retval = 0;
FINISH_OP(op);
return 2;
}
}
if (op->opcode == BS_OP_DELETE && op->version && obj->version > op->version)
{
// A guarded delete (phase 2 sweep of a recorded deletion): the object has a
// newer head than the deletion being swept - it was recreated above it.
// Leave it alone
// Already deleted
op->retval = 0;
FINISH_OP(op);
return 2;
}
uint64_t version = 0;
if (op->opcode == BS_OP_TOMBSTONE)
{
version = op->version ? op->version : obj->version + 1;
if (obj->version >= version)
{
// The version is occupied by data
op->retval = -EEXIST;
FINISH_OP(op);
return 2;
}
}
PRIV(op)->write_type = BS_HEAP_DELETE;
BS_SUBMIT_CHECK_SQES(1);
int res = op->opcode == BS_OP_TOMBSTONE
? heap->add_tombstone(obj, version, &PRIV(op)->modified_block)
: heap->add_delete(obj, &PRIV(op)->modified_block);
int res = heap->add_delete(obj, &PRIV(op)->modified_block);
assert(res != EAGAIN);
if (res == ENOSPC)
goto enospc;
@@ -181,23 +145,12 @@ int blockstore_impl_t::dequeue_write(blockstore_op_t *op)
prepare_meta_block_write(PRIV(op)->modified_block);
PRIV(op)->pending_ops++;
PRIV(op)->op_state = 5;
if (op->opcode == BS_OP_TOMBSTONE)
op->version = version;
write_iodepth++;
}
// FIXME: Allow to do initial writes as buffered, not redirected
// FIXME: Allow to do direct writes over holes
else if (!obj || heap->is_absent(obj) || op->offset == 0 && op->len == dsk.data_block_size)
{
// An absent chain may be rewritten as new - unless its head is a versioned
// tombstone: a recorded deletion must not be silently reset away
if (obj && heap->is_absent(obj) && obj->type() == BS_HEAP_DELETE && obj->version != 0 &&
op->version && op->version <= obj->version)
{
op->retval = -EEXIST;
FINISH_OP(op);
return 2;
}
// Big (redirect) write
PRIV(op)->write_type = dsk.disable_data_fsync || op->opcode != BS_OP_WRITE_STABLE ? BS_HEAP_BIG_WRITE : _REDIRECT_INTENT;
BS_SUBMIT_CHECK_SQES(1);

View File

@@ -406,13 +406,6 @@ void blockstore_impl_t::enqueue_op(blockstore_op_t *op)
ringloop->set_immediate([op]() { std::function<void (blockstore_op_t*)>(op->callback)(op); });
return;
}
if (op->opcode == BS_OP_TOMBSTONE)
{
// Tombstones are only supported by the heap blockstore (meta_format 3)
op->retval = -EOPNOTSUPP;
ringloop->set_immediate([op]() { std::function<void (blockstore_op_t*)>(op->callback)(op); });
return;
}
if ((op->opcode == BS_OP_WRITE || op->opcode == BS_OP_WRITE_STABLE || op->opcode == BS_OP_DELETE) && !enqueue_write(op))
{
ringloop->set_immediate([op]() { std::function<void (blockstore_op_t*)>(op->callback)(op); });
@@ -548,7 +541,6 @@ resume_1:
void blockstore_impl_t::process_list(blockstore_op_t *op)
{
op->tombstone_count = 0; // the v1 store never has tombstones
uint32_t list_pg = op->pg_number+1;
uint32_t pg_count = op->pg_count;
uint64_t pg_stripe_size = op->pg_alignment;

View File

@@ -394,16 +394,14 @@ void cluster_client_t::send_list(inode_list_osd_t *cur_list)
}
else
{
// Tombstones are not unstable versions, don't count them
uint64_t n_unstable = op->reply.hdr.retval > op->reply.sec_list.stable_count + op->reply.sec_list.tombstone_count
? op->reply.hdr.retval - op->reply.sec_list.stable_count - op->reply.sec_list.tombstone_count : 0;
if (n_unstable > 0)
if (op->reply.sec_list.stable_count < op->reply.hdr.retval)
{
// Unstable objects, if present, mean that someone still writes into the inode. Warn the user about it.
cur_list->pg->has_unstable = true;
fprintf(
stderr, "[PG %u/%u] Inode still has %ju unstable object versions out of total %ju - is it still open?\n",
cur_list->pg->lst->pool_id, cur_list->pg->pg_num, n_unstable, op->reply.hdr.retval
cur_list->pg->lst->pool_id, cur_list->pg->pg_num, op->reply.hdr.retval - op->reply.sec_list.stable_count,
op->reply.hdr.retval
);
}
if (log_level > 0)

View File

@@ -94,8 +94,15 @@ void osd_messenger_t::init()
{
init_iothreads();
}
clock_gettime(CLOCK_MONOTONIC, &keepalive_last);
keepalive_timer_id = tfd->set_timer(1000, true, [this](int)
{
timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
if (keepalive_catch_up(now))
{
return;
}
std::vector<uint64_t> clients_to_stop;
std::vector<osd_op_t*> ops_to_send;
auto cl_it = clients.begin();
@@ -175,6 +182,24 @@ void osd_messenger_t::init()
});
}
bool osd_messenger_t::keepalive_catch_up(const timespec & now)
{
int64_t since_ms = (int64_t)(now.tv_sec - keepalive_last.tv_sec)*1000 +
(now.tv_nsec - keepalive_last.tv_nsec)/1000000;
keepalive_last = now;
if (since_ms < 100)
{
// Catch-up call of the same wakeup
return true;
}
if (since_ms >= 2000 && log_level > 0)
{
// The timer period is 1 s, the rest is the stall
fprintf(stderr, "Event loop was blocked for about %jd ms, keepalive counted it as one tick\n",
(intmax_t)(since_ms - 1000));
}
return false;
}
osd_messenger_t::~osd_messenger_t()
{
if (keepalive_timer_id >= 0)

View File

@@ -219,6 +219,7 @@ protected:
friend struct osd_client_t;
int keepalive_timer_id = -1;
timespec keepalive_last = {};
uint32_t receive_buffer_size = 0;
int peer_connect_interval = 0;
@@ -314,6 +315,7 @@ public:
void connect_peer(osd_num_t osd_num, json11::Json peer_state);
void stop_client(uint64_t client_id, bool force_delete = false);
void destroy_client(osd_client_t *cl);
bool keepalive_catch_up(const timespec & now);
void outbox_push(osd_op_t *cur_op);
std::function<void(osd_op_t*)> exec_op;
std::function<void(osd_num_t)> repeer_pgs;

View File

@@ -24,5 +24,4 @@ const char* osd_op_names[] = {
"scrub",
"describe",
"sec_lock",
"sec_tombstone",
};

View File

@@ -31,9 +31,7 @@
#define OSD_OP_SCRUB 17
#define OSD_OP_DESCRIBE 18
#define OSD_OP_SEC_LOCK 19
// write a versioned tombstone (deleted-marker) on the secondary OSD
#define OSD_OP_SEC_TOMBSTONE 20
#define OSD_OP_MAX 20
#define OSD_OP_MAX 19
#define OSD_RW_MAX 64*1024*1024
#define OSD_PROTOCOL_VERSION 1
@@ -52,6 +50,7 @@
#define LOC_INCONSISTENT 4
#define OSD_LIST_PRIMARY 1
#define OSD_DEL_SUPPORT_LEFT_ON_DEAD 1
#define OSD_DEL_LEFT_ON_DEAD 2
@@ -212,6 +211,7 @@ struct __attribute__((__packed__)) osd_op_sec_list_t
// for OSD_LIST_PRIMARY, only a single-PG listing is allowed
uint64_t flags;
};
struct __attribute__((__packed__)) osd_reply_sec_list_t
{
osd_reply_header_t header;
@@ -220,10 +220,6 @@ struct __attribute__((__packed__)) osd_reply_sec_list_t
uint64_t stable_count;
// flags - OSD_LIST_PRIMARY or 0
uint64_t flags;
// count of trailing tombstone entries in the reply list (new in tombstone support).
// Reply layout is [stable][unstable][tombstones]: entries in
// [retval-tombstone_count .. retval) are versioned tombstones. Old OSDs report 0.
uint64_t tombstone_count;
};
// read, write or delete command for the primary OSD (must be within individual stripe)

View File

@@ -45,27 +45,25 @@ const char *pg_state_names[17] = {
"scrubbing",
};
const int object_state_bit_count = 9;
const int object_state_bit_count = 8;
const int object_state_bits[9] = {
const int object_state_bits[8] = {
OBJ_DEGRADED,
OBJ_INCOMPLETE,
OBJ_MISPLACED,
OBJ_CORRUPTED,
OBJ_INCONSISTENT,
OBJ_TOMB,
OBJ_NEEDS_STABLE,
OBJ_NEEDS_ROLLBACK,
0,
};
const char *object_state_names[9] = {
const char *object_state_names[8] = {
"degraded",
"incomplete",
"misplaced",
"corrupted",
"inconsistent",
"tomb",
"needs_stable",
"needs_rollback",
"clean",

View File

@@ -42,9 +42,6 @@
// OBJ_INCONSISTENT is when its replicas don't match, but it's unclear which one is correct
// OBJ_INCONSISTENT may be set with CORRUPTED, but never with other states
#define OBJ_INCONSISTENT 0x20
// OBJ_TOMB marks an object whose target version is a tombstone: it's absent, so it
// must not be "recovered" - its stale copies are cleaned by the phase 2 sweep
#define OBJ_TOMB 0x40
#define OBJ_NEEDS_STABLE 0x10000
#define OBJ_NEEDS_ROLLBACK 0x20000

View File

@@ -622,6 +622,11 @@ end_free:
close(fd);
}
static void vitastor_err_exit(void *opaque, int retval, const char *errstr)
{
exit(1);
}
static int vitastor_file_open(BlockDriverState *bs, QDict *options, int flags, Error **errp)
{
VitastorRPC task;
@@ -659,7 +664,9 @@ static int vitastor_file_open(BlockDriverState *bs, QDict *options, int flags, E
strarray_push_kv(&opt, "rdma_gid_index", qdict_get_try_str(options, "rdma-gid-index"));
strarray_push_kv(&opt, "rdma_mtu", qdict_get_try_str(options, "rdma-mtu"));
strarray_push_kv(&opt, "client_writeback_allowed", (flags & BDRV_O_NOCACHE) ? "0" : "1");
#if defined VITASTOR_C_API_VERSION && VITASTOR_C_API_VERSION >= 6
strarray_push_kv(&opt, "client_exit_on_error", "0");
#endif
strarray_push_kv(&opt, "__version_check_buffer", version_buffer);
client->proxy = vitastor_c_create_uring_json(opt.items, opt.len);
client->auto_loop = 0;
@@ -716,6 +723,7 @@ static int vitastor_file_open(BlockDriverState *bs, QDict *options, int flags, E
#endif
BDRV_POLL_WHILE(bs, !task.complete);
}
#if defined VITASTOR_C_API_VERSION && VITASTOR_C_API_VERSION >= 6
if ((ret = vitastor_c_is_failed(client->proxy, &errstr)))
{
error_setg(errp, errstr);
@@ -723,6 +731,8 @@ static int vitastor_file_open(BlockDriverState *bs, QDict *options, int flags, E
vitastor_close(bs);
return -ret;
}
vitastor_c_on_fatal_error(client->proxy, vitastor_err_exit, NULL);
#endif
client->image = image;
if (client->image)
{

View File

@@ -251,6 +251,14 @@ int vitastor_c_is_failed(vitastor_c *client, char **errstr)
return 0;
}
void vitastor_c_on_fatal_error(vitastor_c *client, VitastorErrorHandler cb, void *opaque)
{
client->cli->set_on_fatal_error_hook([=](int retval, const std::string & error)
{
cb(opaque, retval, error.c_str());
});
}
void vitastor_c_on_ready(vitastor_c *client, VitastorIOHandler cb, void *opaque)
{
client->cli->on_ready([=]()

View File

@@ -7,7 +7,7 @@
#define VITASTOR_QEMU_PROXY_H
// C API wrapper version
#define VITASTOR_C_API_VERSION 5
#define VITASTOR_C_API_VERSION 6
#ifndef POOL_ID_BITS
#define POOL_ID_BITS 16
@@ -33,6 +33,7 @@ typedef struct vitastor_c vitastor_c;
typedef void VitastorReadHandler(void *opaque, long retval, uint64_t version);
typedef void VitastorIOHandler(void *opaque, long retval);
typedef void VitastorErrorHandler(void *opaque, int retval, const char *errstr);
typedef void VitastorReadBitmapHandler(void *opaque, long retval, uint8_t *bitmap);
// QEMU
@@ -54,6 +55,7 @@ void* vitastor_c_get_internal_client(vitastor_c *client);
void vitastor_c_destroy(vitastor_c *client);
int vitastor_c_is_ready(vitastor_c *client);
int vitastor_c_is_failed(vitastor_c *client, char **errstr);
void vitastor_c_on_fatal_error(vitastor_c *client, VitastorErrorHandler cb, void *opaque);
void vitastor_c_on_ready(vitastor_c *client, VitastorIOHandler cb, void *opaque);
int vitastor_c_uring_register_eventfd(vitastor_c *client);
void vitastor_c_uring_wait_ready(vitastor_c *client);

View File

@@ -156,25 +156,21 @@ struct cli_raw_ls_t
}
else
{
uint64_t n_tomb = op->reply.sec_list.tombstone_count;
uint64_t total = op->reply.hdr.retval;
for (uint64_t i = 0; i < total; i++)
for (uint64_t i = 0; i < op->reply.hdr.retval; i++)
{
auto & ov = ((obj_ver_id*)op->buf)[i];
bool is_tomb = n_tomb > 0 && i >= total - n_tomb;
bool is_stable = i < op->reply.sec_list.stable_count;
if (parent->json_output)
{
printf("%s{\"osd\":%ju,\"inode\":\"0x%jx\",\"stripe\":\"0x%jx\",\"version\":%ju,\"stable\":%s,\"tombstone\":%s}",
printf("%s{\"osd\":%ju,\"inode\":\"0x%jx\",\"stripe\":\"0x%jx\",\"version\":%ju,\"stable\":%s}",
first ? "" : ",\n", osd_num, ov.oid.inode, ov.oid.stripe, ov.version,
is_stable ? "true" : "false", is_tomb ? "true" : "false");
i < op->reply.sec_list.stable_count ? "true" : "false");
first = false;
}
else
{
printf("OSD %ju - %jx:%jx v%ju%s\n",
osd_num, ov.oid.inode, ov.oid.stripe, ov.version,
is_tomb ? " tombstone" : (is_stable ? " stable" : ""));
i < op->reply.sec_list.stable_count ? " stable" : "");
}
}
}

View File

@@ -167,7 +167,6 @@ osd_t::~osd_t()
pending_owned_ops.clear();
for (auto & pp: pgs)
{
cleanup_pg_sweep(pp.second);
if (pp.second.flush_batch)
{
delete pp.second.flush_batch;
@@ -795,8 +794,7 @@ void osd_t::print_slow()
}
bufprintf(": %s id=%ju", osd_op_names[op->req.hdr.opcode], op->req.hdr.id);
if (op->req.hdr.opcode == OSD_OP_SEC_READ || op->req.hdr.opcode == OSD_OP_SEC_WRITE ||
op->req.hdr.opcode == OSD_OP_SEC_WRITE_STABLE || op->req.hdr.opcode == OSD_OP_SEC_DELETE ||
op->req.hdr.opcode == OSD_OP_SEC_TOMBSTONE)
op->req.hdr.opcode == OSD_OP_SEC_WRITE_STABLE || op->req.hdr.opcode == OSD_OP_SEC_DELETE)
{
bufprintf(" %jx:%jx v", op->req.sec_rw.oid.inode, op->req.sec_rw.oid.stripe);
if (op->req.sec_rw.version == UINT64_MAX)
@@ -807,7 +805,7 @@ void osd_t::print_slow()
{
bufprintf("%ju", op->req.sec_rw.version);
}
if (op->req.hdr.opcode != OSD_OP_SEC_DELETE && op->req.hdr.opcode != OSD_OP_SEC_TOMBSTONE)
if (op->req.hdr.opcode != OSD_OP_SEC_DELETE)
{
bufprintf(" offset=%x len=%x", op->req.sec_rw.offset, op->req.sec_rw.len);
}
@@ -841,7 +839,7 @@ void osd_t::print_slow()
}
if (op->req.hdr.opcode == OSD_OP_SEC_READ || op->req.hdr.opcode == OSD_OP_SEC_WRITE ||
op->req.hdr.opcode == OSD_OP_SEC_WRITE_STABLE || op->req.hdr.opcode == OSD_OP_SEC_DELETE ||
op->req.hdr.opcode == OSD_OP_SEC_TOMBSTONE ||
op->req.hdr.opcode == OSD_OP_SEC_SYNC || op->req.hdr.opcode == OSD_OP_SEC_LIST ||
op->req.hdr.opcode == OSD_OP_SEC_STABILIZE || op->req.hdr.opcode == OSD_OP_SEC_ROLLBACK ||
op->req.hdr.opcode == OSD_OP_SEC_READ_BMP)
{

View File

@@ -402,12 +402,8 @@ class osd_t
void submit_primary_subop(osd_op_t *cur_op, osd_op_t *subop,
osd_rmw_stripe_t *si, bool wr, inode_t inode, uint64_t op_version);
bool submit_to_osd(osd_op_t *subop, osd_num_t osd_num);
void submit_primary_del_subops(osd_op_t *cur_op, osd_num_t *cur_set, uint64_t set_size, pg_osd_set_t & loc_set, bool as_tombstone = false);
void submit_primary_del_batch(osd_op_t *cur_op, obj_ver_osd_t *chunks_to_delete, int chunks_to_delete_count, bool as_tombstone = false);
void enqueue_pg_sweep(pg_t & pg, object_id oid, uint64_t version, const pg_osd_set_t & locs, bool ready);
void try_drain_pg_sweep(pg_t & pg);
void pg_sweep_subop_done(struct pg_sweep_ctx_t *ctx, int chunk_idx, int64_t retval);
void cleanup_pg_sweep(pg_t & pg);
void submit_primary_del_subops(osd_op_t *cur_op, osd_num_t *cur_set, uint64_t set_size, pg_osd_set_t & loc_set);
void submit_primary_del_batch(osd_op_t *cur_op, obj_ver_osd_t *chunks_to_delete, int chunks_to_delete_count);
void submit_primary_sync_subops(osd_op_t *cur_op);
void submit_primary_stab_subops(osd_op_t *cur_op);
void submit_primary_rollback_subops(osd_op_t *cur_op, const osd_num_t* osd_set);

View File

@@ -1241,10 +1241,6 @@ void osd_t::report_pg_states()
{
if (pg_it->second.state == PG_OFFLINE)
{
// An in-flight sweep batch outlives the PG: its last
// chunk's callback frees it (a failed pgs.find is
// handled there), so only detach it from this pg
pg_it->second.sweep_ctx = NULL;
// Forget offline PGs after reporting their state
// (if the state wasn't changed again)
if (pg_it->second.scheme == POOL_SCHEME_EC)

View File

@@ -263,12 +263,6 @@ bool osd_t::pick_next_recovery(osd_recovery_op_t &op)
// Restart scanning from the next object
for (auto obj_it = src.upper_bound(recovery_last_oid); obj_it != src.end(); obj_it++)
{
if (obj_it->second->state & OBJ_TOMB)
{
// A recorded deletion is absence: there's nothing to recover,
// the phase 2 sweep cleans the stale copies instead
continue;
}
if (recovery_ops.find(obj_it->first) == recovery_ops.end())
{
op.degraded = recovery_last_degraded;
@@ -385,7 +379,7 @@ void osd_t::tune_recovery()
{
static int accounted_ops[] = {
OSD_OP_SEC_READ, OSD_OP_SEC_WRITE, OSD_OP_SEC_WRITE_STABLE,
OSD_OP_SEC_STABILIZE, OSD_OP_SEC_SYNC, OSD_OP_SEC_DELETE, OSD_OP_SEC_TOMBSTONE
OSD_OP_SEC_STABILIZE, OSD_OP_SEC_SYNC, OSD_OP_SEC_DELETE
};
uint64_t total_client_usec = 0, total_recovery_usec = 0, recovery_count = 0;
for (int i = 0; i < sizeof(accounted_ops)/sizeof(accounted_ops[0]); i++)

View File

@@ -354,9 +354,7 @@ bool osd_t::continue_pg_peering(pg_t & pg)
}
if (pg.peering_state->lists_done)
{
pg.sweep_epoch++;
pg.calc_object_states(log_level);
try_drain_pg_sweep(pg);
report_pg_state(pg);
schedule_scrub(pg);
inconsistent_objects += pg.inconsistent_objects.size();
@@ -558,14 +556,13 @@ void osd_t::submit_list_subop(osd_num_t role_osd, pg_peering_state_t *ps)
}
add_bs_subop_stats(op);
printf(
"[PG %u/%u] Got object list from OSD %ju (local): %jd object versions (%ju of them stable, %ju tombstones)\n",
ps->pool_id, ps->pg_num, role_osd, bs_op->retval, bs_op->version, bs_op->tombstone_count
"[PG %u/%u] Got object list from OSD %ju (local): %jd object versions (%ju of them stable)\n",
ps->pool_id, ps->pg_num, role_osd, bs_op->retval, bs_op->version
);
ps->list_results[role_osd] = {
.buf = (obj_ver_id*)op->bs_op->buf,
.total_count = (uint64_t)op->bs_op->retval,
.stable_count = op->bs_op->version,
.tombstone_count = op->bs_op->tombstone_count,
};
ps->list_ops.erase(role_osd);
delete op->bs_op;
@@ -615,15 +612,13 @@ void osd_t::submit_list_subop(osd_num_t role_osd, pg_peering_state_t *ps)
return;
}
printf(
"[PG %u/%u] Got object list from OSD %ju: %jd object versions (%ju of them stable, %ju tombstones)\n",
ps->pool_id, ps->pg_num, role_osd, op->reply.hdr.retval, op->reply.sec_list.stable_count,
op->reply.sec_list.tombstone_count
"[PG %u/%u] Got object list from OSD %ju: %jd object versions (%ju of them stable)\n",
ps->pool_id, ps->pg_num, role_osd, op->reply.hdr.retval, op->reply.sec_list.stable_count
);
ps->list_results[role_osd] = {
.buf = (obj_ver_id*)op->buf,
.total_count = (uint64_t)op->reply.hdr.retval,
.stable_count = op->reply.sec_list.stable_count,
.tombstone_count = op->reply.sec_list.tombstone_count,
};
// set op->buf to NULL so it doesn't get freed
op->buf = NULL;

View File

@@ -10,7 +10,6 @@ struct obj_ver_role
uint64_t version;
osd_num_t osd_num;
bool is_stable;
bool is_tomb;
};
inline bool operator < (const obj_ver_role & a, const obj_ver_role & b)
@@ -48,7 +47,6 @@ struct pg_obj_state_check_t
uint64_t target_ver = 0;
uint64_t n_copies = 0, has_roles = 0, n_roles = 0, n_stable = 0, n_mismatched = 0;
uint64_t n_unstable = 0, n_invalid = 0;
bool target_tomb = false;
pg_osd_set_t osd_set;
int log_level;
@@ -187,20 +185,6 @@ void pg_obj_state_check_t::finish_object()
ver_end = list_pos;
}
obj_end = list_pos;
// A tombstone means "absent at this version". Delete wins over data at the same
// version: a stable data copy at the tombstone version is a stale racing write.
target_tomb = false;
if (target_ver)
{
for (int i = ver_start; i < ver_end; i++)
{
if (list[i].is_tomb)
{
target_tomb = true;
break;
}
}
}
// Remember the decision
uint64_t state = 0;
if (n_invalid > 0)
@@ -219,22 +203,15 @@ void pg_obj_state_check_t::finish_object()
for (int i = obj_start; i < obj_end; i++)
{
auto & pcs = pieces[(obj_piece_id_t){ .oid = list[i].oid, .osd_num = list[i].osd_num }];
if (!list[i].is_tomb)
if (!pcs.max_ver)
{
// Tombstones are not data versions of a piece
if (!pcs.max_ver)
{
pcs.max_ver = list[i].version;
}
if (list[i].is_stable && !pcs.stable_ver)
{
pcs.stable_ver = list[i].version;
}
pcs.max_ver = list[i].version;
}
// Data conflicting with the tombstone at the target version is above the target
bool above_target = list[i].version > target_ver ||
(target_tomb && list[i].version == target_ver && !list[i].is_tomb);
if (!above_target && !pcs.max_target)
if (list[i].is_stable && !pcs.stable_ver)
{
pcs.stable_ver = list[i].version;
}
if (list[i].version <= target_ver && !pcs.max_target)
{
pcs.max_target = list[i].version;
}
@@ -245,18 +222,16 @@ void pg_obj_state_check_t::finish_object()
if (pcs.stable_ver < pcs.max_ver)
{
auto & act = pg->flush_actions[pp.first];
bool above_target = pcs.max_ver > target_ver ||
(target_tomb && pcs.max_ver == target_ver);
// osd_set doesn't include rollback/stable states, so don't include them in the state code either
if (above_target)
if (pcs.max_ver > target_ver)
{
act.rollback = true;
act.rollback_to = pcs.max_target;
}
if (pcs.stable_ver < (above_target ? pcs.max_target : pcs.max_ver))
if (pcs.stable_ver < (pcs.max_ver > target_ver ? pcs.max_target : pcs.max_ver))
{
act.make_stable = true;
act.stable_to = above_target ? pcs.max_target : pcs.max_ver;
act.stable_to = pcs.max_ver > target_ver ? pcs.max_target : pcs.max_ver;
}
}
}
@@ -265,7 +240,7 @@ void pg_obj_state_check_t::finish_object()
{
return;
}
if (!target_tomb && !replicated && n_roles < pg->pg_data_size)
if (!replicated && n_roles < pg->pg_data_size)
{
if (log_level > 1)
{
@@ -274,7 +249,7 @@ void pg_obj_state_check_t::finish_object()
state = OBJ_INCOMPLETE;
pg->state = pg->state | PG_HAS_INCOMPLETE;
}
else if (!target_tomb && (replicated ? n_copies : n_roles) < pg->pg_cursize)
else if ((replicated ? n_copies : n_roles) < pg->pg_cursize)
{
if (log_level > 1)
{
@@ -298,84 +273,27 @@ void pg_obj_state_check_t::finish_object()
for (int i = obj_start; i < obj_end; i++)
{
printf("v%ju present on: osd %ju, role %jd%s\n", list[i].version, list[i].osd_num,
(list[i].oid.stripe & STRIPE_MASK),
list[i].is_tomb ? " (tombstone)" : (list[i].is_stable ? " (stable)" : ""));
(list[i].oid.stripe & STRIPE_MASK), list[i].is_stable ? " (stable)" : "");
}
}
pg->total_count++;
auto sweep_it = pg->sweep_queue.find(oid);
// A member whose chain the sweep already erased but which missed the rewrite
// above the deletion looks "clean empty" in LIST - it isn't, it's outdated
bool swept_absent = !target_tomb &&
sweep_it != pg->sweep_queue.end() && sweep_it->second.version < target_ver;
if (state != 0 || ver_end < obj_end || target_tomb || swept_absent)
if (state != 0 || ver_end < obj_end)
{
osd_set.clear();
for (int i = ver_start; i < ver_end; i++)
{
if (target_tomb && !list[i].is_tomb)
{
// Data copies at the tombstone version don't count as target copies
continue;
}
osd_set.push_back((pg_obj_loc_t){
.role = (list[i].oid.stripe & STRIPE_MASK),
.osd_num = list[i].osd_num,
.loc_bad = 0,
});
}
if (target_tomb)
{
// Mark stale data copies at the tombstone version as outdated
for (int i = ver_start; i < ver_end; i++)
{
if (!list[i].is_tomb)
{
osd_set.push_back((pg_obj_loc_t){
.role = (list[i].oid.stripe & STRIPE_MASK),
.osd_num = list[i].osd_num,
.loc_bad = LOC_OUTDATED,
});
if (!(state & (OBJ_INCOMPLETE | OBJ_DEGRADED)))
{
state |= OBJ_MISPLACED;
pg->state = pg->state | PG_HAS_MISPLACED;
}
}
}
// Data above the adopted tombstone is a racing write the member never
// saw rolled back: the delete is owed here too. Degraded until the
// pending rollback (flush_actions) erases it
for (int i = obj_start; i < ver_start; i++)
{
if (list[i].is_tomb)
{
continue;
}
osd_set.push_back((pg_obj_loc_t){
.role = (list[i].oid.stripe & STRIPE_MASK),
.osd_num = list[i].osd_num,
.loc_bad = LOC_OUTDATED,
});
if (!(state & (OBJ_INCOMPLETE | OBJ_DEGRADED)))
{
state |= OBJ_DEGRADED;
pg->state = pg->state | PG_HAS_DEGRADED;
}
}
}
}
if (ver_end < obj_end)
{
// Check for outdated versions not present in the current target OSD set
for (int i = ver_end; i < obj_end; i++)
{
if (target_tomb && list[i].is_tomb)
{
// An older recorded deletion under the target tombstone is ordinary
// history: the sweep erases it together with everything else below
continue;
}
int j;
for (j = 0; j < osd_set.size(); j++)
{
@@ -389,8 +307,7 @@ void pg_obj_state_check_t::finish_object()
break;
}
}
if (j >= osd_set.size() && (target_tomb ||
pg->cur_set[list[i].oid.stripe & STRIPE_MASK] != list[i].osd_num))
if (j >= osd_set.size() && pg->cur_set[list[i].oid.stripe & STRIPE_MASK] != list[i].osd_num)
{
osd_set.push_back((pg_obj_loc_t){
.role = (list[i].oid.stripe & STRIPE_MASK),
@@ -399,73 +316,12 @@ void pg_obj_state_check_t::finish_object()
});
if (!(state & (OBJ_INCOMPLETE | OBJ_DEGRADED)))
{
if (target_tomb && list[i].is_stable)
{
// A stable copy below the adopted tombstone is an incomplete
// deletion: the object is absent, this member just never
// applied the delete. Degraded, not misplaced - the delete
// is owed here, the sweep will collect it
state |= OBJ_DEGRADED;
pg->state = pg->state | PG_HAS_DEGRADED;
}
else
{
state |= OBJ_MISPLACED;
pg->state = pg->state | PG_HAS_MISPLACED;
}
state |= OBJ_MISPLACED;
pg->state = pg->state | PG_HAS_MISPLACED;
}
}
}
}
if (swept_absent)
{
// Mark swept members that missed the rewrite as outdated copies
for (auto & loc: sweep_it->second.locs)
{
int j;
for (j = 0; j < osd_set.size(); j++)
{
if (osd_set[j].osd_num == loc.osd_num && osd_set[j].role == loc.role)
{
break;
}
}
if (j >= osd_set.size())
{
osd_set.push_back((pg_obj_loc_t){
.role = loc.role, .osd_num = loc.osd_num, .loc_bad = LOC_OUTDATED,
});
if (!(state & (OBJ_INCOMPLETE | OBJ_DEGRADED)))
{
state |= OBJ_DEGRADED;
pg->state = pg->state | PG_HAS_DEGRADED;
}
}
}
}
if (target_tomb)
{
// A deletion recorded on disk: queue the phase 2 sweep. The tombstone is durable
// by definition (it came from a LIST), so the sweep only waits for every OSD to return
if (sweep_it == pg->sweep_queue.end() || sweep_it->second.version < target_ver)
{
pg->sweep_queue[oid] = (pg_sweep_entry_t){
.version = target_ver, .ready = true, .head = true, .locs = osd_set,
};
}
else if (sweep_it->second.version == target_ver)
{
sweep_it->second.head = true;
}
}
else if (sweep_it != pg->sweep_queue.end() && sweep_it->second.version < target_ver)
{
// The head moved above the recorded deletion (a rewrite): the sweep still owes
// its members, but the object exists now - reads must never answer zeros for it
sweep_it->second.head = false;
}
if (target_tomb && state != 0)
state |= OBJ_TOMB;
if (target_ver < max_ver)
{
pg->ver_override[oid] = target_ver;
@@ -571,7 +427,6 @@ void pg_t::calc_object_states(int log_level)
for (auto it: ps->list_results)
{
auto nstab = it.second.stable_count;
auto ntomb = it.second.tombstone_count;
auto n = it.second.total_count;
auto osd_num = it.first;
uint64_t start = st.list.size();
@@ -587,8 +442,7 @@ void pg_t::calc_object_states(int log_level)
.oid = ov->oid,
.version = ov->version,
.osd_num = osd_num,
.is_stable = i < nstab || i >= n - ntomb,
.is_tomb = ntomb > 0 && i >= n - ntomb,
.is_stable = i < nstab,
};
}
free(it.second.buf);

View File

@@ -39,8 +39,6 @@ struct pg_list_result_t
obj_ver_id *buf = NULL;
uint64_t total_count;
uint64_t stable_count;
// trailing tombstone entries (reply layout is [stable][unstable][tombstones])
uint64_t tombstone_count = 0;
};
struct osd_op_t;
@@ -85,18 +83,6 @@ struct pg_flush_batch_t
int flush_objects = 0;
};
// One recorded deletion (tombstone) awaiting phase 2 sweep: the sweep may only run
// when all PG OSDs are alive and the tombstone is durable
struct pg_sweep_entry_t
{
uint64_t version = 0; // The tombstone version to sweep; data at or below it dies too
bool ready = false; // Durable (from LIST / after fsync / fsync not required)
// True while the adopted chain head IS this tombstone. A rewrite above it
// flips this off: then reads must fan out again, not answer zeros
bool head = false;
pg_osd_set_t locs; // Known copy locations, outdated and misplaced included
};
struct pg_t
{
int state = 0;
@@ -139,15 +125,6 @@ struct pg_t
std::map<obj_piece_id_t, flush_action_t> flush_actions;
std::vector<obj_ver_osd_t> copies_to_delete_after_sync;
btree::btree_map<object_id, uint64_t> ver_override;
// Phase 2 of two-phase deletion: base oid => recorded deletion to sweep
std::map<object_id, pg_sweep_entry_t> sweep_queue;
bool sweep_running = false;
// Bumped on every completed peering; a sweep batch may only erase its entries
// when no peering has re-scanned the cluster in between
uint64_t sweep_epoch = 0;
// The in-flight sweep batch, if any. Its completion callbacks are its only
// normal owner; ~osd_t frees it when those can never arrive
struct pg_sweep_ctx_t *sweep_ctx = NULL;
pg_peering_state_t *peering_state = NULL;
pg_flush_batch_t *flush_batch = NULL;

View File

@@ -291,7 +291,6 @@ void osd_t::continue_primary_read(osd_op_t *cur_op)
else if (op_data->st == 3)
goto resume_3;
resume_0:
cur_op->reply.rw.bitmap_len = 0;
{
// Reset read ranges. On a retry we can come here with read ranges left on
@@ -350,36 +349,9 @@ resume_0:
{
op_data->flags |= OP_DATA_ENOENT_OK;
}
// A versioned tombstone awaiting its phase 2 sweep means the adopted chain
// head is a recorded deletion: the object is absent by definition. Serve
// zeros at the tombstone version instead of fanning out reads that can
// only return ENOENT (or -EIO on a degraded object with outdated copies)
uint64_t tomb_hole_ver = 0;
if (pg)
{
auto sweep_it = pg->sweep_queue.find(op_data->oid);
if (sweep_it != pg->sweep_queue.end() && sweep_it->second.head)
tomb_hole_ver = sweep_it->second.version;
}
if (!pg || tomb_hole_ver || pg->state == PG_ACTIVE || pg->scheme == POOL_SCHEME_REPLICATED)
if (!pg || pg->state == PG_ACTIVE || pg->scheme == POOL_SCHEME_REPLICATED)
{
// Fast happy-path
if (tomb_hole_ver)
{
assert(!cur_op->buf);
cur_op->buf = alloc_read_buffer(op_data->stripes, pg ? pg->pg_data_size : 1, 0);
for (int role = 0; role < (pg ? pg->pg_data_size : 1); role++)
{
if (op_data->stripes[role].read_end != 0 &&
op_data->stripes[role].read_end != UINT32_MAX)
memset(op_data->stripes[role].read_buf, 0,
op_data->stripes[role].read_end -
op_data->stripes[role].read_start);
memset(op_data->stripes[role].bmp_buf, 0, clean_entry_bitmap_size);
}
op_data->fact_ver = tomb_hole_ver;
goto resume_2;
}
if (pg && pg->scheme == POOL_SCHEME_REPLICATED &&
op_data->object_state && (op_data->object_state->state & OBJ_INCOMPLETE))
{
@@ -405,14 +377,12 @@ resume_0:
}
}
resume_1:
if (op_data->n_subops > 0)
{
op_data->st = 1;
return;
}
resume_2:
if (op_data->errors > 0)
{
if (pg && (op_data->errcode == -EIO || op_data->errcode == -EDOM))
@@ -811,32 +781,7 @@ bool osd_t::remove_object_from_state(object_id & oid, pg_osd_set_state_t **objec
return false;
}
bool changed = false;
bool erased = false;
// The state entry is shared by every object with the same location set and
// its bits are fixed when the entry is created, while each object gets
// registered into the map chosen by its own state bits at add time. A
// registration can therefore sit in another map than the one the entry's
// bits point at: erase it from the map that really holds it, otherwise
// the stale map entry outlives the state_dict node and the next
// get_object_osd_set dereferences freed memory
auto unlink_map = [&](btree::btree_map<object_id, pg_osd_set_state_t*> & m,
uint64_t osd_t::*osd_counter, uint64_t pg_bit, bool misplaced_cond)
{
auto it = m.find(oid);
if (it == m.end() || it->second != *object_state)
{
return;
}
m.erase(it);
(this->*osd_counter)--;
(*object_state)->object_count--;
erased = true;
if (!m.size() && !(misplaced_cond && pg.copies_to_delete_after_sync.size()))
{
pg.state = pg.state & ~pg_bit;
changed = true;
}
};
(*object_state)->object_count--;
if ((*object_state)->state & OBJ_CORRUPTED)
{
this->corrupted_objects--;
@@ -847,20 +792,51 @@ bool osd_t::remove_object_from_state(object_id & oid, pg_osd_set_state_t **objec
changed = true;
}
}
unlink_map(pg.inconsistent_objects, &osd_t::inconsistent_objects, PG_HAS_INCONSISTENT, false);
unlink_map(pg.incomplete_objects, &osd_t::incomplete_objects, PG_HAS_INCOMPLETE, false);
unlink_map(pg.degraded_objects, &osd_t::degraded_objects, PG_HAS_DEGRADED, false);
unlink_map(pg.misplaced_objects, &osd_t::misplaced_objects, PG_HAS_MISPLACED, true);
if (!((*object_state)->state & (OBJ_INCONSISTENT | OBJ_INCOMPLETE | OBJ_DEGRADED | OBJ_MISPLACED)))
if ((*object_state)->state & OBJ_INCONSISTENT)
{
this->inconsistent_objects--;
pg.inconsistent_objects.erase(oid);
if (!pg.inconsistent_objects.size())
{
pg.state = pg.state & ~PG_HAS_INCONSISTENT;
changed = true;
}
}
else if ((*object_state)->state & OBJ_INCOMPLETE)
{
// Successful write means that object is not incomplete anymore
this->incomplete_objects--;
pg.incomplete_objects.erase(oid);
if (!pg.incomplete_objects.size())
{
pg.state = pg.state & ~PG_HAS_INCOMPLETE;
changed = true;
}
}
else if ((*object_state)->state & OBJ_DEGRADED)
{
this->degraded_objects--;
pg.degraded_objects.erase(oid);
if (!pg.degraded_objects.size())
{
pg.state = pg.state & ~PG_HAS_DEGRADED;
changed = true;
}
}
else if ((*object_state)->state & OBJ_MISPLACED)
{
this->misplaced_objects--;
pg.misplaced_objects.erase(oid);
if (!pg.misplaced_objects.size() && !pg.copies_to_delete_after_sync.size())
{
pg.state = pg.state & ~PG_HAS_MISPLACED;
changed = true;
}
}
else
{
throw std::runtime_error("BUG: Invalid object state: "+std::to_string((*object_state)->state));
}
if (!erased)
{
// No registration referencing the entry was found: keep the decrement
// the accounting always performed
(*object_state)->object_count--;
}
if (changed && immediate_commit != IMMEDIATE_ALL)
{
// Trigger double automatic sync after changing PG state when we're running with fsyncs.
@@ -973,9 +949,6 @@ void osd_t::continue_primary_del(osd_op_t *cur_op)
}
osd_primary_op_data_t *op_data = cur_op->op_data;
auto & pg = *op_data->pg;
// v2 stores persist tombstones: every primary delete becomes two-phase (tombstone
// first, sweep later when all peers are alive). v1 keeps the legacy single-phase delete
bool tombstone = bs->supports_tombstones();
if (op_data->st == 1) goto resume_1;
else if (op_data->st == 2) goto resume_2;
else if (op_data->st == 3) goto resume_3;
@@ -1041,9 +1014,9 @@ resume_3:
{
return;
}
// Submit tombstones (phase 1)
// Submit deletes
op_data->fact_ver++;
submit_primary_del_subops(cur_op, NULL, 0, op_data->object_state ? op_data->object_state->osd_set : pg.cur_loc_set, tombstone);
submit_primary_del_subops(cur_op, NULL, 0, op_data->object_state ? op_data->object_state->osd_set : pg.cur_loc_set);
resume_4:
if (op_data->n_subops > 0)
{
@@ -1067,16 +1040,6 @@ resume_5:
}
// Remove version override
pg.ver_override.erase(op_data->oid);
// Remember the copy locations before the object state is dropped: the phase 2
// sweep has to reach outdated and misplaced copies too
pg_osd_set_t sweep_locs;
if (op_data->object_state)
{
for (auto & loc: op_data->object_state->osd_set)
{
sweep_locs.push_back(loc);
}
}
// Mark PG and OSDs as dirty
for (auto & chunk: (op_data->object_state ? op_data->object_state->osd_set : pg.cur_loc_set))
{
@@ -1108,12 +1071,6 @@ resume_5:
}
}
pg.total_count--;
if (tombstone)
{
// Phase 2: sweep the tombstone when every OSD is alive and the tombstone is
// durable (fsynced - or already fsynced on write with immediate_commit=all)
enqueue_pg_sweep(pg, op_data->oid, op_data->fact_ver, sweep_locs, immediate_commit == IMMEDIATE_ALL);
}
}
cur_op->reply.hdr.retval = 0;
// indicate possibly unfinished (left_on_dead) deletions

View File

@@ -27,8 +27,6 @@ struct osd_primary_op_data_t
object_id oid = {};
uint64_t target_ver = 0;
uint64_t orig_ver = 0, fact_ver = 0;
// fact_ver was answered by a tombstone head ('absent at version fact_ver')
uint8_t fact_tomb = 0;
int n_subops = 0, done = 0, errors = 0, drops = 0, errcode = 0;
uint64_t flags = 0;
int stripe_count = 0;

View File

@@ -216,10 +216,7 @@ void osd_t::continue_primary_list(osd_op_t *cur_op)
std::set<object_id> oids;
obj_ver_id *rbuf = (obj_ver_id*)bs_op->buf;
uint64_t total_count = bs_op->retval;
// Tombstones mean "absent here" - don't count them as existing objects.
// Objects that still have stale copies on other OSDs will be re-added via
// the state dict below.
for (uint64_t i = 0; i < total_count - bs_op->tombstone_count; i++)
for (uint64_t i = 0; i < total_count; i++)
{
oids.insert(rbuf[i].oid);
}

View File

@@ -127,7 +127,6 @@ void osd_t::submit_primary_subops(int submit_type, uint64_t op_version, const os
op_data->fact_ver = 0;
op_data->done = op_data->errors = op_data->drops = op_data->errcode = 0;
op_data->n_subops = n_subops;
if (!n_subops)
{
op_data->errcode = -EIO;
@@ -200,9 +199,6 @@ void osd_t::submit_primary_subop(osd_op_t *cur_op, osd_op_t *subop,
clock_gettime(CLOCK_REALTIME, &subop->tv_begin);
subop->op_type = (uint64_t)cur_op; // also dirty
subop->osd_num = this->osd_num;
// The blockstore overwrites op->version with the result; keep the request
// version on the subop so completion can tell them apart
subop->req.sec_rw.version = op_version;
subop->bs_op = new blockstore_op_t((blockstore_op_t){
.opcode = (uint64_t)(wr ? (cur_op->op_data->pg->scheme == POOL_SCHEME_REPLICATED ? BS_OP_WRITE_STABLE : BS_OP_WRITE) : BS_OP_READ),
.callback = [subop, this](blockstore_op_t *bs_subop)
@@ -317,7 +313,6 @@ static uint64_t bs_op_to_osd_op[] = {
OSD_OP_SEC_DELETE, // BS_OP_DELETE = 6
OSD_OP_SEC_LIST, // BS_OP_LIST = 7
OSD_OP_SEC_ROLLBACK, // BS_OP_ROLLBACK = 8
OSD_OP_SEC_TOMBSTONE, // BS_OP_TOMBSTONE = 9
};
void osd_t::handle_primary_bs_subop(osd_op_t *subop)
@@ -331,6 +326,7 @@ void osd_t::handle_primary_bs_subop(osd_op_t *subop)
if (bs_op->opcode == BS_OP_READ || bs_op->opcode == BS_OP_WRITE || bs_op->opcode == BS_OP_WRITE_STABLE)
{
subop->req.sec_rw.oid = bs_op->oid;
subop->req.sec_rw.version = bs_op->version;
subop->req.sec_rw.len = bs_op->len;
subop->reply.sec_rw.version = bs_op->version;
}
@@ -392,44 +388,13 @@ void osd_t::handle_primary_subop(osd_op_t *subop, osd_op_t *cur_op)
// 2) ENOENT is not an error for clean EC object reads if all replicas return ENOENT
// (i.e. ENOENT is not an error, but fact_ver mismatch is)
// 3) ENOENT is not an error for scrub reads
// 4) ENOENT carrying a version is a tombstone head: the member recorded
// the deletion, absence is its answer - zeros and the tombstone version
// are the truth, never an error. A write over it is a recreation.
// A bare ENOENT is legitimate as well when peering adopted a tombstone
// head: the chain may already have been swept or never have reached
// this member
// 5) A read of version 0 asks for the state before any write: empty is
// always the right answer there, absence of the chain is not an error
// 6) A bare ENOENT over a clean object is tolerated only when nothing else
// can change the answer: a half-applied delete would otherwise be
// answered with unverified zeros. Reads that tolerate absence (full-cover
// reads, scrub) tolerate it while no other op is queued on the object,
// and the write holding the queue slot tolerates it always - its own
// RMW reads can't interleave with a delete, and a recreate-write over a
// swept tombstone legitimately sees zero old state
// 7) In all other cases ENOENT is an error!
// Absence that carries its own proof: a versioned answer is a tombstone
// head, a v0 request can only be answered by emptiness
bool legit_absent = subop->reply.sec_rw.version != 0 ||
subop->req.sec_rw.version == 0;
bool del_running = false, owns_queue = false;
if (op_data->pg)
{
auto wq_it = op_data->pg->write_queue.find(op_data->oid);
if (wq_it != op_data->pg->write_queue.end())
{
owns_queue = wq_it->second == cur_op;
del_running = !owns_queue;
}
}
if (legit_absent || owns_queue || ((op_data->flags & OP_DATA_ENOENT_OK) && !del_running))
// 4) In all other cases ENOENT is an error!
if (op_data->flags & OP_DATA_ENOENT_OK)
{
retval = expected;
if (expected > 0)
memset(((osd_rmw_stripe_t*)subop->rmw_buf)->read_buf, 0, expected);
// The reported version is kept: over a versioned tombstone it's the
// tombstone version, so recreations are written above the recorded deletion
subop->reply.sec_rw.version = 0;
}
else
retval = -EIO;
@@ -458,15 +423,8 @@ void osd_t::handle_primary_subop(osd_op_t *subop, osd_op_t *cur_op)
#endif
if (!(op_data->flags & OP_DATA_SKIP_VER_CHECK))
{
// A -ENOENT carrying a version means 'absent at this version': it's a
// tombstone head, not a data version. It never conflicts with data
// replies - the head of the history is simply the highest version
// seen, and recreations are written above the recorded deletion
bool is_tomb = opcode == OSD_OP_SEC_READ && subop->rmw_buf &&
((osd_rmw_stripe_t*)subop->rmw_buf)->not_exists;
if (op_data->fact_ver != version && op_data->done > 0 &&
(version != 0 && op_data->fact_ver != 0 || !(op_data->flags & OP_DATA_ENOENT_OK)) &&
!is_tomb && !op_data->fact_tomb)
(version != 0 && op_data->fact_ver != 0 || !(op_data->flags & OP_DATA_ENOENT_OK)))
{
fprintf(
stderr, "different fact_versions returned from %s %jx:%jx subops for a %s op: %ju vs %ju\n",
@@ -475,13 +433,8 @@ void osd_t::handle_primary_subop(osd_op_t *subop, osd_op_t *cur_op)
);
retval = -ERANGE;
}
else if (!(op_data->flags & OP_DATA_ENOENT_OK) || version > op_data->fact_ver)
{
// ENOENT_OK tolerates absent (version 0) chains mixed with tombstones:
// the head of the history is the highest version seen
else
op_data->fact_ver = version;
op_data->fact_tomb = is_tomb ? 1 : 0;
}
}
}
if (retval != expected)
@@ -499,11 +452,10 @@ void osd_t::handle_primary_subop(osd_op_t *subop, osd_op_t *cur_op)
else
printf("locally: retval = %d (expected %d)\n", retval, expected);
}
else if (opcode == OSD_OP_SEC_DELETE || opcode == OSD_OP_SEC_TOMBSTONE)
else if (opcode == OSD_OP_SEC_DELETE)
{
printf(
"%s subop to %jx:%jx v%ju failed on osd %jd: retval = %d (expected %d)\n",
opcode == OSD_OP_SEC_TOMBSTONE ? "tombstone" : "delete",
"delete subop to %jx:%jx v%ju failed on osd %jd: retval = %d (expected %d)\n",
subop->req.sec_del.oid.inode, subop->req.sec_del.oid.stripe, subop->req.sec_del.version,
peer_osd, retval, expected
);
@@ -563,7 +515,6 @@ void osd_t::handle_primary_subop(osd_op_t *subop, osd_op_t *cur_op)
subop->rmw_buf = NULL;
op_data->done++;
}
if ((op_data->errors + op_data->done) >= op_data->n_subops)
{
if (!op_data->errors || !op_data->done || opcode != OSD_OP_SEC_WRITE && opcode != OSD_OP_SEC_WRITE_STABLE)
@@ -611,7 +562,7 @@ bool contains_osd(osd_num_t *osd_set, uint64_t size, osd_num_t osd_num)
return false;
}
void osd_t::submit_primary_del_subops(osd_op_t *cur_op, osd_num_t *cur_set, uint64_t set_size, pg_osd_set_t & loc_set, bool as_tombstone)
void osd_t::submit_primary_del_subops(osd_op_t *cur_op, osd_num_t *cur_set, uint64_t set_size, pg_osd_set_t & loc_set)
{
osd_primary_op_data_t *op_data = cur_op->op_data;
bool rep = op_data->pg->scheme == POOL_SCHEME_REPLICATED;
@@ -674,10 +625,10 @@ void osd_t::submit_primary_del_subops(osd_op_t *cur_op, osd_num_t *cur_set, uint
}
}
}
submit_primary_del_batch(cur_op, extra_chunks, chunks_to_del, as_tombstone);
submit_primary_del_batch(cur_op, extra_chunks, chunks_to_del);
}
void osd_t::submit_primary_del_batch(osd_op_t *cur_op, obj_ver_osd_t *chunks_to_delete, int chunks_to_delete_count, bool as_tombstone)
void osd_t::submit_primary_del_batch(osd_op_t *cur_op, obj_ver_osd_t *chunks_to_delete, int chunks_to_delete_count)
{
osd_primary_op_data_t *op_data = cur_op->op_data;
op_data->n_subops = chunks_to_delete_count;
@@ -696,7 +647,7 @@ void osd_t::submit_primary_del_batch(osd_op_t *cur_op, obj_ver_osd_t *chunks_to_
clock_gettime(CLOCK_REALTIME, &subops[i].tv_begin);
subops[i].op_type = (uint64_t)cur_op;
subops[i].bs_op = new blockstore_op_t({
.opcode = (uint64_t)(as_tombstone ? BS_OP_TOMBSTONE : BS_OP_DELETE),
.opcode = BS_OP_DELETE,
.callback = [subop = &subops[i], this](blockstore_op_t *bs_subop)
{
handle_primary_bs_subop(subop);
@@ -714,7 +665,7 @@ void osd_t::submit_primary_del_batch(osd_op_t *cur_op, obj_ver_osd_t *chunks_to_
subops[i].req = (osd_any_op_t){ .sec_del = {
.header = {
.magic = SECONDARY_OSD_OP_MAGIC,
.opcode = (uint64_t)(as_tombstone ? OSD_OP_SEC_TOMBSTONE : OSD_OP_SEC_DELETE),
.opcode = OSD_OP_SEC_DELETE,
},
.oid = chunk.oid,
.version = chunk.version,
@@ -973,297 +924,3 @@ void osd_t::pg_continue_queued_op(osd_op_t *next_op)
else
continue_primary_del(next_op);
}
// Phase 2 of two-phase deletion: sweep a recorded deletion (the tombstone and any data
// below it) off every live OSD. It may only run when all PG peers are alive and the
// tombstone is durable (fsynced, LIST-observed, or fsync not required at all) - until then
// the entry waits in pg.sweep_queue. Guarded by version on the blockstore side: a newer
// head means the object was recreated above the deletion and the sweep skips it
struct pg_sweep_ctx_t
{
pool_pg_num_t pg_key;
std::vector<object_id> oids;
std::vector<uint64_t> versions;
std::vector<uint8_t> ok;
std::vector<int> chunk_entry;
uint64_t epoch = 0; // pg.sweep_epoch at dispatch; a peering in between vetoes the erase
// Local delete ops still running; unfinished ones are freed by ~osd_t
std::vector<blockstore_op_t*> bs_ops;
// Chunks are still being submitted: a synchronously failed dispatch may
// not finalize the batch in the middle of the dispatch loop
bool dispatching = false;
int inflight = 0;
};
void osd_t::pg_sweep_subop_done(pg_sweep_ctx_t *ctx, int chunk_idx, int64_t retval)
{
if (chunk_idx >= 0)
{
int entry = ctx->chunk_entry[chunk_idx];
if (retval < 0)
{
// A peer died or restarted mid-sweep. Keep the entry for the next drain:
// peering or the next SYNC will retry it
ctx->ok[entry] = 0;
}
if (--ctx->inflight > 0)
{
return;
}
}
if (ctx->dispatching)
{
// The drain loop finalizes when the last dispatch returns
return;
}
auto pg_it = pgs.find(ctx->pg_key);
if (pg_it == pgs.end())
{
delete ctx;
return;
}
pg_t & pg = pg_it->second;
for (unsigned idx = 0; idx < ctx->oids.size(); idx++)
{
if (!ctx->ok[idx])
{
continue;
}
auto qit = pg.sweep_queue.find(ctx->oids[idx]);
if (qit == pg.sweep_queue.end() || qit->second.version != ctx->versions[idx] ||
ctx->epoch != pg.sweep_epoch)
{
// A peering completed while this batch was in flight: its LIST results may
// have revealed new holders. Keep the entry for the re-drain it triggered
continue;
}
pg.sweep_queue.erase(qit);
// The recorded deletion is applied everywhere now: the object is
// clean-absent. Drop every state registration it may carry: recomputed
// states re-register the object under a new signature and can leave
// stale entries in the other per-state maps, so it has to be erased
// from each of them. A recreation would have erased the queue entry
// above, so these registrations can only belong to the deleted
// incarnation
bool state_changed = false;
auto unlink_state = [&](auto & m, uint64_t osd_t::*counter, uint64_t pg_bit)
{
auto sit = m.find(ctx->oids[idx]);
if (sit == m.end())
return;
// Only the registration is dropped here. The shared state_dict
// entry aggregates every object with this location set and the
// recomputation flow can leave its count divergent from the live
// registrations, so releasing it from here could free an entry
// the other maps still reference; peering rebuilds these maps
// and reclaims such entries later
pg_osd_set_state_t *st = sit->second;
st->object_count--;
(this->*counter)--;
m.erase(sit);
if (!m.size())
pg.state = pg.state & ~pg_bit;
state_changed = true;
};
unlink_state(pg.inconsistent_objects, &osd_t::inconsistent_objects, PG_HAS_INCONSISTENT);
unlink_state(pg.incomplete_objects, &osd_t::incomplete_objects, PG_HAS_INCOMPLETE);
unlink_state(pg.degraded_objects, &osd_t::degraded_objects, PG_HAS_DEGRADED);
unlink_state(pg.misplaced_objects, &osd_t::misplaced_objects, PG_HAS_MISPLACED);
if (state_changed)
report_pg_state(pg);
}
pg.sweep_running = false;
pg.sweep_ctx = NULL;
delete ctx;
try_drain_pg_sweep(pg);
}
// The PG is going away with the sweep still in flight: free the batch. Only
// ~osd_t may call this - the callbacks of the unfinished chunks must already
// be dead (the messenger and the blockstore cancel theirs during teardown)
void osd_t::cleanup_pg_sweep(pg_t & pg)
{
if (!pg.sweep_ctx)
return;
for (blockstore_op_t *op : pg.sweep_ctx->bs_ops)
if (op)
delete op;
delete pg.sweep_ctx;
pg.sweep_ctx = NULL;
pg.sweep_running = false;
}
void osd_t::enqueue_pg_sweep(pg_t & pg, object_id oid, uint64_t version, const pg_osd_set_t & locs, bool ready)
{
auto it = pg.sweep_queue.find(oid);
if (it == pg.sweep_queue.end())
{
pg.sweep_queue[oid] = (pg_sweep_entry_t){ .version = version, .ready = ready, .locs = locs };
}
else if (it->second.version < version)
{
it->second = (pg_sweep_entry_t){ .version = version, .ready = ready, .locs = locs };
}
else if (ready)
{
it->second.ready = true;
}
try_drain_pg_sweep(pg);
}
void osd_t::try_drain_pg_sweep(pg_t & pg)
{
if (pg.sweep_running || in_destruction || !(pg.state & PG_ACTIVE) || pg.dead_peers.size() > 0)
{
return;
}
bool rep = pg.scheme == POOL_SCHEME_REPLICATED;
pg_sweep_ctx_t *ctx = new pg_sweep_ctx_t();
ctx->pg_key = { .pool_id = pg.pool_id, .pg_num = pg.pg_num };
std::vector<obj_ver_osd_t> chunks;
for (auto & q: pg.sweep_queue)
{
const object_id & oid = q.first;
const pg_sweep_entry_t & ent = q.second;
if (!ent.ready)
{
continue;
}
int idx = ctx->oids.size();
ctx->oids.push_back(oid);
ctx->versions.push_back(ent.version);
size_t entry_start = chunks.size();
// Every role of the current set (a delete of an absent copy is a no-op) and
// every recorded copy location, outdated and misplaced copies included
for (uint64_t role = 0; role < pg.cur_set.size(); role++)
{
if (!pg.cur_set[role])
{
continue;
}
chunks.push_back((obj_ver_osd_t){
.osd_num = pg.cur_set[role],
.oid = { .inode = oid.inode, .stripe = oid.stripe | (rep ? 0 : role) },
.version = ent.version,
});
}
// Every live peer must also confirm: a holder we forgot about (history
// cleanup) or never saw can resurrect its chain otherwise. A guarded
// no-op delete over an absent chain costs one round trip
for (osd_num_t peer_osd: pg.cur_peers)
{
for (uint64_t role = 0; role < (rep ? 1 : pg.pg_data_size); role++)
{
object_id role_oid = { .inode = oid.inode, .stripe = oid.stripe | role };
bool dup = false;
for (size_t j = entry_start; j < chunks.size(); j++)
{
if (chunks[j].osd_num == peer_osd && chunks[j].oid == role_oid)
{
dup = true;
break;
}
}
if (dup == false)
{
chunks.push_back((obj_ver_osd_t){
.osd_num = peer_osd, .oid = role_oid, .version = ent.version,
});
}
}
}
for (auto & loc: ent.locs)
{
if (!loc.osd_num)
{
continue;
}
object_id role_oid = { .inode = oid.inode, .stripe = oid.stripe | (rep ? 0 : (uint64_t)loc.role) };
bool dup = false;
for (size_t j = entry_start; j < chunks.size(); j++)
{
if (chunks[j].osd_num == loc.osd_num && chunks[j].oid == role_oid)
{
dup = true;
break;
}
}
if (!dup)
{
chunks.push_back((obj_ver_osd_t){
.osd_num = loc.osd_num, .oid = role_oid, .version = ent.version,
});
}
}
for (size_t j = entry_start; j < chunks.size(); j++)
{
ctx->chunk_entry.push_back(idx);
}
}
if (!ctx->oids.size() || !chunks.size())
{
delete ctx;
return;
}
pg.sweep_running = true;
pg.sweep_ctx = ctx;
ctx->epoch = pg.sweep_epoch;
ctx->dispatching = true;
ctx->inflight = chunks.size();
ctx->ok.assign(ctx->oids.size(), 1);
ctx->bs_ops.assign(chunks.size(), NULL);
for (unsigned i = 0; i < chunks.size(); i++)
{
auto & chunk = chunks[i];
if (chunk.osd_num == osd_num)
{
blockstore_op_t *bs_op = new blockstore_op_t({
.opcode = (uint64_t)BS_OP_DELETE,
.callback = [this, ctx, i](blockstore_op_t *op)
{
int64_t retval = op->retval;
ctx->bs_ops[i] = NULL;
delete op;
pg_sweep_subop_done(ctx, i, retval);
},
{ {
.oid = chunk.oid,
.version = chunk.version,
} },
});
ctx->bs_ops[i] = bs_op;
bs->enqueue_op(bs_op);
}
else
{
osd_op_t *subop = new osd_op_t();
subop->op_type = OSD_OP_OUT;
subop->req = (osd_any_op_t){ .sec_del = {
.header = {
.magic = SECONDARY_OSD_OP_MAGIC,
.opcode = OSD_OP_SEC_DELETE,
},
.oid = chunk.oid,
.version = chunk.version,
.flags = OSD_OP_RECOVERY_RELATED,
} };
subop->callback = [this, ctx, i](osd_op_t *op)
{
int64_t retval = op->reply.hdr.retval;
pending_owned_ops.erase(op);
delete op;
pg_sweep_subop_done(ctx, i, retval);
};
// The messenger doesn't own the op beyond the connection; if the
// OSD dies with the reply still on the wire ~osd_t frees it
pending_owned_ops.insert(subop);
submit_to_osd(subop, chunk.osd_num);
}
}
ctx->dispatching = false;
if (ctx->inflight == 0)
{
// Every chunk completed during dispatch; run the finalization now
pg_sweep_subop_done(ctx, -1, 0);
}
}

View File

@@ -298,16 +298,6 @@ resume_8:
if (op_data->dirty_pgs[i].pg_num != 0)
{
auto & pg = pgs.at(op_data->dirty_pgs[i]);
if (!op_data->errcode)
{
// The journals of these PGs are fsynced now, so tombstones in them
// are durable. Phase 2 may sweep them once every peer is alive
for (auto & q: pg.sweep_queue)
{
q.second.ready = true;
}
try_drain_pg_sweep(pg);
}
rm_inflight(pg);
}
}

View File

@@ -107,11 +107,6 @@ retry_1:
op_data->stripes[role].read_error = false;
op_data->stripes[role].not_exists = false;
op_data->stripes[role].osd_num = 0;
// Drop the previous round's read plan too: its buffer is freed below
// when the state changed, and the dispatch below recomputes everything
op_data->stripes[role].read_start = 0;
op_data->stripes[role].read_end = 0;
op_data->stripes[role].read_buf = NULL;
}
op_data->done = op_data->errors = op_data->drops = op_data->errcode = 0;
op_data->fact_ver = 0;
@@ -146,7 +141,6 @@ retry_1:
if (!cur_op->rmw_buf)
{
// Refuse partial overwrite of an incomplete object
cur_op->reply.hdr.retval = -EIO;
goto continue_others;
}
@@ -363,14 +357,6 @@ resume_12:
// Remove version override just after the write, but before stabilizing
pg.ver_override.erase(op_data->oid);
}
// A write above the recorded deletion recreates the object: the chain head is
// data again, there's nothing left for the phase 2 sweep to protect. A newer
// delete's sweep entry (if any) survives and will be picked up by flush
{
auto sweep_it = pg.sweep_queue.find(op_data->oid);
if (sweep_it != pg.sweep_queue.end() && sweep_it->second.version < op_data->target_ver)
pg.sweep_queue.erase(sweep_it);
}
if (op_data->object_state)
{
// Any kind of a non-clean object can have extra chunks, because we don't record objects
@@ -490,18 +476,6 @@ resume_9:
}
cur_op->reply.hdr.retval = cur_op->req.rw.len;
cur_op->reply.rw.version = op_data->fact_ver;
{
auto sweep_it = pg.sweep_queue.find(op_data->oid);
if (sweep_it != pg.sweep_queue.end() && sweep_it->second.head &&
sweep_it->second.version < cur_op->req.rw.version)
{
// The object was recreated above the recorded deletion: reads must
// stop answering zeros from the sweep fast path. The sweep itself
// still owes any member holding chains at or below its version
sweep_it->second.head = false;
}
}
continue_others:
osd_op_t *next_op = NULL;
auto next_it = pg.write_queue.find(op_data->oid);

View File

@@ -45,7 +45,6 @@ void osd_t::scrub_list(pool_pg_num_t pg_id, osd_num_t role_osd, object_id min_oi
.buf = (obj_ver_id*)op->bs_op->buf,
.total_count = (uint64_t)op->bs_op->retval,
.stable_count = op->bs_op->version,
.tombstone_count = op->bs_op->tombstone_count,
};
delete op->bs_op;
op->bs_op = NULL;
@@ -91,7 +90,6 @@ void osd_t::scrub_list(pool_pg_num_t pg_id, osd_num_t role_osd, object_id min_oi
.buf = (obj_ver_id*)op->buf,
.total_count = (uint64_t)op->reply.hdr.retval,
.stable_count = op->reply.sec_list.stable_count,
.tombstone_count = op->reply.sec_list.tombstone_count,
};
// set op->buf to NULL so it doesn't get freed
op->buf = NULL;
@@ -136,9 +134,7 @@ int osd_t::pick_next_scrub(object_id & next_oid)
// Continue scrubbing from the next object
if (scrub_last_pg == pg_it->first)
{
// Tombstone entries at the tail don't need data comparison - skip them
uint64_t scrub_scan_end = scrub_cur_list.total_count - scrub_cur_list.tombstone_count;
while (scrub_list_pos < scrub_scan_end)
while (scrub_list_pos < scrub_cur_list.total_count)
{
auto oid = scrub_cur_list.buf[scrub_list_pos].oid;
oid.stripe &= ~STRIPE_MASK;
@@ -159,7 +155,7 @@ int osd_t::pick_next_scrub(object_id & next_oid)
}
}
if (scrub_last_pg == pg_it->first &&
scrub_list_pos >= scrub_cur_list.total_count - scrub_cur_list.tombstone_count &&
scrub_list_pos >= scrub_cur_list.total_count &&
scrub_cur_list.stable_count < scrub_list_limit)
{
// End of the list, mark this PG as scrubbed and go to the next PG

View File

@@ -18,8 +18,7 @@ void osd_t::secondary_op_callback(osd_op_t *op)
{
op->reply.sec_rw.version = op->bs_op->version;
}
else if (op->req.hdr.opcode == OSD_OP_SEC_DELETE ||
op->req.hdr.opcode == OSD_OP_SEC_TOMBSTONE)
else if (op->req.hdr.opcode == OSD_OP_SEC_DELETE)
{
op->reply.sec_del.version = op->bs_op->version;
}
@@ -41,7 +40,6 @@ void osd_t::secondary_op_callback(osd_op_t *op)
op->iov.push_back(op->buf, op->bs_op->retval * sizeof(obj_ver_id));
}
op->reply.sec_list.stable_count = op->bs_op->version;
op->reply.sec_list.tombstone_count = op->bs_op->tombstone_count;
}
int retval = op->bs_op->retval;
delete op->bs_op;
@@ -116,7 +114,13 @@ bool osd_t::sec_check_pg_lock(osd_num_t primary_osd, const object_id &oid, uint3
void osd_t::exec_secondary_real(osd_op_t *cur_op)
{
osd_client_t *cl = msgr.clients.at(cur_op->client_id);
auto cl_it = msgr.clients.find(cur_op->client_id);
if (cl_it == msgr.clients.end())
{
// The client is already disconnected - may happen in a timer from exec_secondary()
return;
}
osd_client_t *cl = cl_it->second;
if (use_perms && !cl->hs_result.peer_is_osd)
{
// Non-OSDs are not allowed to execute "secondary" operations except LIST
@@ -166,9 +170,8 @@ void osd_t::exec_secondary_real(osd_op_t *cur_op)
: (cur_op->req.hdr.opcode == OSD_OP_SEC_STABILIZE ? BS_OP_STABLE
: (cur_op->req.hdr.opcode == OSD_OP_SEC_ROLLBACK ? BS_OP_ROLLBACK
: (cur_op->req.hdr.opcode == OSD_OP_SEC_DELETE ? BS_OP_DELETE
: (cur_op->req.hdr.opcode == OSD_OP_SEC_TOMBSTONE ? BS_OP_TOMBSTONE
: (cur_op->req.hdr.opcode == OSD_OP_SEC_LIST ? BS_OP_LIST
: -1)))))))));
: -1))))))));
if (cur_op->req.hdr.opcode == OSD_OP_SEC_READ ||
cur_op->req.hdr.opcode == OSD_OP_SEC_WRITE ||
cur_op->req.hdr.opcode == OSD_OP_SEC_WRITE_STABLE)
@@ -202,8 +205,7 @@ void osd_t::exec_secondary_real(osd_op_t *cur_op)
cur_op->bs_op->retval = cur_op->bs_op->len;
#endif
}
else if (cur_op->req.hdr.opcode == OSD_OP_SEC_DELETE ||
cur_op->req.hdr.opcode == OSD_OP_SEC_TOMBSTONE)
else if (cur_op->req.hdr.opcode == OSD_OP_SEC_DELETE)
{
if (!sec_check_pg_lock(cl->in_osd_num, cur_op->req.sec_del.oid, cur_op->req.sec_del.flags))
{

View File

@@ -96,16 +96,6 @@ add_dependencies(build_tests test_blockstore_chaos)
target_link_libraries(test_blockstore_chaos vitastor_blk vitastor_common)
add_test(NAME test_blockstore_chaos COMMAND test_blockstore_chaos)
# test_peering_tombstone
add_executable(test_peering_tombstone
EXCLUDE_FROM_ALL
test_peering_tombstone.cpp
../osd/osd_peering_pg.cpp
)
target_link_libraries(test_peering_tombstone util)
add_dependencies(build_tests test_peering_tombstone)
add_test(NAME test_peering_tombstone COMMAND test_peering_tombstone)
# test_atomic
add_executable(test_atomic test_atomic.cpp)
target_link_libraries(test_atomic util)

View File

@@ -2844,11 +2844,9 @@ void test_read_enoent_waits_behind_running_delete()
f.exec(read);
// The copy this read reads from is already deleted - the subop answers
// raw -ENOENT (a vanished chain carries version 0; the blockstore always
// stamps the reply version, the mock requires the test to do it)
// raw -ENOENT
auto *local_read = f.bs->take(BS_OP_READ);
assert(local_read->len == 4096);
local_read->version = 0;
local_read->retval = -ENOENT;
local_read->callback(local_read);
@@ -2868,11 +2866,10 @@ void test_read_enoent_waits_behind_running_delete()
f.peer_write_ok(2, OSD_OP_SEC_DELETE, 1);
assert(delete_retval == 0);
// The retry subops arrive. The local chain is a plain delete marker: the
// object is non-existent, so the read resolves as zeros with version 0
// The retry subops arrive. The object is really gone now, so the read has
// to resolve as non-existent: zeros with version 0
local_read = f.bs->take(BS_OP_READ);
assert(local_read->len == 4096);
local_read->version = 0;
local_read->retval = -ENOENT;
local_read->callback(local_read);
@@ -2931,7 +2928,6 @@ void test_read_enoent_without_racing_op_marks_corrupted()
auto *local_read = f.bs->take(BS_OP_READ);
assert(local_read->len == 4096);
local_read->version = 0; // raw ENOENT: a vanished chain answers version 0
local_read->retval = -ENOENT;
local_read->callback(local_read);
// (no peer subop: a replicated read goes to the one member holding the object)

View File

@@ -2168,224 +2168,6 @@ static void test_big_write_after_redirect_intent()
free(op2.buf);
}
// Tombstone: a versioned delete marker that survives compaction and restart,
// is reported by LIST in a dedicated trailing section, and can be swept by a
// plain versionless delete after all peers are back
static void test_tombstone()
{
printf("\n-- test_tombstone\n");
bs_test_t test;
test.default_cfg();
test.init();
assert(!test.bs->reshard_start(1, 1, 0x20000, 0));
object_id oid1 = { .inode = INODE_WITH_POOL(1, 1), .stripe = 0 };
object_id oid2 = { .inode = INODE_WITH_POOL(1, 1), .stripe = 128*1024 };
object_id oid3 = { .inode = INODE_WITH_POOL(1, 1), .stripe = 256*1024 };
struct listing_t
{
int64_t retval; uint64_t stable, tomb; obj_ver_id *lst;
};
auto do_list = [&](uint32_t limit) -> listing_t
{
blockstore_op_t lop;
lop.opcode = BS_OP_LIST;
lop.min_oid = { .inode = INODE_WITH_POOL(1, 1), .stripe = 0 };
lop.max_oid = { .inode = INODE_WITH_POOL(1, 1000), .stripe = 0 };
lop.pg_alignment = 128*1024;
lop.pg_count = 1;
lop.pg_number = 0;
lop.list_stable_limit = limit;
test.exec_op(&lop, false);
assert(lop.retval >= 0);
return (listing_t){ .retval = lop.retval, .stable = (uint64_t)lop.version,
.tomb = lop.tombstone_count, .lst = (obj_ver_id*)lop.buf };
};
blockstore_op_t op;
printf("writing 1:0 v1 4K\n");
op.opcode = BS_OP_WRITE_STABLE;
op.oid = oid1;
op.version = 1;
op.offset = 0;
op.len = 4096;
op.buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, 4096);
memset(op.buf, 0xaa, 4096);
test.exec_op(&op, false);
assert(op.retval == op.len);
free(op.buf);
op.buf = NULL;
printf("tombstone with auto version\n");
op.opcode = BS_OP_TOMBSTONE;
op.version = 0;
op.offset = 0;
op.len = 0;
test.exec_op(&op, false);
assert(op.retval == 0 && op.version == 2);
{
auto l = do_list(0);
assert(l.retval == 1 && l.stable == 0 && l.tomb == 1);
assert((l.lst[0] == (obj_ver_id){ .oid = oid1, .version = 2 }));
free(l.lst);
}
printf("read over a tombstone returns ENOENT\n");
op.opcode = BS_OP_READ;
op.version = 0;
op.len = 4096;
op.buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, 4096);
test.exec_op(&op, false);
assert(op.retval == -ENOENT);
free(op.buf);
op.buf = NULL;
printf("repeated tombstones are no-ops\n");
op.opcode = BS_OP_TOMBSTONE;
op.version = 2;
op.len = 0;
test.exec_op(&op, false);
assert(op.retval == 0);
op.version = 1;
test.exec_op(&op, false);
assert(op.retval == 0 && op.version == 2);
printf("a rewrite cancels the deletion\n");
op.opcode = BS_OP_WRITE_STABLE;
op.version = 3;
op.len = 4096;
op.buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, 4096);
memset(op.buf, 0xbb, 4096);
test.exec_op(&op, false);
assert(op.retval == 4096);
free(op.buf);
op.buf = NULL;
{
auto l = do_list(0);
assert(l.retval == 1 && l.stable == 1 && l.tomb == 0);
assert((l.lst[0] == (obj_ver_id){ .oid = oid1, .version = 3 }));
free(l.lst);
}
printf("tombstone over an occupied version -> EEXIST, a higher one is written\n");
op.opcode = BS_OP_TOMBSTONE;
op.len = 0;
op.version = 3;
test.exec_op(&op, false);
assert(op.retval == -EEXIST);
op.version = 5;
test.exec_op(&op, false);
assert(op.retval == 0 && op.version == 5);
{
auto l = do_list(0);
assert(l.retval == 1 && l.stable == 0 && l.tomb == 1);
assert((l.lst[0] == (obj_ver_id){ .oid = oid1, .version = 5 }));
free(l.lst);
}
printf("the tombstone survives compaction\n");
test.force_compaction();
{
auto l = do_list(0);
assert(l.retval == 1 && l.stable == 0 && l.tomb == 1);
assert((l.lst[0] == (obj_ver_id){ .oid = oid1, .version = 5 }));
free(l.lst);
}
printf("the tombstone survives a restart\n");
test.destroy_bs();
test.init();
assert(!test.bs->reshard_start(1, 1, 0x20000, 0));
{
auto l = do_list(0);
assert(l.retval == 1 && l.tomb == 1);
assert((l.lst[0] == (obj_ver_id){ .oid = oid1, .version = 5 }));
free(l.lst);
}
printf("a versionless delete sweeps the tombstone away\n");
op.opcode = BS_OP_DELETE;
op.oid = oid1;
op.version = 0;
op.len = 0;
test.exec_op(&op, false);
assert(op.retval == 0);
test.force_compaction();
{
auto l = do_list(0);
assert(l.retval == 0 && l.stable == 0 && l.tomb == 0);
free(l.lst);
}
printf("tombstones survive list_stable_limit truncation\n");
op.opcode = BS_OP_WRITE_STABLE;
op.len = 4096;
op.buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, 4096);
memset(op.buf, 0xcc, 4096);
for (object_id oid: { oid1, oid2, oid3 })
{
op.oid = oid;
op.version = 1;
test.exec_op(&op, false);
assert(op.retval == 4096);
}
free(op.buf);
op.buf = NULL;
op.opcode = BS_OP_TOMBSTONE;
op.oid = oid2;
op.version = 0;
op.len = 0;
test.exec_op(&op, false);
assert(op.retval == 0 && op.version == 2);
// A rewrite brings oid2 back as a stable version, cancelling the deletion
op.opcode = BS_OP_WRITE_STABLE;
op.oid = oid2;
op.version = 3;
op.len = 4096;
op.buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, 4096);
memset(op.buf, 0xee, 4096);
test.exec_op(&op, false);
assert(op.retval == 4096);
free(op.buf);
op.buf = NULL;
// Put an unstable write over oid3 and tombstone it - the tombstone wins and
// the unstable rewrite below it isn't reported
op.opcode = BS_OP_WRITE;
op.oid = oid3;
op.version = 2;
op.len = 4096;
op.buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, 4096);
memset(op.buf, 0xdd, 4096);
test.exec_op(&op, false);
assert(op.retval == 4096);
free(op.buf);
op.buf = NULL;
op.opcode = BS_OP_TOMBSTONE;
op.oid = oid3;
op.version = 0;
op.len = 0;
test.exec_op(&op, false);
assert(op.retval == 0 && op.version == 3);
{
// [oid1 v1][oid2 v3 stable][oid3 tomb v3] - oid3's unstable v2 is hidden
auto l = do_list(2);
assert(l.retval == 3 && l.stable == 2 && l.tomb == 1);
assert((l.lst[0] == (obj_ver_id){ .oid = oid1, .version = 1 }));
assert((l.lst[1] == (obj_ver_id){ .oid = oid2, .version = 3 }));
assert((l.lst[2] == (obj_ver_id){ .oid = oid3, .version = 3 }));
free(l.lst);
// limit cuts stable only - the tombstone stays
auto l2 = do_list(1);
assert(l2.retval == 2 && l2.stable == 1 && l2.tomb == 1);
assert((l2.lst[0] == (obj_ver_id){ .oid = oid1, .version = 1 }));
assert((l2.lst[1] == (obj_ver_id){ .oid = oid3, .version = 3 }));
free(l2.lst);
}
}
int main(int narg, char *args[])
{
test_simple();
@@ -2417,6 +2199,5 @@ int main(int narg, char *args[])
test_compact_intent_write_in_partial_csum_block();
test_no_intent_over_unwritten_compaction();
test_big_write_after_redirect_intent();
test_tombstone();
return 0;
}

View File

@@ -54,8 +54,6 @@ struct chaos_probs_t
// Submit nothing, just let the simulation run for one event
uint32_t wait = 500;
uint32_t write = 60, del = 6, read = 40, sync = 30, stabilize = 50, rollback = 6;
// Versioned tombstones - only used on configurations with .tombstones = true
uint32_t tomb = 6;
// Restart the store cleanly - everything in flight is allowed to finish first
uint32_t restart = 1;
// Pull the plug right now, whatever happens to be in flight
@@ -68,9 +66,6 @@ struct chaos_probs_t
};
static chaos_probs_t probs;
// Set when --p-tombstone is given explicitly - then tombstones are used on every
// v2 configuration, not only the ones marked with .tombstones
static bool tomb_given = false;
// What a single step decided to do
enum chaos_action_t
@@ -79,7 +74,6 @@ enum chaos_action_t
ACT_RESTART,
ACT_WRITE,
ACT_DELETE,
ACT_TOMBSTONE,
ACT_READ,
ACT_SYNC,
ACT_STABILIZE,
@@ -106,8 +100,6 @@ struct chaos_cfg_t
// This can't be mixed within one object: writing a stable version on top of an
// unstable one is rejected with EINVAL, and a pool is always one or the other
bool instant_writes;
// Write tombstones instead of plain deletes (only the heap store supports them)
bool tombstones = false;
};
// Extra diagnostics for a deadlock, only available in the new implementation
@@ -156,9 +148,6 @@ struct obj_model_t
// The bitmap is opaque to the blockstore but it travels with the entry through
// compaction, recovery and rollbacks just like the data does
std::map<uint64_t, uint8_t> bmp;
// Sequence number -> the op was a versioned tombstone (vs a plain delete).
// A tombstone pins the version floor: writes must continue above it
std::map<uint64_t, bool> tomb;
};
struct pending_t
@@ -193,9 +182,9 @@ struct chaos_t
disk_mock_t *data_disk = NULL, *meta_disk = NULL;
BS *bs = NULL;
obj_model_t objs[OBJ_COUNT];
uint64_t crashes = 0, restarts = 0, writes = 0, deletes = 0, tombstones = 0, syncs = 0, stabilizes = 0;
uint64_t crashes = 0, restarts = 0, writes = 0, deletes = 0, syncs = 0, stabilizes = 0;
uint64_t rollbacks = 0, refused_writes = 0, checked_reads = 0, step_no = 0;
bool use_fsync = false, instant_writes = false, tombstones_enabled = false;
bool use_fsync = false, instant_writes = false;
uint64_t seq_id = 0;
bool trace = false;
@@ -212,8 +201,6 @@ struct chaos_t
{
use_fsync = cfg.use_fsync;
instant_writes = cfg.instant_writes;
tombstones_enabled = cfg.tombstones ||
(tomb_given && strcmp(cfg.impl, "v1") != 0);
config["data_device"] = "./test_data.bin";
config["data_device_size"] = "268435456";
config["data_device_sect"] = "4096";
@@ -467,29 +454,6 @@ struct chaos_t
return submit(p);
}
// A tombstone is a delete that keeps its version visible in listings until
// it's swept. The model records it exactly like a deletion (empty content)
pending_t *submit_tombstone(int obj)
{
auto & m = objs[obj];
auto *p = new pending_t();
p->obj = obj;
p->touched.push_back(obj);
p->version = ++m.submitted;
p->bs_version = m.next_version++;
p->op.opcode = BS_OP_TOMBSTONE;
p->op.oid = oid(obj);
p->op.version = p->bs_version;
p->op.offset = 0;
p->op.len = 0;
p->op.buf = NULL;
p->on_success = [this, obj]() { written(obj); };
tombstones++;
if (trace)
printf("tombstone %jx:%jx v%ju", p->op.oid.inode, p->op.oid.stripe, p->bs_version);
return submit(p);
}
pending_t *submit_sync()
{
auto *p = new pending_t();
@@ -541,11 +505,8 @@ struct chaos_t
auto & m = objs[obj];
if (m.content.at(m.acked).empty())
{
// The object is gone. A plain delete lets numbering restart from 1;
// a tombstone pins its version: the store refuses to write at or below a
// recorded deletion until the phase 2 sweep clears it
auto kit = m.tomb.find(m.acked);
m.next_version = kit != m.tomb.end() && kit->second ? m.ver.at(m.acked) + 1 : 1;
// The object is gone, so the next write starts numbering over again
m.next_version = 1;
m.can_rollback = false;
m.deleted_upto = m.acked;
to_stabilize.erase(obj);
@@ -599,7 +560,6 @@ struct chaos_t
{
const uint32_t w[ACT_COUNT] = {
probs.crash, probs.restart, probs.write, probs.del,
tombstones_enabled ? probs.tomb : 0,
probs.read, probs.sync, probs.stabilize, probs.rollback, probs.wait,
};
uint64_t total = 0;
@@ -638,7 +598,6 @@ struct chaos_t
{
case ACT_WRITE: submitted = try_write(false); break;
case ACT_DELETE: submitted = try_write(true); break;
case ACT_TOMBSTONE: submitted = try_tombstone(); break;
case ACT_READ: submitted = try_read(); break;
case ACT_SYNC: submitted = try_sync(); break;
case ACT_STABILIZE: submitted = try_stabilize(); break;
@@ -708,16 +667,6 @@ struct chaos_t
return true;
}
bool try_tombstone()
{
auto cand = free_objects(true);
if (!cand.size())
return false;
int obj = cand[rnd(0, cand.size()-1)];
submit_tombstone(obj);
return true;
}
// Read a random part of a random object. Ranges are aligned to the write granularity
// but not to the checksum block size, so they cut across checksum blocks and across
// the boundaries of the extents that were actually written.
@@ -815,7 +764,6 @@ struct chaos_t
{
m.ver.erase(m.content.rbegin()->first);
m.bmp.erase(m.content.rbegin()->first);
m.tomb.erase(m.content.rbegin()->first);
m.content.erase(std::prev(m.content.end()));
}
m.acked = m.synced = m.durable;
@@ -903,7 +851,7 @@ struct chaos_t
return;
}
bool is_write = p->op.opcode == BS_OP_WRITE || p->op.opcode == BS_OP_WRITE_STABLE ||
p->op.opcode == BS_OP_DELETE || p->op.opcode == BS_OP_TOMBSTONE;
p->op.opcode == BS_OP_DELETE;
bool ok = p->done && (p->op.opcode == BS_OP_WRITE || p->op.opcode == BS_OP_WRITE_STABLE
? p->op.retval == (int)p->op.len : p->op.retval == 0);
if (p->done && !ok)
@@ -940,8 +888,7 @@ struct chaos_t
auto & m = objs[p->obj];
m.content[p->version] = p->content;
m.ver[p->version] = p->bs_version;
m.tomb[p->version] = p->op.opcode == BS_OP_TOMBSTONE;
if (p->op.opcode != BS_OP_DELETE && p->op.opcode != BS_OP_TOMBSTONE)
if (p->op.opcode != BS_OP_DELETE)
m.bmp[p->version] = bitmap_byte(p->obj, p->bs_version);
if (ok)
m.acked = p->version;
@@ -953,7 +900,6 @@ struct chaos_t
static const char *op_name(pending_t *p)
{
return p->op.opcode == BS_OP_DELETE ? "delete"
: p->op.opcode == BS_OP_TOMBSTONE ? "tombstone"
: p->op.opcode == BS_OP_SYNC ? "sync"
: p->op.opcode == BS_OP_STABLE ? "stabilize"
: p->op.opcode == BS_OP_ROLLBACK ? "rollback"
@@ -1209,9 +1155,9 @@ struct chaos_t
m.acked = m.synced = m.submitted;
m.can_rollback = false;
m.deleted_upto = 0;
// Continue numbering above whatever the store came back with - a read
// over a tombstone reports its version, so the floor survives restart
m.next_version = last_read_version + 1;
// Continue numbering above whatever the store came back with, or start
// over from 1 if the object is gone
m.next_version = exists ? last_read_version+1 : 1;
return;
}
}
@@ -1222,8 +1168,7 @@ struct chaos_t
m.content.clear();
m.ver.clear();
m.bmp.clear();
m.tomb.clear();
m.next_version = last_read_version + 1;
m.next_version = 1;
m.can_rollback = false;
m.deleted_upto = 0;
return;
@@ -1264,21 +1209,19 @@ struct chaos_t
template<class BS>
static void run_impl(const chaos_cfg_t & cfg, int meta_format, uint32_t seed, uint64_t steps, bool trace)
{
printf("\n-- chaos %s seed=%u steps=%ju fsync=%d csum_block=%s writes=%s%s\n",
printf("\n-- chaos %s seed=%u steps=%ju fsync=%d csum_block=%s writes=%s\n",
cfg.impl, seed, steps, cfg.use_fsync ? 1 : 0,
cfg.csum_block ? std::to_string(cfg.csum_block).c_str() : "none",
cfg.instant_writes ? "instant" : "two-phase",
(cfg.tombstones || (tomb_given && strcmp(cfg.impl, "v1") != 0)) ? " tombstones" : "");
cfg.instant_writes ? "instant" : "two-phase");
chaos_t<BS> t;
t.configure(cfg, meta_format);
t.trace = trace;
t.create(seed);
t.run(steps);
printf("OK: %ju writes (%ju refused with EAGAIN), %ju deletes, %ju tombstones, %ju syncs, "
"%ju stabilizes, %ju rollbacks, %ju crashes, %ju clean restarts, %ju verified reads, "
"%ju disk ops\n",
t.writes, t.refused_writes, t.deletes, t.tombstones, t.syncs, t.stabilizes, t.rollbacks,
t.crashes, t.restarts, t.checked_reads, t.data_disk->completed_ops);
printf("OK: %ju writes (%ju refused with EAGAIN), %ju deletes, %ju syncs, %ju stabilizes, "
"%ju rollbacks, %ju crashes, %ju clean restarts, %ju verified reads, %ju disk ops\n",
t.writes, t.refused_writes, t.deletes, t.syncs, t.stabilizes, t.rollbacks, t.crashes,
t.restarts, t.checked_reads, t.data_disk->completed_ops);
}
// Both implementations, both commit modes, and checksum blocks equal to and larger than
@@ -1309,12 +1252,6 @@ static const chaos_cfg_t configs[] = {
{ .impl = "v1", .use_fsync = true , .csum_block = 0 , .instant_writes = true },
{ .impl = "v1", .use_fsync = true , .csum_block = 4096 , .instant_writes = true },
{ .impl = "v1", .use_fsync = true , .csum_block = 16384, .instant_writes = true },
// The same matrix plus tombstones on the heap store: a versioned delete that
// survives compaction and is visible in listings until it's swept
{ .impl = "v2", .use_fsync = false, .csum_block = 4096 , .instant_writes = false, .tombstones = true },
{ .impl = "v2", .use_fsync = true , .csum_block = 4096 , .instant_writes = false, .tombstones = true },
{ .impl = "v2", .use_fsync = false, .csum_block = 4096 , .instant_writes = true , .tombstones = true },
{ .impl = "v2", .use_fsync = true , .csum_block = 4096 , .instant_writes = true , .tombstones = true },
};
static void run_one(const chaos_cfg_t & cfg, uint32_t seed, uint64_t steps, bool trace)
@@ -1355,8 +1292,6 @@ static const char *help_text =
" --p-wait <n> Submit nothing, just let the simulation run (default %u)\n"
" --p-write <n> Write a random range of a random object (default %u)\n"
" --p-delete <n> Delete an existing object (default %u)\n"
" --p-tombstone <n> Write a tombstone over an existing object instead of deleting\n"
" it (default %u; only on configurations that support it)\n"
" --p-read <n> Read back and verify a random object (default %u)\n"
" --p-sync <n> Sync (default %u)\n"
" --p-stabilize <n> Commit whatever became stabilizable (default %u)\n"
@@ -1372,7 +1307,7 @@ static void print_help(int cfg_count, int default_seeds, int default_fixed, int
{
chaos_probs_t d;
printf(help_text, default_seeds, default_fixed, default_random, default_steps, d.max_inflight,
d.wait, d.write, d.del, d.tomb, d.read, d.sync, d.stabilize, d.rollback, d.restart, d.crash,
d.wait, d.write, d.del, d.read, d.sync, d.stabilize, d.rollback, d.restart, d.crash,
d.full_read, cfg_count);
for (int i = 0; i < cfg_count; i++)
printf(" %2d: %s, fsync=%d, csum_block=%s, writes=%s\n", i, configs[i].impl,
@@ -1486,7 +1421,6 @@ int main(int narg, char *args[])
else if (!strcmp(opt, "--p-wait")) { take(v); probs.wait = (uint32_t)v; }
else if (!strcmp(opt, "--p-write")) { take(v); probs.write = (uint32_t)v; }
else if (!strcmp(opt, "--p-delete")) { take(v); probs.del = (uint32_t)v; }
else if (!strcmp(opt, "--p-tombstone")) { take(v); probs.tomb = (uint32_t)v; tomb_given = true; }
else if (!strcmp(opt, "--p-read")) { take(v); probs.read = (uint32_t)v; }
else if (!strcmp(opt, "--p-sync")) { take(v); probs.sync = (uint32_t)v; }
else if (!strcmp(opt, "--p-stabilize")) { take(v); probs.stabilize = (uint32_t)v; }

View File

@@ -2888,24 +2888,6 @@ static void test_zero_write_over_rollback_to_zero()
free(buf);
}
// Tombstones are a heap-store (meta_format 3) feature, the v1 store must refuse them
static void test_tombstone_unsupported()
{
printf("\n-- test_tombstone_unsupported\n");
bs_test_t test;
test.default_cfg();
test.init();
blockstore_op_t op;
op.opcode = BS_OP_TOMBSTONE;
op.oid = { .inode = INODE_WITH_POOL(1, 1), .stripe = 0 };
op.version = 1;
op.offset = 0;
op.len = 0;
op.buf = NULL;
test.exec_op(&op);
assert(op.retval == -EOPNOTSUPP);
}
int main(int narg, char *args[])
{
test_preserve_corruption();
@@ -2939,6 +2921,5 @@ int main(int narg, char *args[])
test_rollback_over_stable_write();
test_sync_waits_for_delete_taking_over_unsynced();
test_zero_write_over_rollback_to_zero();
test_tombstone_unsupported();
return 0;
}

View File

@@ -2448,19 +2448,19 @@ void test_reshard_list()
_test_small_write(heap, dsk, 2, 0x60000, 3, 4096, 4096, 0, false, buffer_area.data()+4096, false);
obj_ver_id *listing = NULL;
size_t stable_count = 0, unstable_count = 0, tombstone_count = 0;
size_t stable_count = 0, unstable_count = 0;
res = heap.list_objects(1, (object_id){ .inode = INODE_WITH_POOL(0, 1) },
(object_id){ .inode = INODE_WITH_POOL(1, 1), .stripe = UINT64_MAX }, &listing, &stable_count, &unstable_count, &tombstone_count);
(object_id){ .inode = INODE_WITH_POOL(1, 1), .stripe = UINT64_MAX }, &listing, &stable_count, &unstable_count);
assert(res == EINVAL);
res = heap.list_objects(1, (object_id){ .inode = INODE_WITH_POOL(1, 1) },
(object_id){ .inode = INODE_WITH_POOL(2, 1), .stripe = UINT64_MAX }, &listing, &stable_count, &unstable_count, &tombstone_count);
(object_id){ .inode = INODE_WITH_POOL(2, 1), .stripe = UINT64_MAX }, &listing, &stable_count, &unstable_count);
assert(res == EINVAL);
res = heap.list_objects(2, (object_id){ .inode = INODE_WITH_POOL(1, 1) },
(object_id){ .inode = INODE_WITH_POOL(1, 1), .stripe = UINT64_MAX }, &listing, &stable_count, &unstable_count, &tombstone_count);
(object_id){ .inode = INODE_WITH_POOL(1, 1), .stripe = UINT64_MAX }, &listing, &stable_count, &unstable_count);
assert(res == EINVAL);
res = heap.list_objects(1, (object_id){ .inode = INODE_WITH_POOL(1, 1) },
(object_id){ .inode = INODE_WITH_POOL(1, UINT64_MAX), .stripe = UINT64_MAX }, &listing, &stable_count, &unstable_count, &tombstone_count);
(object_id){ .inode = INODE_WITH_POOL(1, UINT64_MAX), .stripe = UINT64_MAX }, &listing, &stable_count, &unstable_count);
assert(res == 0);
assert(stable_count == 4);
assert(unstable_count == 2);
@@ -2468,7 +2468,7 @@ void test_reshard_list()
listing = NULL;
res = heap.list_objects(1, (object_id){ .inode = INODE_WITH_POOL(1, 1) },
(object_id){ .inode = INODE_WITH_POOL(1, 1), .stripe = UINT64_MAX }, &listing, &stable_count, &unstable_count, &tombstone_count);
(object_id){ .inode = INODE_WITH_POOL(1, 1), .stripe = UINT64_MAX }, &listing, &stable_count, &unstable_count);
assert(res == 0);
assert(stable_count == 3);
assert(unstable_count == 0);
@@ -2485,10 +2485,10 @@ void test_reshard_list()
assert(!heap.read_entry((object_id){ .inode = INODE_WITH_POOL(1, 2), .stripe = 0x80000 }));
res = heap.list_objects(3, (object_id){ .inode = INODE_WITH_POOL(1, 1) },
(object_id){ .inode = INODE_WITH_POOL(1, 1), .stripe = UINT64_MAX }, &listing, &stable_count, &unstable_count, &tombstone_count);
(object_id){ .inode = INODE_WITH_POOL(1, 1), .stripe = UINT64_MAX }, &listing, &stable_count, &unstable_count);
assert(res == EINVAL);
res = heap.list_objects(1, (object_id){ .inode = INODE_WITH_POOL(1, 1) },
(object_id){ .inode = INODE_WITH_POOL(1, 1), .stripe = UINT64_MAX }, &listing, &stable_count, &unstable_count, &tombstone_count);
(object_id){ .inode = INODE_WITH_POOL(1, 1), .stripe = UINT64_MAX }, &listing, &stable_count, &unstable_count);
assert(res == 0);
assert(stable_count == 2);
assert(unstable_count == 0);
@@ -2496,7 +2496,7 @@ void test_reshard_list()
listing = NULL;
res = heap.list_objects(2, (object_id){ .inode = INODE_WITH_POOL(1, 1) },
(object_id){ .inode = INODE_WITH_POOL(1, UINT64_MAX), .stripe = UINT64_MAX }, &listing, &stable_count, &unstable_count, &tombstone_count);
(object_id){ .inode = INODE_WITH_POOL(1, UINT64_MAX), .stripe = UINT64_MAX }, &listing, &stable_count, &unstable_count);
assert(res == 0);
assert(stable_count == 2);
assert(unstable_count == 2);
@@ -2523,9 +2523,9 @@ void test_reshard_chunked()
_test_big_write(heap, dsk, 1, i*0x20000, 1, i*0x20000, true, 0, 0, buffer_area.data());
obj_ver_id *listing = NULL;
size_t stable_count = 0, unstable_count = 0, tombstone_count = 0;
size_t stable_count = 0, unstable_count = 0;
res = heap.list_objects(1, (object_id){ .inode = INODE_WITH_POOL(1, 1) },
(object_id){ .inode = INODE_WITH_POOL(1, UINT64_MAX), .stripe = UINT64_MAX }, &listing, &stable_count, &unstable_count, &tombstone_count);
(object_id){ .inode = INODE_WITH_POOL(1, UINT64_MAX), .stripe = UINT64_MAX }, &listing, &stable_count, &unstable_count);
assert(res == 0);
assert(stable_count == 30);
assert(unstable_count == 0);
@@ -2540,7 +2540,7 @@ void test_reshard_chunked()
assert(!heap.reshard_check(1, 2, 0x20000));
res = heap.list_objects(1, (object_id){ .inode = INODE_WITH_POOL(1, 1) },
(object_id){ .inode = INODE_WITH_POOL(1, 1), .stripe = UINT64_MAX }, &listing, &stable_count, &unstable_count, &tombstone_count);
(object_id){ .inode = INODE_WITH_POOL(1, 1), .stripe = UINT64_MAX }, &listing, &stable_count, &unstable_count);
assert(res == 0);
assert(stable_count == 0);
assert(unstable_count == 0);
@@ -2558,7 +2558,7 @@ void test_reshard_chunked()
assert(heap.reshard_check(1, 2, 0x20000));
res = heap.list_objects(1, (object_id){ .inode = INODE_WITH_POOL(1, 1) },
(object_id){ .inode = INODE_WITH_POOL(1, 1), .stripe = UINT64_MAX }, &listing, &stable_count, &unstable_count, &tombstone_count);
(object_id){ .inode = INODE_WITH_POOL(1, 1), .stripe = UINT64_MAX }, &listing, &stable_count, &unstable_count);
assert(res == 0);
assert(stable_count == 15);
assert(unstable_count == 0);
@@ -2566,7 +2566,7 @@ void test_reshard_chunked()
listing = NULL;
res = heap.list_objects(2, (object_id){ .inode = INODE_WITH_POOL(1, 1) },
(object_id){ .inode = INODE_WITH_POOL(1, 1), .stripe = UINT64_MAX }, &listing, &stable_count, &unstable_count, &tombstone_count);
(object_id){ .inode = INODE_WITH_POOL(1, 1), .stripe = UINT64_MAX }, &listing, &stable_count, &unstable_count);
assert(res == 0);
assert(stable_count == 15);
assert(unstable_count == 0);

View File

@@ -9,6 +9,7 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <poll.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
@@ -162,8 +163,89 @@ static void test_stop_client_with_stuck_send(ring_loop_t *ringloop, bool zerocop
printf("test_stop_client_with_stuck_send(%s) passed\n", zerocopy ? "zerocopy" : "copy");
}
static timespec ts_ms(int64_t ms)
{
return (timespec){ .tv_sec = ms/1000, .tv_nsec = (ms%1000)*1000000 };
}
// Keepalive must count at most one tick per event loop wakeup (USTOR-4408)
static void test_keepalive_catch_up()
{
printf("test_keepalive_catch_up\n");
osd_messenger_t *msgr = new osd_messenger_t();
msgr->parse_config(json11::Json::object { { "log_level", 1 } });
struct { int64_t at_ms; bool skip; } steps[] = {
{ 100000, false }, // first call
{ 101000, false }, // regular 1s ticks
{ 102000, false },
{ 103600, false }, // tick delayed by 600 ms
{ 104000, false }, // next on-time tick 400 ms later is counted too
{ 115000, false }, // event loop was blocked for 11s: one tick
{ 115000, true }, // catch-up calls of the same wakeup
{ 115001, true },
{ 115002, true },
{ 116000, false }, // regular ticks again
{ 119000, false }, // chronic stalls: one tick per stall,
{ 119001, true },
{ 122000, false }, // so a dead peer is still detected
{ 122001, true },
{ 125000, false },
};
for (auto & s: steps)
{
bool skip = msgr->keepalive_catch_up(ts_ms(s.at_ms));
if (skip != s.skip)
{
printf(" at %jd ms: expected %s, got %s\n", (intmax_t)s.at_ms,
s.skip ? "skip" : "count", skip ? "skip" : "count");
assert(skip == s.skip);
}
}
delete msgr;
}
// The same with the real timerfd_manager: after a 3s stall it fires the 1s timer
// several times in one wakeup, only one of them must be counted
static void test_keepalive_after_stall()
{
printf("test_keepalive_after_stall\n");
int timer_fd = -1;
std::function<void(int, int)> timer_handler;
timerfd_manager_t *tfd = new timerfd_manager_t([&](int fd, bool wr, std::function<void(int, int)> cb)
{
timer_fd = fd;
timer_handler = cb;
});
osd_messenger_t *msgr = new osd_messenger_t();
// As init() does
timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
msgr->keepalive_catch_up(now);
int fired = 0, counted = 0;
tfd->set_timer(1000, true, [&](int)
{
timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
fired++;
if (!msgr->keepalive_catch_up(now))
counted++;
});
sleep(3);
pollfd pfd = { .fd = timer_fd, .events = POLLIN };
int r = poll(&pfd, 1, 2000);
assert(r == 1);
timer_handler(timer_fd, POLLIN);
printf(" timer fired %d times in one wakeup, %d counted\n", fired, counted);
assert(fired >= 2);
assert(counted == 1);
delete msgr;
delete tfd;
}
int main(int narg, char *args[])
{
test_keepalive_catch_up();
test_keepalive_after_stall();
ring_loop_t *ringloop;
try
{

View File

@@ -1,204 +0,0 @@
// Copyright (c) Vitaliy Filippov, 2019+
// License: VNPL-1.1 or GNU GPL-2.0+ (see README.md for details)
//
// Unit tests for tombstone adoption in pg_t::calc_object_states.
// Replicated pool, pg_size=3, cur_set={1,2,3}. LIST layout per OSD is
// [stable][unstable][tombstones] as reported by blockstore BS_OP_LIST.
#ifndef _LARGEFILE64_SOURCE
#define _LARGEFILE64_SOURCE
#endif
#include <stdio.h>
#include <assert.h>
#include <vector>
#include "malloc_or_die.h"
#include "osd_peering_pg.h"
#define INODE INODE_WITH_POOL(1, 1)
struct list_builder
{
std::vector<obj_ver_id> stable, unstable, tomb;
list_builder& st(uint64_t v)
{
stable.push_back((obj_ver_id){ .oid = { INODE, 0 }, .version = v });
return *this;
}
list_builder& un(uint64_t v)
{
unstable.push_back((obj_ver_id){ .oid = { INODE, 0 }, .version = v });
return *this;
}
list_builder& tb(uint64_t v)
{
tomb.push_back((obj_ver_id){ .oid = { INODE, 0 }, .version = v });
return *this;
}
pg_list_result_t result()
{
size_t n = stable.size() + unstable.size() + tomb.size();
pg_list_result_t r = {
.buf = (obj_ver_id*)malloc_or_die(sizeof(obj_ver_id) * (n ? n : 1)),
.total_count = n,
.stable_count = stable.size(),
.tombstone_count = tomb.size(),
};
size_t pos = 0;
for (auto & e: stable) r.buf[pos++] = e;
for (auto & e: unstable) r.buf[pos++] = e;
for (auto & e: tomb) r.buf[pos++] = e;
return r;
}
};
static pg_t make_pg(pg_peering_state_t *ps)
{
pg_t pg = {
.scheme = POOL_SCHEME_REPLICATED,
.pg_cursize = 3,
.pg_size = 3,
.pg_minsize = 2,
.pg_data_size = 3,
.pool_id = 1,
.pg_num = 1,
.target_set = { 1, 2, 3 },
.cur_set = { 1, 2, 3 },
};
pg.peering_state = ps;
return pg;
}
// S1: tombstone at v2 on all 3 OSDs - fully deleted everywhere = clean, invisible
static void test_clean_tombstone()
{
printf("-- clean_tombstone\n");
pg_peering_state_t *ps = new pg_peering_state_t();
for (osd_num_t osd = 1; osd <= 3; osd++)
ps->list_results[osd] = list_builder().tb(2).result();
pg_t pg = make_pg(ps);
pg.calc_object_states(0);
assert(pg.state & PG_ACTIVE);
assert(!(pg.state & PG_HAS_DEGRADED));
assert(!(pg.state & PG_HAS_UNCLEAN));
assert(pg.total_count == 1);
assert(pg.clean_count == 1);
assert(pg.state_dict.size() == 0);
assert(pg.flush_actions.size() == 0);
assert(pg.ver_override.size() == 0);
}
// S2: tombstone at v2 on OSDs 1,2; old stable data v1 on OSD 3 = incomplete
// deletion: target is the tombstone, object is degraded, OSD 3 copy is outdated
static void test_incomplete_delete()
{
printf("-- incomplete_delete\n");
pg_peering_state_t *ps = new pg_peering_state_t();
ps->list_results[1] = list_builder().tb(2).result();
ps->list_results[2] = list_builder().tb(2).result();
ps->list_results[3] = list_builder().st(1).result();
pg_t pg = make_pg(ps);
pg.calc_object_states(0);
assert(pg.state & PG_ACTIVE);
assert(pg.state & PG_HAS_DEGRADED);
assert(pg.state_dict.size() == 1);
auto & st = pg.state_dict.begin()->second;
assert(st.state & OBJ_DEGRADED);
assert(st.object_count == 1);
// OSDs 1 and 2 hold the target (tombstone), OSD 3 holds an outdated copy
assert(st.osd_set.size() == 3);
assert(st.osd_set[0].osd_num == 1 && !st.osd_set[0].loc_bad);
assert(st.osd_set[1].osd_num == 2 && !st.osd_set[1].loc_bad);
assert(st.osd_set[2].osd_num == 3 && st.osd_set[2].loc_bad == LOC_OUTDATED);
// Nothing unstable - no flush actions, data below the tombstone is swept in phase 2
assert(pg.flush_actions.size() == 0);
assert(pg.ver_override.size() == 0);
assert(pg.degraded_objects.size() == 1);
}
// S3: stable data v2 on OSD 1 conflicts with tombstone v2 - delete wins:
// the data copy is outdated and misplaced, target copies are just the tombstones
static void test_delete_wins_at_same_version()
{
printf("-- delete_wins_at_same_version\n");
pg_peering_state_t *ps = new pg_peering_state_t();
ps->list_results[1] = list_builder().st(2).result();
ps->list_results[2] = list_builder().tb(2).result();
ps->list_results[3] = list_builder().tb(2).result();
pg_t pg = make_pg(ps);
pg.calc_object_states(0);
assert(pg.state & PG_ACTIVE);
assert(pg.state & PG_HAS_MISPLACED);
assert(pg.state_dict.size() == 1);
auto & st = pg.state_dict.begin()->second;
assert(st.state & OBJ_MISPLACED);
// The conflicting data copy must be present as outdated, tombstones as good
int good = 0, outdated = 0;
for (auto & loc: st.osd_set)
{
if (loc.loc_bad & LOC_OUTDATED)
{
outdated++;
assert(loc.osd_num == 1);
}
else
{
good++;
assert(loc.osd_num == 2 || loc.osd_num == 3);
}
}
assert(good == 2 && outdated == 1);
assert(pg.flush_actions.size() == 0);
}
// S4: unstable write v3 raced with a committed tombstone v2 on another OSD:
// target is the tombstone, OSD 2 must be rolled back, the object is unclean+degraded
static void test_unstable_above_tombstone()
{
printf("-- unstable_above_tombstone\n");
pg_peering_state_t *ps = new pg_peering_state_t();
ps->list_results[1] = list_builder().tb(2).result();
ps->list_results[2] = list_builder().un(3).result();
ps->list_results[3] = list_builder().tb(2).result();
pg_t pg = make_pg(ps);
pg.calc_object_states(0);
assert(pg.state & PG_ACTIVE);
assert(pg.state & PG_HAS_UNCLEAN);
assert(pg.state & PG_HAS_DEGRADED);
// OSD 2 has no stable data below v3 - roll it back to 0 (nothing to keep)
assert(pg.flush_actions.size() == 1);
auto & act = pg.flush_actions.begin()->second;
assert(pg.flush_actions.begin()->first.osd_num == 2);
assert(act.rollback && act.rollback_to == 0);
// Reads must not see the unstable v3
assert(pg.ver_override.size() == 1);
assert(pg.ver_override.begin()->second == 2);
}
// S5: a rewrite above a tombstone (v2) cancels the deletion: stable v3 everywhere
// is a normal clean object, the hidden tombstone is not reported by LIST
static void test_rewrite_after_delete()
{
printf("-- rewrite_after_delete\n");
pg_peering_state_t *ps = new pg_peering_state_t();
for (osd_num_t osd = 1; osd <= 3; osd++)
ps->list_results[osd] = list_builder().st(3).result();
pg_t pg = make_pg(ps);
pg.calc_object_states(0);
assert(pg.state & PG_ACTIVE);
assert(!(pg.state & (PG_HAS_DEGRADED | PG_HAS_UNCLEAN | PG_HAS_MISPLACED)));
assert(pg.clean_count == 1);
assert(pg.state_dict.size() == 0);
}
int main(int argc, char *argv[])
{
test_clean_tombstone();
test_incomplete_delete();
test_delete_wins_at_same_version();
test_unstable_above_tombstone();
test_rewrite_after_delete();
printf("OK: %d scenario(s)\n", 5);
return 0;
}

File diff suppressed because it is too large Load Diff