Skip to content

Commit

Permalink
feat: goroutine id upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
CC11001100 committed Sep 23, 2023
1 parent 09ea8ff commit dae4b33
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/storage-lock/go-storage-lock
go 1.19

require (
github.com/golang-infrastructure/go-goroutine-id v0.0.0-20230331174358-98b48a64077b
github.com/golang-infrastructure/go-goroutine-id v0.0.0-20230917075314-f1af231c0b06
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.5
Expand All @@ -16,7 +16,7 @@ require (
github.com/golang-infrastructure/go-iterator v0.0.0-20230524171120-56988a9b127c // indirect
github.com/golang-infrastructure/go-pointer v0.0.5 // indirect
github.com/golang-infrastructure/go-reflect-utils v0.0.0-20221130143747-965ef2eb09c3 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang-infrastructure/go-goroutine-id v0.0.0-20230331174358-98b48a64077b h1:kt3zNiijgkfPm47YaL4MaQJkw0T7ukEEttnCQMOcWxo=
github.com/golang-infrastructure/go-goroutine-id v0.0.0-20230331174358-98b48a64077b/go.mod h1:1L+eneS0HXUlZP0tmESGhlmpJ3hl063JGz6UQaJCmY0=
github.com/golang-infrastructure/go-goroutine-id v0.0.0-20230917075314-f1af231c0b06 h1:A28MrYe3pSClGhMVyTQF6wd3h3Tt/U31nddoK60+HZQ=
github.com/golang-infrastructure/go-goroutine-id v0.0.0-20230917075314-f1af231c0b06/go.mod h1:1L+eneS0HXUlZP0tmESGhlmpJ3hl063JGz6UQaJCmY0=
github.com/golang-infrastructure/go-iterator v0.0.0-20230524171120-56988a9b127c h1:h4321AFRVv5rTKcColUjE5pa+Y1exG1e6aEXn43L/Eg=
github.com/golang-infrastructure/go-iterator v0.0.0-20230524171120-56988a9b127c/go.mod h1:Guf14ZZ7f7qiE0YpZbUkICcm7LWc3nrn3/gDObT//WI=
github.com/golang-infrastructure/go-pointer v0.0.5 h1:wzZ/XnXKzD3DWECTnUpUh+xAlGSWqfn/pQyusPNsqrQ=
Expand All @@ -11,6 +13,8 @@ github.com/golang-infrastructure/go-reflect-utils v0.0.0-20221130143747-965ef2eb
github.com/golang-infrastructure/go-reflect-utils v0.0.0-20221130143747-965ef2eb09c3/go.mod h1:zqXYxqOBa1mL2ilBK6PuH/Wb/Iego7en6XhiKWdZQHI=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
Expand Down
2 changes: 1 addition & 1 deletion owner_id_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewOwnerIdGenerator() *OwnerIdGenerator {
func (x *OwnerIdGenerator) GenOwnerId() string {
// 这里为了可读性并没有将区分度最高的UUID放在前面,这是假设使用此分布式锁的各个竞争者的Hostname基本都不会相同
// 因为是同一台机器上使用分布式锁不是很有意义
return fmt.Sprintf("%s-%s-%s", x.defaultLockPrefix, goroutine_id.GetGoroutineIDAsString(), utils.RandomID())
return fmt.Sprintf("%s-%s-%s", x.defaultLockPrefix, goroutine_id.GetGoroutineIdAsString(), utils.RandomID())
}

// 获取当前机器的Hostname作为唯一ID的前缀
Expand Down

0 comments on commit dae4b33

Please sign in to comment.