lib/metricstore/inserter.rb
# Returns a list of the values that were newly inserted, or else nil
# if there was contention, and we have to retry.
Returns a list of the values that were newly inserted, or else nil
if there was contention, and we have to retry.
Returns a list of the values that were newly inserted or else nil if there was contention and we have to retry .
def handle_update(key, values, ttl, errors)
      return [] if values.nil? || values.empty?
      list, cas = kvstore.fetch(key, :ttl => ttl)
      if list.nil?
        if values == 'overflow' || values.size > list_threshold
          if kvstore.add(key, 'overflow', :ttl => ttl)
            return []
          else
            retry_update(key, 'overflow', ttl, errors)
            return nil
          end
        elsif kvstore.add(key, values.to_a, :ttl => ttl)
          return values
        else
          retry_update(key, values, ttl, errors)
          return nil
        end
      elsif list == 'overflow'
        return []
      else
        list = Set.new(list)
        values = values.reject{ |v| list.include?(v) }
        return [] if values.empty?
        new_list = values + list.to_a
        if new_list.size > list_threshold
          if kvstore.set(key, 'overflow', :cas => cas, :ttl => ttl)
            return []
          else
            retry_update(key, 'overflow', ttl, errors)
            return nil
          end
        elsif kvstore.set(key, new_list, :cas => cas, :ttl => ttl)
          return values
        else
          retry_update(key, values, ttl, errors)
          return nil
        end
      end
    end
def handle_update ( key , values , ttl , errors ) return [ ] if values . nil? || values . empty? list , cas = kvstore . fetch ( key , :ttl => ttl ) if list . nil? if values == 'overflow' || values . size > list_threshold if kvstore . add ( key , 'overflow' , :ttl => ttl ) return [ ] else retry_update ( key , 'overflow' , ttl , errors ) return nil end elsif kvstore . add ( key , values . to_a , :ttl => ttl ) return values else retry_update ( key , values , ttl , errors ) return nil end elsif list == 'overflow' return [ ] else list = Set . new ( list ) values = values . reject { | v | list . include? ( v ) } return [ ] if values . empty? new_list = values + list . to_a if new_list . size > list_threshold if kvstore . set ( key , 'overflow' , :cas => cas , :ttl => ttl ) return [ ] else retry_update ( key , 'overflow' , ttl , errors ) return nil end elsif kvstore . set ( key , new_list , :cas => cas , :ttl => ttl ) return values else retry_update ( key , values , ttl , errors ) return nil end end end
Returns a list of the values that were newly inserted, or else nil
if there was contention, and we have to retry.
Returns a list of the values that were newly inserted or else nil if there was contention and we have to retry .
#TODO: there's room here for a local cache optimization # collision # collision # collision # collision
key
<not_specific>
values
<not_specific>
ttl
<not_specific>
errors
<not_specific>