Skip to content

Commit

Permalink
Remove unified logger mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
prestonvasquez committed Sep 13, 2023
1 parent 7e967b0 commit 42897f7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
6 changes: 3 additions & 3 deletions mongo/integration/unified/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const (
func newTestContext(
ctx context.Context,
entityMap *EntityMap,
expectedLogMessageCount uint64,
expectedLogMessageCount int,
hasOperationalFailPoint bool,
) context.Context {
ctx = context.WithValue(ctx, operationalFailPointKey, hasOperationalFailPoint)
Expand Down Expand Up @@ -84,6 +84,6 @@ func entities(ctx context.Context) *EntityMap {
return ctx.Value(entitiesKey).(*EntityMap)
}

func expectedLogMessageCount(ctx context.Context) uint64 {
return ctx.Value(expectedLogMessageCountKey).(uint64)
func expectedLogMessageCount(ctx context.Context) int {
return ctx.Value(expectedLogMessageCountKey).(int)
}
21 changes: 8 additions & 13 deletions mongo/integration/unified/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package unified

import (
"sync"
"sync/atomic"

"go.mongodb.org/mongo-driver/internal/logger"
Expand All @@ -23,13 +22,12 @@ type orderedLogMessage struct {
// Logger is the Sink used to captured log messages for logger verification in
// the unified spec tests.
type Logger struct {
bufSize uint64
lastOrder uint64
bufSize int
lastOrder int32
logQueue chan orderedLogMessage
mu sync.RWMutex
}

func newLogger(olm *observeLogMessages, bufSize uint64) *Logger {
func newLogger(olm *observeLogMessages, bufSize int) *Logger {
if olm == nil {
return nil
}
Expand All @@ -44,18 +42,13 @@ func newLogger(olm *observeLogMessages, bufSize uint64) *Logger {
// Info implements the logger.Sink interface's "Info" method for printing log
// messages.
func (log *Logger) Info(level int, msg string, args ...interface{}) {
log.mu.Lock()
defer log.mu.Unlock()

if log.logQueue == nil {
return
}

defer func() { atomic.AddUint64(&log.lastOrder, 1) }()

// If the order is greater than the buffer size, we must return. This
// would indicate that the logQueue channel has been closed.
if log.lastOrder > log.bufSize {
if log.lastOrder > int32(log.bufSize) {
return
}

Expand All @@ -75,10 +68,12 @@ func (log *Logger) Info(level int, msg string, args ...interface{}) {
logMessage: logMessage,
}

// If the order has reached the buffer size, then close the channe.
if log.lastOrder == log.bufSize {
// If the order has reached the buffer size, then close the channel.
if log.lastOrder == int32(log.bufSize) {
close(log.logQueue)
}

atomic.AddInt32(&log.lastOrder, 1)
}

// Error implements the logger.Sink interface's "Error" method for printing log
Expand Down
4 changes: 2 additions & 2 deletions mongo/integration/unified/unified_spec_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ func (tc *TestCase) Run(ls LoggerSkipper) error {
}

// Count the number of expected log messages over all clients.
var expectedLogCount uint64
var expectedLogCount int
for _, clientLog := range tc.ExpectLogMessages {
expectedLogCount += uint64(len(clientLog.LogMessages))
expectedLogCount += len(clientLog.LogMessages)
}

testCtx := newTestContext(context.Background(), tc.entities, expectedLogCount, tc.setsFailPoint())
Expand Down

0 comments on commit 42897f7

Please sign in to comment.