fairy 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +674 -0
- data/Makefile +116 -0
- data/README +15 -0
- data/bin/fairy +582 -0
- data/bin/fairy-cat +74 -0
- data/bin/fairy-cp +128 -0
- data/bin/fairy-rm +122 -0
- data/bin/subcmd/controller +41 -0
- data/bin/subcmd/inspector +81 -0
- data/bin/subcmd/master +43 -0
- data/bin/subcmd/node +47 -0
- data/bin/subcmd/processor +54 -0
- data/doc/programming-interface.html +240 -0
- data/doc/programming-interface.rd +300 -0
- data/etc/fairy.conf.tmpl +118 -0
- data/ext/simple_hash/extconf.rb +4 -0
- data/ext/simple_hash/simple_hash.c +42 -0
- data/fairy.gemspec +60 -0
- data/lib/fairy/client/addins.rb +20 -0
- data/lib/fairy/client/barrier.rb +29 -0
- data/lib/fairy/client/basic-group-by.rb +52 -0
- data/lib/fairy/client/cat.rb +41 -0
- data/lib/fairy/client/direct-product.rb +51 -0
- data/lib/fairy/client/equijoin.rb +79 -0
- data/lib/fairy/client/exec.rb +54 -0
- data/lib/fairy/client/filter.rb +62 -0
- data/lib/fairy/client/find.rb +35 -0
- data/lib/fairy/client/group-by.rb +194 -0
- data/lib/fairy/client/here.rb +84 -0
- data/lib/fairy/client/inject.rb +70 -0
- data/lib/fairy/client/input-file.rb +53 -0
- data/lib/fairy/client/input-iota.rb +49 -0
- data/lib/fairy/client/input-local-file.rb +188 -0
- data/lib/fairy/client/input-varray.rb +30 -0
- data/lib/fairy/client/input.rb +42 -0
- data/lib/fairy/client/io-filter.rb +26 -0
- data/lib/fairy/client/junction.rb +31 -0
- data/lib/fairy/client/map.rb +34 -0
- data/lib/fairy/client/merge-group-by.rb +71 -0
- data/lib/fairy/client/output-file.rb +64 -0
- data/lib/fairy/client/output-local-file.rb +60 -0
- data/lib/fairy/client/output-null.rb +47 -0
- data/lib/fairy/client/output-varray.rb +50 -0
- data/lib/fairy/client/output.rb +29 -0
- data/lib/fairy/client/roma-put.rb +62 -0
- data/lib/fairy/client/roma.rb +156 -0
- data/lib/fairy/client/seg-join.rb +61 -0
- data/lib/fairy/client/seg-map.rb +78 -0
- data/lib/fairy/client/seg-shuffle.rb +35 -0
- data/lib/fairy/client/seg-split.rb +27 -0
- data/lib/fairy/client/seg-zip.rb +60 -0
- data/lib/fairy/client/select.rb +38 -0
- data/lib/fairy/client/sort.rb +48 -0
- data/lib/fairy/client/sort18.rb +56 -0
- data/lib/fairy/client/sort19.rb +61 -0
- data/lib/fairy/client/there.rb +47 -0
- data/lib/fairy/client/top_n_into_roma.rb +34 -0
- data/lib/fairy/client/wc.rb +92 -0
- data/lib/fairy/controller.rb +1103 -0
- data/lib/fairy/logger.rb +107 -0
- data/lib/fairy/master/addins.rb +20 -0
- data/lib/fairy/master/atom.rb +17 -0
- data/lib/fairy/master/c-barrier.rb +283 -0
- data/lib/fairy/master/c-basic-group-by.rb +250 -0
- data/lib/fairy/master/c-cat.rb +159 -0
- data/lib/fairy/master/c-direct-product.rb +203 -0
- data/lib/fairy/master/c-exec.rb +68 -0
- data/lib/fairy/master/c-filter.rb +422 -0
- data/lib/fairy/master/c-find.rb +138 -0
- data/lib/fairy/master/c-group-by.rb +64 -0
- data/lib/fairy/master/c-here.rb +80 -0
- data/lib/fairy/master/c-inject.rb +119 -0
- data/lib/fairy/master/c-input-file.rb +46 -0
- data/lib/fairy/master/c-input-iota.rb +66 -0
- data/lib/fairy/master/c-input-local-file.rb +117 -0
- data/lib/fairy/master/c-input-varray.rb +53 -0
- data/lib/fairy/master/c-input.rb +24 -0
- data/lib/fairy/master/c-inputtable.rb +31 -0
- data/lib/fairy/master/c-inputtable18.rb +36 -0
- data/lib/fairy/master/c-inputtable19.rb +35 -0
- data/lib/fairy/master/c-io-filter.rb +28 -0
- data/lib/fairy/master/c-junction.rb +54 -0
- data/lib/fairy/master/c-map.rb +27 -0
- data/lib/fairy/master/c-merge-group-by.rb +241 -0
- data/lib/fairy/master/c-output-file.rb +84 -0
- data/lib/fairy/master/c-output-local-file.rb +19 -0
- data/lib/fairy/master/c-output-null.rb +45 -0
- data/lib/fairy/master/c-output-varray.rb +57 -0
- data/lib/fairy/master/c-output.rb +20 -0
- data/lib/fairy/master/c-seg-join.rb +141 -0
- data/lib/fairy/master/c-seg-map.rb +26 -0
- data/lib/fairy/master/c-seg-shuffle.rb +87 -0
- data/lib/fairy/master/c-seg-split.rb +110 -0
- data/lib/fairy/master/c-seg-zip.rb +132 -0
- data/lib/fairy/master/c-select.rb +27 -0
- data/lib/fairy/master/c-sort.rb +108 -0
- data/lib/fairy/master/c-there.rb +57 -0
- data/lib/fairy/master/c-wc.rb +232 -0
- data/lib/fairy/master/job-interpriter.rb +19 -0
- data/lib/fairy/master/scheduler.rb +24 -0
- data/lib/fairy/master.rb +329 -0
- data/lib/fairy/node/addins.rb +19 -0
- data/lib/fairy/node/p-barrier.rb +95 -0
- data/lib/fairy/node/p-basic-group-by.rb +252 -0
- data/lib/fairy/node/p-direct-product.rb +153 -0
- data/lib/fairy/node/p-exec.rb +30 -0
- data/lib/fairy/node/p-filter.rb +363 -0
- data/lib/fairy/node/p-find.rb +111 -0
- data/lib/fairy/node/p-group-by.rb +1534 -0
- data/lib/fairy/node/p-here.rb +21 -0
- data/lib/fairy/node/p-identity.rb +24 -0
- data/lib/fairy/node/p-inject.rb +127 -0
- data/lib/fairy/node/p-input-file.rb +108 -0
- data/lib/fairy/node/p-input-iota.rb +39 -0
- data/lib/fairy/node/p-input-local-file.rb +61 -0
- data/lib/fairy/node/p-input-varray.rb +26 -0
- data/lib/fairy/node/p-io-filter.rb +28 -0
- data/lib/fairy/node/p-map.rb +40 -0
- data/lib/fairy/node/p-merger-group-by.rb +48 -0
- data/lib/fairy/node/p-output-file.rb +104 -0
- data/lib/fairy/node/p-output-local-file.rb +14 -0
- data/lib/fairy/node/p-output-null.rb +32 -0
- data/lib/fairy/node/p-output-varray.rb +41 -0
- data/lib/fairy/node/p-seg-join.rb +82 -0
- data/lib/fairy/node/p-seg-map.rb +34 -0
- data/lib/fairy/node/p-seg-split.rb +61 -0
- data/lib/fairy/node/p-seg-zip.rb +79 -0
- data/lib/fairy/node/p-select.rb +40 -0
- data/lib/fairy/node/p-single-exportable.rb +90 -0
- data/lib/fairy/node/p-sort.rb +195 -0
- data/lib/fairy/node/p-task.rb +113 -0
- data/lib/fairy/node/p-there.rb +44 -0
- data/lib/fairy/node/p-wc.rb +266 -0
- data/lib/fairy/node.rb +187 -0
- data/lib/fairy/processor.rb +510 -0
- data/lib/fairy/share/base-app.rb +114 -0
- data/lib/fairy/share/block-source.rb +234 -0
- data/lib/fairy/share/conf.rb +396 -0
- data/lib/fairy/share/debug.rb +21 -0
- data/lib/fairy/share/encoding.rb +17 -0
- data/lib/fairy/share/fast-tempfile.rb +93 -0
- data/lib/fairy/share/file-place.rb +176 -0
- data/lib/fairy/share/hash-1.rb +20 -0
- data/lib/fairy/share/hash-md5.rb +28 -0
- data/lib/fairy/share/hash-murmur.rb +69 -0
- data/lib/fairy/share/hash-rb18.rb +20 -0
- data/lib/fairy/share/hash-simple-hash.rb +28 -0
- data/lib/fairy/share/inspector.rb +16 -0
- data/lib/fairy/share/lc/exceptions.rb +82 -0
- data/lib/fairy/share/lc/ja/exceptions.rb +81 -0
- data/lib/fairy/share/locale.rb +17 -0
- data/lib/fairy/share/log.rb +215 -0
- data/lib/fairy/share/pool-dictionary.rb +53 -0
- data/lib/fairy/share/port-marshaled-queue.rb +347 -0
- data/lib/fairy/share/port.rb +1697 -0
- data/lib/fairy/share/reference.rb +45 -0
- data/lib/fairy/share/stdout.rb +56 -0
- data/lib/fairy/share/tr.rb +16 -0
- data/lib/fairy/share/varray.rb +147 -0
- data/lib/fairy/share/vfile.rb +183 -0
- data/lib/fairy/version.rb +8 -0
- data/lib/fairy.rb +206 -0
- data/sample/grep.rb +46 -0
- data/sample/ping.rb +19 -0
- data/sample/sort.rb +102 -0
- data/sample/wordcount.rb +61 -0
- data/spec/README +12 -0
- data/spec/fairy1_spec.rb +31 -0
- data/spec/fairy2_spec.rb +42 -0
- data/spec/fairy3_spec.rb +126 -0
- data/spec/fairy4_spec.rb +63 -0
- data/spec/fairy5_spec.rb +45 -0
- data/spec/fairy6_spec.rb +52 -0
- data/spec/fairy7_spec.rb +58 -0
- data/spec/fairy8_spec.rb +48 -0
- data/spec/mkdat.rb +148 -0
- data/spec/run_all.sh +65 -0
- data/test/testc.rb +7111 -0
- data/tools/cap_recipe/Capfile +144 -0
- data/tools/cap_recipe/cluster.yml.sample +14 -0
- data/tools/fairy_perf_graph.rb +444 -0
- data/tools/git-tag +44 -0
- data/tools/log-analysis.rb +62 -0
- data/tools/svn-ls-diff +38 -0
- data/tools/svn-tags +37 -0
- metadata +298 -0
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (C) 2007-2010 Rakuten, Inc.
|
4
|
+
#
|
5
|
+
|
6
|
+
require "fairy/node/p-io-filter"
|
7
|
+
require "fairy/node/p-basic-group-by"
|
8
|
+
|
9
|
+
module Fairy
|
10
|
+
class PMergeGroupBy<PBasicGroupBy
|
11
|
+
Processor.def_export self
|
12
|
+
|
13
|
+
def initialize(id, ntask, bjob, opts, block_source)
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
# class NPostFilter<NSingleExportFilter
|
18
|
+
# Processor.def_export self
|
19
|
+
|
20
|
+
# def initialize(processor, bjob, opts, block_source)
|
21
|
+
# super
|
22
|
+
# @block_source = block_source
|
23
|
+
# end
|
24
|
+
|
25
|
+
# def start
|
26
|
+
# basic_start do
|
27
|
+
# @key_value = {}
|
28
|
+
# @hash_proc = BBlock.new(@block_source, @context, self)
|
29
|
+
|
30
|
+
# @import.each do |e|
|
31
|
+
# key = key(e)
|
32
|
+
# @key_value[e] = [] unless @key_value.key?(e)
|
33
|
+
# @key_value[e].push e
|
34
|
+
# end
|
35
|
+
# for key, values in @key_value
|
36
|
+
# @export.push [key, values]
|
37
|
+
# end
|
38
|
+
# end
|
39
|
+
# end
|
40
|
+
|
41
|
+
# def key(e)
|
42
|
+
# @hash_proc.yield(e)
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (C) 2007-2010 Rakuten, Inc.
|
4
|
+
#
|
5
|
+
|
6
|
+
require "uri"
|
7
|
+
|
8
|
+
require "fairy/node/p-io-filter"
|
9
|
+
|
10
|
+
module Fairy
|
11
|
+
class POutputFile<PIOFilter
|
12
|
+
Processor.def_export self
|
13
|
+
|
14
|
+
ST_OUTPUT_FINISH = :ST_OUTPUT_FINISH
|
15
|
+
|
16
|
+
def initialize(id, ntask, bjob, opt, vf)
|
17
|
+
super
|
18
|
+
@vfile = vf
|
19
|
+
|
20
|
+
# @imports = Queue.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def input=(input)
|
24
|
+
super
|
25
|
+
start
|
26
|
+
end
|
27
|
+
|
28
|
+
# def add_input(input)
|
29
|
+
# unless input
|
30
|
+
# @imports.push nil
|
31
|
+
# return self
|
32
|
+
# end
|
33
|
+
# policy = @opts[:prequeuing_policy]
|
34
|
+
# import = Import.new(policy)
|
35
|
+
# import.add_key(input.key)
|
36
|
+
# input.output = import
|
37
|
+
# import.set_log_callback do |n|
|
38
|
+
# Log::verbose(self, "IMPORT POP: #{n}")
|
39
|
+
# end
|
40
|
+
# @imports.push import
|
41
|
+
# self
|
42
|
+
# end
|
43
|
+
|
44
|
+
def basic_start(&block)
|
45
|
+
Log::debug(self, "START")
|
46
|
+
output_uri = gen_real_file_name
|
47
|
+
@vfile.set_real_file(no, output_uri)
|
48
|
+
|
49
|
+
Log::debug(self, "write real file: #{output_uri}")
|
50
|
+
begin
|
51
|
+
output_file = URI.parse(output_uri).path
|
52
|
+
rescue
|
53
|
+
Log::debug_exception(self)
|
54
|
+
raise
|
55
|
+
end
|
56
|
+
|
57
|
+
unless File.exist?(File.dirname(output_file))
|
58
|
+
create_dir(File.dirname(output_file))
|
59
|
+
end
|
60
|
+
|
61
|
+
File.open(output_file, "w") do |io|
|
62
|
+
Log::debug(self, "start write real file: #{output_uri}")
|
63
|
+
@input.each do |l|
|
64
|
+
io.puts l
|
65
|
+
end
|
66
|
+
Log::debug(self, "finish write real file: #{output_uri}")
|
67
|
+
end
|
68
|
+
self.status = ST_OUTPUT_FINISH
|
69
|
+
end
|
70
|
+
|
71
|
+
def create_dir(path)
|
72
|
+
unless File.exist?(File.dirname(path))
|
73
|
+
create_dir(File.dirname(path))
|
74
|
+
end
|
75
|
+
begin
|
76
|
+
Dir.mkdir(path)
|
77
|
+
rescue Errno::EEXIST
|
78
|
+
# 無視
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
IPADDR_REGEXP = /::ffff:([0-9]+\.){3}[0-9]+|[0-9a-f]+:([0-9a-f]*:)[0-9a-f]*/
|
83
|
+
|
84
|
+
def gen_real_file_name
|
85
|
+
host= processor.addr
|
86
|
+
root = CONF.VF_ROOT
|
87
|
+
prefix = CONF.VF_PREFIX
|
88
|
+
base_name = @vfile.base_name
|
89
|
+
no = @input.no
|
90
|
+
|
91
|
+
|
92
|
+
if IPADDR_REGEXP =~ host
|
93
|
+
begin
|
94
|
+
host = Resolv.getname(host)
|
95
|
+
rescue
|
96
|
+
# ホスト名が分からない場合 は そのまま ipv6 アドレスにする
|
97
|
+
host = "[#{host}]"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
format("file://#{host}#{root}/#{prefix}/#{base_name}-%03d", no)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (C) 2007-2010 Rakuten, Inc.
|
4
|
+
#
|
5
|
+
|
6
|
+
require "fairy/node/p-io-filter"
|
7
|
+
|
8
|
+
module Fairy
|
9
|
+
class POutputNull<PIOFilter
|
10
|
+
Processor.def_export self
|
11
|
+
|
12
|
+
ST_OUTPUT_FINISH = :ST_OUTPUT_FINISH
|
13
|
+
|
14
|
+
# DeepConnect.def_single_method_spec(self, "REF new(REF, REF, VAL, REF)")
|
15
|
+
|
16
|
+
def initialize(id, ntask, bjob, opt)
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def input=(input)
|
21
|
+
super
|
22
|
+
start
|
23
|
+
end
|
24
|
+
|
25
|
+
def basic_start(&block)
|
26
|
+
for l in @input
|
27
|
+
l
|
28
|
+
end
|
29
|
+
self.status = ST_OUTPUT_FINISH
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (C) 2007-2010 Rakuten, Inc.
|
4
|
+
#
|
5
|
+
|
6
|
+
require "fairy/node/p-io-filter"
|
7
|
+
|
8
|
+
require "fairy/share/varray"
|
9
|
+
|
10
|
+
module Fairy
|
11
|
+
class POutputVArray<PIOFilter
|
12
|
+
Processor.def_export self
|
13
|
+
|
14
|
+
ST_OUTPUT_FINISH = :ST_OUTPUT_FINISH
|
15
|
+
|
16
|
+
# DeepConnect.def_single_method_spec(self, "REF new(REF, REF, VAL, REF)")
|
17
|
+
|
18
|
+
# def initialize(processor, bjob, opt, varray, idx)
|
19
|
+
def initialize(id, ntask, bjob, opt, idx)
|
20
|
+
super
|
21
|
+
@no_in_bjob = idx
|
22
|
+
end
|
23
|
+
|
24
|
+
def input=(input)
|
25
|
+
super
|
26
|
+
start
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def basic_start(&block)
|
31
|
+
array = []
|
32
|
+
for l in @input
|
33
|
+
array.push l
|
34
|
+
end
|
35
|
+
|
36
|
+
processor.register_varray_element(array)
|
37
|
+
@bjob.varray.arrays_put(@no_in_bjob, array)
|
38
|
+
self.status = ST_OUTPUT_FINISH
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (C) 2007-2010 Rakuten, Inc.
|
4
|
+
#
|
5
|
+
|
6
|
+
require "fairy/node/p-io-filter"
|
7
|
+
require "fairy/node/p-single-exportable"
|
8
|
+
|
9
|
+
module Fairy
|
10
|
+
class PSegJoin<PSingleExportFilter
|
11
|
+
Processor.def_export self
|
12
|
+
|
13
|
+
def initialize(id, ntask, bjob, opts, block_source)
|
14
|
+
super
|
15
|
+
@block_source = block_source
|
16
|
+
|
17
|
+
@join_imports = nil
|
18
|
+
@join_imports_mutex = Mutex.new
|
19
|
+
@join_imports_cv = ConditionVariable.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def join_imports
|
23
|
+
@join_imports_mutex.synchronize do
|
24
|
+
while !@join_imports
|
25
|
+
@join_imports_cv.wait(@join_imports_mutex)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
@join_imports
|
29
|
+
end
|
30
|
+
|
31
|
+
DeepConnect.def_method_spec(self, "VAL join_imports")
|
32
|
+
|
33
|
+
def join_inputs=(jinputs)
|
34
|
+
policy = @opts[:prequeuing_policy]
|
35
|
+
@join_imports_mutex.synchronize do
|
36
|
+
@join_imports = jinputs.collect{|jinput|
|
37
|
+
if jinput
|
38
|
+
import = Import.new(policy)
|
39
|
+
import.no = jinput.no
|
40
|
+
import.add_key(jinput.key)
|
41
|
+
import.set_log_callback do |n, key|
|
42
|
+
Log::verbose(self, "IMPORT POP key=#{key}: #{n}")
|
43
|
+
end
|
44
|
+
|
45
|
+
import
|
46
|
+
else
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
}
|
50
|
+
@join_imports_cv.broadcast
|
51
|
+
end
|
52
|
+
@join_imports
|
53
|
+
end
|
54
|
+
|
55
|
+
DeepConnect.def_method_spec(self, :rets => "VAL", :method => :join_inputs=, :args => "VAL")
|
56
|
+
|
57
|
+
def basic_each(&block)
|
58
|
+
@map_proc = BBlock.new(@block_source, @context, self)
|
59
|
+
arg = [@input]
|
60
|
+
arg.push *join_imports
|
61
|
+
arg.push block
|
62
|
+
|
63
|
+
@map_proc.yield(*arg)
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
# def start
|
68
|
+
# super do
|
69
|
+
# @map_proc = BBlock.new(@block_source, @context, self)
|
70
|
+
# arg = [@import]
|
71
|
+
# arg.push *join_imports
|
72
|
+
# arg.push @export
|
73
|
+
|
74
|
+
# Log::debug(self, "START")
|
75
|
+
# #Log::debug(self, @block_source.source)
|
76
|
+
# # @map_proc.yield(@import, *join_imports, @export)
|
77
|
+
# @map_proc.yield(*arg)
|
78
|
+
# Log::debug(self, "END")
|
79
|
+
# end
|
80
|
+
# end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require "fairy/node/p-io-filter"
|
4
|
+
require "fairy/node/p-single-exportable"
|
5
|
+
|
6
|
+
module Fairy
|
7
|
+
class PSegMap<PSingleExportFilter
|
8
|
+
Processor.def_export self
|
9
|
+
|
10
|
+
# DeepConnect.def_single_method_spec(self, "REF new(REF, REF, VAL, VAL)")
|
11
|
+
|
12
|
+
def initialize(id, ntask, bjob, opts, block_source)
|
13
|
+
super
|
14
|
+
@block_source = block_source
|
15
|
+
# @map_proc = eval("proc{#{@block_source}}", TOPLEVEL_BINDING)
|
16
|
+
# @map_proc = @context.create_proc(@block_source)
|
17
|
+
end
|
18
|
+
|
19
|
+
# def start
|
20
|
+
# super do
|
21
|
+
# @map_proc = BBlock.new(@block_source, @context, self)
|
22
|
+
# @map_proc.yield(@import, @export)
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
|
26
|
+
def basic_each(&block)
|
27
|
+
@map_proc = BBlock.new(@block_source, @context, self)
|
28
|
+
@map_proc.yield(@input, block)
|
29
|
+
end
|
30
|
+
|
31
|
+
# basic_nextがない
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (C) 2007-2010 Rakuten, Inc.
|
4
|
+
#
|
5
|
+
|
6
|
+
require "fairy/node/p-io-filter"
|
7
|
+
|
8
|
+
module Fairy
|
9
|
+
class PSegSplit<PIOFilter
|
10
|
+
Processor.def_export self
|
11
|
+
|
12
|
+
# DeepConnect.def_single_method_spec(self, "REF new(REF, VAL, VAL)")
|
13
|
+
|
14
|
+
def initialize(id, ntask, bjob, opts, n)
|
15
|
+
super
|
16
|
+
@no_split = n
|
17
|
+
|
18
|
+
policy = @opts[:postqueuing_policy]
|
19
|
+
@exports = @no_split.times.collect{Export.new(policy)}
|
20
|
+
end
|
21
|
+
|
22
|
+
attr_reader :exports
|
23
|
+
DeepConnect.def_method_spec(self, "VAL exports")
|
24
|
+
|
25
|
+
def start_export
|
26
|
+
Log::debug(self, "START_EXPORT")
|
27
|
+
# return unless @status == ST_WAIT_IMPORT
|
28
|
+
start do
|
29
|
+
begin
|
30
|
+
@input.each_slice(@no_split) do |ll|
|
31
|
+
if ll.size < @no_split
|
32
|
+
ll.fill(0, @no_split){|idx| ll[idx] ||= END_OF_STREAM}
|
33
|
+
end
|
34
|
+
@exports.zip(ll) do |exp, l|
|
35
|
+
exp.push l
|
36
|
+
end
|
37
|
+
end
|
38
|
+
ensure
|
39
|
+
@exports.each{|exp| exp.push END_OF_STREAM}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# def start
|
45
|
+
# super do
|
46
|
+
# begin
|
47
|
+
# @import.each_slice(@no_split) do |ll|
|
48
|
+
# if ll.size < @no_split
|
49
|
+
# ll.fill(0, @no_split){|idx| ll[idx] ||= END_OF_STREAM}
|
50
|
+
# end
|
51
|
+
# @exports.zip(ll) do |exp, l|
|
52
|
+
# exp.push l
|
53
|
+
# end
|
54
|
+
# end
|
55
|
+
# ensure
|
56
|
+
# @exports.each{|exp| exp.push END_OF_STREAM}
|
57
|
+
# end
|
58
|
+
# end
|
59
|
+
# end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (C) 2007-2010 Rakuten, Inc.
|
4
|
+
#
|
5
|
+
|
6
|
+
require "fairy/node/p-io-filter"
|
7
|
+
require "fairy/node/p-single-exportable"
|
8
|
+
|
9
|
+
module Fairy
|
10
|
+
class PSegZip<PSingleExportFilter
|
11
|
+
Processor.def_export self
|
12
|
+
|
13
|
+
# DeepConnect.def_single_method_spec(self, "REF new(REF, VAL, VAL, VAL)")
|
14
|
+
|
15
|
+
def initialize(id, ntask, bjob, opts, block_source)
|
16
|
+
super
|
17
|
+
@block_source = block_source
|
18
|
+
# @map_proc = eval("proc{#{@block_source}}", TOPLEVEL_BINDING)
|
19
|
+
# @map_proc = @context.create_proc(@block_source)
|
20
|
+
|
21
|
+
@zip_imports = nil
|
22
|
+
@zip_imports_mutex = Mutex.new
|
23
|
+
@zip_imports_cv = ConditionVariable.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def zip_imports
|
27
|
+
@zip_imports_mutex.synchronize do
|
28
|
+
while !@zip_imports
|
29
|
+
@zip_imports_cv.wait(@zip_imports_mutex)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
@zip_imports
|
33
|
+
end
|
34
|
+
|
35
|
+
DeepConnect.def_method_spec(self, "VAL zip_imports")
|
36
|
+
|
37
|
+
def zip_inputs=(zinputs)
|
38
|
+
|
39
|
+
policy = @opts[:prequeuing_policy]
|
40
|
+
# 仮
|
41
|
+
@zip_imports_mutex.synchronize do
|
42
|
+
@zip_imports = zinputs.collect{|zinput|
|
43
|
+
import = Import.new(policy)
|
44
|
+
import.no = zinput.no
|
45
|
+
import.add_key(zinput.key)
|
46
|
+
import.set_log_callback do |n, key|
|
47
|
+
Log::verbose(self, "IMPORT POP key=#{key}: #{n}")
|
48
|
+
end
|
49
|
+
|
50
|
+
import
|
51
|
+
}
|
52
|
+
@zip_imports_cv.broadcast
|
53
|
+
end
|
54
|
+
@zip_imports
|
55
|
+
end
|
56
|
+
DeepConnect.def_method_spec(self, :rets => "VAL", :method => :zip_inputs=, :args => "VAL")
|
57
|
+
|
58
|
+
def basic_each(&block)
|
59
|
+
@map_proc = BBlock.new(@block_source, @context, self)
|
60
|
+
@input.each do |e|
|
61
|
+
zips = zip_imports.collect{|import| import.pop}
|
62
|
+
if Import::CTLTOKEN_NULLVALUE === (v = @map_proc.yield(e, *zips))
|
63
|
+
next
|
64
|
+
end
|
65
|
+
block.call v
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# def start
|
70
|
+
# super do
|
71
|
+
# @map_proc = BBlock.new(@block_source, @context, self)
|
72
|
+
# @import.each do |e|
|
73
|
+
# zips = zip_imports.collect{|import| import.pop}
|
74
|
+
# @export.push @map_proc.yield(e, *zips)
|
75
|
+
# end
|
76
|
+
# end
|
77
|
+
# end
|
78
|
+
end
|
79
|
+
end
|