class Riak::Client::ProtobuffsBackend

Constants

MESSAGE_CODES
QUORUMS
UINTMAX

Attributes

client[RW]
node[RW]

Public Class Methods

new(client, node) click to toggle source
# File lib/riak/client/protobuffs_backend.rb, line 36
def initialize(client, node)
  @client = client
  @node = node
end
simple(method, code) click to toggle source
# File lib/riak/client/protobuffs_backend.rb, line 26
def self.simple(method, code)
  define_method method do
    socket.write([1, MESSAGE_CODES.index(code)].pack('NC'))
    decode_response
  end
end

Public Instance Methods

get_index(bucket, index, query) click to toggle source

Performs a secondary-index query via emulation through MapReduce. @param [String, Bucket] bucket the bucket to query @param [String] index the index to query @param [String, Integer, Range] query the equality query or

range query to perform

@return [Array<String>] a list of keys matching the query

# File lib/riak/client/protobuffs_backend.rb, line 47
def get_index(bucket, index, query)
  mr = Riak::MapReduce.new(client).index(bucket, index, query)
  unless mapred_phaseless?
    mr.reduce(%w[riak_kv_mapreduce reduce_identity], :arg => {:reduce_phase_only_1 => true}, :keep => true)
  end
  mapred(mr).map {|p| p.last }
end
socket() click to toggle source
# File lib/riak/client/protobuffs_backend.rb, line 81
def socket
  @socket ||= new_socket
end
teardown() click to toggle source

Gracefully shuts down this connection.

# File lib/riak/client/protobuffs_backend.rb, line 77
def teardown
  reset_socket
end

Private Instance Methods

decode_response() click to toggle source

Implemented by subclasses

# File lib/riak/client/protobuffs_backend.rb, line 91
def decode_response
  raise NotImplementedError
end
denormalize_quorum_value(q) click to toggle source
# File lib/riak/client/protobuffs_backend.rb, line 139
def denormalize_quorum_value(q)
  QUORUMS.invert[q] || q.to_i
end
get_server_version() click to toggle source
# File lib/riak/client/protobuffs_backend.rb, line 86
def get_server_version
  server_info[:server_version]
end
new_socket() click to toggle source
# File lib/riak/client/protobuffs_backend.rb, line 95
def new_socket
  raise NotImplementedError
end
normalize_quorum_value(q) click to toggle source
# File lib/riak/client/protobuffs_backend.rb, line 135
def normalize_quorum_value(q)
  QUORUMS[q.to_s] || q.to_i
end
normalize_quorums(options = {}) click to toggle source
# File lib/riak/client/protobuffs_backend.rb, line 125
def normalize_quorums(options = {})
  options.dup.tap do |o|
    [:r, :pr, :w, :pw, :dw, :rw].each do |k|
      next o[k] = normalize_quorum_value(o[k]) if o[k]
      s = k.to_s
      o[k] = o[s] = denormalize_quorum_value(o[s]) if o[s]
    end
  end
end
prune_unsupported_options(req, options = {}) click to toggle source
# File lib/riak/client/protobuffs_backend.rb, line 105
def prune_unsupported_options(req, options = {})
  unless quorum_controls?
    [:notfound_ok, :basic_quorum, :pr, :pw].each {|k| options.delete k }
  end
  unless key_object_bucket_timeouts?
    options.delete :timeout
  end
  unless pb_head?
    [:head, :return_head].each {|k| options.delete k }
  end
  unless tombstone_vclocks?
    options.delete :deletedvclock
    options.delete :vclock if req == :DelReq
  end
  unless pb_conditionals?
    [:if_not_modified, :if_none_match, :if_modified].each {|k| options.delete k }
  end
  options
end
reset_socket() click to toggle source
# File lib/riak/client/protobuffs_backend.rb, line 99
def reset_socket
  reset_server_version
  @socket.close if @socket && !@socket.closed?
  @socket = nil
end