github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/pingcap/go-themis/lock.go (about)

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