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的服务器会话或逻辑会话是客户端会话用来支持因果一致性和可重试写入的底层框架。

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. 从3.6开始,MongoDB驱动程序将所有操作与服务器会话相关联,但未确认的写操作除外。The following options are available for all commands to support association with a server session:以下选项可用于支持与服务器会话关联的所有命令:

Important重要

mongosh and the drivers assign these options to the commands in the session.和驱动程序将这些选项分配给会话中的命令。

Option选项Type类型Description描述
lsidDocumentThe document that specifies the unique id of the session associated with the command. 指定与命令关联的会话的唯一id的文档。If the txnNumber is specified, the lsid is required.如果指定了txnNumber,则需要lsid
txnNumber64-bit integer

A strictly increasing non-negative number that uniquely identifies the command in the command's session.一个严格递增的非负数,唯一标识命令会话中的命令。

If specified, the command must also include the lsid option.如果指定,该命令还必须包括lsid选项。

For the delete, insert, and update commands that take an array of statements, the following option is also available:对于采用语句数组的deleteinsertupdate命令,还可以使用以下选项:

Important重要

Do not manually set stmtIds. 不要手动设置stmtIdsMongoDB sets the stmtIds to be strictly increasing non-negative numbers.MongoDB将stmtIds设置为严格递增非负数。

OptionType类型Description描述
stmtIdsArray of 32-bit integers32位整数数组Array of numbers that uniquely identify their respective write operations within the write command.在write命令中唯一标识其各自写入操作的数字数组。

Sessions Commands会话命令

The following commands can be used to list, manage, and kill server sessions throughout MongoDB clusters:以下命令可用于列出、管理和终止整个MongoDB集群中的服务器会话:

Commands命令Descriptions描述
endSessionsExpires specified server sessions.使指定的服务器会话过期。
killAllSessionsKills all server sessions.终止所有服务器会话。
killAllSessionsByPatternKills all server sessions that match the specified pattern.终止与指定模式匹配的所有服务器会话。
killSessionsKills specified server sessions.终止指定的服务器会话。
refreshSessionsRefreshes idle server sessions.刷新空闲服务器会话。
startSessionStarts a new server session.启动新的服务器会话。

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.如果部署过渡到身份验证而没有任何停机时间,则无法使用任何没有所有者的会话。

Tip提示
See also: 参阅:
←  Default MongoDB Read Concerns/Write ConcernsStable API →