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.
 
 
 
 
 
 

74 lines
2.0 KiB

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