Simplified distributed block storage with strong consistency, like in Ceph
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

112 lines
2.7 KiB

  1. // Copyright (c) Vitaliy Filippov, 2019+
  2. // License: VNPL-1.0 (see README.md for details)
  3. struct copy_buffer_t
  4. {
  5. uint64_t offset, len;
  6. void *buf;
  7. };
  8. struct meta_sector_t
  9. {
  10. uint64_t offset, len;
  11. int state;
  12. void *buf;
  13. int usage_count;
  14. };
  15. struct flusher_sync_t
  16. {
  17. bool fsync_meta;
  18. int ready_count;
  19. int state;
  20. };
  21. struct flusher_meta_write_t
  22. {
  23. uint64_t sector, pos;
  24. bool submitted;
  25. void *buf;
  26. std::map<uint64_t, meta_sector_t>::iterator it;
  27. };
  28. class journal_flusher_t;
  29. // Journal flusher coroutine
  30. class journal_flusher_co
  31. {
  32. blockstore_impl_t *bs;
  33. journal_flusher_t *flusher;
  34. int wait_state, wait_count;
  35. struct io_uring_sqe *sqe;
  36. struct ring_data_t *data;
  37. std::list<flusher_sync_t>::iterator cur_sync;
  38. obj_ver_id cur;
  39. std::map<obj_ver_id, dirty_entry>::iterator dirty_it, dirty_start, dirty_end;
  40. std::map<object_id, uint64_t>::iterator repeat_it;
  41. std::function<void(ring_data_t*)> simple_callback_r, simple_callback_w;
  42. bool skip_copy, has_delete, has_writes;
  43. blockstore_clean_db_t::iterator clean_it;
  44. std::vector<copy_buffer_t> v;
  45. std::vector<copy_buffer_t>::iterator it;
  46. int copy_count;
  47. uint64_t clean_loc, old_clean_loc;
  48. flusher_meta_write_t meta_old, meta_new;
  49. bool clean_init_bitmap;
  50. uint64_t clean_bitmap_offset, clean_bitmap_len;
  51. void *new_clean_bitmap;
  52. uint64_t new_trim_pos;
  53. // local: scan_dirty()
  54. uint64_t offset, end_offset, submit_offset, submit_len;
  55. friend class journal_flusher_t;
  56. bool scan_dirty(int wait_base);
  57. bool modify_meta_read(uint64_t meta_loc, flusher_meta_write_t &wr, int wait_base);
  58. void update_clean_db();
  59. bool fsync_batch(bool fsync_meta, int wait_base);
  60. public:
  61. journal_flusher_co();
  62. bool loop();
  63. };
  64. // Journal flusher itself
  65. class journal_flusher_t
  66. {
  67. int trim_wanted = 0;
  68. bool dequeuing;
  69. int flusher_count;
  70. int flusher_start_threshold;
  71. journal_flusher_co *co;
  72. blockstore_impl_t *bs;
  73. friend class journal_flusher_co;
  74. int journal_trim_counter, journal_trim_interval;
  75. bool trimming;
  76. void* journal_superblock;
  77. int active_flushers;
  78. int syncing_flushers;
  79. std::list<flusher_sync_t> syncs;
  80. std::map<object_id, uint64_t> sync_to_repeat;
  81. std::map<uint64_t, meta_sector_t> meta_sectors;
  82. std::deque<object_id> flush_queue;
  83. std::map<object_id, uint64_t> flush_versions;
  84. public:
  85. journal_flusher_t(int flusher_count, blockstore_impl_t *bs);
  86. ~journal_flusher_t();
  87. void loop();
  88. bool is_active();
  89. void mark_trim_possible();
  90. void request_trim();
  91. void release_trim();
  92. void enqueue_flush(obj_ver_id oid);
  93. void unshift_flush(obj_ver_id oid, bool force);
  94. void remove_flush(object_id oid);
  95. };