mirror of
https://github.com/minio/minio.git
synced 2025-11-09 05:34:56 -05:00
unify single-node and distributed namespace locking (#2401)
This commit is contained in:
committed by
Harshavardhana
parent
b7c169d71d
commit
b0f3f94163
17
vendor/github.com/minio/dsync/dmutex.go
generated
vendored
17
vendor/github.com/minio/dsync/dmutex.go
generated
vendored
@@ -35,7 +35,6 @@ type DMutex struct {
|
||||
m sync.Mutex // Mutex to prevent multiple simultaneous locks from this node
|
||||
|
||||
// TODO: Decide: create per object or create once for whole class
|
||||
clnts []*rpc.Client
|
||||
}
|
||||
|
||||
type Granted struct {
|
||||
@@ -45,13 +44,13 @@ type Granted struct {
|
||||
}
|
||||
|
||||
func connectLazy(dm *DMutex) {
|
||||
if dm.clnts == nil {
|
||||
dm.clnts = make([]*rpc.Client, n)
|
||||
if clnts == nil {
|
||||
clnts = make([]*rpc.Client, n)
|
||||
}
|
||||
for i := range dm.clnts {
|
||||
if dm.clnts[i] == nil {
|
||||
for i := range clnts {
|
||||
if clnts[i] == nil {
|
||||
// pass in unique path (as required by server.HandleHTTP()
|
||||
dm.clnts[i], _ = rpc.DialHTTPPath("tcp", nodes[i], rpcPaths[i])
|
||||
clnts[i], _ = rpc.DialHTTPPath("tcp", nodes[i], rpcPaths[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,7 +77,7 @@ func (dm *DMutex) Lock() {
|
||||
ids := make([]string, n)
|
||||
|
||||
// try to acquire the lock
|
||||
success := lock(dm.clnts, &locks, &ids, dm.Name)
|
||||
success := lock(clnts, &locks, &ids, dm.Name)
|
||||
if success {
|
||||
// if success, copy array to object
|
||||
dm.locks = make([]bool, n)
|
||||
@@ -118,7 +117,7 @@ func (dm *DMutex) tryLockTimeout() bool {
|
||||
ids := make([]string, n)
|
||||
|
||||
// try to acquire the lock
|
||||
success := lock(dm.clnts, &locks, &ids, dm.Name)
|
||||
success := lock(clnts, &locks, &ids, dm.Name)
|
||||
if success {
|
||||
// if success, copy array to object
|
||||
dm.locks = make([]bool, n)
|
||||
@@ -286,7 +285,7 @@ func (dm *DMutex) Unlock() {
|
||||
// We don't need to wait until we have released all the locks (or the quorum)
|
||||
// (a subsequent lock will retry automatically in case it would fail to get
|
||||
// quorum)
|
||||
for index, c := range dm.clnts {
|
||||
for index, c := range clnts {
|
||||
|
||||
if dm.locks[index] {
|
||||
// broadcast lock release to all nodes the granted the lock
|
||||
|
||||
1
vendor/github.com/minio/dsync/dsync.go
generated
vendored
1
vendor/github.com/minio/dsync/dsync.go
generated
vendored
@@ -29,6 +29,7 @@ const DefaultPath = "/rpc/dsync"
|
||||
var n int
|
||||
var nodes []string
|
||||
var rpcPaths []string
|
||||
var clnts []*rpc.Client
|
||||
|
||||
func closeClients(clients []*rpc.Client) {
|
||||
for _, clnt := range clients {
|
||||
|
||||
Reference in New Issue
Block a user