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.
 
 
 
 
 
 

59 lines
1.7 KiB

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