模块:Mongo::CursorHost

包含在:
Mongo::Collection::View::Iterable Database::View Index::View
定义于:
lib/mongo/cursor_host.rb

Overview

为“托管”(或生成)游标的实体实现设置和配置的共享关注。

包含此关注的类或模块必须实现:

* timeout_ms -- this must return either the operation level timeout_ms
    (if set) or an inherited timeout_ms from a hierarchically higher
    level (if any).

实例属性摘要折叠

实例方法摘要折叠

实例属性详细信息

#cursornil | Cursor (readonly)

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

返回与此视图关联的游标(如果有)。

返回:

  • (nil | Cursor)

    游标(如果有)。



17
18
19
# File 'lib/ Mongo/cursor_host.rb', line 17

def cursor
  @cursor
end

# timeout_mode :cursor_lifetime | :iteration(只读)

返回值 此对象要使用的超时模式。

返回:

  • ( :cursor_lifetime | :iteration )

    该对象要使用的超时模式。



21
22
23
# File 'lib/ Mongo/cursor_host.rb', line 21

def timeout_mode
  @timeout_mode
end

实例方法详细信息

#validate_timeout_mode!(options, forbid: []) ⇒ Object

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

确保超时模式适用于已提供的其他选项。

rubocop:disable 指标

参数:

  • 选项 (哈希)

    要检查的选项。

  • forbid ( Array< Symbol > ) (默认为: []

    要禁止的此类选项列表。

引发:

  • ( ArgumentError )

    如果检测到不一致或不兼容的选项。



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/ Mongo/cursor_host.rb', line 35

def validate_timeout_mode!(选项, forbid: [])
  forbid. do |key|
    提高 ArgumentError, " 此处不允许 #{ key } " if 选项.键?(key)
  end

  cursor_type = 选项[:cursor_type]
  timeout_mode = 选项[:timeout_mode]

  if timeout_ms
    # "可追加游标仅支持ITERATION 值
    # timeoutMode 选项。 这是默认值,驱动程序必须
    # 如果该选项设立为 CURSOR_LIFETIME,则会出现错误。"
    if cursor_type
      timeout_mode ||= :iteration
      if timeout_mode == :cursor_lifetime
        提高 ArgumentError, ' 可追加游标仅支持`timeout_mode: :iteration` '
      end

      # "如果设立了[maxAwaitTimeMS] 选项,则驱动程序必须出错,
      # timeoutMS设立为非零值,maxAwaitTimeMS 为
      # 大于或等于 timeoutMS。"
      max_await_time_ms = 选项[:max_await_time_ms] || 0
      if cursor_type == :tailable_await && max_await_time_ms >= timeout_ms
        提高 ArgumentError, ' :max_await_time_ms 不得 >= :timeout_ms '
      end
    else
      # "对于不可追加游标,timeoutMode 的默认值
      # 为 CURSOR_LIFETIME。”
      timeout_mode ||= :cursor_lifetime
    end
  elsif timeout_mode
    # "如果设立了timeoutMode 而未设置 timeoutMS,则驱动程序必须出错。"
    提高 ArgumentError, ' :timeout_ms 必须设立,如果 :timeout_mode 已设立'
  end

  if timeout_mode == :iteration && respond_to?(:写入?) && 写入?
    提高 ArgumentError, ' timeout_mode=:带有 $out 或 $merge 的聚合管道不支持迭代 '
  end

  # 将其设立为实例变量,而不是更新选项,
  # 因为如果游标类型发生更改(例如,通过 #configure()),新的
  # View实例必须能够选择不同的默认timeout_mode
  # 如果最初未设立timeout_mode。
  @timeout_mode = timeout_mode
end