From d0d015361c2994358c7d88209dc99b40e57d2e94 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 5 Sep 2018 08:25:55 -0700 Subject: [PATCH] Fix config subsystem to wait on quorum number of formatted disks (#6407) --- cmd/server-main.go | 6 +++--- cmd/xl-sets.go | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/cmd/server-main.go b/cmd/server-main.go index 74f43753b..cf41f3d42 100644 --- a/cmd/server-main.go +++ b/cmd/server-main.go @@ -318,6 +318,9 @@ func serverMain(ctx *cli.Context) { initFederatorBackend(newObject) } + // Re-enable logging + logger.Disable = false + // Create a new config system. globalConfigSys = NewConfigSys() @@ -336,9 +339,6 @@ func serverMain(ctx *cli.Context) { logger.FatalIf(err, "Unable to initialize disk caching") } - // Re-enable logging - logger.Disable = false - // Create new policy system. globalPolicySys = NewPolicySys() diff --git a/cmd/xl-sets.go b/cmd/xl-sets.go index ee65adfff..2f0808c34 100644 --- a/cmd/xl-sets.go +++ b/cmd/xl-sets.go @@ -168,6 +168,34 @@ func (s *xlSets) reInitDisks(refFormat *formatXLV3, storageDisks []StorageAPI, f return xlDisks } +// connectDisksWithQuorum is same as connectDisks but waits +// for quorum number of formatted disks to be online in +// any given sets. +func (s *xlSets) connectDisksWithQuorum() { + var onlineDisks int + for onlineDisks < (len(s.endpoints)/2)+1 { + for _, endpoint := range s.endpoints { + if s.isConnected(endpoint) { + continue + } + disk, format, err := connectEndpoint(endpoint) + if err != nil { + printEndpointError(endpoint, err) + continue + } + i, j, err := findDiskIndex(s.format, format) + if err != nil { + // Close the internal connection to avoid connection leaks. + disk.Close() + printEndpointError(endpoint, err) + continue + } + s.xlDisks[i][j] = disk + onlineDisks++ + } + } +} + // connectDisks - attempt to connect all the endpoints, loads format // and re-arranges the disks in proper position. func (s *xlSets) connectDisks() { @@ -260,8 +288,8 @@ func newXLSets(endpoints EndpointList, format *formatXLV3, setCount int, drivesP go s.sets[i].cleanupStaleMultipartUploads(context.Background(), globalMultipartCleanupInterval, globalMultipartExpiry, globalServiceDoneCh) } - // Connect disks right away. - s.connectDisks() + // Connect disks right away, but wait until we have `format.json` quorum. + s.connectDisksWithQuorum() // Start the disk monitoring and connect routine. go s.monitorAndConnectEndpoints(defaultMonitorConnectEndpointInterval)