forked from vitalif/vitastor
Add simplified interface to read blockstore bitmaps synchronously
parent
2c2f08aca2
commit
f01eea07d3
|
@ -38,6 +38,11 @@ void blockstore_t::enqueue_op(blockstore_op_t *op)
|
|||
impl->enqueue_op(op);
|
||||
}
|
||||
|
||||
int blockstore_t::read_bitmap(object_id oid, uint64_t target_version, void *bitmap, uint64_t *result_version)
|
||||
{
|
||||
return impl->read_bitmap(oid, target_version, bitmap, result_version);
|
||||
}
|
||||
|
||||
std::unordered_map<object_id, uint64_t> & blockstore_t::get_unstable_writes()
|
||||
{
|
||||
return impl->unstable_writes;
|
||||
|
|
|
@ -179,6 +179,9 @@ public:
|
|||
// Submission
|
||||
void enqueue_op(blockstore_op_t *op);
|
||||
|
||||
// Simplified synchronous operation: get object bitmap & current version
|
||||
int read_bitmap(object_id oid, uint64_t target_version, void *bitmap, uint64_t *result_version = NULL);
|
||||
|
||||
// Unstable writes are added here (map of object_id -> version)
|
||||
std::unordered_map<object_id, uint64_t> & get_unstable_writes();
|
||||
|
||||
|
|
|
@ -324,6 +324,9 @@ public:
|
|||
// Submission
|
||||
void enqueue_op(blockstore_op_t *op);
|
||||
|
||||
// Simplified synchronous operation: get object bitmap & current version
|
||||
int read_bitmap(object_id oid, uint64_t target_version, void *bitmap, uint64_t *result_version = NULL);
|
||||
|
||||
// Unstable writes are added here (map of object_id -> version)
|
||||
std::unordered_map<object_id, uint64_t> unstable_writes;
|
||||
|
||||
|
|
|
@ -268,3 +268,50 @@ void blockstore_impl_t::handle_read_event(ring_data_t *data, blockstore_op_t *op
|
|||
FINISH_OP(op);
|
||||
}
|
||||
}
|
||||
|
||||
int blockstore_impl_t::read_bitmap(object_id oid, uint64_t target_version, void *bitmap, uint64_t *result_version)
|
||||
{
|
||||
auto dirty_it = dirty_db.upper_bound((obj_ver_id){
|
||||
.oid = oid,
|
||||
.version = UINT64_MAX,
|
||||
});
|
||||
if (dirty_it != dirty_db.begin())
|
||||
dirty_it--;
|
||||
if (dirty_it != dirty_db.end())
|
||||
{
|
||||
while (dirty_it->first.oid == oid)
|
||||
{
|
||||
if (target_version >= dirty_it->first.version)
|
||||
{
|
||||
if (result_version)
|
||||
*result_version = dirty_it->first.version;
|
||||
if (bitmap)
|
||||
{
|
||||
void *bmp_ptr = (clean_entry_bitmap_size > sizeof(void*) ? dirty_it->second.bitmap : &dirty_it->second.bitmap);
|
||||
memcpy(bitmap, bmp_ptr, clean_entry_bitmap_size);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (dirty_it == dirty_db.begin())
|
||||
break;
|
||||
dirty_it--;
|
||||
}
|
||||
}
|
||||
auto clean_it = clean_db.find(oid);
|
||||
if (clean_it != clean_db.end())
|
||||
{
|
||||
if (result_version)
|
||||
*result_version = clean_it->second.version;
|
||||
if (bitmap)
|
||||
{
|
||||
void *bmp_ptr = get_clean_entry_bitmap(clean_it->second.location, clean_entry_bitmap_size);
|
||||
memcpy(bitmap, bmp_ptr, clean_entry_bitmap_size);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (result_version)
|
||||
*result_version = 0;
|
||||
if (bitmap)
|
||||
memset(bitmap, 0, clean_entry_bitmap_size);
|
||||
return -ENOENT;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue