store.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package model
  2. // zookeeper save the store meta data.
  3. //
  4. // /rack -- rack root path
  5. // |
  6. // /rack-a -------- --------- /rack-b -- rack node path
  7. // |
  8. // /store-a -------- /store-b -- store node path (data: {"stat":"localhost:6061","admin":"localhost:6063","api":"localhost:6062","status":0})
  9. // | |
  10. // /volume-1 - - /volume-4 volume node path (data: /tmp/block_1,/tmp/block_1.idx,1)
  11. // /volume-2 - - /volume-5
  12. // /volume-3 - - /volume-6
  13. // Store status const.
  14. const (
  15. // bit
  16. StoreStatusEnableBit = 31
  17. StoreStatusReadBit = 0
  18. StoreStatusWriteBit = 1
  19. StoreStatusSyncBit = 2
  20. // status
  21. StoreStatusInit = 0 // 0
  22. StoreStatusEnable = (1 << StoreStatusEnableBit) // 2147483648
  23. StoreStatusRead = StoreStatusEnable | (1 << StoreStatusReadBit) // 2147483649
  24. StoreStatusWrite = StoreStatusEnable | (1 << StoreStatusWriteBit) // 2147483650
  25. StoreStatusHealth = StoreStatusRead | StoreStatusWrite // 2147483651
  26. StoreStatusSync = StoreStatusEnable | (1 << StoreStatusSyncBit) // 2147483652
  27. StoreStatusFail = StoreStatusEnable // 2147483648
  28. )
  29. // Rack get all store and volume.
  30. type Rack struct {
  31. Stores map[string]*Store `json:"stores"`
  32. }
  33. // Store meta data.
  34. type Store struct {
  35. Stat string `json:"stat"`
  36. Admin string `json:"admin"`
  37. API string `json:"api"`
  38. ID string `json:"id"`
  39. Rack string `json:"rack"`
  40. Status int `json:"status"`
  41. States struct {
  42. Init bool `json:"init"`
  43. Enable bool `json:"enable"`
  44. Read bool `json:"read"`
  45. Write bool `json:"write"`
  46. Sync bool `json:"sync"`
  47. Fail bool `json:"fail"`
  48. } `json:"states"`
  49. Volumes []string `json:"volumes"`
  50. }
  51. // ParseStates parse states.
  52. func (s *Store) ParseStates() {
  53. s.States.Init = s.Status == StoreStatusInit
  54. s.States.Enable = s.Status&StoreStatusEnable == StoreStatusEnable
  55. s.States.Read = s.Status&StoreStatusRead == StoreStatusRead
  56. s.States.Write = s.Status&StoreStatusWrite == StoreStatusWrite
  57. s.States.Sync = s.Status&StoreStatusSync == StoreStatusSync
  58. s.States.Fail = s.Status == StoreStatusFail
  59. }