Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 0 additions & 62 deletions lib/riak/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,56 +246,20 @@ def client_id
end
end

# Deletes a file stored via the "Luwak" interface
# @param [String] filename the key/filename to delete
def delete_file(filename)
http do |h|
h.delete_file(filename)
end
true
end

# Delete an object. See Bucket#delete
def delete_object(bucket, key, options = {})
backend do |b|
b.delete_object(bucket, key, options)
end
end

# Checks whether a file exists in "Luwak".
# @param [String] key the key to check
# @return [true, false] whether the key exists in "Luwak"
def file_exists?(key)
http do |h|
h.file_exists?(key)
end
end
alias :file_exist? :file_exists?

# Bucket properties. See Bucket#props
def get_bucket_props(bucket)
backend do |b|
b.get_bucket_props bucket
end
end

# Retrieves a large file/IO object from Riak via the "Luwak"
# interface. Streams the data to a temporary file unless a block
# is given.
# @param [String] filename the key/filename for the object
# @return [IO, nil] the file (also having content_type and
# original_filename accessors). The file will need to be
# reopened to be read. nil will be returned if a block is given.
# @yield [chunk] stream contents of the file through the
# block. Passing the block will result in nil being returned
# from the method.
# @yieldparam [String] chunk a single chunk of the object's data
def get_file(filename, &block)
http do |h|
h.get_file(filename, &block)
end
end

# Queries a secondary index on a bucket. See Bucket#get_index
def get_index(bucket, index, query, options={})
backend do |b|
Expand Down Expand Up @@ -527,22 +491,6 @@ def stamp
@stamp ||= Riak::Stamp.new(self)
end

# Stores a large file/IO-like object in Riak via the "Luwak" interface.
# @overload store_file(filename, content_type, data)
# Stores the file at the given key/filename
# @param [String] filename the key/filename for the object
# @param [String] content_type the MIME Content-Type for the data
# @param [IO, String] data the contents of the file
# @overload store_file(content_type, data)
# Stores the file with a server-determined key/filename
# @param [String] content_type the MIME Content-Type for the data
# @param [String, #read] data the contents of the file
# @return [String] the key/filename where the object was stored
def store_file(*args)
http do |h|
h.store_file(*args)
end
end

# Stores an object in Riak.
def store_object(object, options = {})
Expand All @@ -568,15 +516,5 @@ def ssl_disable
n.ssl_disable
end
end

# @private
class LuwakFile < DelegateClass(Tempfile)
attr_accessor :original_filename, :content_type
alias :key :original_filename
def initialize(fn)
super(Tempfile.new(fn))
@original_filename = fn
end
end
end
end
63 changes: 0 additions & 63 deletions lib/riak/client/http_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,69 +322,6 @@ def update_search_index(index, updates)
post(200, solr_update_path(index), updates, {'Content-Type' => 'text/xml'})
end

# (Luwak) Fetches a file from the Luwak large-file interface.
# @param [String] filename the name of the file
# @yield [chunk] A block which will receive individual chunks of
# the file as they are streamed
# @yieldparam [String] chunk a block of the file
# @return [IO, nil] the file (also having content_type and
# original_filename accessors). The file will need to be
# reopened to be read
def get_file(filename, &block)
if block_given?
get(200, luwak_path(filename), &block)
nil
else
tmpfile = LuwakFile.new(escape(filename))
begin
response = get(200, luwak_path(filename)) do |chunk|
tmpfile.write chunk
end
tmpfile.content_type = response[:headers]['content-type'].first
tmpfile
ensure
tmpfile.close
end
end
end

# (Luwak) Detects whether a file exists in the Luwak large-file
# interface.
# @param [String] filename the name of the file
# @return [true,false] whether the file exists
def file_exists?(filename)
result = head([200,404], luwak_path(filename))
result[:code] == 200
end

# (Luwak) Deletes a file from the Luwak large-file interface.
# @param [String] filename the name of the file
def delete_file(filename)
delete([204,404], luwak_path(filename))
end

# (Luwak) Uploads a file to the Luwak large-file interface.
# @overload store_file(filename, content_type, data)
# Stores the file at the given key/filename
# @param [String] filename the key/filename for the object
# @param [String] content_type the MIME Content-Type for the data
# @param [IO, String] data the contents of the file
# @overload store_file(content_type, data)
# Stores the file with a server-determined key/filename
# @param [String] content_type the MIME Content-Type for the data
# @param [String, #read] data the contents of the file
# @return [String] the key/filename where the object was stored
def store_file(*args)
data, content_type, filename = args.reverse
if filename
put(204, luwak_path(filename), data, {"Content-Type" => content_type})
filename
else
response = post(201, luwak_path(nil), data, {"Content-Type" => content_type})
response[:headers]["location"].first.split("/").last
end
end

private
def normalize_search_response(json)
{}.tap do |result|
Expand Down
15 changes: 0 additions & 15 deletions lib/riak/client/http_backend/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

require 'riak/failed_request'
require 'riak/client/http_backend'
require 'riak/link'
Expand Down Expand Up @@ -148,16 +147,6 @@ def solr_update_path(index)
end
end

# @return [URI] a URL path for the Luwak interface
def luwak_path(key)
raise t('luwak_unsupported') unless luwak_wm_file
if key
path(luwak_wm_file, escape(key))
else
path(luwak_wm_file)
end
end

private
def server_config
@server_config ||= {}.tap do |hash|
Expand Down Expand Up @@ -217,10 +206,6 @@ def riak_solr_searcher_wm
def riak_solr_indexer_wm
server_config[:riak_solr_indexer_wm]
end

def luwak_wm_file
server_config[:luwak_wm_file]
end
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions lib/riak/client/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Node
include Util::Escape

VALID_OPTIONS = [:host, :http_port, :pb_port, :http_paths, :prefix,
:mapred, :luwak, :solr, :port, :basic_auth, :ssl_options, :ssl]
:mapred, :solr, :port, :basic_auth, :ssl_options, :ssl]

# For a score which halves in 10 seconds, choose
# ln(1/2)/10
Expand Down Expand Up @@ -37,7 +37,6 @@ def initialize(client, opts = {})
@http_paths = {
:prefix => opts[:prefix] || "/riak/",
:mapred => opts[:mapred] || "/mapred",
:luwak => opts[:luwak] || "/luwak",
:solr => opts[:solr] || "/solr" # Unused?
}.merge(opts[:http_paths] || {})
self.basic_auth = opts[:basic_auth]
Expand Down
1 change: 0 additions & 1 deletion lib/riak/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ en:
loading_bucket: "while loading bucket '%{name}'"
list_buckets: "Riak::Client#buckets is an expensive operation that should not be used in production.\n %{backtrace}"
list_keys: "Riak::Bucket#keys is an expensive operation that should not be used in production.\n %{backtrace}"
luwak_unsupported: "Riak server does not support Luwak. Enable it in app.config before using."
missing_block: "A block must be given."
missing_host_and_port: "You must specify a host and port, or use the defaults of 127.0.0.1:8098"
module_function_pair_required: "function must have two elements when an array"
Expand Down
1 change: 0 additions & 1 deletion lib/riak/locale/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ fr:
loading_bucket: "pendant le chargement du bucket '%{name}'"
list_buckets: "Riak::Client#buckets est une opération coûteuse et ne doit pas être utilisée en production.\n %{backtrace}"
list_keys: "Riak::Bucket#keys est une opération coûteuse et ne doit pas être utilisée en production.\n %{backtrace}"
luwak_unsupported: "Le serveur Riak ne supporte pas Luwak. Activez-le dans app.config avant de l'utiliser"
missing_block: "Un bloc doit être fourni."
missing_host_and_port: "Vous devez spécifier un hôte et un port, utiliser la valeur par défaut : 127.0.0.1:8098"
module_function_pair_required: "la fonction doit avoir deux élément lorsqu'elle est définie par un tableau"
Expand Down
3 changes: 0 additions & 3 deletions lib/riak/node/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ class Node
:riak_search => {
:enabled => true
},
:luwak => {
:enabled => true
},
:merge_index => {
:buffer_rollover_size => 1048576,
:max_compact_segments => 20
Expand Down
51 changes: 0 additions & 51 deletions spec/integration/riak/http_backends_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,57 +51,6 @@
@backend.get_bucket_props(bucket)['n_val'].should == original_n
end
end

context "using Luwak", :version => "< 1.1.0" do
let(:file) { File.open(__FILE__) }
let(:key) { "spec.rb" }
let(:string) { file.read }

def retry_400
begin
yield
rescue Riak::HTTPFailedRequest => e
# Riak 1.0.x (and possibly earlier) has a bug in
# mochiweb that will sometimes leave dangling 400
# responses on the wire between requests when the
# connection is left open. This will happen sometimes
# immediately after a store_file request.
if e.code == 400
retry
else
raise
end
end
end

it "should store an IO with a given key" do
@backend.store_file(key, 'text/plain', file)
stored_file = retry_400 { @backend.get_file(key) }
stored_file.content_type.should == 'text/plain'
stored_file.size.should == file.size
end

it "should store a String with a given key" do
@backend.store_file(key, 'text/plain', string)
stored_file = retry_400 { @backend.get_file(key) }
stored_file.content_type.should == 'text/plain'
stored_file.size.should == string.bytesize
end

it "should store an IO with a server-defined key" do
key = @backend.store_file('text/plain', file)
stored_file = retry_400 { @backend.get_file(key) }
stored_file.content_type.should == 'text/plain'
stored_file.size.should == file.size
end

it "should store a String with a server-defined key" do
key = @backend.store_file('text/plain', string)
stored_file = retry_400 { @backend.get_file(key) }
stored_file.content_type.should == 'text/plain'
stored_file.size.should == string.bytesize
end
end
end
end
end
Expand Down
53 changes: 0 additions & 53 deletions spec/riak/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@
client.nodes.first.http_paths[:mapred].should == "/mr"
end

it "should accept a luwak path" do
client = Riak::Client.new(:luwak => "/beans")
client.nodes.first.http_paths[:luwak].should == "/beans"
end

it "should accept a solr path" do
client = Riak::Client.new(:solr => "/solar")
client.nodes.first.http_paths[:solr].should == "/solar"
Expand Down Expand Up @@ -280,54 +275,6 @@
end
end

describe "Luwak (large-files) support" do
describe "storing a file" do
before :each do
@client = Riak::Client.new
@http = mock(Riak::Client::HTTPBackend)
@http.stub!(:node).and_return(@client.node)
@client.stub!(:http).and_yield(@http)
end

it "should store the file via the HTTP interface" do
@http.should_receive(:store_file).with("text/plain", "Hello, world").and_return("123456789")
@client.store_file("text/plain", "Hello, world").should == "123456789"
end
end

describe "retrieving a file" do
before :each do
@client = Riak::Client.new
@http = mock(Riak::Client::HTTPBackend)
@http.stub!(:node).and_return(@client.node)
@client.stub!(:http).and_yield(@http)
end

it "should fetch via HTTP" do
@http.should_receive(:get_file).with("greeting.txt")
@client.get_file("greeting.txt")
end
end

it "should delete a file" do
@client = Riak::Client.new
@http = mock(Riak::Client::HTTPBackend)
@http.stub!(:node).and_return(@client.nodes.first)
@client.stub!(:http).and_yield(@http)
@http.should_receive(:delete_file).with("greeting.txt")
@client.delete_file("greeting.txt")
end

it "should detect if file exists via HTTP" do
@client = Riak::Client.new
@http = mock(Riak::Client::HTTPBackend)
@http.stub!(:node).and_return(@client.nodes.first)
@client.stub!(:http).and_yield(@http)
@http.should_receive(:file_exists?).and_return(true)
@client.file_exists?("foo").should be_true
end
end

describe "ssl", :ssl => true do
before :each do
@client = Riak::Client.new
Expand Down
Loading