类:Mongo::ClusterTime Private

继承:
BSON::Document
  • 对象
显示全部
定义于:
lib/ Mongo/cluster_time.rb

Overview

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

ClusterTime 封装了集群时间存储和操作。

对集群时间执行的主节点 (primary node in the replica set)操作是将其提前:给定另一个集群时间,选择两个时间中较新的一个。

此类提供了用于确定哪个集群时间较新的比较方法,并在集群时间文档中缺少实际时间时以 lint 模式提供诊断。

在命名空间下定义

模块: 消费者

类方法摘要折叠

实例方法摘要折叠

构造函数详情

#initialize (elements = nil) ⇒ ClusterTime

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

返回 ClusterTime 的新实例。

[查看源代码]

30
31
32
33
34
35
36
# File 'lib/ Mongo/cluster_time.rb', line 30

def 初始化(元素 = nil)
  

  if Lint.已启用? && !self[' clusterTime ']
    提高 ArgumentError, ' Creating a 集群 time without clusterTime 字段 '
  end
end

类方法详细信息

[] (doc) ⇒对象

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

将BSON::Document 转换为 ClusterTime。

doc 可以为 nil,在这种情况下返回 nil。

[查看源代码]

97
98
99
100
101
102
103
# File 'lib/ Mongo/cluster_time.rb', line 97

def [ ](doc)
  if doc.nil? || doc.is_a?(ClusterTime)
    doc
  else
    ClusterTime.new(doc)
  end
end

实例方法详细信息

# < (other) ⇒对象

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

[查看源代码]

78
79
80
# File 'lib/ Mongo/cluster_time.rb', line 78

def <(其他)
  (self <=> 其他) == -1
end

# <= (other) ⇒对象

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

[查看源代码]

75
76
77
# File 'lib/ Mongo/cluster_time.rb', line 75

def <=(其他)
  (self <=> 其他) != 1
end

# <=> (other) ⇒对象

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

通过比较时间戳来比较两个 ClusterTime 实例。

[查看源代码]

56
57
58
59
60
61
62
63
64
# File 'lib/ Mongo/cluster_time.rb', line 56

def <=>(其他)
  if self[' clusterTime '] && 其他[' clusterTime ']
    self[' clusterTime '] <=> 其他[' clusterTime ']
  elsif !self[' clusterTime ']
    提高 ArgumentError, "当接收器缺少 clusterTime key 时,无法比较集群时间: #{ inspect } "
  else 其他[' clusterTime ']
    提高 ArgumentError, " Cannot比较集群时间,当 other 缺少 clusterTime key: #{ other.inspect} "
  end
end

# == (other) ⇒对象

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

通过比较时间戳来比较两个 ClusterTime 实例。

[查看源代码]

83
84
85
86
87
88
89
90
91
# File 'lib/ Mongo/cluster_time.rb', line 83

def ==(其他)
  if self[' clusterTime '] && 其他[' clusterTime '] &&
    self[' clusterTime '] == 其他[' clusterTime ']
  then
    true
  else
    false
  end
end

# > (other) ⇒对象

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

[查看源代码]

72
73
74
# File 'lib/ Mongo/cluster_time.rb', line 72

def >(其他)
  (self <=> 其他) == 1
end

# >= (other) ⇒对象

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

旧版 Ruby 不通过 <=> 实现其他逻辑操作符。 TODO 修改了实施jira.mongodb.org/browse/RUBY-{1 1622时是否需要这些方法。

[查看源代码]

69
70
71
# File 'lib/ Mongo/cluster_time.rb', line 69

def >=(其他)
  (self <=> 其他) != -1
end

# advance (other) ⇒对象

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

将接收器中的集群时间提前到other中的集群时间。

other 可以为零或晚于接收器中的集群时间;在这些情况下,接收者会按原样返回。 如果接收器提前,则返回一个新的 ClusterTime 对象。

返回值为 nil 或 ClusterTime实例。

[查看源代码]

45
46
47
48
49
50
51
52
53
# File 'lib/ Mongo/cluster_time.rb', line 45

def advance(其他)
  if self[' clusterTime '] && 其他[' clusterTime '] &&
    其他[' clusterTime '] > self[' clusterTime ']
  then
    ClusterTime[其他]
  else
    self
  end
end