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.

themis_secondary_lock.go 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package themis
  2. import (
  3. "bytes"
  4. "encoding/binary"
  5. "github.com/juju/errors"
  6. "github.com/ngaut/log"
  7. "github.com/pingcap/go-hbase"
  8. "github.com/pingcap/go-hbase/iohelper"
  9. )
  10. type themisSecondaryLock struct {
  11. *themisLock
  12. primaryCoordinate *hbase.ColumnCoordinate
  13. }
  14. func newThemisSecondaryLock() *themisSecondaryLock {
  15. return &themisSecondaryLock{
  16. themisLock: &themisLock{
  17. clientAddr: "null",
  18. },
  19. primaryCoordinate: &hbase.ColumnCoordinate{},
  20. }
  21. }
  22. func (l *themisSecondaryLock) Primary() Lock {
  23. pl := newThemisPrimaryLock()
  24. pl.coordinate = l.primaryCoordinate
  25. pl.ts = l.ts
  26. pl.clientAddr = l.clientAddr
  27. pl.addSecondary(l.coordinate, l.typ)
  28. return pl
  29. }
  30. func (l *themisSecondaryLock) Secondaries() []Lock {
  31. return nil
  32. }
  33. func (l *themisSecondaryLock) Role() LockRole {
  34. return RoleSecondary
  35. }
  36. func (l *themisSecondaryLock) Encode() []byte {
  37. buf := bytes.NewBuffer(nil)
  38. binary.Write(buf, binary.BigEndian, uint8(0))
  39. l.themisLock.write(buf)
  40. // TODO: handle error, now just log
  41. if err := l.primaryCoordinate.Write(buf); err != nil {
  42. log.Warnf("write error, primary coordinate: %s, buf: %s, err: %v", l, buf, err)
  43. }
  44. return buf.Bytes()
  45. }
  46. func (l *themisSecondaryLock) parse(r iohelper.ByteMultiReader) error {
  47. l.themisLock.parse(r)
  48. primary := &hbase.ColumnCoordinate{}
  49. err := primary.ParseField(r)
  50. if err != nil {
  51. return errors.Trace(err)
  52. }
  53. l.primaryCoordinate = primary
  54. return nil
  55. }