Sha256: 5fd9a53178765d820f7dcf50920f1cc01301352986907b534d6dbcdaad132ca7

Contents?: true

Size: 1.38 KB

Versions: 19

Compression:

Stored size: 1.38 KB

Contents

require 'flydata-core/source_pos_base'

# 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 SourcePosBase

  def initialize(txid_snapshot)
    @txid_snapshot_str = txid_snapshot.to_s

    return if set_predefined_flags(@txid_snapshot_str)
    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

  # Override (Comparable)
  def <=>(other)
    s = super
    return s if s

    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

19 entries across 19 versions & 1 rubygems

Version Path
flydata-0.8.10.2 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.8.10.1 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.8.9.11 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.8.10 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.8.9 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.8.8 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.8.7 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.8.6 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.8.5 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.8.4 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.8.3 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.8.2 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.8.1 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.8.0 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.7.19 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.7.18 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.7.17 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.7.16 flydata-core/lib/flydata-core/postgresql/snapshot.rb
flydata-0.7.15 flydata-core/lib/flydata-core/postgresql/snapshot.rb