Use endpoint url when printing disks status in distributed mode (#3151)

master
Anis Elleuch 8 years ago committed by Harshavardhana
parent 226a69fe15
commit 79601d27f2
  1. 4
      cmd/fs-v1_test.go
  2. 39
      cmd/prepare-storage-msg.go
  3. 30
      cmd/prepare-storage-msg_test.go
  4. 18
      cmd/prepare-storage.go
  5. 2
      cmd/server-main.go
  6. 2
      cmd/test-utils_test.go
  7. 4
      cmd/xl-v1_test.go

@ -61,7 +61,7 @@ func TestNewFS(t *testing.T) {
}
// Initializes all disks with XL
err = waitForFormatDisks(true, endpoints[0], xlStorageDisks)
err = waitForFormatDisks(true, endpoints, xlStorageDisks)
if err != nil {
t.Fatalf("Unable to format XL %s", err)
}
@ -79,7 +79,7 @@ func TestNewFS(t *testing.T) {
}
for _, testCase := range testCases {
if err = waitForFormatDisks(true, endpoints[0], []StorageAPI{testCase.disk}); err != testCase.expectedErr {
if err = waitForFormatDisks(true, endpoints, []StorageAPI{testCase.disk}); err != testCase.expectedErr {
t.Errorf("expected: %s, got :%s", testCase.expectedErr, err)
}
}

@ -18,6 +18,7 @@ package cmd
import (
"fmt"
"net/url"
"sync"
humanize "github.com/dustin/go-humanize"
@ -85,14 +86,14 @@ func getHealMsg(firstEndpoint string, storageDisks []StorageAPI) string {
}
// Prints regular message when we have sufficient disks to start the cluster.
func printRegularMsg(storageDisks []StorageAPI, fn printOnceFunc) {
msg := getRegularMsg(storageDisks)
func printRegularMsg(endpoints []*url.URL, storageDisks []StorageAPI, fn printOnceFunc) {
msg := getStorageInitMsg("\nInitializing data volume.", endpoints, storageDisks)
fn(msg)
}
// Constructs a formatted regular message when we have sufficient disks to start the cluster.
func getRegularMsg(storageDisks []StorageAPI) string {
msg := colorBlue("\nInitializing data volume.")
func getStorageInitMsg(titleMsg string, endpoints []*url.URL, storageDisks []StorageAPI) string {
msg := colorBlue(titleMsg)
disksInfo, _, _ := getDisksInfo(storageDisks)
for i, info := range disksInfo {
if storageDisks[i] == nil {
@ -101,7 +102,7 @@ func getRegularMsg(storageDisks []StorageAPI) string {
msg += fmt.Sprintf(
"\n[%s] %s - %s %s",
int2Str(i+1, len(storageDisks)),
storageDisks[i],
endpoints[i],
humanize.IBytes(uint64(info.Total)),
func() string {
if info.Total > 0 {
@ -115,35 +116,11 @@ func getRegularMsg(storageDisks []StorageAPI) string {
}
// Prints initialization message when cluster is being initialized for the first time.
func printFormatMsg(storageDisks []StorageAPI, fn printOnceFunc) {
msg := getFormatMsg(storageDisks)
func printFormatMsg(endpoints []*url.URL, storageDisks []StorageAPI, fn printOnceFunc) {
msg := getStorageInitMsg("\nInitializing data volume for the first time.", endpoints, storageDisks)
fn(msg)
}
// Generate a formatted message when cluster is being initialized for the first time.
func getFormatMsg(storageDisks []StorageAPI) string {
msg := colorBlue("\nInitializing data volume for the first time.")
disksInfo, _, _ := getDisksInfo(storageDisks)
for i, info := range disksInfo {
if storageDisks[i] == nil {
continue
}
msg += fmt.Sprintf(
"\n[%s] %s - %s %s",
int2Str(i+1, len(storageDisks)),
storageDisks[i],
humanize.IBytes(uint64(info.Total)),
func() string {
if info.Total > 0 {
return "online"
}
return "offline"
}(),
)
}
return msg
}
func printConfigErrMsg(storageDisks []StorageAPI, sErrs []error, fn printOnceFunc) {
msg := getConfigErrMsg(storageDisks, sErrs)
fn(msg)

@ -16,7 +16,10 @@
package cmd
import "testing"
import (
"net/url"
"testing"
)
// Tests heal message to be correct and properly formatted.
func TestHealMsg(t *testing.T) {
@ -32,43 +35,48 @@ func TestHealMsg(t *testing.T) {
nilDisks[5] = nil
authErrs := make([]error, len(storageDisks))
authErrs[5] = errAuthentication
endpointURL, err := url.Parse("http://10.1.10.1:9000")
if err != nil {
t.Fatal("Unexpected error:", err)
}
endpointURLs := make([]*url.URL, len(storageDisks))
for idx := 0; idx < len(endpointURLs); idx++ {
endpointURLs[idx] = endpointURL
}
testCases := []struct {
endPoint string
endPoints []*url.URL
storageDisks []StorageAPI
serrs []error
}{
// Test - 1 for valid disks and errors.
{
endPoint: "http://10.1.10.1:9000",
endPoints: endpointURLs,
storageDisks: storageDisks,
serrs: errs,
},
// Test - 2 for one of the disks is nil.
{
endPoint: "http://10.1.10.1:9000",
endPoints: endpointURLs,
storageDisks: nilDisks,
serrs: errs,
},
// Test - 3 for one of the errs is authentication.
{
endPoint: "http://10.1.10.1:9000",
endPoints: endpointURLs,
storageDisks: nilDisks,
serrs: authErrs,
},
}
for i, testCase := range testCases {
msg := getHealMsg(testCase.endPoint, testCase.storageDisks)
msg := getHealMsg(testCase.endPoints[0].String(), testCase.storageDisks)
if msg == "" {
t.Fatalf("Test: %d Unable to get heal message.", i+1)
}
msg = getRegularMsg(testCase.storageDisks)
msg = getStorageInitMsg("init", testCase.endPoints, testCase.storageDisks)
if msg == "" {
t.Fatalf("Test: %d Unable to get regular message.", i+1)
}
msg = getFormatMsg(testCase.storageDisks)
if msg == "" {
t.Fatalf("Test: %d Unable to get format message.", i+1)
}
msg = getConfigErrMsg(testCase.storageDisks, testCase.serrs)
if msg == "" {
t.Fatalf("Test: %d Unable to get config error message.", i+1)

@ -185,7 +185,11 @@ func prepForInitXL(firstDisk bool, sErrs []error, diskCount int) InitActions {
// Implements a jitter backoff loop for formatting all disks during
// initialization of the server.
func retryFormattingDisks(firstDisk bool, firstEndpoint *url.URL, storageDisks []StorageAPI) error {
func retryFormattingDisks(firstDisk bool, endpoints []*url.URL, storageDisks []StorageAPI) error {
if len(endpoints) == 0 {
return errInvalidArgument
}
firstEndpoint := endpoints[0]
if firstEndpoint == nil {
return errInvalidArgument
}
@ -217,14 +221,14 @@ func retryFormattingDisks(firstDisk bool, firstEndpoint *url.URL, storageDisks [
return errCorruptedFormat
case FormatDisks:
console.Eraseline()
printFormatMsg(storageDisks, printOnceFn())
printFormatMsg(endpoints, storageDisks, printOnceFn())
return initFormatXL(storageDisks)
case InitObjectLayer:
console.Eraseline()
// Validate formats load before proceeding forward.
err := genericFormatCheck(formatConfigs, sErrs)
if err == nil {
printRegularMsg(storageDisks, printOnceFn())
printRegularMsg(endpoints, storageDisks, printOnceFn())
}
return err
case WaitForHeal:
@ -303,7 +307,11 @@ func initStorageDisks(endpoints, ignoredEndpoints []*url.URL) ([]StorageAPI, err
}
// Format disks before initialization object layer.
func waitForFormatDisks(firstDisk bool, firstEndpoint *url.URL, storageDisks []StorageAPI) (err error) {
func waitForFormatDisks(firstDisk bool, endpoints []*url.URL, storageDisks []StorageAPI) (err error) {
if len(endpoints) == 0 {
return errInvalidArgument
}
firstEndpoint := endpoints[0]
if firstEndpoint == nil {
return errInvalidArgument
}
@ -312,7 +320,7 @@ func waitForFormatDisks(firstDisk bool, firstEndpoint *url.URL, storageDisks []S
}
// Start retry loop retrying until disks are formatted properly, until we have reached
// a conditional quorum of formatted disks.
err = retryFormattingDisks(firstDisk, firstEndpoint, storageDisks)
err = retryFormattingDisks(firstDisk, endpoints, storageDisks)
if err != nil {
return err
}

@ -474,7 +474,7 @@ func serverMain(c *cli.Context) {
}(tls)
// Wait for formatting of disks.
err = waitForFormatDisks(firstDisk, endpoints[0], storageDisks)
err = waitForFormatDisks(firstDisk, endpoints, storageDisks)
fatalIf(err, "formatting storage disks failed")
// Once formatted, initialize object layer.

@ -1560,7 +1560,7 @@ func initObjectLayer(endpoints, ignoredEndpoints []*url.URL) (ObjectLayer, []Sto
return nil, nil, err
}
err = waitForFormatDisks(true, endpoints[0], storageDisks)
err = waitForFormatDisks(true, endpoints, storageDisks)
if err != nil {
return nil, nil, err
}

@ -161,7 +161,7 @@ func TestNewXL(t *testing.T) {
t.Fatal("Unexpected error: ", err)
}
err = waitForFormatDisks(true, endpoints[0], nil)
err = waitForFormatDisks(true, endpoints, nil)
if err != errInvalidArgument {
t.Fatalf("Expecting error, got %s", err)
}
@ -172,7 +172,7 @@ func TestNewXL(t *testing.T) {
}
// Initializes all erasure disks
err = waitForFormatDisks(true, endpoints[0], storageDisks)
err = waitForFormatDisks(true, endpoints, storageDisks)
if err != nil {
t.Fatalf("Unable to format disks for erasure, %s", err)
}

Loading…
Cancel
Save