Server Sessions服务器会话
On this page本页内容
Overview概述
MongoDB's server sessions, or logical sessions, are the underlying framework used by client sessions to support Causal Consistency and retryable writes.MongoDB的服务器会话或逻辑会话是客户端会话用于支持因果一致性和可重试写入的底层框架。
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. 从3.6开始,MongoDB驱动程序将所有操作与服务器会话相关联,但未确认的写入除外。The following options are available for all commands to support association with a server session:以下选项可用于所有支持与服务器会话关联的命令:
mongosh
and the drivers assign these options to the commands in the session.并且驱动程序将这些选项分配给会话中的命令。
Option | ||
---|---|---|
lsid | Document | txnNumber is specified, the lsid is required.txnNumber ,则需要lsid 。 |
txnNumber | 64-bit integer | lsid option. lsid 选项。 |
For the 对于采用语句数组的delete
, insert
, and update
commands that take an array of statements, the following option is also available:delete
、insert
和update
命令,还可以使用以下选项:
Do not manually set 不要手动设置stmtIds
. stmtIds
。MongoDB sets the MongoDB将stmtId设置为严格递增的非负数。stmtIds
to be strictly increasing non-negative numbers.
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.如果部署过渡到身份验证而没有任何停机时间,则无法使用任何没有所有者的会话。