@ -33,28 +33,41 @@ import (
"github.com/minio/minio/pkg/sync/errgroup"
"github.com/minio/minio/pkg/sync/errgroup"
)
)
var printEndpointError = func ( ) func ( Endpoint , error ) {
var printEndpointError = func ( ) func ( Endpoint , error , bool ) {
var mutex sync . Mutex
var mutex sync . Mutex
printOnce := make ( map [ Endpoint ] map [ string ] bool )
printOnce := make ( map [ Endpoint ] map [ string ] int )
return func ( endpoint Endpoint , err error ) {
return func ( endpoint Endpoint , err error , once bool ) {
reqInfo := ( & logger . ReqInfo { } ) . AppendTags ( "endpoint" , endpoint . String ( ) )
reqInfo := ( & logger . ReqInfo { } ) . AppendTags ( "endpoint" , endpoint . String ( ) )
ctx := logger . SetReqInfo ( GlobalContext , reqInfo )
ctx := logger . SetReqInfo ( GlobalContext , reqInfo )
mutex . Lock ( )
mutex . Lock ( )
defer mutex . Unlock ( )
defer mutex . Unlock ( )
m , ok := printOnce [ endpoint ]
m , ok := printOnce [ endpoint ]
if ! ok {
if ! ok {
m = make ( map [ string ] bool )
m = make ( map [ string ] int )
m [ err . Error ( ) ] = true
m [ err . Error ( ) ] ++
printOnce [ endpoint ] = m
printOnce [ endpoint ] = m
if once {
logger . LogAlwaysIf ( ctx , err )
logger . LogAlwaysIf ( ctx , err )
return
return
}
}
if m [ err . Error ( ) ] {
}
// Once is set and we are here means error was already
// printed once.
if once {
return
return
}
}
m [ err . Error ( ) ] = true
// once not set, check if same error occurred 3 times in
logger . LogAlwaysIf ( ctx , err )
// a row, then make sure we print it to call attention.
if m [ err . Error ( ) ] > 2 {
logger . LogAlwaysIf ( ctx , fmt . Errorf ( "Following error has been printed %d times.. %w" , m [ err . Error ( ) ] , err ) )
// Reduce the count to introduce further delay in printing
// but let it again print after the 2th attempt
m [ err . Error ( ) ] --
m [ err . Error ( ) ] --
}
m [ err . Error ( ) ] ++
}
}
} ( )
} ( )