From 8392d2f510a7c4f5787f6361620ec47c91e531a3 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 20 Nov 2019 02:09:30 -0800 Subject: [PATCH] Preserve same deploymentID on all zones (#8542) --- cmd/admin-handlers_test.go | 2 +- cmd/endpoint-ellipses.go | 1 + cmd/format-xl.go | 5 ++++- cmd/prepare-storage.go | 8 ++++---- cmd/server-main.go | 16 ++++++++++------ cmd/test-utils_test.go | 14 +++++++++----- cmd/xl-sets_test.go | 6 +++--- cmd/xl-zones.go | 2 +- 8 files changed, 33 insertions(+), 21 deletions(-) diff --git a/cmd/admin-handlers_test.go b/cmd/admin-handlers_test.go index 126c35244..a3de1dfb6 100644 --- a/cmd/admin-handlers_test.go +++ b/cmd/admin-handlers_test.go @@ -114,7 +114,7 @@ func initTestXLObjLayer() (ObjectLayer, []string, error) { return nil, nil, err } endpoints := mustGetNewEndpoints(xlDirs...) - format, err := waitForFormatXL(true, endpoints, 1, 16) + format, err := waitForFormatXL(true, endpoints, 1, 16, "") if err != nil { removeRoots(xlDirs) return nil, nil, err diff --git a/cmd/endpoint-ellipses.go b/cmd/endpoint-ellipses.go index 03263a285..aa4184cbf 100644 --- a/cmd/endpoint-ellipses.go +++ b/cmd/endpoint-ellipses.go @@ -287,6 +287,7 @@ func createServerEndpoints(serverAddr string, args ...string) (EndpointZones, Se if _, err := GetAllSets(args...); err != nil { return nil, -1, err } + for _, arg := range args { setArgs, err := GetAllSets(arg) if err != nil { diff --git a/cmd/format-xl.go b/cmd/format-xl.go index 2aa2f9d3f..9bed3c9c4 100644 --- a/cmd/format-xl.go +++ b/cmd/format-xl.go @@ -718,7 +718,7 @@ func fixFormatXLV3(storageDisks []StorageAPI, endpoints Endpoints, formats []*fo } // initFormatXL - save XL format configuration on all disks. -func initFormatXL(ctx context.Context, storageDisks []StorageAPI, setCount, disksPerSet int) (format *formatXLV3, err error) { +func initFormatXL(ctx context.Context, storageDisks []StorageAPI, setCount, disksPerSet int, deploymentID string) (format *formatXLV3, err error) { format = newFormatXLV3(setCount, disksPerSet) formats := make([]*formatXLV3, len(storageDisks)) @@ -726,6 +726,9 @@ func initFormatXL(ctx context.Context, storageDisks []StorageAPI, setCount, disk for j := 0; j < disksPerSet; j++ { newFormat := *format newFormat.XL.This = format.XL.Sets[i][j] + if deploymentID != "" { + newFormat.ID = deploymentID + } formats[i*disksPerSet+j] = &newFormat } } diff --git a/cmd/prepare-storage.go b/cmd/prepare-storage.go index 5f6bc1eb9..fcb4dd29c 100644 --- a/cmd/prepare-storage.go +++ b/cmd/prepare-storage.go @@ -174,7 +174,7 @@ var errXLV3ThisEmpty = fmt.Errorf("XL format version 3 has This field empty") // connect to list of endpoints and load all XL disk formats, validate the formats are correct // and are in quorum, if no formats are found attempt to initialize all of them for the first // time. additionally make sure to close all the disks used in this attempt. -func connectLoadInitFormats(retryCount int, firstDisk bool, endpoints Endpoints, setCount, drivesPerSet int) (*formatXLV3, error) { +func connectLoadInitFormats(retryCount int, firstDisk bool, endpoints Endpoints, setCount, drivesPerSet int, deploymentID string) (*formatXLV3, error) { // Initialize all storage disks storageDisks, errs := initStorageDisksWithErrors(endpoints) defer closeStorageDisks(storageDisks) @@ -216,7 +216,7 @@ func connectLoadInitFormats(retryCount int, firstDisk bool, endpoints Endpoints, // All disks report unformatted we should initialized everyone. if shouldInitXLDisks(sErrs) && firstDisk { // Initialize erasure code format on disks - format, err := initFormatXL(context.Background(), storageDisks, setCount, drivesPerSet) + format, err := initFormatXL(context.Background(), storageDisks, setCount, drivesPerSet, deploymentID) if err != nil { return nil, err } @@ -286,7 +286,7 @@ func connectLoadInitFormats(retryCount int, firstDisk bool, endpoints Endpoints, } // Format disks before initialization of object layer. -func waitForFormatXL(firstDisk bool, endpoints Endpoints, setCount, disksPerSet int) (format *formatXLV3, err error) { +func waitForFormatXL(firstDisk bool, endpoints Endpoints, setCount, disksPerSet int, deploymentID string) (format *formatXLV3, err error) { if len(endpoints) == 0 || setCount == 0 || disksPerSet == 0 { return nil, errInvalidArgument } @@ -318,7 +318,7 @@ func waitForFormatXL(firstDisk bool, endpoints Endpoints, setCount, disksPerSet for { select { case retryCount := <-retryTimerCh: - format, err := connectLoadInitFormats(retryCount, firstDisk, endpoints, setCount, disksPerSet) + format, err := connectLoadInitFormats(retryCount, firstDisk, endpoints, setCount, disksPerSet, deploymentID) if err != nil { switch err { case errNotFirstDisk: diff --git a/cmd/server-main.go b/cmd/server-main.go index 4720608b1..2d96540ff 100644 --- a/cmd/server-main.go +++ b/cmd/server-main.go @@ -208,7 +208,7 @@ func initSafeModeInit(buckets []BucketInfo) (err error) { return err } - defer func() { + defer func(objLock RWLocker) { objLock.Unlock() if err != nil { @@ -226,7 +226,7 @@ func initSafeModeInit(buckets []BucketInfo) (err error) { // not proceeding waiting for admin action. handleSignals() } - }() + }(objLock) // Calls New() for all sub-systems. newAllSubsystems() @@ -437,13 +437,17 @@ func newObjectLayer(endpointZones EndpointZones) (newObject ObjectLayer, err err return NewFSObjectLayer(endpointZones[0].Endpoints[0].Path) } - var formats []*formatXLV3 - for _, ep := range endpointZones { - format, err := waitForFormatXL(ep.Endpoints[0].IsLocal, ep.Endpoints, ep.SetCount, ep.DrivesPerSet) + var formats = make([]*formatXLV3, len(endpointZones)) + var deploymentID string + for i, ep := range endpointZones { + formats[i], err = waitForFormatXL(ep.Endpoints[0].IsLocal, ep.Endpoints, + ep.SetCount, ep.DrivesPerSet, deploymentID) if err != nil { return nil, err } - formats = append(formats, format) + if deploymentID == "" { + deploymentID = formats[i].ID + } } return newXLZones(endpointZones, formats) } diff --git a/cmd/test-utils_test.go b/cmd/test-utils_test.go index 326efa01d..1ffb38674 100644 --- a/cmd/test-utils_test.go +++ b/cmd/test-utils_test.go @@ -189,7 +189,7 @@ func prepareXLSets32() (ObjectLayer, []string, error) { endpoints := append(endpoints1, endpoints2...) fsDirs := append(fsDirs1, fsDirs2...) - format, err := waitForFormatXL(true, endpoints, 2, 16) + format, err := waitForFormatXL(true, endpoints, 2, 16, "") if err != nil { removeRoots(fsDirs) return nil, nil, err @@ -1585,13 +1585,17 @@ func newTestObjectLayer(endpointZones EndpointZones) (newObject ObjectLayer, err return NewFSObjectLayer(endpointZones[0].Endpoints[0].Path) } - var formats []*formatXLV3 - for _, ep := range endpointZones { - format, err := waitForFormatXL(ep.Endpoints[0].IsLocal, ep.Endpoints, ep.SetCount, ep.DrivesPerSet) + var formats = make([]*formatXLV3, len(endpointZones)) + var deploymentID string + for i, ep := range endpointZones { + formats[i], err = waitForFormatXL(ep.Endpoints[0].IsLocal, ep.Endpoints, + ep.SetCount, ep.DrivesPerSet, deploymentID) if err != nil { return nil, err } - formats = append(formats, format) + if deploymentID == "" { + deploymentID = formats[i].ID + } } zones, err := newXLZones(endpointZones, formats) diff --git a/cmd/xl-sets_test.go b/cmd/xl-sets_test.go index 4dd688922..b4e4465ea 100644 --- a/cmd/xl-sets_test.go +++ b/cmd/xl-sets_test.go @@ -76,18 +76,18 @@ func TestNewXLSets(t *testing.T) { } endpoints := mustGetNewEndpoints(erasureDisks...) - _, err := waitForFormatXL(true, endpoints, 0, 16) + _, err := waitForFormatXL(true, endpoints, 0, 16, "") if err != errInvalidArgument { t.Fatalf("Expecting error, got %s", err) } - _, err = waitForFormatXL(true, nil, 1, 16) + _, err = waitForFormatXL(true, nil, 1, 16, "") if err != errInvalidArgument { t.Fatalf("Expecting error, got %s", err) } // Initializes all erasure disks - format, err := waitForFormatXL(true, endpoints, 1, 16) + format, err := waitForFormatXL(true, endpoints, 1, 16, "") if err != nil { t.Fatalf("Unable to format disks for erasure, %s", err) } diff --git a/cmd/xl-zones.go b/cmd/xl-zones.go index e1e3bfcfc..d3059aae5 100644 --- a/cmd/xl-zones.go +++ b/cmd/xl-zones.go @@ -1207,7 +1207,7 @@ func (z *xlZones) HealFormat(ctx context.Context, dryRun bool) (madmin.HealResul } for _, zone := range z.zones { result, err := zone.HealFormat(ctx, dryRun) - if err != nil { + if err != nil && err != errNoHealRequired { logger.LogIf(ctx, err) continue }