mirror of
https://github.com/minio/minio.git
synced 2025-04-20 10:37:31 -04:00
Cleanup and make a safer code (#5794)
This commit is contained in:
parent
76cc65531c
commit
954142a98f
@ -356,6 +356,13 @@ func (a adminAPIHandlers) ListLocksHandler(w http.ResponseWriter, r *http.Reques
|
|||||||
func (a adminAPIHandlers) ClearLocksHandler(w http.ResponseWriter, r *http.Request) {
|
func (a adminAPIHandlers) ClearLocksHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := newContext(r, "ClearLocks")
|
ctx := newContext(r, "ClearLocks")
|
||||||
|
|
||||||
|
// Get object layer instance.
|
||||||
|
objLayer := newObjectLayerFn()
|
||||||
|
if objLayer == nil {
|
||||||
|
writeErrorResponseJSON(w, ErrServerNotInitialized, r.URL)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
adminAPIErr := checkAdminRequestAuthType(r, globalServerConfig.GetRegion())
|
adminAPIErr := checkAdminRequestAuthType(r, globalServerConfig.GetRegion())
|
||||||
if adminAPIErr != ErrNone {
|
if adminAPIErr != ErrNone {
|
||||||
writeErrorResponseJSON(w, adminAPIErr, r.URL)
|
writeErrorResponseJSON(w, adminAPIErr, r.URL)
|
||||||
@ -387,7 +394,7 @@ func (a adminAPIHandlers) ClearLocksHandler(w http.ResponseWriter, r *http.Reque
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
newObjectLayerFn().ClearLocks(ctx, volLocks)
|
objLayer.ClearLocks(ctx, volLocks)
|
||||||
|
|
||||||
// Reply with list of locks cleared, as json.
|
// Reply with list of locks cleared, as json.
|
||||||
writeSuccessResponseJSON(w, jsonBytes)
|
writeSuccessResponseJSON(w, jsonBytes)
|
||||||
@ -561,7 +568,6 @@ func (a adminAPIHandlers) HealHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
// GetConfigHandler - GET /minio/admin/v1/config
|
// GetConfigHandler - GET /minio/admin/v1/config
|
||||||
// Get config.json of this minio setup.
|
// Get config.json of this minio setup.
|
||||||
func (a adminAPIHandlers) GetConfigHandler(w http.ResponseWriter, r *http.Request) {
|
func (a adminAPIHandlers) GetConfigHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// Validate request signature.
|
// Validate request signature.
|
||||||
adminAPIErr := checkAdminRequestAuthType(r, globalServerConfig.GetRegion())
|
adminAPIErr := checkAdminRequestAuthType(r, globalServerConfig.GetRegion())
|
||||||
if adminAPIErr != ErrNone {
|
if adminAPIErr != ErrNone {
|
||||||
@ -569,12 +575,6 @@ func (a adminAPIHandlers) GetConfigHandler(w http.ResponseWriter, r *http.Reques
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if objectLayer is initialized, if not return.
|
|
||||||
if newObjectLayerFn() == nil {
|
|
||||||
writeErrorResponseJSON(w, ErrServerNotInitialized, r.URL)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Take a read lock on minio/config.json. NB minio is a
|
// Take a read lock on minio/config.json. NB minio is a
|
||||||
// reserved bucket name and wouldn't conflict with normal
|
// reserved bucket name and wouldn't conflict with normal
|
||||||
// object operations.
|
// object operations.
|
||||||
|
@ -89,7 +89,12 @@ func (lc localAdminClient) ReInitFormat(dryRun bool) error {
|
|||||||
|
|
||||||
// ListLocks - Fetches lock information from local lock instrumentation.
|
// ListLocks - Fetches lock information from local lock instrumentation.
|
||||||
func (lc localAdminClient) ListLocks(bucket, prefix string, duration time.Duration) ([]VolumeLockInfo, error) {
|
func (lc localAdminClient) ListLocks(bucket, prefix string, duration time.Duration) ([]VolumeLockInfo, error) {
|
||||||
return listLocksInfo(bucket, prefix, duration), nil
|
// check if objectLayer is initialized, if not return.
|
||||||
|
objectAPI := newObjectLayerFn()
|
||||||
|
if objectAPI == nil {
|
||||||
|
return nil, errServerNotInitialized
|
||||||
|
}
|
||||||
|
return objectAPI.ListLocks(context.Background(), bucket, prefix, duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc remoteAdminClient) SignalService(s serviceSignal) (err error) {
|
func (rc remoteAdminClient) SignalService(s serviceSignal) (err error) {
|
||||||
|
@ -102,7 +102,14 @@ func (s *adminCmd) ListLocks(query *ListLocksQuery, reply *ListLocksReply) error
|
|||||||
if err := query.IsAuthenticated(); err != nil {
|
if err := query.IsAuthenticated(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
volLocks := listLocksInfo(query.Bucket, query.Prefix, query.Duration)
|
objectAPI := newObjectLayerFn()
|
||||||
|
if objectAPI == nil {
|
||||||
|
return errServerNotInitialized
|
||||||
|
}
|
||||||
|
volLocks, err := objectAPI.ListLocks(context.Background(), query.Bucket, query.Prefix, query.Duration)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
*reply = ListLocksReply{VolLocks: volLocks}
|
*reply = ListLocksReply{VolLocks: volLocks}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -66,9 +65,3 @@ type OpsLockState struct {
|
|||||||
Status statusType `json:"status"` // Status can be Running/Ready/Blocked.
|
Status statusType `json:"status"` // Status can be Running/Ready/Blocked.
|
||||||
Since time.Time `json:"since"` // Time when the lock was initially held.
|
Since time.Time `json:"since"` // Time when the lock was initially held.
|
||||||
}
|
}
|
||||||
|
|
||||||
// listLocksInfo - Fetches locks held on bucket, matching prefix held for longer than duration.
|
|
||||||
func listLocksInfo(bucket, prefix string, duration time.Duration) []VolumeLockInfo {
|
|
||||||
locksInfo, _ := newObjectLayerFn().ListLocks(context.Background(), bucket, prefix, duration)
|
|
||||||
return locksInfo
|
|
||||||
}
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
@ -99,7 +100,10 @@ func TestListLocksInfo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range testCases {
|
for i, test := range testCases {
|
||||||
actual := listLocksInfo(test.bucket, test.prefix, test.duration)
|
actual, err := objAPI.ListLocks(context.Background(), test.bucket, test.prefix, test.duration)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Test %d - Expected success, got %s", i+1, err)
|
||||||
|
}
|
||||||
if len(actual) != test.numLocks {
|
if len(actual) != test.numLocks {
|
||||||
t.Errorf("Test %d - Expected %d locks but observed %d locks",
|
t.Errorf("Test %d - Expected %d locks but observed %d locks",
|
||||||
i+1, test.numLocks, len(actual))
|
i+1, test.numLocks, len(actual))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user