Class: ActiveSupport::Cache::CouchbaseStore::AllMutations

Inherits:
Object
  • Object
show all
Defined in:
lib/active_support/cache/couchbase_store.rb,
/home/runner/work/couchbase-ruby-client/couchbase-ruby-client/lib/active_support/cache/couchbase_store.rb

Overview

mutation_tracking: :all: the newest token of every vBucket written to, at most one per vBucket however many writes there were.

Instance Method Summary collapse

Constructor Details

#initialize ⇒ AllMutations

Returns a new instance of AllMutations.



73
74
75
76
# File 'lib/active_support/cache/couchbase_store.rb', line 73

def initialize
  @tokens = {}
  @lock = Mutex.new
end

Instance Method Details

#mutation_state ⇒ Object



92
93
94
95
# File 'lib/active_support/cache/couchbase_store.rb', line 92

def mutation_state
  tokens = @lock.synchronize { @tokens.values }
  ::Couchbase::MutationState.new(*tokens) unless tokens.empty?
end

#record(*tokens) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/active_support/cache/couchbase_store.rb', line 78

def record(*tokens)
  @lock.synchronize do
    tokens.compact.each do |token|
      key = [token.bucket_name, token.partition_id]
      known = @tokens[key]
      # After a failover the partition_uuid changes and sequence numbers
      # do not compare across it, so the token recorded last is kept.
      next if known && known.partition_uuid == token.partition_uuid && known.sequence_number >= token.sequence_number

      @tokens[key] = token
    end
  end
end