From 734d07a53237853b06561c63be297fba8d238935 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 23 Nov 2020 09:07:50 -0800 Subject: [PATCH] fix: all hosts local and port same should be local erasure setup (#10951) this is needed to avoid initializing notification peers that can lead to races in many sub-systems fixes #10950 --- cmd/endpoint-ellipses.go | 14 +++++++------- cmd/endpoint.go | 4 ++-- cmd/endpoint_test.go | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/endpoint-ellipses.go b/cmd/endpoint-ellipses.go index 86426f113..822b73f8f 100644 --- a/cmd/endpoint-ellipses.go +++ b/cmd/endpoint-ellipses.go @@ -361,24 +361,19 @@ func createServerEndpoints(serverAddr string, args ...string) ( return endpointServerSets, setupType, nil } - var prevSetupType SetupType var foundPrevLocal bool for _, arg := range args { setArgs, err := GetAllSets(uint64(setDriveCount), arg) if err != nil { return nil, -1, err } - var endpointList Endpoints - endpointList, setupType, err = CreateEndpoints(serverAddr, foundPrevLocal, setArgs...) + endpointList, gotSetupType, err := CreateEndpoints(serverAddr, foundPrevLocal, setArgs...) if err != nil { return nil, -1, err } if setDriveCount != 0 && setDriveCount != len(setArgs[0]) { return nil, -1, fmt.Errorf("All serverSets should have same drive per set ratio - expected %d, got %d", setDriveCount, len(setArgs[0])) } - if prevSetupType != UnknownSetupType && prevSetupType != setupType { - return nil, -1, fmt.Errorf("All serverSets should be of the same setup-type to maintain the original SLA expectations - expected %s, got %s", prevSetupType, setupType) - } if err = endpointServerSets.Add(ZoneEndpoints{ SetCount: len(setArgs), DrivesPerSet: len(setArgs[0]), @@ -390,7 +385,12 @@ func createServerEndpoints(serverAddr string, args ...string) ( if setDriveCount == 0 { setDriveCount = len(setArgs[0]) } - prevSetupType = setupType + if setupType == UnknownSetupType { + setupType = gotSetupType + } + if setupType == ErasureSetupType && gotSetupType == DistErasureSetupType { + setupType = DistErasureSetupType + } } return endpointServerSets, setupType, nil diff --git a/cmd/endpoint.go b/cmd/endpoint.go index a42aa6244..87f5757f4 100644 --- a/cmd/endpoint.go +++ b/cmd/endpoint.go @@ -689,14 +689,14 @@ func CreateEndpoints(serverAddr string, foundLocal bool, args ...[]string) (Endp // All endpoints are pointing to local host if len(endpoints) == localEndpointCount { - // If all endpoints have same port number, Just treat it as distErasure setup + // If all endpoints have same port number, Just treat it as local erasure setup // using URL style endpoints. if len(localPortSet) == 1 { if len(localServerHostSet) > 1 { return endpoints, setupType, config.ErrInvalidErasureEndpoints(nil).Msg("all local endpoints should not have different hostnames/ips") } - return endpoints, DistErasureSetupType, nil + return endpoints, ErasureSetupType, nil } // Even though all endpoints are local, but those endpoints use different ports. diff --git a/cmd/endpoint_test.go b/cmd/endpoint_test.go index 145c10420..2e5024dca 100644 --- a/cmd/endpoint_test.go +++ b/cmd/endpoint_test.go @@ -246,7 +246,7 @@ func TestCreateEndpoints(t *testing.T) { Endpoint{URL: &url.URL{Scheme: "http", Host: "localhost", Path: "/d2"}, IsLocal: true}, Endpoint{URL: &url.URL{Scheme: "http", Host: "localhost", Path: "/d3"}, IsLocal: true}, Endpoint{URL: &url.URL{Scheme: "http", Host: "localhost", Path: "/d4"}, IsLocal: true}, - }, DistErasureSetupType, nil}, + }, ErasureSetupType, nil}, // DistErasure Setup with URLEndpointType having mixed naming to local host. {"127.0.0.1:10000", [][]string{{"http://localhost/d1", "http://localhost/d2", "http://127.0.0.1/d3", "http://127.0.0.1/d4"}}, "", Endpoints{}, -1, fmt.Errorf("all local endpoints should not have different hostnames/ips")},