123456789_123456789_123456789_123456789_123456789_

Class: Mongo::ClusterTime Private

Do not use. This class is for internal use only.
Relationships & Source Files
Namespace Children
Modules:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, BSON::Document
Instance Chain:
self, BSON::Document
Inherits: BSON::Document
  • Object
Defined in: lib/mongo/cluster_time.rb

Overview

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.

Class Method Summary

Instance Method Summary

  • #<(other) Internal use only
  • #<=(other) Internal use only
  • #<=>(other) Internal use only

    Compares two ClusterTime instances by comparing their timestamps.

  • #==(other) Internal use only

    Compares two ClusterTime instances by comparing their timestamps.

  • #>(other) Internal use only
  • #>=(other) Internal use only

    Older Rubies do not implement other logical operators through <=>.

  • #advance(other) Internal use only

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

Class Method Details

.[](doc)

Converts a BSON::Document to a ClusterTime.

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

[ GitHub ]

  
# File '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)

[ GitHub ]

  
# File 'lib/mongo/cluster_time.rb', line 78

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

#<=(other)

[ GitHub ]

  
# File 'lib/mongo/cluster_time.rb', line 75

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

#<=>(other)

Compares two ClusterTime instances by comparing their timestamps.

[ GitHub ]

  
# File '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)

Compares two ClusterTime instances by comparing their timestamps.

[ GitHub ]

  
# File '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)

[ GitHub ]

  
# File 'lib/mongo/cluster_time.rb', line 72

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

#>=(other)

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.

[ GitHub ]

  
# File 'lib/mongo/cluster_time.rb', line 69

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

#advance(other)

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.

[ GitHub ]

  
# File '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