From 4bf90ca67fc62ae9cff2dd18cc9ed233acf56b5e Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 29 Oct 2020 09:25:43 -0700 Subject: [PATCH] fix: handle a crash when AskDisks is set to -1 (#10777) --- cmd/data-update-tracker.go | 2 +- cmd/metacache-server-sets.go | 3 +++ cmd/metacache-set.go | 17 +++++------------ cmd/peer-rest-client.go | 4 ++++ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cmd/data-update-tracker.go b/cmd/data-update-tracker.go index 88a3be678..10405abaf 100644 --- a/cmd/data-update-tracker.go +++ b/cmd/data-update-tracker.go @@ -403,7 +403,7 @@ func (d *dataUpdateTracker) deserialize(src io.Reader, newerThan time.Time) erro return err } switch tmp[0] { - case 1, 2: + case 1, 2, 3: logger.Info(color.Green("dataUpdateTracker: ") + "deprecated data version, updating.") return nil case dataUpdateTrackerVersion: diff --git a/cmd/metacache-server-sets.go b/cmd/metacache-server-sets.go index 288869f65..6be6c73cb 100644 --- a/cmd/metacache-server-sets.go +++ b/cmd/metacache-server-sets.go @@ -124,6 +124,9 @@ func (z *erasureServerSets) listPath(ctx context.Context, o listPathOptions) (en case "disk": // Ask single disk. o.AskDisks = 1 + default: + // By default asks at max 3 disks. + o.AskDisks = 3 } } diff --git a/cmd/metacache-set.go b/cmd/metacache-set.go index 7de2f9c80..d5d96cd6a 100644 --- a/cmd/metacache-set.go +++ b/cmd/metacache-set.go @@ -542,17 +542,9 @@ func (er *erasureObjects) listPath(ctx context.Context, o listPathOptions) (entr // We need to ask disks. disks := er.getOnlineDisks() - var askDisks = o.AskDisks - switch askDisks { - // 50% or at least 3. - case -1: - o.AskDisks = getReadQuorum(len(er.getDisks())) - if o.AskDisks < 3 { - o.AskDisks = 3 - } - // Default is 3 disks. - case 0: - askDisks = 3 + askDisks := o.AskDisks + if askDisks == -1 { + askDisks = getReadQuorum(er.SetDriveCount()) } if len(disks) < askDisks { @@ -565,10 +557,11 @@ func (er *erasureObjects) listPath(ctx context.Context, o listPathOptions) (entr return } - // Select askDisks random disks, 3 is ok. + // Select askDisks random disks. if len(disks) > askDisks { disks = disks[:askDisks] } + var readers = make([]*metacacheReader, askDisks) for i := range disks { r, w := io.Pipe() diff --git a/cmd/peer-rest-client.go b/cmd/peer-rest-client.go index 0e925ff1f..e90e0a022 100644 --- a/cmd/peer-rest-client.go +++ b/cmd/peer-rest-client.go @@ -852,6 +852,10 @@ func (client *peerRESTClient) ConsoleLog(logCh chan interface{}, doneCh <-chan s // but 'all' will contain nil entry for local client. // The 'all' slice will be in the same order across the cluster. func newPeerRestClients(endpoints EndpointServerSets) (remote, all []*peerRESTClient) { + if !globalIsDistErasure { + // Only useful in distributed setups + return nil, nil + } hosts := endpoints.hostsSorted() remote = make([]*peerRESTClient, 0, len(hosts)) all = make([]*peerRESTClient, len(hosts))