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.
 
 
 
 
 
 

72 lines
2.0 KiB

  1. // Copyright (c) Vitaliy Filippov, 2019+
  2. // License: VNPL-1.0 or GNU GPL-2.0+ (see README.md for details)
  3. #pragma once
  4. #include <stdint.h>
  5. #include <functional>
  6. // 16 bytes per object/stripe id
  7. // stripe = (start of the parity stripe + peer role)
  8. // i.e. for example (256KB + one of 0,1,2)
  9. struct __attribute__((__packed__)) object_id
  10. {
  11. uint64_t inode;
  12. uint64_t stripe;
  13. };
  14. inline bool operator == (const object_id & a, const object_id & b)
  15. {
  16. return a.inode == b.inode && a.stripe == b.stripe;
  17. }
  18. inline bool operator != (const object_id & a, const object_id & b)
  19. {
  20. return a.inode != b.inode || a.stripe != b.stripe;
  21. }
  22. inline bool operator < (const object_id & a, const object_id & b)
  23. {
  24. return a.inode < b.inode || a.inode == b.inode && a.stripe < b.stripe;
  25. }
  26. // 56 = 24 + 32 bytes per dirty entry in memory (obj_ver_id => dirty_entry)
  27. struct __attribute__((__packed__)) obj_ver_id
  28. {
  29. object_id oid;
  30. uint64_t version;
  31. };
  32. inline bool operator < (const obj_ver_id & a, const obj_ver_id & b)
  33. {
  34. return a.oid < b.oid || a.oid == b.oid && a.version < b.version;
  35. }
  36. namespace std
  37. {
  38. template<> struct hash<object_id>
  39. {
  40. inline size_t operator()(const object_id &s) const
  41. {
  42. size_t seed = 0;
  43. // Copy-pasted from spp::hash_combine()
  44. seed ^= (s.inode + 0xc6a4a7935bd1e995 + (seed << 6) + (seed >> 2));
  45. seed ^= (s.stripe + 0xc6a4a7935bd1e995 + (seed << 6) + (seed >> 2));
  46. return seed;
  47. }
  48. };
  49. template<> struct hash<obj_ver_id>
  50. {
  51. inline size_t operator()(const obj_ver_id &s) const
  52. {
  53. size_t seed = 0;
  54. // Copy-pasted from spp::hash_combine()
  55. seed ^= (s.oid.inode + 0xc6a4a7935bd1e995 + (seed << 6) + (seed >> 2));
  56. seed ^= (s.oid.stripe + 0xc6a4a7935bd1e995 + (seed << 6) + (seed >> 2));
  57. seed ^= (s.version + 0xc6a4a7935bd1e995 + (seed << 6) + (seed >> 2));
  58. return seed;
  59. }
  60. };
  61. }