|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* MinIO Cloud Storage, (C) 2016-2019 MinIO, Inc. |
|
|
|
* MinIO Cloud Storage, (C) 2016-2020 MinIO, Inc. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
@ -328,7 +328,7 @@ func (a adminAPIHandlers) DataUsageInfoHandler(w http.ResponseWriter, r *http.Re |
|
|
|
writeSuccessResponseJSON(w, dataUsageInfoJSON) |
|
|
|
writeSuccessResponseJSON(w, dataUsageInfoJSON) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func newLockEntry(l lockRequesterInfo, resource, server string) *madmin.LockEntry { |
|
|
|
func lriToLockEntry(l lockRequesterInfo, resource, server string) *madmin.LockEntry { |
|
|
|
entry := &madmin.LockEntry{ |
|
|
|
entry := &madmin.LockEntry{ |
|
|
|
Timestamp: l.Timestamp, |
|
|
|
Timestamp: l.Timestamp, |
|
|
|
Resource: resource, |
|
|
|
Resource: resource, |
|
|
@ -337,14 +337,14 @@ func newLockEntry(l lockRequesterInfo, resource, server string) *madmin.LockEntr |
|
|
|
ID: l.UID, |
|
|
|
ID: l.UID, |
|
|
|
} |
|
|
|
} |
|
|
|
if l.Writer { |
|
|
|
if l.Writer { |
|
|
|
entry.Type = "Write" |
|
|
|
entry.Type = "WRITE" |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
entry.Type = "Read" |
|
|
|
entry.Type = "READ" |
|
|
|
} |
|
|
|
} |
|
|
|
return entry |
|
|
|
return entry |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func topLockEntries(peerLocks []*PeerLocks) madmin.LockEntries { |
|
|
|
func topLockEntries(peerLocks []*PeerLocks, count int) madmin.LockEntries { |
|
|
|
entryMap := make(map[string]*madmin.LockEntry) |
|
|
|
entryMap := make(map[string]*madmin.LockEntry) |
|
|
|
for _, peerLock := range peerLocks { |
|
|
|
for _, peerLock := range peerLocks { |
|
|
|
if peerLock == nil { |
|
|
|
if peerLock == nil { |
|
|
@ -356,20 +356,19 @@ func topLockEntries(peerLocks []*PeerLocks) madmin.LockEntries { |
|
|
|
if val, ok := entryMap[lockReqInfo.UID]; ok { |
|
|
|
if val, ok := entryMap[lockReqInfo.UID]; ok { |
|
|
|
val.ServerList = append(val.ServerList, peerLock.Addr) |
|
|
|
val.ServerList = append(val.ServerList, peerLock.Addr) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
entryMap[lockReqInfo.UID] = newLockEntry(lockReqInfo, k, peerLock.Addr) |
|
|
|
entryMap[lockReqInfo.UID] = lriToLockEntry(lockReqInfo, k, peerLock.Addr) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
var lockEntries = make(madmin.LockEntries, 0) |
|
|
|
var lockEntries = make(madmin.LockEntries, 0, len(entryMap)) |
|
|
|
for _, v := range entryMap { |
|
|
|
for _, v := range entryMap { |
|
|
|
lockEntries = append(lockEntries, *v) |
|
|
|
lockEntries = append(lockEntries, *v) |
|
|
|
} |
|
|
|
} |
|
|
|
sort.Sort(lockEntries) |
|
|
|
sort.Sort(lockEntries) |
|
|
|
const listCount int = 10 |
|
|
|
if len(lockEntries) > count { |
|
|
|
if len(lockEntries) > listCount { |
|
|
|
lockEntries = lockEntries[:count] |
|
|
|
lockEntries = lockEntries[:listCount] |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return lockEntries |
|
|
|
return lockEntries |
|
|
|
} |
|
|
|
} |
|
|
@ -391,6 +390,16 @@ func (a adminAPIHandlers) TopLocksHandler(w http.ResponseWriter, r *http.Request |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
count := 10 // by default list only top 10 entries
|
|
|
|
|
|
|
|
if countStr := r.URL.Query().Get("count"); countStr != "" { |
|
|
|
|
|
|
|
var err error |
|
|
|
|
|
|
|
count, err = strconv.Atoi(countStr) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
peerLocks := globalNotificationSys.GetLocks(ctx) |
|
|
|
peerLocks := globalNotificationSys.GetLocks(ctx) |
|
|
|
// Once we have received all the locks currently used from peers
|
|
|
|
// Once we have received all the locks currently used from peers
|
|
|
|
// add the local peer locks list as well.
|
|
|
|
// add the local peer locks list as well.
|
|
|
@ -398,12 +407,13 @@ func (a adminAPIHandlers) TopLocksHandler(w http.ResponseWriter, r *http.Request |
|
|
|
for _, llocker := range globalLockServers { |
|
|
|
for _, llocker := range globalLockServers { |
|
|
|
getRespLocks = append(getRespLocks, llocker.DupLockMap()) |
|
|
|
getRespLocks = append(getRespLocks, llocker.DupLockMap()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
peerLocks = append(peerLocks, &PeerLocks{ |
|
|
|
peerLocks = append(peerLocks, &PeerLocks{ |
|
|
|
Addr: getHostName(r), |
|
|
|
Addr: getHostName(r), |
|
|
|
Locks: getRespLocks, |
|
|
|
Locks: getRespLocks, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
topLocks := topLockEntries(peerLocks) |
|
|
|
topLocks := topLockEntries(peerLocks, count) |
|
|
|
|
|
|
|
|
|
|
|
// Marshal API response
|
|
|
|
// Marshal API response
|
|
|
|
jsonBytes, err := json.Marshal(topLocks) |
|
|
|
jsonBytes, err := json.Marshal(topLocks) |
|
|
|