Class: Fairy::CWC

Inherits:
CInput show all
Defined in:
lib/fairy/master/c-wc.rb

Defined Under Namespace

Classes: CPostFilter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CInput

#output=

Methods inherited from CFilter

#abort_create_node, #add_node, #assgin_number_of_nodes?, #break_create_node, #break_running, #create_and_add_node, #create_import, #create_node, #create_nodes, #def_job_pool_variable, #each_node, #each_node_exist_only, #handle_exception, #job_pool_dict, #job_pool_variable, #njob_creation_params, #nodes, #number_of_nodes, #number_of_nodes=, #pool_dict, #postmapping_policy, #start_export, #start_watch_node_status, #update_status, watch_status, watch_status=, #watch_status?

Constructor Details

#initialize(controller, opts) ⇒ CWC

Returns a new instance of CWC.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fairy/master/c-wc.rb', line 22

def initialize(controller, opts)
  super

  @no_of_exports = 0

  # key -> [export, ...]
  @exports = {}
  @exports_mutex = Mutex.new
  @exports_cv = ConditionVariable.new

#      @pre_exports_queue = Queue.new
  @exports_queue = Queue.new

  @each_export_by_thread = nil
  @each_export_by_thread_mutex = Mutex.new

  @hash_seed = controller.hash_seed
end

Instance Attribute Details

#hash_seedObject (readonly)

Returns the value of attribute hash_seed.



41
42
43
# File 'lib/fairy/master/c-wc.rb', line 41

def hash_seed
  @hash_seed
end

Class Method Details

.open(controller, opts, descripter) ⇒ Object



15
16
17
18
19
# File 'lib/fairy/master/c-wc.rb', line 15

def CWC.open(controller, opts, descripter)
  bfile = CWC.new(controller, opts)
  bfile.open(desctipter)
  bfile
end

Instance Method Details

#add_exports(key, export, njob) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/fairy/master/c-wc.rb', line 108

def add_exports(key, export, njob)
  @exports_mutex.synchronize do
	if exports = @exports[key]
	  export.output = exports.first.output if exports.first.output?
	  export.no = exports.first.no
	  exports.push export
	else
	  export.no = @no_of_exports
	  @no_of_exports += 1
	  @exports[key] = [export]
	  @exports_queue.push [export, njob]
#	  @pre_exports_queue.push [export, njob]
	end
  end
end

#all_node_arrived?Boolean

Returns:

  • (Boolean)


156
157
158
# File 'lib/fairy/master/c-wc.rb', line 156

def all_node_arrived?
  @nodes_mutex.synchronize{@number_of_nodes}
end

#all_node_imported?Boolean

Returns:

  • (Boolean)


160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/fairy/master/c-wc.rb', line 160

def all_node_imported?
  # すべてのnjobがそろったか?
  return false unless @nodes_mutex.synchronize{@number_of_nodes}

  each_node(:exist_only) do |node|
	st = @nodes_status[node]
	# こちらはNG: outputが設定されていないとまずい.
	# すべてのnodeがそろったとしてもすべてのexportがそろっているとは限らない
#	unless [:ST_FINISH, :ST_EXPORT_FINISH, :ST_WAIT_EXPORT_FINISH, :ST_ALL_IMPORTED].include?(st)
	unless [:ST_FINISH, :ST_EXPORT_FINISH, :ST_WAIT_EXPORT_FINISH].include?(st)
	  return false
	end
  end
  true
end

#bind_export(exp, imp) ⇒ Object



104
105
106
# File 'lib/fairy/master/c-wc.rb', line 104

def bind_export(exp, imp)
  # do nothing
end

#each_assigned_filter(&block) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/fairy/master/c-wc.rb', line 65

def each_assigned_filter(&block)
  super

  @each_export_by_thread_mutex.synchronize do
	@each_export_by_thread.join if @each_export_by_thread
  end
end

#each_export_by(njob, mapper, &block) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/fairy/master/c-wc.rb', line 73

def each_export_by(njob, mapper, &block)
  @each_export_by_thread_mutex.synchronize do
	return if @each_export_by_thread

	@each_export_by_thread = Thread.start{
	  # すべての njob がそろうまで待つ
	  # 後段が先にスケジュールされてデッドロックするのを避けるため.
	  number_of_nodes

	  begin
 while pair = @exports_queue.pop
   exp, njob = pair
Log::debug(self, "EXPORT_BY, #{exp.key}")
   block.call exp

   @exports_mutex.synchronize do
		if @exports[exp.key].first == exp
@exports[exp.key][1..-1].each do |e|
  e.output = exp.output
end
		end
   end
 end
	  rescue
 Log::fatal_exception
 raise
	  end
	}
  end
end

#inputObject



55
56
57
# File 'lib/fairy/master/c-wc.rb', line 55

def input
  @cfile_place
end

#node_class_nameObject



43
44
45
# File 'lib/fairy/master/c-wc.rb', line 43

def node_class_name
  "PWC"
end

#open(vf) ⇒ Object



47
48
49
50
51
52
# File 'lib/fairy/master/c-wc.rb', line 47

def open(vf)
  @vfile = vf
  @cfile_place = CFilePlace.new(@vfile)

  start_create_nodes
end

#start_create_nodesObject



59
60
61
62
63
# File 'lib/fairy/master/c-wc.rb', line 59

def start_create_nodes
  super

  start_watch_all_node_imported
end

#start_watch_all_node_importedObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/fairy/master/c-wc.rb', line 129

def start_watch_all_node_imported
  Thread.start do
	# すべての njob がそろうまで待つ
	# 後段が先にスケジュールされてデッドロックするのを避けるため.
Log::debug(self, "START_WATCH_ALL_NODE_IMPORTED: S")
	number_of_nodes

Log::debug(self, "START_WATCH_ALL_NODE_IMPORTED: 1")

Log::debug(self, "START_WATCH_ALL_NODE_IMPORTED: 2")
	# すべての exports がそろうまで待つ
	@nodes_status_mutex.synchronize do
	  while !all_node_imported?
 @nodes_status_cv.wait(@nodes_status_mutex)
	  end
	end
	@exports_queue.push nil

Log::debug(self, "START_WATCH_ALL_NODE_IMPORTED: 4")
	for key, exports in @exports
	  exports.first.output_no_import = exports.size
	end
Log::debug(self, "START_WATCH_ALL_NODE_IMPORTED: E")
  end
  nil
end

#update_exports(key, export, njob) ⇒ Object



124
125
126
127
# File 'lib/fairy/master/c-wc.rb', line 124

def update_exports(key, export, njob)
  add_exports(key, export, njob)
  nil
end