2020-09-17 23:02:40 +03:00
|
|
|
// Copyright (c) Vitaliy Filippov, 2019+
|
2021-02-06 01:26:07 +03:00
|
|
|
// License: VNPL-1.1 (see README.md for details)
|
2020-09-17 23:02:40 +03:00
|
|
|
|
2019-11-13 17:45:37 +03:00
|
|
|
struct copy_buffer_t
|
|
|
|
{
|
|
|
|
uint64_t offset, len;
|
|
|
|
void *buf;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct meta_sector_t
|
|
|
|
{
|
|
|
|
uint64_t offset, len;
|
|
|
|
int state;
|
|
|
|
void *buf;
|
|
|
|
int usage_count;
|
|
|
|
};
|
|
|
|
|
2019-11-14 02:29:34 +03:00
|
|
|
struct flusher_sync_t
|
|
|
|
{
|
2019-12-02 23:16:19 +03:00
|
|
|
bool fsync_meta;
|
2019-11-14 02:29:34 +03:00
|
|
|
int ready_count;
|
|
|
|
int state;
|
|
|
|
};
|
|
|
|
|
2019-12-02 02:11:23 +03:00
|
|
|
struct flusher_meta_write_t
|
|
|
|
{
|
|
|
|
uint64_t sector, pos;
|
|
|
|
bool submitted;
|
2019-12-02 02:44:56 +03:00
|
|
|
void *buf;
|
2019-12-02 02:11:23 +03:00
|
|
|
std::map<uint64_t, meta_sector_t>::iterator it;
|
|
|
|
};
|
|
|
|
|
2019-11-13 17:45:37 +03:00
|
|
|
class journal_flusher_t;
|
|
|
|
|
|
|
|
// Journal flusher coroutine
|
2019-11-14 02:29:34 +03:00
|
|
|
class journal_flusher_co
|
2019-11-13 17:45:37 +03:00
|
|
|
{
|
2019-12-15 14:49:10 +03:00
|
|
|
blockstore_impl_t *bs;
|
2019-11-13 17:45:37 +03:00
|
|
|
journal_flusher_t *flusher;
|
|
|
|
int wait_state, wait_count;
|
|
|
|
struct io_uring_sqe *sqe;
|
|
|
|
struct ring_data_t *data;
|
2020-01-12 02:11:09 +03:00
|
|
|
|
|
|
|
std::list<flusher_sync_t>::iterator cur_sync;
|
|
|
|
|
2019-11-13 17:45:37 +03:00
|
|
|
obj_ver_id cur;
|
2020-01-24 20:10:18 +03:00
|
|
|
std::map<obj_ver_id, dirty_entry>::iterator dirty_it, dirty_start, dirty_end;
|
2020-01-12 02:11:09 +03:00
|
|
|
std::map<object_id, uint64_t>::iterator repeat_it;
|
|
|
|
std::function<void(ring_data_t*)> simple_callback_r, simple_callback_w;
|
|
|
|
|
2020-06-02 14:02:39 +03:00
|
|
|
bool skip_copy, has_delete, has_writes;
|
2020-03-04 17:12:27 +03:00
|
|
|
blockstore_clean_db_t::iterator clean_it;
|
2019-11-13 17:45:37 +03:00
|
|
|
std::vector<copy_buffer_t> v;
|
|
|
|
std::vector<copy_buffer_t>::iterator it;
|
2019-11-28 14:41:03 +03:00
|
|
|
int copy_count;
|
2020-01-12 02:11:09 +03:00
|
|
|
uint64_t clean_loc, old_clean_loc;
|
2019-12-02 02:11:23 +03:00
|
|
|
flusher_meta_write_t meta_old, meta_new;
|
2020-01-12 02:11:09 +03:00
|
|
|
bool clean_init_bitmap;
|
|
|
|
uint64_t clean_bitmap_offset, clean_bitmap_len;
|
|
|
|
void *new_clean_bitmap;
|
|
|
|
|
2020-10-24 00:27:03 +03:00
|
|
|
uint64_t new_trim_pos;
|
|
|
|
|
2020-01-12 02:11:09 +03:00
|
|
|
// local: scan_dirty()
|
|
|
|
uint64_t offset, end_offset, submit_offset, submit_len;
|
|
|
|
|
2019-11-13 17:45:37 +03:00
|
|
|
friend class journal_flusher_t;
|
2020-01-12 02:11:09 +03:00
|
|
|
bool scan_dirty(int wait_base);
|
2019-12-02 02:11:23 +03:00
|
|
|
bool modify_meta_read(uint64_t meta_loc, flusher_meta_write_t &wr, int wait_base);
|
|
|
|
void update_clean_db();
|
2019-12-02 23:16:19 +03:00
|
|
|
bool fsync_batch(bool fsync_meta, int wait_base);
|
2019-11-13 17:45:37 +03:00
|
|
|
public:
|
2019-11-14 02:29:34 +03:00
|
|
|
journal_flusher_co();
|
2019-12-02 02:11:23 +03:00
|
|
|
bool loop();
|
2019-11-13 17:45:37 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Journal flusher itself
|
|
|
|
class journal_flusher_t
|
|
|
|
{
|
2020-06-01 16:12:26 +03:00
|
|
|
int trim_wanted = 0;
|
2020-03-07 17:36:58 +03:00
|
|
|
bool dequeuing;
|
2021-03-24 01:58:33 +03:00
|
|
|
int min_flusher_count, max_flusher_count, cur_flusher_count, target_flusher_count;
|
2020-06-01 16:12:26 +03:00
|
|
|
int flusher_start_threshold;
|
2019-11-13 17:45:37 +03:00
|
|
|
journal_flusher_co *co;
|
2019-12-15 14:49:10 +03:00
|
|
|
blockstore_impl_t *bs;
|
2019-11-13 17:45:37 +03:00
|
|
|
friend class journal_flusher_co;
|
2019-11-14 02:29:34 +03:00
|
|
|
|
2019-11-15 14:09:41 +03:00
|
|
|
int journal_trim_counter, journal_trim_interval;
|
2020-10-24 00:27:03 +03:00
|
|
|
bool trimming;
|
2019-11-28 14:41:03 +03:00
|
|
|
void* journal_superblock;
|
2019-11-15 14:09:41 +03:00
|
|
|
|
2019-12-02 23:16:19 +03:00
|
|
|
int active_flushers;
|
2020-03-09 00:35:54 +03:00
|
|
|
int syncing_flushers;
|
2019-11-14 02:29:34 +03:00
|
|
|
std::list<flusher_sync_t> syncs;
|
2019-11-15 13:58:35 +03:00
|
|
|
std::map<object_id, uint64_t> sync_to_repeat;
|
|
|
|
|
2019-11-13 17:45:37 +03:00
|
|
|
std::map<uint64_t, meta_sector_t> meta_sectors;
|
2019-11-15 13:58:35 +03:00
|
|
|
std::deque<object_id> flush_queue;
|
|
|
|
std::map<object_id, uint64_t> flush_versions;
|
2021-07-17 16:13:41 +03:00
|
|
|
|
|
|
|
bool try_find_older(std::map<obj_ver_id, dirty_entry>::iterator & dirty_end, obj_ver_id & cur);
|
|
|
|
|
2019-11-15 13:58:35 +03:00
|
|
|
public:
|
2021-03-24 01:58:33 +03:00
|
|
|
journal_flusher_t(blockstore_impl_t *bs);
|
2019-11-13 17:45:37 +03:00
|
|
|
~journal_flusher_t();
|
|
|
|
void loop();
|
2019-11-25 01:29:07 +03:00
|
|
|
bool is_active();
|
2020-10-24 00:52:21 +03:00
|
|
|
void mark_trim_possible();
|
2020-06-01 16:12:26 +03:00
|
|
|
void request_trim();
|
|
|
|
void release_trim();
|
2019-11-28 00:26:53 +03:00
|
|
|
void enqueue_flush(obj_ver_id oid);
|
2020-12-04 19:31:33 +03:00
|
|
|
void unshift_flush(obj_ver_id oid, bool force);
|
|
|
|
void remove_flush(object_id oid);
|
2021-07-17 16:13:41 +03:00
|
|
|
void dump_diagnostics();
|
2019-11-13 17:45:37 +03:00
|
|
|
};
|