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.
 
 
 
 
 
 

58 lines
1.7 KiB

  1. // Copyright (c) Vitaliy Filippov, 2019+
  2. // License: VNPL-1.0 (see README.md for details)
  3. #define _LARGEFILE64_SOURCE
  4. #include "osd_peering_pg.h"
  5. #define STRIPE_SHIFT 12
  6. /**
  7. * TODO tests for object & pg state calculation.
  8. *
  9. * 1) pg=1,2,3. objects:
  10. * v1=1s,2s,3s -> clean
  11. * v1=1s,2s,3 v2=1s,2s,_ -> degraded + needs_rollback
  12. * v1=1s,2s,_ -> degraded
  13. * v1=1s,2s,3s v2=1,6,_ -> degraded + needs_stabilize
  14. * v1=2s,1s,3s -> misplaced
  15. * v1=4,5,6 -> misplaced + needs_stabilize
  16. * v1=1s,2s,6s -> misplaced
  17. * 2) ...
  18. */
  19. int main(int argc, char *argv[])
  20. {
  21. pg_t pg = {
  22. .state = PG_PEERING,
  23. .pg_num = 1,
  24. .target_set = { 1, 2, 3 },
  25. .cur_set = { 1, 2, 3 },
  26. .peering_state = new pg_peering_state_t(),
  27. };
  28. for (uint64_t osd_num = 1; osd_num <= 3; osd_num++)
  29. {
  30. pg_list_result_t r = {
  31. .buf = (obj_ver_id*)malloc_or_die(sizeof(obj_ver_id) * 1024*1024*8),
  32. .total_count = 1024*1024*8,
  33. .stable_count = (uint64_t)(1024*1024*8 - (osd_num == 1 ? 10 : 0)),
  34. };
  35. for (uint64_t i = 0; i < r.total_count; i++)
  36. {
  37. r.buf[i] = {
  38. .oid = {
  39. .inode = 1,
  40. .stripe = (i << STRIPE_SHIFT) | (osd_num-1),
  41. },
  42. .version = (uint64_t)(osd_num == 1 && i >= r.total_count - 10 ? 2 : 1),
  43. };
  44. }
  45. pg.peering_state->list_results[osd_num] = r;
  46. }
  47. pg.calc_object_states(0);
  48. printf("deviation variants=%ld clean=%lu\n", pg.state_dict.size(), pg.clean_count);
  49. for (auto it: pg.state_dict)
  50. {
  51. printf("dev: state=%lx\n", it.second.state);
  52. }
  53. return 0;
  54. }