-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(NODE-2843): implement sessions advanceClusterTime method #2920
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
Changes from all commits
7b45be3
90b0efc
3f9f27b
ff3a2b0
5cfcc98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import { PromiseProvider } from './promise_provider'; | |
import { Binary, Long, Timestamp, Document } from './bson'; | ||
import { ReadPreference } from './read_preference'; | ||
import { isTransactionCommand, TxnState, Transaction, TransactionOptions } from './transactions'; | ||
import { resolveClusterTime, ClusterTime } from './sdam/common'; | ||
import { _advanceClusterTime, ClusterTime } from './sdam/common'; | ||
import { isSharded } from './cmap/wire_protocol/shared'; | ||
import { | ||
MongoError, | ||
|
@@ -249,6 +249,34 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> { | |
} | ||
} | ||
|
||
/** | ||
* Advances the clusterTime for a ClientSession to the provided clusterTime of another ClientSession | ||
* | ||
* @param clusterTime - the $clusterTime returned by the server from another session in the form of a document containing the `BSON.Timestamp` clusterTime and signature | ||
*/ | ||
advanceClusterTime(clusterTime: ClusterTime): void { | ||
if (!clusterTime || typeof clusterTime !== 'object') { | ||
throw new MongoInvalidArgumentError('input cluster time must be an object'); | ||
} | ||
if (!clusterTime.clusterTime || clusterTime.clusterTime._bsontype !== 'Timestamp') { | ||
throw new MongoInvalidArgumentError( | ||
'input cluster time "clusterTime" property must be a valid BSON Timestamp' | ||
); | ||
} | ||
if ( | ||
!clusterTime.signature || | ||
clusterTime.signature.hash?._bsontype !== 'Binary' || | ||
(typeof clusterTime.signature.keyId !== 'number' && | ||
clusterTime.signature.keyId?._bsontype !== 'Long') // apparently we decode the key to number? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nbbeeken Just bringing your attention to this change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just so I do not block this PR: looks correct to me. Remind me to tell you the deeper issue here / file a ticket next week, has to do with BSON |
||
) { | ||
throw new MongoInvalidArgumentError( | ||
'input cluster time must have a valid "signature" property with BSON Binary hash and BSON Long keyId' | ||
); | ||
} | ||
|
||
_advanceClusterTime(this, clusterTime); | ||
} | ||
|
||
/** | ||
* Used to determine if this session equals another | ||
* | ||
|
@@ -886,7 +914,7 @@ export function applySession( | |
|
||
export function updateSessionFromResponse(session: ClientSession, document: Document): void { | ||
if (document.$clusterTime) { | ||
resolveClusterTime(session, document.$clusterTime); | ||
_advanceClusterTime(session, document.$clusterTime); | ||
} | ||
|
||
if (document.operationTime && session && session.supports.causalConsistency) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.