Large bucket support admin API Changes (#2372)

This commit is contained in:
Harshavardhana
2018-02-15 18:35:05 -08:00
committed by kannappanr
parent 335a53ad29
commit 97c7984bca
8 changed files with 237 additions and 93 deletions
+6 -6
View File
@@ -32,7 +32,7 @@ func newHRI(i *madmin.HealResultItem) *hri {
// getObjectHCCChange - returns before and after color change for
// objects
func (h hri) getObjectHCCChange() (b, a hCol, err error) {
func (h hri) getObjectHCCChange() (b, a col, err error) {
parityShards := h.ParityBlocks
dataShards := h.DataBlocks
@@ -51,13 +51,13 @@ func (h hri) getObjectHCCChange() (b, a hCol, err error) {
// getReplicatedFileHCCChange - fetches health color code for metadata
// files that are replicated.
func (h hri) getReplicatedFileHCCChange() (b, a hCol, err error) {
getColCode := func(numAvail int) (c hCol, err error) {
func (h hri) getReplicatedFileHCCChange() (b, a col, err error) {
getColCode := func(numAvail int) (c col, err error) {
// calculate color code for replicated object similar
// to erasure coded objects
quorum := h.DiskCount/2 + 1
surplus := numAvail - quorum
parity := h.DiskCount - quorum
quorum := h.DiskCount/h.SetCount/2 + 1
surplus := numAvail/h.SetCount - quorum
parity := h.DiskCount/h.SetCount - quorum
c, err = getHColCode(surplus, parity)
return
}
+45 -56
View File
@@ -34,33 +34,8 @@ const (
lineWidth = 80
)
// An alias of string to represent the health color code of an object
type hCol string
const (
hColGrey hCol = "Grey"
hColRed = "Red"
hColYellow = "Yellow"
hColGreen = "Green"
)
// getHPrintCol - map color code to color for printing
func getHPrintCol(c hCol) *color.Color {
switch c {
case hColGrey:
return color.New(color.FgWhite, color.Bold)
case hColRed:
return color.New(color.FgRed, color.Bold)
case hColYellow:
return color.New(color.FgYellow, color.Bold)
case hColGreen:
return color.New(color.FgGreen, color.Bold)
}
return nil
}
var (
hColOrder = []hCol{hColRed, hColYellow, hColGreen}
hColOrder = []col{colRed, colYellow, colGreen}
hColTable = map[int][]int{
1: {0, -1, 1},
2: {0, 1, 2},
@@ -73,12 +48,12 @@ var (
}
)
func getHColCode(surplusShards, parityShards int) (c hCol, err error) {
func getHColCode(surplusShards, parityShards int) (c col, err error) {
if parityShards < 1 || parityShards > 8 || surplusShards > parityShards {
return c, fmt.Errorf("Invalid parity shard count/surplus shard count given")
}
if surplusShards < 0 {
return hColGrey, err
return colGrey, err
}
colRow := hColTable[parityShards]
for index, val := range colRow {
@@ -115,7 +90,7 @@ type uiData struct {
ObjectsByOnlineDrives map[int]int64
// Map of health color code to number of objects with that
// health color code.
HealthCols map[hCol]int64
HealthCols map[col]int64
// channel to receive a prompt string to indicate activity on
// the terminal
@@ -147,7 +122,7 @@ func (ui *uiData) updateStats(i madmin.HealResultItem) error {
// Fetch health color after heal:
var err error
var afterCol hCol
var afterCol col
h := newHRI(&i)
switch h.Type {
case madmin.HealItemMetadata, madmin.HealItemBucket:
@@ -188,15 +163,15 @@ func (ui *uiData) getProgress() (oCount, objSize, duration string) {
return
}
func (ui *uiData) getPercentsNBars() (p map[hCol]float64, b map[hCol]string) {
func (ui *uiData) getPercentsNBars() (p map[col]float64, b map[col]string) {
// barChar, emptyBarChar := "█", "░"
barChar, emptyBarChar := "█", " "
barLen := 12
sum := float64(ui.ItemsScanned)
cols := []hCol{hColGrey, hColRed, hColYellow, hColGreen}
cols := []col{colGrey, colRed, colYellow, colGreen}
p = make(map[hCol]float64, len(cols))
b = make(map[hCol]string, len(cols))
p = make(map[col]float64, len(cols))
b = make(map[col]string, len(cols))
var filledLen int
for _, col := range cols {
v := float64(ui.HealthCols[col])
@@ -215,17 +190,17 @@ func (ui *uiData) getPercentsNBars() (p map[hCol]float64, b map[hCol]string) {
}
func (ui *uiData) printItemsQuietly(s *madmin.HealTaskStatus) (err error) {
lpad := func(s hCol) string {
lpad := func(s col) string {
return fmt.Sprintf("%-6s", string(s))
}
rpad := func(s hCol) string {
rpad := func(s col) string {
return fmt.Sprintf("%6s", string(s))
}
printColStr := func(before, after hCol) {
printColStr := func(before, after col) {
console.PrintC("[" + lpad(before) + " -> " + rpad(after) + "] ")
}
var b, a hCol
var b, a col
for _, item := range s.Items {
h := newHRI(&item)
switch h.Type {
@@ -265,20 +240,33 @@ func (ui *uiData) printItemsJSON(s *madmin.HealTaskStatus) (err error) {
After string `json:"after"`
}
type healRec struct {
Status string `json:"status"`
Error string `json:"error,omitempty"`
Type string `json:"type"`
Name string `json:"name"`
Health change `json:"health"`
Drives map[string]change `json:"drives"`
Size int64 `json:"size"`
Status string `json:"status"`
Error string `json:"error,omitempty"`
Type string `json:"type"`
Name string `json:"name"`
Before struct {
Color string `json:"color"`
Offline int `json:"offline"`
Online int `json:"online"`
Missing int `json:"missing"`
Corrupted int `json:"corrupted"`
Drives []madmin.HealDriveInfo `json:"drives"`
} `json:"before"`
After struct {
Color string `json:"color"`
Offline int `json:"offline"`
Online int `json:"online"`
Missing int `json:"missing"`
Corrupted int `json:"corrupted"`
Drives []madmin.HealDriveInfo `json:"drives"`
} `json:"after"`
Size int64 `json:"size"`
}
makeHR := func(h *hri) (r healRec, err error) {
r.Status = "success"
r.Type, r.Name = h.getHRTypeAndName()
r.Drives = make(map[string]change)
var b, a hCol
var b, a col
switch h.Type {
case madmin.HealItemMetadata, madmin.HealItemBucket:
b, a, err = h.getReplicatedFileHCCChange()
@@ -291,13 +279,14 @@ func (ui *uiData) printItemsJSON(s *madmin.HealTaskStatus) (err error) {
if err != nil {
return r, err
}
r.Health.Before = strings.ToLower(string(b))
r.Health.After = strings.ToLower(string(a))
for k := range h.DriveInfo.Before {
r.Drives[k] = change{h.DriveInfo.Before[k], h.DriveInfo.After[k]}
}
r.Before.Color = strings.ToLower(string(b))
r.After.Color = strings.ToLower(string(a))
r.Before.Online, r.After.Online = h.GetOnlineCounts()
r.Before.Missing, r.After.Missing = h.GetMissingCounts()
r.Before.Corrupted, r.After.Corrupted = h.GetCorruptedCounts()
r.Before.Offline, r.After.Offline = h.GetOfflineCounts()
r.Before.Drives = h.Before.Drives
r.After.Drives = h.After.Drives
return r, nil
}
@@ -364,10 +353,10 @@ func (ui *uiData) updateUI(s *madmin.HealTaskStatus) (err error) {
console.PrintC(fmt.Sprintf(" %s\n", scannedStr))
console.PrintC(fmt.Sprintf(" %s\n", healedStr))
dspOrder := []hCol{hColGreen, hColYellow, hColRed, hColGrey}
dspOrder := []col{colGreen, colYellow, colRed, colGrey}
printColors := []*color.Color{}
for _, c := range dspOrder {
printColors = append(printColors, getHPrintCol(c))
printColors = append(printColors, getPrintCol(c))
}
t := console.NewTable(printColors, []bool{false, true, true}, 4)
+1 -1
View File
@@ -123,7 +123,7 @@ func mainAdminHeal(ctx *cli.Context) error {
ForceStart: forceStart,
HealOpts: &opts,
ObjectsByOnlineDrives: make(map[int]int64),
HealthCols: make(map[hCol]int64),
HealthCols: make(map[col]int64),
CurChan: cursorAnimate(),
}
errorIf(
+52 -9
View File
@@ -1,5 +1,5 @@
/*
* Minio Client (C) 2016 Minio, Inc.
* Minio Client (C) 2016,2017,2018 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -74,6 +74,17 @@ type xlBackend struct {
Type backendType `json:"backendType"`
OnlineDisks int `json:"onlineDisks"`
OfflineDisks int `json:"offlineDisks"`
// Data disks for currently configured Standard storage class.
StandardSCData int `json:"standardSCData"`
// Parity disks for currently configured Standard storage class.
StandardSCParity int `json:"standardSCParity"`
// Data disks for currently configured Reduced Redundancy storage class.
RRSCData int `json:"rrSCData"`
// Parity disks for currently configured Reduced Redundancy storage class.
RRSCParity int `json:"rrSCParity"`
// List of all disk status.
Sets [][]madmin.DriveInfo `json:"sets"`
}
// backendStatus represents the overall information of all backend storage types
@@ -100,6 +111,31 @@ type infoMessage struct {
*ServerInfo
}
func countOnlineDrives(drives []madmin.DriveInfo) int {
var i = 0
for _, drive := range drives {
if drive.State == madmin.DriveStateOk {
i++
}
}
return i
}
func countMissingDrives(drives []madmin.DriveInfo) int {
var i = 0
for _, drive := range drives {
switch drive.State {
case madmin.DriveStateOffline:
fallthrough
case madmin.DriveStateMissing:
fallthrough
case madmin.DriveStateCorrupt:
i++
}
}
return i
}
// String colorized service status message.
func (u infoMessage) String() (msg string) {
defer func() {
@@ -129,7 +165,8 @@ func (u infoMessage) String() (msg string) {
// Print server information
// Uptime
msg += fmt.Sprintf(" Uptime : %s since %s\n", console.Colorize("Info", "online"), humanize.Time(time.Now().UTC().Add(-u.ServerInfo.Properties.Uptime)))
msg += fmt.Sprintf(" Uptime : %s since %s\n", console.Colorize("Info", "online"),
humanize.Time(time.Now().UTC().Add(-u.ServerInfo.Properties.Uptime)))
// Version
msg += fmt.Sprintf(" Version : %s\n", u.ServerInfo.Properties.Version)
// Region
@@ -144,18 +181,18 @@ func (u infoMessage) String() (msg string) {
}
msg += fmt.Sprintf(" SQS ARNs : %s\n", sqsARNs)
// Incoming/outgoing
msg += fmt.Sprintf(" Network : Incoming %s, Outgoing %s\n",
msg += fmt.Sprintf(" Stats : Incoming %s, Outgoing %s\n",
humanize.IBytes(u.ServerInfo.ConnStats.TotalInputBytes),
humanize.IBytes(u.ServerInfo.ConnStats.TotalOutputBytes))
// Get storage information
msg += fmt.Sprintf(" Storage : Total %s, Free %s",
msg += fmt.Sprintf(" Storage : Total %s, Free %s\n",
humanize.IBytes(uint64(u.StorageInfo.Total)),
humanize.IBytes(uint64(u.StorageInfo.Free)),
)
if v, ok := u.ServerInfo.StorageInfo.Backend.(xlBackend); ok {
msg += fmt.Sprintf(", Online Disks: %d, Offline Disks: %d", v.OnlineDisks, v.OfflineDisks)
msg += fmt.Sprintf(" Disks : %s, %s\n", console.Colorize("Info", v.OnlineDisks),
console.Colorize("InfoFail", v.OfflineDisks))
}
return
}
@@ -180,6 +217,7 @@ func mainAdminInfo(ctx *cli.Context) error {
checkAdminInfoSyntax(ctx)
console.SetColor("Info", color.New(color.FgGreen, color.Bold))
console.SetColor("InfoDegraded", color.New(color.FgYellow, color.Bold))
console.SetColor("InfoFail", color.New(color.FgRed, color.Bold))
// Get the alias parameter from cli
@@ -230,9 +268,14 @@ func mainAdminInfo(ctx *cli.Context) error {
if serverInfo.Data.StorageInfo.Backend.Type == madmin.Erasure {
storageInfo.Backend = xlBackend{
Type: erasureType,
OnlineDisks: serverInfo.Data.StorageInfo.Backend.OnlineDisks,
OfflineDisks: serverInfo.Data.StorageInfo.Backend.OfflineDisks,
Type: erasureType,
OnlineDisks: serverInfo.Data.StorageInfo.Backend.OnlineDisks,
OfflineDisks: serverInfo.Data.StorageInfo.Backend.OfflineDisks,
StandardSCData: serverInfo.Data.StorageInfo.Backend.StandardSCData,
StandardSCParity: serverInfo.Data.StorageInfo.Backend.StandardSCParity,
RRSCData: serverInfo.Data.StorageInfo.Backend.RRSCData,
RRSCParity: serverInfo.Data.StorageInfo.Backend.RRSCParity,
Sets: serverInfo.Data.StorageInfo.Backend.Sets,
}
} else {
storageInfo.Backend = fsBackend{
+44
View File
@@ -0,0 +1,44 @@
/*
* Minio Client (C) 2018 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cmd
import "github.com/fatih/color"
// An alias of string to represent the health color code of an object
type col string
const (
colGrey col = "Grey"
colRed = "Red"
colYellow = "Yellow"
colGreen = "Green"
)
// getPrintCol - map color code to color for printing
func getPrintCol(c col) *color.Color {
switch c {
case colGrey:
return color.New(color.FgWhite, color.Bold)
case colRed:
return color.New(color.FgRed, color.Bold)
case colYellow:
return color.New(color.FgYellow, color.Bold)
case colGreen:
return color.New(color.FgGreen, color.Bold)
}
return nil
}
+77 -18
View File
@@ -1,10 +1,8 @@
/*
* Minio Cloud Storage, (C) 2017 Minio, Inc.
* Minio Cloud Storage, (C) 2017, 2018 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
@@ -75,6 +73,13 @@ const (
DriveStateMissing = "missing"
)
// HealDriveInfo - struct for an individual drive info item.
type HealDriveInfo struct {
UUID string `json:"uuid"`
Endpoint string `json:"endpoint"`
State string `json:"state"`
}
// HealResultItem - struct for an individual heal result item
type HealResultItem struct {
ResultIndex int64 `json:"resultId"`
@@ -85,33 +90,87 @@ type HealResultItem struct {
ParityBlocks int `json:"parityBlocks,omitempty"`
DataBlocks int `json:"dataBlocks,omitempty"`
DiskCount int `json:"diskCount"`
DriveInfo struct {
// below maps are from drive endpoint to drive state
Before map[string]string `json:"before"`
After map[string]string `json:"after"`
} `json:"drives"`
SetCount int `json:"setCount"`
// below slices are from drive info.
Before struct {
Drives []HealDriveInfo `json:"drives"`
} `json:"before"`
After struct {
Drives []HealDriveInfo `json:"drives"`
} `json:"after"`
ObjectSize int64 `json:"objectSize"`
}
// InitDrives - initialize maps used to represent drive info
func (hri *HealResultItem) InitDrives() {
hri.DriveInfo.Before = make(map[string]string)
hri.DriveInfo.After = make(map[string]string)
// GetMissingCounts - returns the number of missing disks before
// and after heal
func (hri *HealResultItem) GetMissingCounts() (b, a int) {
if hri == nil {
return
}
for _, v := range hri.Before.Drives {
if v.State == DriveStateMissing {
b++
}
}
for _, v := range hri.After.Drives {
if v.State == DriveStateMissing {
a++
}
}
return
}
// GetOnlineCounts - returns the number of online disks before and
// after heal
// GetOfflineCounts - returns the number of offline disks before
// and after heal
func (hri *HealResultItem) GetOfflineCounts() (b, a int) {
if hri == nil {
return
}
for _, v := range hri.Before.Drives {
if v.State == DriveStateOffline {
b++
}
}
for _, v := range hri.After.Drives {
if v.State == DriveStateOffline {
a++
}
}
return
}
// GetCorruptedCounts - returns the number of corrupted disks before
// and after heal
func (hri *HealResultItem) GetCorruptedCounts() (b, a int) {
if hri == nil {
return
}
for _, v := range hri.Before.Drives {
if v.State == DriveStateCorrupt {
b++
}
}
for _, v := range hri.After.Drives {
if v.State == DriveStateCorrupt {
a++
}
}
return
}
// GetOnlineCounts - returns the number of online disks before
// and after heal
func (hri *HealResultItem) GetOnlineCounts() (b, a int) {
if hri == nil {
return
}
for _, v := range hri.DriveInfo.Before {
if v == DriveStateOk {
for _, v := range hri.Before.Drives {
if v.State == DriveStateOk {
b++
}
}
for _, v := range hri.DriveInfo.After {
if v == DriveStateOk {
for _, v := range hri.After.Drives {
if v.State == DriveStateOk {
a++
}
}
+9
View File
@@ -38,6 +38,10 @@ const (
// Add your own backend.
)
// DriveInfo - represents each drive info, describing
// status, uuid and endpoint.
type DriveInfo HealDriveInfo
// StorageInfo - represents total capacity of underlying storage.
type StorageInfo struct {
// Total disk space.
@@ -52,8 +56,13 @@ type StorageInfo struct {
// Following fields are only meaningful if BackendType is Erasure.
OnlineDisks int // Online disks during server startup.
OfflineDisks int // Offline disks during server startup.
StandardSCData int // Data disks for currently configured Standard storage class.
StandardSCParity int // Parity disks for currently configured Standard storage class.
RRSCData int // Data disks for currently configured Reduced Redundancy storage class.
RRSCParity int // Parity disks for currently configured Reduced Redundancy storage class.
// List of all disk status, this is only meaningful if BackendType is Erasure.
Sets [][]DriveInfo
}
}
+3 -3
View File
@@ -98,10 +98,10 @@
"revisionTime": "2017-10-28T03:50:25Z"
},
{
"checksumSHA1": "n3+/OaoRx2CGB9ltQhSInfuaS4g=",
"checksumSHA1": "vw2iLuyiXCNSAC9NLRZzvHi8Ii0=",
"path": "github.com/minio/minio/pkg/madmin",
"revision": "5cdcc73bd5c3b3461274e009f435f502988a09f0",
"revisionTime": "2018-01-25T13:54:00Z"
"revision": "fb96779a8a141e1012590841ef2cc7f0e4207eb5",
"revisionTime": "2018-02-16T01:45:57Z"
},
{
"checksumSHA1": "5r3V/rzpVqjJvzE/K5sR2LHEteM=",