From e5caffb6acbe3436186ea348712c70d77181f7c1 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sun, 10 Nov 2019 13:26:56 +0300 Subject: [PATCH] Allow to read specific versions --- blockstore.cpp | 6 ++---- blockstore.h | 10 +++++----- blockstore_read.cpp | 3 +-- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/blockstore.cpp b/blockstore.cpp index 6c301f0c..a99f1e3b 100644 --- a/blockstore.cpp +++ b/blockstore.cpp @@ -66,8 +66,7 @@ void blockstore::handle_event(ring_data_t *data) else { struct blockstore_operation* op = (struct blockstore_operation*)data->op; - if ((op->flags & OP_TYPE_MASK) == OP_READ_DIRTY || - (op->flags & OP_TYPE_MASK) == OP_READ) + if ((op->flags & OP_TYPE_MASK) == OP_READ) { handle_read_event(data, op); } @@ -145,8 +144,7 @@ void blockstore::loop() unsigned ring_space = io_uring_sq_space_left(ringloop->ring); unsigned prev_sqe_pos = ringloop->ring->sq.sqe_tail; int dequeue_op = 0; - if ((op->flags & OP_TYPE_MASK) == OP_READ_DIRTY || - (op->flags & OP_TYPE_MASK) == OP_READ) + if ((op->flags & OP_TYPE_MASK) == OP_READ) { dequeue_op = dequeue_read(op); } diff --git a/blockstore.h b/blockstore.h index 997b46c1..e8c59564 100644 --- a/blockstore.h +++ b/blockstore.h @@ -171,11 +171,10 @@ public: // In fact, adding a write operation must immediately result in dirty_db being populated #define OP_READ 1 -#define OP_READ_DIRTY 2 -#define OP_WRITE 3 -#define OP_SYNC 4 -#define OP_STABLE 5 -#define OP_DELETE 6 +#define OP_WRITE 2 +#define OP_SYNC 3 +#define OP_STABLE 4 +#define OP_DELETE 5 #define OP_TYPE_MASK 0x7 // Suspend operation until there are more free SQEs @@ -192,6 +191,7 @@ struct blockstore_operation std::function callback; uint32_t flags; object_id oid; + // For reads: version=0 -> last stable, version=UINT64_MAX -> last unstable, version=X -> specific version uint64_t version; uint32_t offset; uint32_t len; diff --git a/blockstore_read.cpp b/blockstore_read.cpp index 3552122a..124f5984 100644 --- a/blockstore_read.cpp +++ b/blockstore_read.cpp @@ -71,7 +71,6 @@ int blockstore::fulfill_read(blockstore_operation *read_op, uint32_t item_start, int blockstore::dequeue_read(blockstore_operation *read_op) { - // FIXME: allow to read specific version auto clean_it = object_db.find(read_op->oid); auto dirty_it = dirty_db.upper_bound((obj_ver_id){ .oid = read_op->oid, @@ -94,7 +93,7 @@ int blockstore::dequeue_read(blockstore_operation *read_op) while (dirty_it->first.oid == read_op->oid) { dirty_entry& dirty = dirty_it->second; - if ((read_op->flags & OP_TYPE_MASK) == OP_READ_DIRTY || IS_STABLE(dirty.state)) + if (IS_STABLE(dirty.state) || read_op->version >= dirty_it->first.version) { if (!fulfill_read(read_op, dirty.offset, dirty.offset + dirty.size, dirty.state, dirty_it->first.version, dirty.location))