map_reduce 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,15 +2,17 @@ module MapReduce
2
2
  class MapLog
3
3
  MAX_BUFFER_SIZE = 2 ** 21 # 2 MB
4
4
 
5
+ attr_reader :log_folder
6
+
5
7
  def initialize(log_folder, task)
6
- @log_folder = log_folder
7
- @task = task
8
+ @task = task || "default"
9
+ @log_folder = File.join(log_folder, @task)
8
10
  @log = ""
9
11
  @log_size = 0
10
12
  end
11
13
 
12
14
  def <<(str)
13
- @log_size += str.size
15
+ @log_size += str.bytesize
14
16
  @log << str << "\n"
15
17
  flush if @log_size >= MAX_BUFFER_SIZE
16
18
  end
@@ -26,17 +28,19 @@ module MapReduce
26
28
  def reset
27
29
  flush
28
30
  if @log_file
29
- fn = File.path(@log_file)
31
+ map_fn = File.path(@log_file)
30
32
  @log_file.close
33
+ reduce_fn = File.join(@log_folder, "reducer.log")
34
+ File.rename(map_fn, reduce_fn)
31
35
  @log_file = nil
32
- fn
36
+ reduce_fn
33
37
  end
34
38
  end
35
39
 
36
40
  def log_file
37
41
  @log_file ||= begin
38
42
  begin
39
- fn = File.join(@log_folder, "map_#{@task}_#{Time.now.to_i}_#{Process.pid}_#{rand(1000)}.log")
43
+ fn = File.join(@log_folder, "mapper.log")
40
44
  end while File.exist?(fn)
41
45
  FileUtils.mkdir_p(@log_folder)
42
46
  File.open(fn, "a")
@@ -23,7 +23,7 @@ module MapReduce
23
23
  end
24
24
  rescue StopIteration => e
25
25
  @file.close
26
- FileUtils.rm(File.path(@file))
26
+ File.unlink(File.path(@file))
27
27
  @lines = nil
28
28
  break
29
29
  end
@@ -43,11 +43,15 @@ module MapReduce
43
43
  end
44
44
 
45
45
  def log_file
46
- fn = @map_log.reset
47
- if fn
48
- @more = true
49
- sort(fn)
50
- fn
46
+ reduce_fn = File.join(@map_log.log_folder, "reducer.log")
47
+ if File.exist? reduce_fn
48
+ reduce_fn
49
+ else
50
+ reduce_fn = @map_log.reset
51
+ if reduce_fn
52
+ sort(reduce_fn)
53
+ reduce_fn
54
+ end
51
55
  end
52
56
  end
53
57
 
@@ -1,3 +1,3 @@
1
1
  module MapReduce
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -4,7 +4,8 @@ describe "MapReduce stack" do
4
4
  describe "single master" do
5
5
  before do
6
6
  @pid1 = fork do
7
- master = MapReduce::Master.new socket: "tcp://127.0.0.1:15555"
7
+ master = MapReduce::Master.new socket: "tcp://127.0.0.1:15555",
8
+ log_folder: "/tmp/map_reduce/master1"
8
9
  trap("SIGINT") do
9
10
  master.stop
10
11
  exit
@@ -12,7 +13,8 @@ describe "MapReduce stack" do
12
13
  master.run
13
14
  end
14
15
  @pid2 = fork do
15
- master = MapReduce::Master.new socket: "tcp://127.0.0.1:15556"
16
+ master = MapReduce::Master.new socket: "tcp://127.0.0.1:15556",
17
+ log_folder: "/tmp/map_reduce/master2"
16
18
  trap("SIGINT") do
17
19
  master.stop
18
20
  exit
@@ -94,7 +96,7 @@ describe "MapReduce stack" do
94
96
  end
95
97
  end
96
98
  data.sort.must_equal (0...100).to_a.map(&:to_s).sort
97
-
99
+
98
100
  EM.stop
99
101
  end.resume
100
102
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: map_reduce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-04 00:00:00.000000000 Z
12
+ date: 2013-07-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -117,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
117
  version: '0'
118
118
  segments:
119
119
  - 0
120
- hash: 1253589631458738880
120
+ hash: 3976831796496443677
121
121
  required_rubygems_version: !ruby/object:Gem::Requirement
122
122
  none: false
123
123
  requirements:
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  version: '0'
127
127
  segments:
128
128
  - 0
129
- hash: 1253589631458738880
129
+ hash: 3976831796496443677
130
130
  requirements: []
131
131
  rubyforge_project:
132
132
  rubygems_version: 1.8.25