Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(POC) GODRIVER-3414 Complete pending reads on conn checkout #1937

Draft
wants to merge 5 commits into
base: v1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions event/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,20 @@ const (

// strings for pool command monitoring types
const (
PoolCreated = "ConnectionPoolCreated"
PoolReady = "ConnectionPoolReady"
PoolCleared = "ConnectionPoolCleared"
PoolClosedEvent = "ConnectionPoolClosed"
ConnectionCreated = "ConnectionCreated"
ConnectionReady = "ConnectionReady"
ConnectionClosed = "ConnectionClosed"
GetStarted = "ConnectionCheckOutStarted"
GetFailed = "ConnectionCheckOutFailed"
GetSucceeded = "ConnectionCheckedOut"
ConnectionReturned = "ConnectionCheckedIn"
PoolCreated = "ConnectionPoolCreated"
PoolReady = "ConnectionPoolReady"
PoolCleared = "ConnectionPoolCleared"
PoolClosedEvent = "ConnectionPoolClosed"
ConnectionCreated = "ConnectionCreated"
ConnectionReady = "ConnectionReady"
ConnectionClosed = "ConnectionClosed"
GetStarted = "ConnectionCheckOutStarted"
GetFailed = "ConnectionCheckOutFailed"
GetSucceeded = "ConnectionCheckedOut"
ConnectionReturned = "ConnectionCheckedIn"
ConnectionPendingReadStarted = "ConnectionPendingReadStarted"
ConnectionPendingReadSucceeded = "ConnectionPendingReadSucceeded"
ConnectionPendingReadFailed = "ConnectionPendingReadFailed"
)

// MonitorPoolOptions contains pool options as formatted in pool events
Expand All @@ -121,9 +124,11 @@ type PoolEvent struct {
Reason string `json:"reason"`
// ServiceID is only set if the Type is PoolCleared and the server is deployed behind a load balancer. This field
// can be used to distinguish between individual servers in a load balanced deployment.
ServiceID *primitive.ObjectID `json:"serviceId"`
Interruption bool `json:"interruptInUseConnections"`
Error error `json:"error"`
ServiceID *primitive.ObjectID `json:"serviceId"`
Interruption bool `json:"interruptInUseConnections"`
Error error `json:"error"`
RequestID int32 `json:"requestId"`
RemainingTime time.Duration `json:"remainingTime"`
}

// PoolMonitor is a function that allows the user to gain access to events occurring in the pool
Expand Down
34 changes: 34 additions & 0 deletions internal/driverutil/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (C) MongoDB, Inc. 2025-present.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

package driverutil

import "context"

type ContextKey string

const (
ContextKeyHasMaxTimeMS ContextKey = "hasMaxTimeMS"
ContextKeyRequestID ContextKey = "requestID"
)

func WithValueHasMaxTimeMS(parentCtx context.Context, val bool) context.Context {
return context.WithValue(parentCtx, ContextKeyHasMaxTimeMS, val)
}

func WithRequestID(parentCtx context.Context, requestID int32) context.Context {
return context.WithValue(parentCtx, ContextKeyRequestID, requestID)
}

func HasMaxTimeMS(ctx context.Context) bool {
return ctx.Value(ContextKeyHasMaxTimeMS) != nil
}

func GetRequestID(ctx context.Context) (int32, bool) {
val, ok := ctx.Value(ContextKeyRequestID).(int32)

return val, ok
}
3 changes: 3 additions & 0 deletions internal/logger/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const (
ConnectionCheckoutFailed = "Connection checkout failed"
ConnectionCheckedOut = "Connection checked out"
ConnectionCheckedIn = "Connection checked in"
ConnectionPendingReadStarted = "Pending read started"
ConnectionPendingReadSucceeded = "Pending read succeeded"
ConnectionPendingReadFailed = "Pending read failed"
ServerSelectionFailed = "Server selection failed"
ServerSelectionStarted = "Server selection started"
ServerSelectionSucceeded = "Server selection succeeded"
Expand Down
12 changes: 12 additions & 0 deletions internal/ptrutil/ptr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (C) MongoDB, Inc. 2024-present.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

package ptrutil

// Ptr will return the memory location of the given value.
func Ptr[T any](val T) *T {
return &val
}
6 changes: 3 additions & 3 deletions mongo/integration/csot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestCSOT_maxTimeMS(t *testing.T) {
},
sendsMaxTimeMSWithTimeoutMS: true,
sendsMaxTimeMSWithContextDeadline: false,
preventsConnClosureWithTimeoutMS: true,
preventsConnClosureWithTimeoutMS: false,
},
{
desc: "FindOneAndDelete",
Expand Down Expand Up @@ -206,7 +206,7 @@ func TestCSOT_maxTimeMS(t *testing.T) {
},
sendsMaxTimeMSWithTimeoutMS: true,
sendsMaxTimeMSWithContextDeadline: false,
preventsConnClosureWithTimeoutMS: true,
preventsConnClosureWithTimeoutMS: false,
},
{
desc: "Watch",
Expand All @@ -220,7 +220,7 @@ func TestCSOT_maxTimeMS(t *testing.T) {
},
sendsMaxTimeMSWithTimeoutMS: true,
sendsMaxTimeMSWithContextDeadline: true,
preventsConnClosureWithTimeoutMS: true,
preventsConnClosureWithTimeoutMS: false,
// Change Streams aren't supported on standalone topologies.
topologies: []mtest.TopologyKind{
mtest.ReplicaSet,
Expand Down
Loading
Loading