mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
lock: Fix support single node XL locking as well.
This commit is contained in:
parent
f655592ff5
commit
bca1385683
@ -109,7 +109,7 @@ func (n *nsLockMap) lock(volume, path string, readLock bool) {
|
|||||||
}
|
}
|
||||||
nsLk.ref++ // Update ref count here to avoid multiple races.
|
nsLk.ref++ // Update ref count here to avoid multiple races.
|
||||||
rwlock := nsLk.writer
|
rwlock := nsLk.writer
|
||||||
if readLock {
|
if readLock && n.isDist {
|
||||||
rwlock = dsync.NewDRWMutex(pathutil.Join(volume, path))
|
rwlock = dsync.NewDRWMutex(pathutil.Join(volume, path))
|
||||||
}
|
}
|
||||||
// Unlock map before Locking NS which might block.
|
// Unlock map before Locking NS which might block.
|
||||||
@ -119,16 +119,17 @@ func (n *nsLockMap) lock(volume, path string, readLock bool) {
|
|||||||
if readLock {
|
if readLock {
|
||||||
rwlock.RLock()
|
rwlock.RLock()
|
||||||
|
|
||||||
// Only add (for reader case) to array after RLock() succeeds
|
if n.isDist {
|
||||||
// (so that we know for sure that element in [0] can be RUnlocked())
|
// Only add (for reader case) to array after RLock() succeeds
|
||||||
n.lockMapMutex.Lock()
|
// (so that we know for sure that element in [0] can be RUnlocked())
|
||||||
if len(nsLk.readerArray) == 0 {
|
n.lockMapMutex.Lock()
|
||||||
nsLk.readerArray = []RWLocker{rwlock}
|
if len(nsLk.readerArray) == 0 {
|
||||||
} else {
|
nsLk.readerArray = []RWLocker{rwlock}
|
||||||
nsLk.readerArray = append(nsLk.readerArray, rwlock)
|
} else {
|
||||||
|
nsLk.readerArray = append(nsLk.readerArray, rwlock)
|
||||||
|
}
|
||||||
|
n.lockMapMutex.Unlock()
|
||||||
}
|
}
|
||||||
n.lockMapMutex.Unlock()
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
rwlock.Lock()
|
rwlock.Lock()
|
||||||
}
|
}
|
||||||
@ -143,13 +144,17 @@ func (n *nsLockMap) unlock(volume, path string, readLock bool) {
|
|||||||
param := nsParam{volume, path}
|
param := nsParam{volume, path}
|
||||||
if nsLk, found := n.lockMap[param]; found {
|
if nsLk, found := n.lockMap[param]; found {
|
||||||
if readLock {
|
if readLock {
|
||||||
if len(nsLk.readerArray) == 0 {
|
if n.isDist {
|
||||||
errorIf(errors.New("Length of reader lock array cannot be 0."), "Invalid reader lock array length detected.")
|
if len(nsLk.readerArray) == 0 {
|
||||||
|
errorIf(errors.New("Length of reader lock array cannot be 0."), "Invalid reader lock array length detected.")
|
||||||
|
}
|
||||||
|
// Release first lock first (FIFO)
|
||||||
|
nsLk.readerArray[0].RUnlock()
|
||||||
|
// And discard first element
|
||||||
|
nsLk.readerArray = nsLk.readerArray[1:]
|
||||||
|
} else {
|
||||||
|
nsLk.writer.RUnlock()
|
||||||
}
|
}
|
||||||
// Release first lock first (FIFO)
|
|
||||||
nsLk.readerArray[0].RUnlock()
|
|
||||||
// And discard first element
|
|
||||||
nsLk.readerArray = nsLk.readerArray[1:]
|
|
||||||
} else {
|
} else {
|
||||||
nsLk.writer.Unlock()
|
nsLk.writer.Unlock()
|
||||||
}
|
}
|
||||||
@ -160,7 +165,7 @@ func (n *nsLockMap) unlock(volume, path string, readLock bool) {
|
|||||||
nsLk.ref--
|
nsLk.ref--
|
||||||
}
|
}
|
||||||
if nsLk.ref == 0 {
|
if nsLk.ref == 0 {
|
||||||
if len(nsLk.readerArray) != 0 {
|
if len(nsLk.readerArray) != 0 && n.isDist {
|
||||||
errorIf(errors.New("Length of reader lock array should be 0 upon deleting map entry."), "Invalid reader lock array length detected.")
|
errorIf(errors.New("Length of reader lock array should be 0 upon deleting map entry."), "Invalid reader lock array length detected.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user