fix the error logs have been omitted because of retryCount never exceed 10 (#14268)

This commit is contained in:
Daniel 2022-02-09 19:14:22 +08:00 committed by GitHub
parent f19a414e09
commit 8ae46bce93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -173,7 +173,7 @@ func isServerResolvable(endpoint Endpoint, timeout time.Duration) error {
// connect to list of endpoints and load all Erasure disk formats, validate the formats are correct // connect to list of endpoints and load all Erasure 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 // 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. // time. additionally make sure to close all the disks used in this attempt.
func connectLoadInitFormats(retryCount int, firstDisk bool, endpoints Endpoints, poolCount, setCount, setDriveCount int, deploymentID, distributionAlgo string) (storageDisks []StorageAPI, format *formatErasureV3, err error) { func connectLoadInitFormats(verboseLogging bool, firstDisk bool, endpoints Endpoints, poolCount, setCount, setDriveCount int, deploymentID, distributionAlgo string) (storageDisks []StorageAPI, format *formatErasureV3, err error) {
// Initialize all storage disks // Initialize all storage disks
storageDisks, errs := initStorageDisksWithErrors(endpoints) storageDisks, errs := initStorageDisksWithErrors(endpoints)
@ -185,7 +185,7 @@ func connectLoadInitFormats(retryCount int, firstDisk bool, endpoints Endpoints,
for i, err := range errs { for i, err := range errs {
if err != nil { if err != nil {
if err == errDiskNotFound && retryCount >= 10 { if err == errDiskNotFound && verboseLogging {
logger.Error("Unable to connect to %s: %v", endpoints[i], isServerResolvable(endpoints[i], time.Second)) logger.Error("Unable to connect to %s: %v", endpoints[i], isServerResolvable(endpoints[i], time.Second))
} else { } else {
logger.Error("Unable to use the drive %s: %v", endpoints[i], err) logger.Error("Unable to use the drive %s: %v", endpoints[i], err)
@ -202,7 +202,7 @@ func connectLoadInitFormats(retryCount int, firstDisk bool, endpoints Endpoints,
// Check if we have // Check if we have
for i, sErr := range sErrs { for i, sErr := range sErrs {
// print the error, nonetheless, which is perhaps unhandled // print the error, nonetheless, which is perhaps unhandled
if sErr != errUnformattedDisk && sErr != errDiskNotFound && retryCount >= 10 { if sErr != errUnformattedDisk && sErr != errDiskNotFound && verboseLogging {
if sErr != nil { if sErr != nil {
logger.Error("Unable to read 'format.json' from %s: %v\n", endpoints[i], sErr) logger.Error("Unable to read 'format.json' from %s: %v\n", endpoints[i], sErr)
} }
@ -307,7 +307,8 @@ func waitForFormatErasure(firstDisk bool, endpoints Endpoints, poolCount, setCou
} }
var tries int var tries int
storageDisks, format, err := connectLoadInitFormats(tries, firstDisk, endpoints, poolCount, setCount, setDriveCount, deploymentID, distributionAlgo) var verboseLogging bool
storageDisks, format, err := connectLoadInitFormats(verboseLogging, firstDisk, endpoints, poolCount, setCount, setDriveCount, deploymentID, distributionAlgo)
if err == nil { if err == nil {
return storageDisks, format, nil return storageDisks, format, nil
} }
@ -321,12 +322,13 @@ func waitForFormatErasure(firstDisk bool, endpoints Endpoints, poolCount, setCou
for { for {
select { select {
case <-ticker.C: case <-ticker.C:
if tries == 10 { // Only log once every 10 iterations, then reset the tries count.
// Reset the tries count such that we log only for every 10 retries. verboseLogging = tries >= 10
if verboseLogging {
tries = 1 tries = 1
} }
storageDisks, format, err := connectLoadInitFormats(tries, firstDisk, endpoints, poolCount, setCount, setDriveCount, deploymentID, distributionAlgo) storageDisks, format, err := connectLoadInitFormats(verboseLogging, firstDisk, endpoints, poolCount, setCount, setDriveCount, deploymentID, distributionAlgo)
if err != nil { if err != nil {
tries++ tries++
switch err { switch err {