Rewrite metadata_init to the same "goto-coroutine" style

blocking-uring-test
Vitaliy Filippov 2019-11-21 21:51:52 +03:00
parent 2b12428cb1
commit 201eeb8516
3 changed files with 57 additions and 47 deletions

View File

@ -8,7 +8,7 @@ journal_flusher_t::journal_flusher_t(int flusher_count, blockstore *bs)
active_until_sync = 0; active_until_sync = 0;
sync_required = true; sync_required = true;
sync_threshold = flusher_count == 1 ? 1 : flusher_count/2; sync_threshold = flusher_count == 1 ? 1 : flusher_count/2;
journal_trim_interval = sync_threshold; journal_trim_interval = 1;//sync_threshold; //FIXME
journal_trim_counter = 0; journal_trim_counter = 0;
journal_superblock = (uint8_t*)memalign(512, 512); journal_superblock = (uint8_t*)memalign(512, 512);
co = new journal_flusher_co[flusher_count]; co = new journal_flusher_co[flusher_count];
@ -42,13 +42,13 @@ journal_flusher_t::~journal_flusher_t()
} }
void journal_flusher_t::loop() void journal_flusher_t::loop()
{
for (int i = 0; i < flusher_count; i++)
{ {
if (!active_flushers && !flush_queue.size()) if (!active_flushers && !flush_queue.size())
{ {
return; return;
} }
for (int i = 0; i < flusher_count; i++)
{
co[i].loop(); co[i].loop();
} }
} }

View File

@ -22,24 +22,27 @@ void blockstore_init_meta::handle_event(ring_data_t *data)
int blockstore_init_meta::loop() int blockstore_init_meta::loop()
{ {
if (metadata_read >= bs->meta_len) if (wait_state == 1)
{ goto resume_1;
return 0;
}
if (!metadata_buffer)
{
metadata_buffer = (uint8_t*)memalign(512, 2*bs->metadata_buf_size); metadata_buffer = (uint8_t*)memalign(512, 2*bs->metadata_buf_size);
if (!metadata_buffer) if (!metadata_buffer)
throw std::bad_alloc(); throw std::bad_alloc();
} while (1)
if (!submitted)
{ {
struct io_uring_sqe *sqe = bs->get_sqe(); resume_1:
if (submitted)
{
wait_state = 1;
return 1;
}
if (metadata_read < bs->meta_len)
{
sqe = bs->get_sqe();
if (!sqe) if (!sqe)
{ {
throw std::runtime_error("io_uring is full while trying to read metadata"); throw std::runtime_error("io_uring is full while trying to read metadata");
} }
struct ring_data_t *data = ((ring_data_t*)sqe->user_data); data = ((ring_data_t*)sqe->user_data);
data->iov = { data->iov = {
metadata_buffer + (prev == 1 ? bs->metadata_buf_size : 0), metadata_buffer + (prev == 1 ? bs->metadata_buf_size : 0),
bs->meta_len - metadata_read > bs->metadata_buf_size ? bs->metadata_buf_size : bs->meta_len - metadata_read, bs->meta_len - metadata_read > bs->metadata_buf_size ? bs->metadata_buf_size : bs->meta_len - metadata_read,
@ -63,15 +66,17 @@ int blockstore_init_meta::loop()
prev_done = 0; prev_done = 0;
done_len = 0; done_len = 0;
} }
if (metadata_read >= bs->meta_len) if (!submitted)
{ {
break;
}
}
// metadata read finished // metadata read finished
printf("Metadata entries loaded: %d\n", entries_loaded);
free(metadata_buffer); free(metadata_buffer);
metadata_buffer = NULL; metadata_buffer = NULL;
return 0; return 0;
} }
return 1;
}
void blockstore_init_meta::handle_entries(struct clean_disk_entry* entries, int count, int block_order) void blockstore_init_meta::handle_entries(struct clean_disk_entry* entries, int count, int block_order)
{ {
@ -83,6 +88,7 @@ void blockstore_init_meta::handle_entries(struct clean_disk_entry* entries, int
auto clean_it = bs->clean_db.find(entries[i].oid); auto clean_it = bs->clean_db.find(entries[i].oid);
if (clean_it == end || clean_it->second.version < entries[i].version) if (clean_it == end || clean_it->second.version < entries[i].version)
{ {
entries_loaded++;
if (clean_it != end) if (clean_it != end)
{ {
// free the previous block // free the previous block

View File

@ -3,9 +3,13 @@
class blockstore_init_meta class blockstore_init_meta
{ {
blockstore *bs; blockstore *bs;
int wait_state = 0, wait_count = 0;
uint8_t *metadata_buffer = NULL; uint8_t *metadata_buffer = NULL;
uint64_t metadata_read = 0; uint64_t metadata_read = 0;
int prev = 0, prev_done = 0, done_len = 0, submitted = 0, done_cnt = 0; int prev = 0, prev_done = 0, done_len = 0, submitted = 0, done_cnt = 0;
int entries_loaded = 0;
struct io_uring_sqe *sqe;
struct ring_data_t *data;
void handle_entries(struct clean_disk_entry* entries, int count, int block_order); void handle_entries(struct clean_disk_entry* entries, int count, int block_order);
void handle_event(ring_data_t *data); void handle_event(ring_data_t *data);
public: public: