-
Notifications
You must be signed in to change notification settings - Fork 1
Implements lock watching and lock pouncing #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
322c112
5edcfd1
8930600
c65adc7
0dae8af
ea80df4
3975b10
38e3514
52b008f
7d05753
35be35b
ed46006
5056971
45c6b67
c4169b1
a6b1173
7891b60
3b9edcf
f88a078
64e2cd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,35 @@ | ||
| github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= | ||
| github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= | ||
| github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
| 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/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc= | ||
| github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= | ||
| github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= | ||
| github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= | ||
| github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= | ||
| github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= | ||
| github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= | ||
| github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | ||
| github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
| github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
| github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= | ||
| github.com/rs/zerolog v1.19.0 h1:hYz4ZVdUgjXTBUmrkrw55j1nHx68LfOKIQk5IYtyScg= | ||
| github.com/rs/zerolog v1.19.0/go.mod h1:IzD0RJ65iWH0w97OQQebJEvTZYvsCUm9WVLWBQrJRjo= | ||
| github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= | ||
| github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
| github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= | ||
| github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
| golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||
| golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= | ||
| golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
| golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
| golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||
| golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= | ||
| golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
| gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= | ||
| gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
| gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= | ||
| gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| for i in {1..10} | ||
SUMUKHA-PK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| do | ||
| go test -race -run TestLockService >> logs | ||
| done | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,18 @@ import "github.com/SystemBuilders/LocKey/internal/lockservice" | |
|
|
||
| // Client describes a client that can be used to interact with | ||
| // the Lockey lockservice. The client can start the lockservice | ||
| // and interact acquire and release locks by making calls to it. | ||
| // and interact by making calls to it. | ||
| // | ||
| // The client has the ability to start the lockservice from its | ||
| // in-built function or it can be started separately. | ||
| // | ||
| // The client offers the user to Acquire a lock, Release a lock, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does ' the client offers the functional of Acquiring and Releasing an object using its descriptor' sound better?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ill go with |
||
| // and Watch or Pounce on any object using it's descriptor. | ||
SUMUKHA-PK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // | ||
| // To acquire a lock on an object, the user is forced to go via | ||
SUMUKHA-PK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // the Pounce function in order to maintain the order of lock | ||
| // acquisition. The Acquire function that is exposed must cleverly | ||
| // handle this problem. | ||
| type Client interface { | ||
| // StartService starts the lockservice Lockey using the given | ||
| // configuration. It provides an appropriate error on failing | ||
|
|
@@ -19,6 +30,22 @@ type Client interface { | |
| // implementation interacts with the underlying server and | ||
| // provides the service. | ||
| Release(lockservice.Descriptors) error | ||
| // Watch can be used to watch the state of lock on a descriptor | ||
| // continously. When the state of the lock changes, the "watcher" | ||
| // will be notified about the change. | ||
| // The channel passed as the argument can be used to stop watching | ||
| // at any point of time. | ||
| watch(lockservice.ObjectDescriptor, chan struct{}) (chan Lock, error) | ||
SUMUKHA-PK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Pounce can be used to "pounce" on a lock that has already been | ||
| // acquired. This is similar to acquire but once a process has | ||
| // opted to pounce, they will be provided first access by having | ||
| // a queue of pouncers. | ||
| // The second, third and fourth arguments dictate the end of the pouncing | ||
| // reign, the owner willing to pounce and allows pouncing on pre-pounced | ||
| // objects respectively. True bool allows pouncing on pre-pounced objects. | ||
| pounce(lockservice.ObjectDescriptor, string, chan struct{}, bool) error | ||
| // Pouncers returns the current pouncers on any particular lock. | ||
| pouncers(lockservice.ObjectDescriptor) []string | ||
| } | ||
|
|
||
| // Config describes the configuration for the lockservice to run on. | ||
|
|
@@ -28,3 +55,18 @@ type Config interface { | |
| // Port provides the port where the server is supposed to run. | ||
| Port() string | ||
| } | ||
|
|
||
| // State describes the state of a lock. | ||
| type State int | ||
|
|
||
| // These are the states of a lock. | ||
| const ( | ||
| acquire State = iota | ||
| Release | ||
| ) | ||
|
|
||
| // Lock includes the state of the lock and the owner. | ||
| type Lock struct { | ||
| Owner string | ||
| LockState State | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specify that the owner of the item is being returned by the function
Currently, it says 'GetElement gets an element from the cache'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we shouldnt be so blunt about it being the
owner, it can technically be anything in the future. Ill mention, it returns associated data will be returned along with an error.