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. package themis
  2. import "github.com/pingcap/go-hbase"
  3. // LockRole is the role of lock
  4. type LockRole int
  5. func (l LockRole) String() string {
  6. if l == RolePrimary {
  7. return "primary"
  8. }
  9. return "secondary"
  10. }
  11. const (
  12. // RolePrimary means this row is primary
  13. RolePrimary LockRole = iota
  14. // RoleSecondary means this row is secondary
  15. RoleSecondary
  16. )
  17. type Lock interface {
  18. // SetCoordinate sets lock's coordinate
  19. SetCoordinate(c *hbase.ColumnCoordinate)
  20. // Coordinate returns the lock's coordinate
  21. Coordinate() *hbase.ColumnCoordinate
  22. // Timestamp returns startTs of the transction which owned this lock
  23. Timestamp() uint64
  24. // SetExpired sets the lock's expired status.
  25. SetExpired(b bool)
  26. // IsExpired returns if lock is expired.
  27. IsExpired() bool
  28. // Type returns the lock's type, Put or Delete
  29. Type() hbase.Type
  30. // Role returns LockRole, primary or secondary
  31. Role() LockRole
  32. // not used now
  33. Context() interface{}
  34. // valid only Role == Primary
  35. Secondaries() []Lock
  36. // Primary returns the primary lock of this lock
  37. Primary() Lock
  38. // Encode encodes the lock to byte slice
  39. Encode() []byte
  40. }
  41. type LockManager interface {
  42. // CleanLock if clean lock success, first return value is transction's commit
  43. // timestamp, otherwise, the second return value is transction's primary
  44. // lock.
  45. CleanLock(c *hbase.ColumnCoordinate, prewriteTs uint64) (uint64, Lock, error)
  46. // EraseLockAndData removes lock and data.
  47. EraseLockAndData(c *hbase.ColumnCoordinate, prewriteTs uint64) error
  48. // GetCommitTimestamp returns a committed transction's commit timestamp.
  49. GetCommitTimestamp(c *hbase.ColumnCoordinate, prewriteTs uint64) (uint64, error)
  50. // [startTs, endTs]
  51. IsLockExists(c *hbase.ColumnCoordinate, startTs, endTs uint64) (bool, error)
  52. }