From dd2089b2646e77fef396e2e62ad313851bfbf04e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 22 Dec 2008 20:44:45 -0800 Subject: [PATCH] Remove NFS support MogileFS 2.x upstream no longer supports it, and it's become a maintenance burden and NFS is a horrible thing anyways. Attempting to use this with servers that support NFS will result in MogileFS::UnsupportedPathError being raised. --- Manifest.txt | 1 - README.txt | 8 ++--- lib/mogilefs.rb | 2 +- lib/mogilefs/mogilefs.rb | 16 +++------- lib/mogilefs/nfsfile.rb | 81 ------------------------------------------------ test/setup.rb | 11 +------ test/test_mogilefs.rb | 44 +++++--------------------- 7 files changed, 16 insertions(+), 147 deletions(-) delete mode 100644 lib/mogilefs/nfsfile.rb diff --git a/Manifest.txt b/Manifest.txt index 3605b1e..9dd4500 100644 --- a/Manifest.txt +++ b/Manifest.txt @@ -11,7 +11,6 @@ lib/mogilefs/client.rb lib/mogilefs/httpfile.rb lib/mogilefs/mogilefs.rb lib/mogilefs/mysql.rb -lib/mogilefs/nfsfile.rb lib/mogilefs/pool.rb lib/mogilefs/util.rb test/setup.rb diff --git a/README.txt b/README.txt index f60229a..71ad0bc 100644 --- a/README.txt +++ b/README.txt @@ -26,7 +26,7 @@ http://git.bogomips.org/cgit/mogilefs-client.git == About A Ruby MogileFS client. MogileFS is a distributed filesystem written -by Danga Interactive. This client supports NFS and HTTP modes. +by Danga Interactive. This client only supports HTTP. For information on MogileFS see: @@ -47,8 +47,6 @@ Then install the gem: hosts = %w[192.168.1.69:6001 192.168.1.70:6001] mg = MogileFS::MogileFS.new(:domain => 'test', :hosts => hosts) - # NFS requires the :root parameter (e.g. :root => '/mnt/mogilefs') - # Stores "A bunch of text to store" into 'some_key' with a class of 'text'. mg.store_content 'some_key', 'text', "A bunch of text to store" @@ -72,5 +70,5 @@ Then install the gem: == WARNING! This client is only supported in HTTP mode. NFS mode was previously -supported but since MogileFS 2.x has dropped support for NFS, do not -expect it to remain working forever. +supported in 1.3.x, but since MogileFS 2.x has dropped support for +NFS, this client has removed support for it. diff --git a/lib/mogilefs.rb b/lib/mogilefs.rb index 1778497..9889d0b 100644 --- a/lib/mogilefs.rb +++ b/lib/mogilefs.rb @@ -22,6 +22,7 @@ module MogileFS def message; 'Empty path for mogile upload'; end end + class UnsupportedPathError < Error; end class RequestTruncatedError < Error; end class InvalidResponseError < Error; end class UnreachableBackendError < Error @@ -31,7 +32,6 @@ module MogileFS end require 'mogilefs/backend' -require 'mogilefs/nfsfile' require 'mogilefs/httpfile' require 'mogilefs/client' require 'mogilefs/bigfile' diff --git a/lib/mogilefs/mogilefs.rb b/lib/mogilefs/mogilefs.rb index b7e2325..a1fc263 100644 --- a/lib/mogilefs/mogilefs.rb +++ b/lib/mogilefs/mogilefs.rb @@ -1,5 +1,4 @@ require 'mogilefs/client' -require 'mogilefs/nfsfile' require 'mogilefs/util' ## @@ -11,11 +10,6 @@ class MogileFS::MogileFS < MogileFS::Client include MogileFS::Bigfile ## - # The path to the local MogileFS mount point if you are using NFS mode. - - attr_reader :root - - ## # The domain of keys for this MogileFS client. attr_reader :domain @@ -27,12 +21,10 @@ class MogileFS::MogileFS < MogileFS::Client ## # Creates a new MogileFS::MogileFS instance. +args+ must include a key - # :domain specifying the domain of this client. A key :root will be used to - # specify the root of the NFS file system. + # :domain specifying the domain of this client. def initialize(args = {}) @domain = args[:domain] - @root = args[:root] @get_file_data_timeout = 5 @@ -99,7 +91,6 @@ class MogileFS::MogileFS < MogileFS::Client paths = (1..res['paths'].to_i).map { |i| res["path#{i}"] } return paths if paths.empty? return paths if paths.first =~ /^http:\/\// - return paths.map { |path| File.join @root, path } end ## @@ -134,12 +125,13 @@ class MogileFS::MogileFS < MogileFS::Client case path when nil, '' then - raise EmptyPathError + raise MogileFS::EmptyPathError when /^http:\/\// then MogileFS::HTTPFile.open(self, res['fid'], path, devid, klass, key, dests, bytes, &block) else - MogileFS::NFSFile.open(self, res['fid'], path, devid, klass, key, &block) + raise MogileFS::UnsupportedPathError, + "path '#{path}' returned by backend is not supported" end end diff --git a/lib/mogilefs/nfsfile.rb b/lib/mogilefs/nfsfile.rb deleted file mode 100644 index d4040c2..0000000 --- a/lib/mogilefs/nfsfile.rb +++ /dev/null @@ -1,81 +0,0 @@ -require 'mogilefs/backend' - -## -# NFSFile wraps up the new file operations for storing files onto an NFS -# storage node. -# -# You really don't want to create an NFSFile by hand. Instead you want to -# create a new file using MogileFS::MogileFS.new_file. - -class MogileFS::NFSFile < File - - ## - # The path of this file not including the local mount point. - - attr_reader :path - - ## - # The key for this file. This key won't represent a real file until you've - # called #close. - - attr_reader :key - - ## - # The class of this file. - - attr_reader :class - - class << self - - ## - # Wraps up File.new with MogileFS-specific data. Use - # MogileFS::MogileFS#new_file instead of this method. - - def new(mg, fid, path, devid, klass, key) - fp = super join(mg.root, path), 'w+' - fp.send :setup, mg, fid, path, devid, klass, key - return fp - end - - ## - # Wraps up File.open with MogileFS-specific data. Use - # MogileFS::MogileFS#new_file instead of this method. - - def open(mg, fid, path, devid, klass, key, &block) - fp = new mg, fid, path, devid, klass, key - - return fp if block.nil? - - begin - yield fp - ensure - fp.close - end - end - - end - - ## - # Closes the file handle and marks it as closed in MogileFS. - - def close - super - @mg.backend.create_close(:fid => @fid, :devid => @devid, - :domain => @mg.domain, :key => @key, - :path => @path) - return nil - end - - private - - def setup(mg, fid, path, devid, klass, key) - @mg = mg - @fid = fid - @path = path - @devid = devid - @klass = klass - @key = key - end - -end - diff --git a/test/setup.rb b/test/setup.rb index d8d213d..cebb6e9 100644 --- a/test/setup.rb +++ b/test/setup.rb @@ -88,20 +88,11 @@ class TestMogileFS < Test::Unit::TestCase undef_method :default_test def setup - @tempdir = File.join Dir.tmpdir, "test_mogilefs_#{$$}" - @root = File.join @tempdir, 'root' - FileUtils.mkdir_p @root - - @client = @klass.new :hosts => ['kaa:6001'], :domain => 'test', - :root => @root + @client = @klass.new :hosts => ['kaa:6001'], :domain => 'test' @backend = FakeBackend.new @client.instance_variable_set '@backend', @backend end - def teardown - FileUtils.rm_rf @tempdir - end - end # for our mock results diff --git a/test/test_mogilefs.rb b/test/test_mogilefs.rb index 31aeeca..884f90d 100644 --- a/test/test_mogilefs.rb +++ b/test/test_mogilefs.rb @@ -13,10 +13,9 @@ class TestMogileFS__MogileFS < TestMogileFS def test_initialize assert_equal 'test', @client.domain - assert_equal @root, @client.root assert_raises ArgumentError do - MogileFS::MogileFS.new :hosts => ['kaa:6001'], :root => '/mogilefs/test' + MogileFS::MogileFS.new :hosts => ['kaa:6001'] end end @@ -95,12 +94,12 @@ class TestMogileFS__MogileFS < TestMogileFS end def test_get_paths - path1 = 'rur-1/dev1/0/000/000/0000000062.fid' - path2 = 'rur-2/dev2/0/000/000/0000000062.fid' + path1 = 'http://rur-1/dev1/0/000/000/0000000062.fid' + path2 = 'http://rur-2/dev2/0/000/000/0000000062.fid' @backend.get_paths = { 'paths' => 2, 'path1' => path1, 'path2' => path2 } - expected = ["#{@root}/#{path1}", "#{@root}/#{path2}"] + expected = [ path1, path2 ] assert_equal expected, @client.get_paths('key').sort end @@ -224,16 +223,6 @@ class TestMogileFS__MogileFS < TestMogileFS assert_equal 1, accept_nr end - def test_size_nfs - path = File.join @root, 'path' - - File.open path, 'w' do |fp| fp.write 'data!' end - - @backend.get_paths = { 'paths' => 1, 'path1' => 'path' } - - assert_equal 5, @client.size('key') - end - def test_store_content_http received = '' expected = "PUT /path HTTP/1.0\r\nContent-Length: 4\r\n\r\ndata" @@ -303,28 +292,9 @@ class TestMogileFS__MogileFS < TestMogileFS 'devid_1' => '1', 'path_1' => '/path', } - - @client.store_content 'new_key', 'test', 'data' - - dest_file = File.join(@root, 'path') - - assert File.exist?(dest_file) - assert_equal 'data', File.read(dest_file) - end - - def test_store_content_nfs_empty - @backend.create_open = { - 'dev_count' => '1', - 'devid_1' => '1', - 'path_1' => '/path', - } - - @client.store_content 'new_key', 'test', '' - - dest_file = File.join(@root, 'path') - - assert File.exist?(dest_file) - assert_equal '', File.read(dest_file) + assert_raises MogileFS::UnsupportedPathError do + @client.store_content 'new_key', 'test', 'data' + end end def test_new_file_http_large -- 2.11.4.GIT