-
Notifications
You must be signed in to change notification settings - Fork 918
GODRIVER-2348 Make CSOT feature-gated behavior the default #1515
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
Conversation
…of 90th percentile
…g connection establishment
…iver into GODRIVER-2762
Co-authored-by: Matt Dale <[email protected]>
API Change Report./mongoincompatible changes(*Cursor).SetMaxTime: removed compatible changes(*Cursor).SetMaxAwaitTime: added ./mongo/optionsincompatible changes(*AggregateOptions).SetMaxTime: removed ./mongo/writeconcernincompatible changesWriteConcern.WTimeout: removed ./x/mongo/driverincompatible changes(*BatchCursor).SetMaxTime: removed compatible changes(*BatchCursor).SetMaxAwaitTime: added ./x/mongo/driver/connstringincompatible changesConnString.WTimeout: removed ./x/mongo/driver/operationincompatible changes(*Aggregate).MaxTime: removed compatible changes(*Hello).OmitMaxTimeMS: added ./x/mongo/driver/sessionincompatible changesClient.CurrentMct: removed compatible changesClient.CurrentWTimeout: added ./x/mongo/driver/topologyincompatible changes##ConnectServer: changed from func(./mongo/address.Address, updateTopologyCallback, ./bson.ObjectID, ...ServerOption) (*Server, error) to func(./mongo/address.Address, updateTopologyCallback, ./bson.ObjectID, time.Duration, ...ServerOption) (*Server, error) compatible changes(*Topology).GetServerSelectionTimeout: added |
…s during connection establishment
8725fca
…iver into GODRIVER-2348
matthewdale
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! 👍
qingyang-hu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
91c94d6
| // connections directly before closing the connection context. This ensures | ||
| // that closing a connection will manifest as an io.EOF error, avoiding | ||
| // non-deterministic connection closure errors. | ||
| defer c.closeConnectContext() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matthewdale We must defer closing the connect context to avoid non-deterministic closure errors. For example running TestErrors/errors_are_wrapped/network_error_during_auth, not defering can result in 1 of 2 errors when closing a connection:
- io.EOF
- connection() error occurred during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-256": connection(localhost:27018[-1761]) socket was unexpectedly closed: context canceled: connection(localhost:27018[-1761]) socket was unexpectedly closed: context canceled
GODRIVER-2348
Summary
The PR attempts to make CSOT feature-gated behavior the default by dropping support for legacy timeout behavior.
Workflow Changes
Remove Contexts From Structs
Putting contexts on structs is an antipattern and makes unifying and creating context timeouts difficult due to the requirement of maintaining them as state (e.g. how do you ensure you never overwrite the context while use in different methods). This PR proposes replacing this practice with the following pattern:
We still need some ability to cancel contexts passed to blocking operations outside of the go routine they are initiated in. So some state will need to be maintained on the initiating object. In this case, a cancelation channel and a sync.Once object.
Unify Timeout Logic
This PR proposes renaming
csot.MakeTimeoutContexttocsot.WithTimeout. Additionally, this update removes the need to create blocks like the following in operaiton execution, watching a change stream, and perform CRUD operations in GridFS:Rename maxTimeMS for cursor to maxAwaitTimeMS
There is still a need to maintain the
maxTimeMSlogic for tailable awaitData cursors. This PR proposes changing the code symbol fromMaxTimetoMaxAwaitTimeto match the operation options (e.g.FindOptions.MaxAwaitTime) and the CSOT specifications. This logic has been deferred to the operation-level viaOperation.DefaultWTimeout.CSOT-Specific Changes
Write Concern
This PR proposes removing the
WTimeoutfield from theWriteConcernobject. It is worth noting that there is still a use case for sending wire messages with thewtimeoutoption set. Specifically, while committing a transaction:The Go Driver organizes this logic by maintaining a copy of the txn write concern on the client session. In this case, given a CSOT, the remainder of that time is used for the value of
wtimeoutrather than the10000ms default.Server Selection
client-side-operations-timeout/client-side-operations-timeout.md#server-selection
The server selection portion of the specification requires a comparison between
timeoutMSandserverSelectionTimeoutMS. It also requires that the remaining timeout be passed to any followup operation establishing or checking out a connection:This workflow proposes building the context in a way that is decoupled from
SelectServerandserver.Connection.Because server selection is made through a
topology.Deploymentinterface, there is no obvious way to extrapolate theserverSelectionTimeoutMSfor use byWithServerSelectionTimeout. Practically, the only implementation oftopology.Deploymentthat accesses the SSTO data formoptions.ClientOptionsistopology.Topologyand so we could assert that implementation before calculating the timeout. However, for extensibility the current proposal is to use an interface:This would extend the
topology.Deploymentinterface with the addition functionGetServerSelectionTimeout().Command Execution
client-side-operations-timeout/client-side-operations-timeout.md#command-execution
The original implementation of CSOT did not apply a context deadline to the
maxTimeMSvalue. See here for the original logic. This PR proposes the following workflow to be spec compliant:Change Streams
client-side-operations-timeout/client-side-operations-timeout.md#change-streams
GridFS API
client-side-operations-timeout/client-side-operations-timeout.md#gridfs-api
The specifications note that all methods in the GridFS bucket API must support the timeoutMS option. It's worth pointing out that all blocking operations within the scope of the database used to construct a GridFS bucket will inherit the client-level timeout value.
Additionally, the specifications require that the timeoutMS option cap the lifetime of the entire stream. The Go Driver currently only ensures this is true if a deadline is set on a context. If relying on the client-level timeout, this value is "refreshed" with every new blocking operation.
Sessions
client-side-operations-timeout/client-side-operations-timeout.md#convenient-transaction-api
Propose implementing the convenient transaction api requirements in GODRIVER-2467 , since the context behavior for convenience transactions are still being debated.
Background & Motivation
v1required deprecating a set of legacy timeout options, gating their use behind a CSOT to avoid making a backwards breaking change. Forv2, we can remove these legacy timeouts altogether.