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.



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

def initialize(controller, opts)
  super

  @no_of_exports = 0

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

#      @pre_exports_queue = XThread::Queue.new
  @exports_queue = XThread::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.



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

def hash_seed
  @hash_seed
end

Class Method Details

.open(controller, opts, descripter) ⇒ Object



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

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



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

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)


158
159
160
# File 'lib/fairy/master/c-wc.rb', line 158

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

#all_node_imported?Boolean

Returns:

  • (Boolean)


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

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



106
107
108
# File 'lib/fairy/master/c-wc.rb', line 106

def bind_export(exp, imp)
  # do nothing
end

#each_assigned_filter(&block) ⇒ Object



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

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



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
103
104
# File 'lib/fairy/master/c-wc.rb', line 75

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



57
58
59
# File 'lib/fairy/master/c-wc.rb', line 57

def input
  @cfile_place
end

#node_class_nameObject



45
46
47
# File 'lib/fairy/master/c-wc.rb', line 45

def node_class_name
  "PWC"
end

#open(vf) ⇒ Object



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

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

  start_create_nodes
end

#start_create_nodesObject



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

def start_create_nodes
  super

  start_watch_all_node_imported
end

#start_watch_all_node_importedObject



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

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



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

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