1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-15 11:58:11 -05:00
forgejo/vendor/github.com/pingcap/go-themis/themis_secondary_lock.go
Thomas Boerger b6a95a8cb3 Integrate public as bindata optionally (#293)
* Dropped unused codekit config

* Integrated dynamic and static bindata for public

* Ignore public bindata

* Add a general generate make task

* Integrated flexible public assets into web command

* Updated vendoring, added all missiong govendor deps

* Made the linter happy with the bindata and dynamic code

* Moved public bindata definition to modules directory

* Ignoring the new bindata path now

* Updated to the new public modules import path

* Updated public bindata command and drop the new prefix
2016-11-30 00:26:36 +08:00

64 lines
1.4 KiB
Go

package themis
import (
"bytes"
"encoding/binary"
"github.com/juju/errors"
"github.com/ngaut/log"
"github.com/pingcap/go-hbase"
"github.com/pingcap/go-hbase/iohelper"
)
type themisSecondaryLock struct {
*themisLock
primaryCoordinate *hbase.ColumnCoordinate
}
func newThemisSecondaryLock() *themisSecondaryLock {
return &themisSecondaryLock{
themisLock: &themisLock{
clientAddr: "null",
},
primaryCoordinate: &hbase.ColumnCoordinate{},
}
}
func (l *themisSecondaryLock) Primary() Lock {
pl := newThemisPrimaryLock()
pl.coordinate = l.primaryCoordinate
pl.ts = l.ts
pl.clientAddr = l.clientAddr
pl.addSecondary(l.coordinate, l.typ)
return pl
}
func (l *themisSecondaryLock) Secondaries() []Lock {
return nil
}
func (l *themisSecondaryLock) Role() LockRole {
return RoleSecondary
}
func (l *themisSecondaryLock) Encode() []byte {
buf := bytes.NewBuffer(nil)
binary.Write(buf, binary.BigEndian, uint8(0))
l.themisLock.write(buf)
// TODO: handle error, now just log
if err := l.primaryCoordinate.Write(buf); err != nil {
log.Warnf("write error, primary coordinate: %s, buf: %s, err: %v", l, buf, err)
}
return buf.Bytes()
}
func (l *themisSecondaryLock) parse(r iohelper.ByteMultiReader) error {
l.themisLock.parse(r)
primary := &hbase.ColumnCoordinate{}
err := primary.ParseField(r)
if err != nil {
return errors.Trace(err)
}
l.primaryCoordinate = primary
return nil
}