diff --git a/blockstore.cpp b/blockstore.cpp index a99f1e3b..487a5c68 100644 --- a/blockstore.cpp +++ b/blockstore.cpp @@ -256,39 +256,7 @@ int blockstore::enqueue_op(blockstore_operation *op) submit_queue.push_back(op); if ((op->flags & OP_TYPE_MASK) == OP_WRITE) { - // Assign version number - auto dirty_it = dirty_db.upper_bound((obj_ver_id){ - .oid = op->oid, - .version = UINT64_MAX, - }); - dirty_it--; - if (dirty_it != dirty_db.end() && dirty_it->first.oid == op->oid) - { - op->version = dirty_it->first.version + 1; - } - else - { - auto clean_it = object_db.find(op->oid); - if (clean_it != object_db.end()) - { - op->version = clean_it->second.version + 1; - } - else - { - op->version = 1; - } - } - // Immediately add the operation into dirty_db, so subsequent reads could see it - dirty_db.emplace((obj_ver_id){ - .oid = op->oid, - .version = op->version, - }, (dirty_entry){ - .state = ST_IN_FLIGHT, - .flags = 0, - .location = 0, - .offset = op->offset, - .size = op->len, - }); + enqueue_write(op); } return 0; } diff --git a/blockstore.h b/blockstore.h index e8c59564..04a40d1d 100644 --- a/blockstore.h +++ b/blockstore.h @@ -277,6 +277,7 @@ class blockstore void handle_read_event(ring_data_t *data, blockstore_operation *op); // Write + void enqueue_write(blockstore_operation *op); int dequeue_write(blockstore_operation *op); void handle_write_event(ring_data_t *data, blockstore_operation *op); diff --git a/blockstore_write.cpp b/blockstore_write.cpp index e4fb4b36..119c484a 100644 --- a/blockstore_write.cpp +++ b/blockstore_write.cpp @@ -1,5 +1,42 @@ #include "blockstore.h" +void blockstore::enqueue_write(blockstore_operation *op) +{ + // Assign version number + auto dirty_it = dirty_db.upper_bound((obj_ver_id){ + .oid = op->oid, + .version = UINT64_MAX, + }); + dirty_it--; + if (dirty_it != dirty_db.end() && dirty_it->first.oid == op->oid) + { + op->version = dirty_it->first.version + 1; + } + else + { + auto clean_it = object_db.find(op->oid); + if (clean_it != object_db.end()) + { + op->version = clean_it->second.version + 1; + } + else + { + op->version = 1; + } + } + // Immediately add the operation into dirty_db, so subsequent reads could see it + dirty_db.emplace((obj_ver_id){ + .oid = op->oid, + .version = op->version, + }, (dirty_entry){ + .state = ST_IN_FLIGHT, + .flags = 0, + .location = 0, + .offset = op->offset, + .size = op->len, + }); +} + // First step of the write algorithm: dequeue operation and submit initial write(s) int blockstore::dequeue_write(blockstore_operation *op) {