Skip to content

Commit

Permalink
Merge pull request #3 from storage-lock/dev
Browse files Browse the repository at this point in the history
refactor
  • Loading branch information
CC11001100 committed Aug 13, 2023
2 parents ce520ab + ec99fee commit 4db648a
Show file tree
Hide file tree
Showing 14 changed files with 968 additions and 583 deletions.
63 changes: 53 additions & 10 deletions actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,70 @@ const (
ActionGetLockInformationError = "get-lock-information-error"
ActionTimeout = "timeout"
ActionSleepRetry = "sleep-retry"
ActionSleep = "Sleep"
ActionGetLeaseExpireTimeError = "getLeaseExpireTime-error"
)

// 获取锁
const (
ActionLockSuccess = "lock-success"
ActionLockError = "lock-error"
ActionLockBegin = "StorageLock.Lock.Begin"
ActionLockFinish = "StorageLock.Lock.Finish"
ActionLockSuccess = "StorageLock.Lock.Begin.Success"
ActionLockError = "StorageLock.Lock.Begin.Error"

ActionTryLockBegin = "StorageLock.Lock.Try.Begin"

ActionLockExists = "StorageLock.Lock.Exists"
ActionLockNotExists = "StorageLock.Lock.NotExists"
ActionLockReleased = "StorageLock.Lock.Released"
ActionLockExpired = "StorageLock.Lock.Expired"
ActionLockReentry = "StorageLock.Lock.Reentry"

ActionLockBusy = "StorageLock.Lock.Begin.Busy"
ActionLockVersionMiss = "StorageLock.Lock.VersionMiss"

ActionLockRollback = "StorageLock.Lock.Rollback"
ActionLockRollbackSuccess = "StorageLock.Lock.Rollback.Success"
ActionLockRollbackError = "StorageLock.Lock.Rollback.Error"
)

// 释放锁
const (
ActionUnlockSuccess = "unlock-success"
ActionUnlockError = "unlock-error"
ActionUnlock = "StorageLock.Unlock"
ActionUnlockFinish = "StorageLock.Unlock.Finish"
ActionUnlockSuccess = "StorageLock.Unlock.Success"
ActionUnlockError = "StorageLock.Unlock.Error"

ActionUnlockRelease = "StorageLock.Unlock.Release"
ActionUnlockReentry = "StorageLock.Unlock.Reentry"

ActionUnlockVersionMiss = "StorageLock.Unlock.VersionMiss"
)

// 看门狗
// 看门狗相关的事件
const (
ActionWatchDogRefreshLease = "refresh-lease"
ActionWatchDogCreate = "watch-dog-create"
ActionWatchDogStop = "watch-dog-stop"
ActionWatchDogStart = "watch-dog-start"
)
ActionWatchDogRefresh = "WatchDog.Refresh"
ActionWatchDogRefreshBegin = "WatchDog.Refresh.Begin"
ActionWatchDogRefreshSuccess = "WatchDog.Refresh.Success"

ActionWatchDogCreate = "WatchDog.Create"
ActionWatchDogCreateSuccess = "WatchDog.Create.Success"
ActionWatchDogCreateError = "WatchDog.Create.Error"

ActionWatchDogStart = "WatchDog.Start"
ActionWatchDogStartSuccess = "WatchDog.Start.Success"
ActionWatchDogStartError = "WatchDog.Start.Error"

ActionWatchDogStop = "WatchDog.Stop"
ActionWatchDogStopSuccess = "WatchDog.Stop.success"
ActionWatchDogStopError = "WatchDog.Stop.error"

ActionWatchDogExit = "WatchDog.Exit"
ActionWatchDogExitByTooManyError = "WatchDog.Exit.TooManyError"
)

const (
PayloadLastVersion = "lastVersion"
PayloadVersionMissCount = "versionMissCount"
PayloadSleep = "sleep"
)
8 changes: 6 additions & 2 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import "errors"

// ErrLockIdEmpty 参数相关的参数检查
var (
ErrLockIdEmpty = errors.New("lock id can not empty")
ErrLeaseExpireAfter = errors.New("LeaseExpireAfter must > time.Second * 3 ")
ErrLockIdEmpty = errors.New("lock id can not empty")
ErrLeaseExpireAfter = errors.New("LeaseExpireAfter must > time.Second * 3 ")
ErrLeaseRefreshInterval = errors.New("LeaseRefreshInterval must < ErrLeaseExpireAfter ")
)

var (

// ErrLockFailed 尝试加锁失败
ErrLockFailed = errors.New("lock failed")

// ErrLockBusy 锁在被其它人持有着
ErrLockBusy = errors.New("lock busy")

// ErrLockAlreadyExists 锁已经存在,无法继续进行给定操作
ErrLockAlreadyExists = errors.New("lock already exists")

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ go 1.19

require (
github.com/golang-infrastructure/go-goroutine-id v0.0.0-20230331174358-98b48a64077b
github.com/storage-lock/go-events v0.0.1
github.com/storage-lock/go-events v0.0.3
github.com/storage-lock/go-storage v0.0.2
github.com/storage-lock/go-storage-events v0.0.2
github.com/storage-lock/go-storage-events v0.0.5
github.com/storage-lock/go-utils v0.0.2
github.com/stretchr/testify v1.8.4
)
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,20 @@ github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjR
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/storage-lock/go-events v0.0.1 h1:8abGhlhmJGzn8Pq/LjAbPfAyGs70ZNjwoc7/OITMmUg=
github.com/storage-lock/go-events v0.0.1/go.mod h1:DKwPgfuq8T8CyPLipH+0XHsNt8hEN4g9krUGfosU2oY=
github.com/storage-lock/go-events v0.0.2 h1:e5zZ5oP3ErSZWJfwIoMwfmV3/PbKQzHg/gvCg3NmSts=
github.com/storage-lock/go-events v0.0.2/go.mod h1:DKwPgfuq8T8CyPLipH+0XHsNt8hEN4g9krUGfosU2oY=
github.com/storage-lock/go-events v0.0.3 h1:QuNbaREe5m1WYC0meKs7SRJ5lY11a18jCJJS/mGD3SA=
github.com/storage-lock/go-events v0.0.3/go.mod h1:DKwPgfuq8T8CyPLipH+0XHsNt8hEN4g9krUGfosU2oY=
github.com/storage-lock/go-storage v0.0.2 h1:N5glUlrr1bbJ8ixYsPmOv+TuhIOObX/65+hrNMPWFDc=
github.com/storage-lock/go-storage v0.0.2/go.mod h1:4vuU2nLdbmzj2UIBKpwB5lj8RI+GnPDZ4YHZ7QAcFHE=
github.com/storage-lock/go-storage-events v0.0.2 h1:gXGiltZvRzZOXsjqhlyessa+Zpk4qI2kjyRGAGsknwM=
github.com/storage-lock/go-storage-events v0.0.2/go.mod h1:+8kr/WdyaVUJiCqi2MKZkWxeIF8DmhTm+s0OkE+XKaw=
github.com/storage-lock/go-storage-events v0.0.3 h1:b7zbhBs3c555ZMBo/fRzZdEITIr+noOvbc41lLSlxkI=
github.com/storage-lock/go-storage-events v0.0.3/go.mod h1:aBMVsOSr61+BLxO3QnU5FwKd5bdMGE4IpV0oDrAg8uQ=
github.com/storage-lock/go-storage-events v0.0.4 h1:w5RpBxXxRNhaDr+3hVhS+W81qmCxtUyK0SAjd7qicg8=
github.com/storage-lock/go-storage-events v0.0.4/go.mod h1:aBMVsOSr61+BLxO3QnU5FwKd5bdMGE4IpV0oDrAg8uQ=
github.com/storage-lock/go-storage-events v0.0.5 h1:qUgB/VZIQNM0PIos67T9D1JIqu3Yiu3+YDpuHEal3FI=
github.com/storage-lock/go-storage-events v0.0.5/go.mod h1:aBMVsOSr61+BLxO3QnU5FwKd5bdMGE4IpV0oDrAg8uQ=
github.com/storage-lock/go-utils v0.0.2 h1:pdacTOlD+AHqwWVmDqZLcjKF+7p8TjsmlvZ9bmmkIfE=
github.com/storage-lock/go-utils v0.0.2/go.mod h1:tx8ATHL7yOC0Nyjpba7hJNk0+QNt2XEnMr8NcGm9Gak=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
Expand Down
159 changes: 0 additions & 159 deletions lease_refresh_goroutine.go

This file was deleted.

Loading

0 comments on commit 4db648a

Please sign in to comment.