Class: Mongo::ClusterTime Private

Inherits:
BSON::Document
  • Object
show all
Defined in:
build/ruby-driver-v2.19/lib/mongo/cluster_time.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

ClusterTime encapsulates cluster time storage and operations.

The primary operation performed on the cluster time is advancing it: given another cluster time, pick the newer of the two.

This class provides comparison methods that are used to figure out which cluster time is newer, and provides diagnostics in lint mode when the actual time is missing from a cluster time document.

Defined Under Namespace

Modules: Consumer

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(elements = nil) ⇒ ClusterTime

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ClusterTime.



30
31
32
33
34
35
36
# File 'build/ruby-driver-v2.19/lib/mongo/cluster_time.rb', line 30

def initialize(elements = nil)
  super

  if Lint.enabled? && !self['clusterTime']
    raise ArgumentError, 'Creating a cluster time without clusterTime field'
  end
end

Class Method Details

.[](doc) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts a BSON::Document to a ClusterTime.

doc can be nil, in which case nil is returned.



97
98
99
100
101
102
103
# File 'build/ruby-driver-v2.19/lib/mongo/cluster_time.rb', line 97

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

Instance Method Details

#<(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



78
79
80
# File 'build/ruby-driver-v2.19/lib/mongo/cluster_time.rb', line 78

def <(other)
  (self <=> other) == -1
end

#<=(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



75
76
77
# File 'build/ruby-driver-v2.19/lib/mongo/cluster_time.rb', line 75

def <=(other)
  (self <=> other) != 1
end

#<=>(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Compares two ClusterTime instances by comparing their timestamps.



56
57
58
59
60
61
62
63
64
# File 'build/ruby-driver-v2.19/lib/mongo/cluster_time.rb', line 56

def <=>(other)
  if self['clusterTime'] && other['clusterTime']
    self['clusterTime'] <=> other['clusterTime']
  elsif !self['clusterTime']
    raise ArgumentError, "Cannot compare cluster times when receiver is missing clusterTime key: #{inspect}"
  else other['clusterTime']
    raise ArgumentError, "Cannot compare cluster times when other is missing clusterTime key: #{other.inspect}"
  end
end

#==(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Compares two ClusterTime instances by comparing their timestamps.



83
84
85
86
87
88
89
90
91
# File 'build/ruby-driver-v2.19/lib/mongo/cluster_time.rb', line 83

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

#>(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



72
73
74
# File 'build/ruby-driver-v2.19/lib/mongo/cluster_time.rb', line 72

def >(other)
  (self <=> other) == 1
end

#>=(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Older Rubies do not implement other logical operators through <=>. TODO revise whether these methods are needed when jira.mongodb.org/browse/RUBY-1622 is implemented.



69
70
71
# File 'build/ruby-driver-v2.19/lib/mongo/cluster_time.rb', line 69

def >=(other)
  (self <=> other) != -1
end

#advance(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Advances the cluster time in the receiver to the cluster time in other.

other can be nil or be behind the cluster time in the receiver; in these cases the receiver is returned unmodified. If receiver is advanced, a new ClusterTime object is returned.

Return value is nil or a ClusterTime instance.



45
46
47
48
49
50
51
52
53
# File 'build/ruby-driver-v2.19/lib/mongo/cluster_time.rb', line 45

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