logger lock should be more granular (#14901)

This PR simplifies few things by splitting
the locks between audit, logger targets to
avoid potential contention between them.

any failures inside audit/logger HTTP
targets must only log to console instead
of other targets to avoid cyclical dependency.

avoids unneeded atomic variables instead
uses RWLock to differentiate a more common
read phase v/s lock phase.
This commit is contained in:
Harshavardhana
2022-05-12 07:20:58 -07:00
committed by GitHub
parent 88dd83a365
commit 9341201132
6 changed files with 114 additions and 58 deletions

View File

@@ -53,6 +53,7 @@ import (
"sync"
"testing"
"time"
"unsafe"
"github.com/fatih/color"
@@ -1183,12 +1184,11 @@ func newTestSignedRequestV4(method, urlStr string, contentLength int64, body io.
return req, nil
}
// Function to generate random string for bucket/object names.
func randString(n int) string {
src := rand.NewSource(UTCNow().UnixNano())
var src = rand.NewSource(time.Now().UnixNano())
func randString(n int) string {
b := make([]byte, n)
// A rand.Int63() generates 63 random bits, enough for letterIdxMax letters!
// A src.Int63() generates 63 random bits, enough for letterIdxMax characters!
for i, cache, remain := n-1, src.Int63(), letterIdxMax; i >= 0; {
if remain == 0 {
cache, remain = src.Int63(), letterIdxMax
@@ -1200,7 +1200,8 @@ func randString(n int) string {
cache >>= letterIdxBits
remain--
}
return string(b)
return *(*string)(unsafe.Pointer(&b))
}
// generate random object name.