Overview概述
MongoDB's server sessions, or logical sessions, are the underlying framework used by client sessions to support Causal Consistency and retryable writes.MongoDB的服务器会话或逻辑会话是客户端会话用于支持因果一致性和可重试写入的底层框架。
Important
Applications use client sessions to interface with server sessions.应用程序使用客户端会话与服务器会话进行交互。
Server sessions are available for replica sets and sharded clusters only.服务器会话仅适用于副本集和分片群集。
Command Options命令选项
Starting in 3.6, MongoDB drivers associate all operations with a server session, with the exception of unacknowledged writes. The following options are available for all commands to support association with a server session:从3.6开始,MongoDB驱动程序将所有操作与服务器会话相关联,但未确认的写入除外。以下选项可用于支持与服务器会话关联的所有命令:
Important
mongosh and the drivers assign these options to the commands in the session.mongosh和驱动程序将这些选项分配给会话中的命令。
lsid | txnNumber is specified, the lsid is required.txnNumber,则需要lsid。 | |
txnNumber |
|
For the 对于采用语句数组的delete, insert, and update commands that take an array of statements, the following option is also available:delete、insert和update命令,还可以使用以下选项:
Important
Do not manually set 不要手动设置stmtIds. MongoDB sets the stmtIds to be strictly increasing non-negative numbers.stmtIds。MongoDB将stmtIds设置为严格递增的非负数。
stmtIds |
Sessions Commands会话命令
The following commands can be used to list, manage, and kill server sessions throughout MongoDB clusters:以下命令可用于列出、管理和终止整个MongoDB集群中的服务器会话:
endSessions | |
killAllSessions | |
killAllSessionsByPattern | |
killSessions | |
refreshSessions | |
startSession |
Sessions and Access Control会话和访问控制
If the deployment enforces authentication/authorization, the user must be authenticated to start a session, and only that user can use the session.如果部署强制执行身份验证/授权,则必须对用户进行身份验证才能启动会话,并且只有该用户可以使用会话。
To use Client Sessions and Causal Consistency Guarantees with 要对$external authentication users (Kerberos, LDAP, or X.509 users), usernames cannot be greater than 10k bytes.$external身份验证用户(Kerberos、LDAP或X.509用户)使用客户端会话和因果一致性保证,用户名不能大于10k字节。
If the deployment does not enforce authentication/authorization, a created session has no owner and can be used by any user on any connection. If a user authenticates and creates a session for a deployment that does not enforce authentication/authorization, that user owns the session. However, any user on any connection may use the session.如果部署不强制执行身份验证/授权,则创建的会话没有所有者,可以由任何连接上的任何用户使用。如果用户对不强制身份验证/授权的部署进行身份验证并创建会话,则该用户拥有该会话。但是,任何连接上的任何用户都可以使用该会话。
If the deployment transitions to authentication without any downtime, any sessions without an owner cannot be used.如果部署在没有停机的情况下转换为身份验证,则任何没有所有者的会话都无法使用。