Sha256: e52f8a985763eeecc44a6c71b99b2284172f5713c001a6323e534708e8ea1a27

Contents?: true

Size: 1.46 KB

Versions: 14

Compression:

Stored size: 1.46 KB

Contents

# Snapshot components
# http://www.postgresql.org/docs/8.3/static/functions-info.html#FUNCTIONS-TXID-SNAPSHOT-PARTS
#
# Example) 10:20:10,14,15 means xmin=10, xmax=20, xip_list=10, 14, 15.

module FlydataCore
module Postgresql

class Snapshot
  include Comparable

  def initialize(txid_snapshot)
    @txid_snapshot_str = txid_snapshot.to_s

    return if self.empty?
    xmin_str, xmax_str, xip_list_str = @txid_snapshot_str.split(':')

    raise ArgumentError, "Invalid snapshot - xmin is empty." if xmin_str.to_s.empty?
    raise ArgumentError, "Invalid snapshot - xmax is empty." if xmax_str.to_s.empty?

    @xmin = xmin_str.to_i
    @xmax = xmax_str.to_i
    @xip_list = xip_list_str.to_s.split(',').collect(&:to_i)
  end

  attr_reader :xmin, :xmax, :xip_list

  def to_s
    @txid_snapshot_str
  end

  def empty?
    @txid_snapshot_str == '-'
  end

  def <=>(other)
    return 0 if empty? && other.empty?
    if self.empty? || other.empty?
      raise ArgumentError.new("comparison with empty source pos failed")
    end

    if @xmin == other.xmin
      if @xmax == other.xmax
        # items xip_list will disappear after the transaction is completed,
        # because xip_list is an active transaction list.
        #
        # The following comparison needs to be true
        #   "10:18:10,11,12" < "10:18:11,12"
        (other.xip_list.size <=> @xip_list.size)
      else
        @xmax <=> other.xmax
      end
    else
      @xmin <=> other.xmin
    end
  end
end

end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
flydata-0.7.14 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.7.13 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.7.12 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.7.11 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.7.10 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.7.9 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.7.8 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.7.7 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.7.6 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.7.5 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.7.4 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.7.2.1 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.7.2 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.7.1 flydata-core/lib/flydata-core/postgresql/snapshot.rb