From 0c6ff50c26e592e9c88e20044e935e94422d2507 Mon Sep 17 00:00:00 2001 From: quix Date: Mon, 15 Sep 2008 23:06:42 -0400 Subject: [PATCH] remove drb from this branch of comp_tree --- .../contrib/quix/lib/quix/diagnostic.rb | 1 + .../comp_tree/contrib/quix/lib/quix/kernel.rb | 1 + contrib/comp_tree/lib/comp_tree/algorithm.rb | 1 - contrib/comp_tree/lib/comp_tree/bucket_ipc.rb | 151 ------------------ contrib/comp_tree/lib/comp_tree/driver.rb | 1 - .../comp_tree/lib/comp_tree/retriable_fork.rb | 43 ----- contrib/comp_tree/test/test_bucketipc.rb | 72 --------- contrib/comp_tree/test/test_comp_tree.rb | 4 + contrib/comp_tree/test/test_exception.rb | 2 +- 9 files changed, 7 insertions(+), 269 deletions(-) delete mode 100644 contrib/comp_tree/lib/comp_tree/bucket_ipc.rb delete mode 100644 contrib/comp_tree/lib/comp_tree/retriable_fork.rb delete mode 100644 contrib/comp_tree/test/test_bucketipc.rb diff --git a/contrib/comp_tree/contrib/quix/lib/quix/diagnostic.rb b/contrib/comp_tree/contrib/quix/lib/quix/diagnostic.rb index bf735e5ba..8424a2d60 100644 --- a/contrib/comp_tree/contrib/quix/lib/quix/diagnostic.rb +++ b/contrib/comp_tree/contrib/quix/lib/quix/diagnostic.rb @@ -1,6 +1,7 @@ require 'rake/comp_tree/tap' +module Rake ; end module Rake::CompTree module Diagnostic def show(desc = nil, stream = STDOUT, &block) diff --git a/contrib/comp_tree/contrib/quix/lib/quix/kernel.rb b/contrib/comp_tree/contrib/quix/lib/quix/kernel.rb index 692ff8abf..3fa55ad3d 100644 --- a/contrib/comp_tree/contrib/quix/lib/quix/kernel.rb +++ b/contrib/comp_tree/contrib/quix/lib/quix/kernel.rb @@ -1,6 +1,7 @@ require 'thread' +module Rake ; end module Rake::CompTree module Misc def let diff --git a/contrib/comp_tree/lib/comp_tree/algorithm.rb b/contrib/comp_tree/lib/comp_tree/algorithm.rb index 5c32094b3..49d49b653 100644 --- a/contrib/comp_tree/lib/comp_tree/algorithm.rb +++ b/contrib/comp_tree/lib/comp_tree/algorithm.rb @@ -1,6 +1,5 @@ require 'rake/comp_tree/diagnostic' -require 'rake/comp_tree/retriable_fork' module Rake::CompTree module Algorithm diff --git a/contrib/comp_tree/lib/comp_tree/bucket_ipc.rb b/contrib/comp_tree/lib/comp_tree/bucket_ipc.rb deleted file mode 100644 index 20e6b1213..000000000 --- a/contrib/comp_tree/lib/comp_tree/bucket_ipc.rb +++ /dev/null @@ -1,151 +0,0 @@ - -require 'drb' -require 'thread' - -require 'rake/comp_tree/retriable_fork' -require 'rake/comp_tree/diagnostic' -require 'rake/comp_tree/tap' - -module Rake::CompTree - module BucketIPC - class Bucket - include Diagnostic - include RetriableFork - - def initialize(address, timeout, wait_interval) - trace "Making bucket with address #{address}" - - @remote_pid = fork { - own_object = Class.new { - attr_accessor(:contents) - }.new - server = DRb.start_service(address, own_object) - debug { - server.verbose = true - } - DRb.thread.join - } - - @remote_object = DRbObject.new_with_uri(address) - @address = address - @timeout = timeout - @wait_interval = wait_interval - end - - attr_accessor(:timeout, :wait_interval) - attr_reader(:address) - - def contents=(new_contents) - connect { - @remote_object.contents = new_contents - } - end - - def contents - connect { - @remote_object.contents - } - end - - def stop - Process.kill("TERM", @remote_pid) - end - - private - - def connect - begin - return yield - rescue DRb::DRbConnError - start = Time.now - begin - Kernel.sleep(@wait_interval) - return yield - rescue DRb::DRbConnError - if Time.now - start > @timeout - raise - end - retry - end - end - end - end - - class DriverBase - def initialize(addresses, timeout, wait_interval) - begin - @buckets = addresses.map { |address| - Bucket.new(address, timeout, wait_interval) - } - if block_given? - yield @buckets - end - ensure - if block_given? - stop - end - end - end - - def stop - if defined?(@buckets) - @buckets.each { |bucket| - bucket.stop - } - end - end - end - - class Driver < DriverBase - DEFAULTS = { - :timeout => 0.5, - :wait_interval => 0.05, - :port_start => 18181, - } - - module BucketCounter - @mutex = Mutex.new - @count = 0 - class << self - def increment_count - @mutex.synchronize { - @count += 1 - } - end - - def map_indexes(num_buckets) - Array.new.tap { |result| - num_buckets.times { - result << yield(increment_count) - } - } - end - end - end - - def initialize(num_buckets, opts_in = {}) - opts = DEFAULTS.merge(opts_in) - - addresses = - if RetriableFork::HAVE_FORK - # - # Assume the existence of fork implies a unix machine. - # - require 'drb/unix' - basename = "drbunix://#{Dir.tmpdir}/bucket.#{Process.pid}.#{rand}" - BucketCounter.map_indexes(num_buckets) { |index| - "#{basename}.#{index}" - } - else - # - # Fallback: use the default socket. - # - BucketCounter.map_indexes(num_buckets) { |index| - "druby://localhost:#{opts[:port_start] + index}" - } - end - super(addresses, opts[:timeout], opts[:wait_interval]) - end - end - end -end diff --git a/contrib/comp_tree/lib/comp_tree/driver.rb b/contrib/comp_tree/lib/comp_tree/driver.rb index 0916c2ea7..519d19e9e 100644 --- a/contrib/comp_tree/lib/comp_tree/driver.rb +++ b/contrib/comp_tree/lib/comp_tree/driver.rb @@ -1,5 +1,4 @@ -require 'rake/comp_tree/bucket_ipc' require 'rake/comp_tree/diagnostic' require 'rake/comp_tree/misc' require 'rake/comp_tree/algorithm' diff --git a/contrib/comp_tree/lib/comp_tree/retriable_fork.rb b/contrib/comp_tree/lib/comp_tree/retriable_fork.rb deleted file mode 100644 index 18fb1ce78..000000000 --- a/contrib/comp_tree/lib/comp_tree/retriable_fork.rb +++ /dev/null @@ -1,43 +0,0 @@ - -module Rake ; end -module Rake::CompTree - module RetriableFork - HAVE_FORK = lambda { - begin - process_id = fork { } - Process.wait(process_id) - rescue NotImplementedError - return false - end - true - }.call - - def fork(retry_wait = 10, retry_max = 10, &block) - num_retries = 0 - begin - Process.fork(&block) - rescue Errno::EAGAIN - num_retries += 1 - if num_retries == retry_max - message = %Q{ - **************************************************************** - Maximum number of EAGAIN signals reached (#{retry_max}) - **************************************************************** - - Either increase your process limit permission (consult your - OS manual) or run this script as superuser. - - **************************************************************** - } - STDERR.puts(message.gsub(%r!^[ \t]+!, "")) - raise - end - STDERR.puts "Caught EGAIN. Retrying in #{retry_wait} seconds." - sleep(retry_wait) - retry - end - end - module_function :fork - end -end - diff --git a/contrib/comp_tree/test/test_bucketipc.rb b/contrib/comp_tree/test/test_bucketipc.rb deleted file mode 100644 index 7d50b30b9..000000000 --- a/contrib/comp_tree/test/test_bucketipc.rb +++ /dev/null @@ -1,72 +0,0 @@ - -$LOAD_PATH.unshift(File.expand_path("#{File.dirname(__FILE__)}/../lib")) - -require 'test/unit' -require 'comp_tree/bucket_ipc' - -Thread.abort_on_exception = true - -class BucketTest < Test::Unit::TestCase - include Rake::CompTree::RetriableFork - - def each_bucket(num_buckets, &block) - if HAVE_FORK - Rake::CompTree::BucketIPC::Driver.new(num_buckets) { |buckets| - buckets.each { |bucket| - yield bucket - } - } - end - end - - def test_1_no_fork - each_bucket(10) { |bucket| - local = bucket.contents = :before - bucket.contents = :after - assert_equal(local, :before) - assert_equal(bucket.contents, :after) - } - end - - def test_2_fork - each_bucket(10) { |bucket| - local = bucket.contents = :before - process_id = fork { - bucket.contents = :after - } - Process.wait(process_id) - assert_equal(local, :before) - assert_equal(bucket.contents, :after) - } - end - - def each_base_test - [ - :test_1_no_fork, - :test_2_fork, - ].each { |method| - yield method - } - end - - def test_3_thread - each_base_test { |method| - Thread.new { - send(method) - }.join - } - end - - def test_4_thread_flood - each_base_test { |method| - (0...10).map { - Thread.new { - send(method) - } - }.each { |thread| - thread.join - } - } - end -end - diff --git a/contrib/comp_tree/test/test_comp_tree.rb b/contrib/comp_tree/test/test_comp_tree.rb index 54dd37580..d89f60e7b 100644 --- a/contrib/comp_tree/test/test_comp_tree.rb +++ b/contrib/comp_tree/test/test_comp_tree.rb @@ -9,6 +9,10 @@ srand(22) module Rake::CompTree + module RetriableFork + HAVE_FORK = false + end + Thread.abort_on_exception = true HAVE_FORK = RetriableFork::HAVE_FORK DO_FORK = (HAVE_FORK and not ARGV.include?("--no-fork")) diff --git a/contrib/comp_tree/test/test_exception.rb b/contrib/comp_tree/test/test_exception.rb index ae9d7fbaa..e0f55cafd 100644 --- a/contrib/comp_tree/test/test_exception.rb +++ b/contrib/comp_tree/test/test_exception.rb @@ -27,7 +27,7 @@ def test_exception if RUBY_PLATFORM =~ %r!java! puts "skipping #{File.basename(__FILE__)}." else - [true, false].each { |use_fork| + [false].each { |use_fork| [true, false].each { |define_all| assert( !system(