filecluster 0.5.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 016165196d545cc809e342d8d7a573087f4f5d31
4
- data.tar.gz: 90171541e2b6c1f81581bd81c9475bf556d9c859
3
+ metadata.gz: 28654ba4883c2627f9e15f503baadaca8f3ab38d
4
+ data.tar.gz: d7029275d6e2ff9977c1698651786174b1c9921d
5
5
  SHA512:
6
- metadata.gz: 974f810d8c7bc2f37851786f3549021e0d100d887b5c2dae805fd2e7134358b337f579ac054cae6c5a305e57e1a39d6fce54ff3136291bf9f06790ff42e72dd6
7
- data.tar.gz: 792e72c575b4a91655283a2a0dc11c760949bc896c31fb0f8cd5d87dabff76059b579b4c9085695d46180b0d5330f5eb30f89f7a58fca98d26648b82948e5587
6
+ metadata.gz: f6b4ea85f5adb7a80580ac90227c10c4bb60df3f5adce2cb5f76d9b1aad95e5c5562bc258e51b655764afdfc8f1f5b1a702575559aaa10864d17a93a10056e56
7
+ data.tar.gz: 7d6dd115fab9ab6d512d389329291b59d841281e8729314b08e685cda5530b6d2ad0f8b7bbdf113710dce5bf31246581f80fd2ea0a62a365e658c055d30fa2c5
@@ -15,6 +15,7 @@ class GlobalDaemonThread < BaseThread
15
15
  end
16
16
 
17
17
  make_item_copies
18
+ make_item_mark_deleted
18
19
  make_deleted_error_items_storages
19
20
  make_deleted_error_items
20
21
  delete_deleted_items
@@ -68,6 +69,28 @@ class GlobalDaemonThread < BaseThread
68
69
  end
69
70
  end
70
71
  end
72
+
73
+ # mark deleted for deferred_delete items
74
+ def make_item_mark_deleted
75
+ $log.debug("GlobalDaemonThread: make_item_mark_deleted")
76
+
77
+ limit = FC::Var.get('daemon_global_tasks_group_limit', 1000).to_i
78
+ loop do
79
+ r = FC::DB.query %(
80
+ SELECT i.id FROM #{FC::Item.table_name} as i, #{FC::Policy.table_name} as p
81
+ WHERE
82
+ i.status = 'deferred_delete' AND i.policy_id = p.id AND
83
+ i.time + p.delete_deferred_time < UNIX_TIMESTAMP()
84
+ LIMIT #{limit}
85
+ )
86
+ break if r.count == 0
87
+ ids = r.map{|e| e['id']}.join(',')
88
+ $log.info("GlobalDaemonThread: mark delete items: #{ids}")
89
+ FC::DB.query("UPDATE #{FC::ItemStorage.table_name} SET status='delete' WHERE item_id in (#{ids})")
90
+ FC::DB.query("UPDATE #{FC::Item.table_name} SET status='delete' WHERE id in (#{ids})")
91
+ sleep 1
92
+ end
93
+ end
71
94
 
72
95
  def delete_deleted_items
73
96
  $log.debug("GlobalDaemonThread: delete_deleted_items")
@@ -10,18 +10,22 @@ module FC
10
10
  def self.options_yml_path
11
11
  File.expand_path(File.dirname(__FILE__) + '../../../bin/db.yml')
12
12
  end
13
+
14
+ def self.symbolize_keys(options)
15
+ options.each_with_object({}) { |el, memo| memo[el[0].to_sym] = el[1] }
16
+ end
13
17
 
14
18
  def self.connect_by_config(options)
15
- @options = options.clone
16
- @options[:port] = @options[:port].to_i if @options[:port]
19
+ @options = symbolize_keys(options)
17
20
  @prefix = @options[:prefix].to_s if @options[:prefix]
18
21
  @connects = {} unless @connects
22
+ @connect_block = nil
19
23
  @connects[Thread.current.object_id] = Mysql2::Client.new(@options)
20
24
  end
21
25
 
22
26
  def self.connect_by_yml(options = {})
23
- db_options = Psych.load(File.read(options_yml_path))
24
- connect_by_config(db_options.merge(options))
27
+ db_options = symbolize_keys(Psych.load(File.read(options_yml_path)))
28
+ connect_by_config(db_options.merge(symbolize_keys(options)))
25
29
  end
26
30
 
27
31
  def self.connect_by_active_record(options = {})
@@ -30,9 +34,10 @@ module FC
30
34
  else
31
35
  connection = ActiveRecord::Base.connection.instance_variable_get(:@connection)
32
36
  end
33
- @options = connection.query_options.clone
34
- @options.merge!(options)
37
+ @options = symbolize_keys(connection.query_options)
38
+ @options.merge!(symbolize_keys(options))
35
39
  @prefix = @options[:prefix].to_s if @options[:prefix]
40
+ @connect_block = nil
36
41
  @connects = {} unless @connects
37
42
  @connects[Thread.current.object_id] = connection
38
43
  end
@@ -43,7 +48,7 @@ module FC
43
48
 
44
49
  def self.connect_by_block(options = {})
45
50
  connection = @connect_block.call
46
- @options = connection.query_options.clone.merge(options)
51
+ @options = connection.query_options.clone.merge(symbolize_keys(options))
47
52
  @prefix = @options[:prefix].to_s if @options[:prefix]
48
53
  @connects = {} unless @connects
49
54
  @connects[Thread.current.object_id] = connection
@@ -68,7 +73,7 @@ module FC
68
73
  elsif options[:host] || options[:database] || options[:username] || options[:password]
69
74
  connect_by_config(options)
70
75
  elsif @options
71
- connect_by_config(@options.merge(options))
76
+ connect_by_config(@options.merge(symbolize_keys(options)))
72
77
  elsif !@no_active_record && defined?(ActiveRecord::Base) && ActiveRecord::Base.connection
73
78
  connect_by_active_record(options)
74
79
  else
@@ -318,5 +323,10 @@ module FC
318
323
  def self.migrate_2
319
324
  FC::DB.query("ALTER TABLE #{@prefix}storages ADD COLUMN dc varchar(255) DEFAULT ''")
320
325
  end
326
+
327
+ def self.migrate_3
328
+ FC::DB.query("ALTER TABLE #{@prefix}items MODIFY COLUMN status ENUM('new', 'ready', 'error', 'delete', 'deferred_delete') NOT NULL DEFAULT 'new'")
329
+ FC::DB.query("ALTER TABLE #{@prefix}policies ADD COLUMN delete_deferred_time int NOT NULL DEFAULT 0")
330
+ end
321
331
  end
322
332
  end
@@ -13,7 +13,7 @@ module FC
13
13
  # :additional_fields - hash of additional FC:Item fields
14
14
  # :no_md5 - don't use md5
15
15
  # If item_name is part of local_path it processed as inplace - local_path is valid path to the item for policy
16
- def self.create_from_local(local_path, item_name, policy, options={})
16
+ def self.create_from_local(local_path, item_name, policy, options={}, &block)
17
17
  raise 'Path not exists' unless File.exists?(local_path)
18
18
  raise 'Policy is not FC::Policy' unless policy.instance_of?(FC::Policy)
19
19
  item_params = options.merge({
@@ -65,7 +65,12 @@ module FC
65
65
  storages.select{|s| storages_names.detect(s.name)}
66
66
  end
67
67
  end
68
- storage = policy.get_proper_storage_for_create(item.size, local_path) unless storage
68
+ if block_given?
69
+ storage ||= FC::Storage.select_proper_storage_for_create(policy.get_create_storages,
70
+ item.size, &block)
71
+ else
72
+ storage ||= policy.get_proper_storage_for_create(item.size, local_path)
73
+ end
69
74
  FC::Error.raise 'No available storage', :item_id => item.id unless storage
70
75
 
71
76
  # mark delete item_storages on replace
@@ -130,8 +135,15 @@ module FC
130
135
  end
131
136
  end
132
137
 
133
- # mark items_storages for delete
138
+ # mark item and his items_storages for deferred delete
139
+ # real delete after policy.delete_deferred_time
134
140
  def mark_deleted
141
+ self.status = 'deferred_delete'
142
+ save
143
+ end
144
+
145
+ # mark item and his items_storages for immediate delete
146
+ def immediate_delete
135
147
  FC::DB.query("UPDATE #{FC::ItemStorage.table_name} SET status='delete' WHERE item_id = #{id}")
136
148
  self.status = 'delete'
137
149
  save
@@ -2,7 +2,7 @@
2
2
 
3
3
  module FC
4
4
  class Policy < DbBase
5
- set_table :policies, 'name, create_storages, copies'
5
+ set_table :policies, 'name, create_storages, copies, delete_deferred_time'
6
6
 
7
7
  class << self
8
8
  attr_accessor :storages_cache_time, :get_create_storages_mutex
@@ -1,3 +1,3 @@
1
1
  module FC
2
- VERSION = '0.5.2'.freeze
2
+ VERSION = '0.5.3'.freeze
3
3
  end
@@ -91,13 +91,16 @@ def item_rm
91
91
  if !item
92
92
  puts "Item #{name} not found."
93
93
  else
94
- s = Readline.readline("Delete? (y/n) ", false).strip.downcase
95
- puts ""
96
- if s == "y" || s == "yes"
97
- item.mark_deleted
98
- puts "ok"
94
+ s = Readline.readline('Immediate delete? (y/n) ', false).strip.downcase
95
+ puts ''
96
+ immediate_delete = s == 'y' || s == 'yes'
97
+ s = Readline.readline('Delete? (y/n) ', false).strip.downcase
98
+ puts ''
99
+ if s == 'y' || s == 'yes'
100
+ immediate_delete ? item.immediate_delete : item.mark_deleted
101
+ puts 'ok'
99
102
  else
100
- puts "Canceled."
103
+ puts 'Canceled.'
101
104
  end
102
105
  end
103
106
  end
@@ -13,11 +13,12 @@ def policies_show
13
13
  if policy = find_policy
14
14
  count = FC::DB.query("SELECT count(*) as cnt FROM #{FC::Item.table_name} WHERE policy_id = #{policy.id}").first['cnt']
15
15
  puts %Q{Policy
16
- ID: #{policy.id}
17
- Name: #{policy.name}
18
- Create storages: #{policy.create_storages}
19
- Copies: #{policy.copies}
20
- Items: #{count}}
16
+ ID: #{policy.id}
17
+ Name: #{policy.name}
18
+ Create storages: #{policy.create_storages}
19
+ Copies: #{policy.copies}
20
+ Delete deferred time: #{policy.delete_deferred_time}
21
+ Items: #{count}}
21
22
  end
22
23
  end
23
24
 
@@ -26,20 +27,27 @@ def policies_add
26
27
  name = stdin_read_val('Name')
27
28
  create_storages = stdin_read_val('Create storages')
28
29
  copies = stdin_read_val('Copies').to_i
30
+ delete_deferred_time = stdin_read_val('Delete deferred time').to_i
29
31
 
30
32
  storages = FC::Storage.where.map(&:name)
31
33
  create_storages = create_storages.split(',').select{|s| storages.member?(s.strip)}.join(',').strip
32
34
 
33
35
  begin
34
- policy = FC::Policy.new(:name => name, :create_storages => create_storages, :copies => copies)
36
+ policy = FC::Policy.new(
37
+ :name => name,
38
+ :create_storages => create_storages,
39
+ :copies => copies,
40
+ :delete_deferred_time => delete_deferred_time
41
+ )
35
42
  rescue Exception => e
36
43
  puts "Error: #{e.message}"
37
44
  exit
38
45
  end
39
46
  puts %Q{\nPolicy
40
- Name: #{name}
41
- Create storages: #{create_storages}
42
- Copies: #{copies}}
47
+ Name: #{name}
48
+ Create storages: #{create_storages}
49
+ Copies: #{copies}
50
+ Delete deferred time: #{delete_deferred_time}}
43
51
  s = Readline.readline("Continue? (y/n) ", false).strip.downcase
44
52
  puts ""
45
53
  if s == "y" || s == "yes"
@@ -74,6 +82,7 @@ def policies_change
74
82
  name = stdin_read_val("Name (now #{policy.name})", true)
75
83
  create_storages = stdin_read_val("Create storages (now #{policy.create_storages})", true)
76
84
  copies = stdin_read_val("Copies (now #{policy.copies})", true)
85
+ delete_deferred_time = stdin_read_val("Delete deferred time (now #{policy.delete_deferred_time})", true)
77
86
 
78
87
  storages = FC::Storage.where.map(&:name)
79
88
  create_storages = create_storages.split(',').select{|s| storages.member?(s.strip)}.join(',').strip unless create_storages.empty?
@@ -83,9 +92,10 @@ def policies_change
83
92
  policy.copies = copies.to_i unless copies.empty?
84
93
 
85
94
  puts %Q{\nStorage
86
- Name: #{policy.name}
87
- Create storages: #{policy.create_storages}
88
- Copies: #{policy.copies}}
95
+ Name: #{policy.name}
96
+ Create storages: #{policy.create_storages}
97
+ Copies: #{policy.copies}
98
+ Delete deferred time: #{policy.delete_deferred_time}}
89
99
  s = Readline.readline("Continue? (y/n) ", false).strip.downcase
90
100
  puts ""
91
101
  if s == "y" || s == "yes"
@@ -109,4 +119,4 @@ def find_policy
109
119
  policy = FC::Policy.where('name = ?', ARGV[2]).first unless policy
110
120
  puts "Policy #{ARGV[2]} not found." unless policy
111
121
  policy
112
- end
122
+ end
@@ -237,7 +237,7 @@ def make_storages_sync(storage, make_delete, silent = false, no_reconnect = fals
237
237
  db_items[path][0] = true
238
238
  next if db_items[path][1] && db_items[path][2] != 'delete'
239
239
  end
240
- delete_files << path if File.file?(f)
240
+ delete_files << path if File.file?(f) && path != 'healthcheck'
241
241
  process_storage_dir_sync.call(path+'/') if File.directory?(f)
242
242
  end
243
243
  end
@@ -5,11 +5,11 @@ require 'timeout'
5
5
  class DaemonTest < Test::Unit::TestCase
6
6
  class << self
7
7
  def startup
8
- @debug = false #show stdout and sterr of fc-daemon
8
+ @@debug = false # show stdout and sterr of fc-daemon
9
9
 
10
10
  dir = File.expand_path(File.dirname(__FILE__))
11
- db_config_file = dir+'/db_test.yml'
12
- daemon_bin = File.expand_path(dir+'/../bin/fc-daemon')
11
+ db_config_file = "#{dir}/db_test.yml"
12
+ daemon_bin = File.expand_path("#{dir}/../bin/fc-daemon")
13
13
 
14
14
  File.open(db_config_file, 'w') do |f|
15
15
  f.write(FC::DB.options.to_yaml)
@@ -27,7 +27,7 @@ class DaemonTest < Test::Unit::TestCase
27
27
  @@pid = t.pid
28
28
  while line = stdout.readline
29
29
  @stotage_checks += 1 if line =~ /Finish stotage check/i
30
- puts line if @debug
30
+ puts line if @@debug
31
31
  end
32
32
  end
33
33
  end
@@ -45,62 +45,86 @@ class DaemonTest < Test::Unit::TestCase
45
45
  `cp #{@@test_file_path} #{@@test_dir_path}/bbb/test2`
46
46
 
47
47
  @@storages = []
48
- @@storages << FC::Storage.new(:name => 'host1-sda', :host => 'host1', :path => '/tmp/host1-sda/', :copy_storages => 'host1-sdb,host1-sdc', :size_limit => 1000000000)
49
- @@storages << FC::Storage.new(:name => 'host1-sdb', :host => 'host1', :path => '/tmp/host1-sdb/', :copy_storages => 'host1-sda,host1-sdc', :size_limit => 1000000000)
50
- @@storages << FC::Storage.new(:name => 'host1-sdc', :host => 'host1', :path => '/tmp/host1-sdc/', :copy_storages => 'host1-sda,host1-sdb', :size_limit => 1000000000)
51
- @@storages.each { |storage| storage.save}
48
+ @@storages << FC::Storage.new(
49
+ :name => 'host1-sda',
50
+ :host => 'host1',
51
+ :path => '/tmp/host1-sda/',
52
+ :copy_storages => 'host1-sdb,host1-sdc',
53
+ :size_limit => 1_000_000_000
54
+ )
55
+ @@storages << FC::Storage.new(
56
+ :name => 'host1-sdb',
57
+ :host => 'host1',
58
+ :path => '/tmp/host1-sdb/',
59
+ :copy_storages => 'host1-sda,host1-sdc',
60
+ :size_limit => 1_000_000_000
61
+ )
62
+ @@storages << FC::Storage.new(
63
+ :name => 'host1-sdc',
64
+ :host => 'host1',
65
+ :path => '/tmp/host1-sdc/',
66
+ :copy_storages => 'host1-sda,host1-sdb',
67
+ :size_limit => 1_000_000_000
68
+ )
69
+ @@storages.each(&:save)
52
70
 
53
- @@policy = FC::Policy.new(:create_storages => 'host1-sda,host1-sdb,host1-sdc', :copies => 2, :name => 'policy 1')
71
+ @@policy = FC::Policy.new(
72
+ :create_storages => 'host1-sda,host1-sdb,host1-sdc',
73
+ :copies => 2,
74
+ :name => 'policy 1',
75
+ :delete_deferred_time => 7
76
+ )
54
77
  @@policy.save
55
78
 
56
79
  @@rule = FC::CopyRule.new(:copy_storages => 'host1-sdc', :rule => 'name == "bla/bla/test3"')
57
80
  @@rule.save
58
81
 
59
82
  # wait for running fc-daemon
60
- Timeout::timeout(5) do
61
- while @stotage_checks < @@storages.size
62
- sleep 0.1
63
- end
83
+ Timeout.timeout(5) do
84
+ sleep 0.1 while @stotage_checks < @@storages.size
64
85
  end
65
86
  end
66
87
 
67
88
  def shutdown
68
- Process.kill("KILL", @@pid)
69
- FC::DB.query("DELETE FROM items_storages")
70
- FC::DB.query("DELETE FROM items")
71
- FC::DB.query("DELETE FROM policies")
72
- FC::DB.query("DELETE FROM storages")
89
+ Process.kill('KILL', @@pid)
90
+ FC::DB.query('DELETE FROM items_storages')
91
+ FC::DB.query('DELETE FROM items')
92
+ FC::DB.query('DELETE FROM policies')
93
+ FC::DB.query('DELETE FROM storages')
73
94
  `rm -rf /tmp/host*-sd*`
74
95
  `rm -rf #{@@test_file_path}`
75
96
  `rm -rf #{@@test_dir_path}`
76
97
  end
77
98
  end
78
99
 
79
- should "daemon_all" do
80
- puts 'Start' if @debug
81
- @@storages.each {|storage| storage.reload}
100
+ should 'daemon_all' do
101
+ puts 'Start' if @@debug
102
+ @@storages.each(&:reload)
82
103
  assert @@storages[0].up?, "Storage #{@@storages[0].name} down"
83
104
  assert @@storages[1].up?, "Storage #{@@storages[1].name} down"
84
105
  assert @@storages[2].up?, "Storage #{@@storages[2].name} down"
85
106
 
86
107
  FC::Storage.any_instance.stubs(:host).returns('host1')
87
108
  FC::Storage.stubs(:curr_host).returns('host1')
88
- assert_nothing_raised { @item1 = FC::Item.create_from_local(@@test_file_path, 'bla/bla/test1', @@policy, {:tag => 'test1'}) }
89
- assert_nothing_raised { @item2 = FC::Item.create_from_local(@@test_file_path, 'bla/bla/test2', @@policy, {:tag => 'test2'}) }
90
- assert_nothing_raised { @item3 = FC::Item.create_from_local(@@test_dir_path, 'bla/bla/test3', @@policy, {:tag => 'test3'}) }
109
+ assert_nothing_raised { @item1 = make_file_item('bla/bla/test1', 'test1') }
110
+ assert_nothing_raised { @item2 = make_file_item('bla/bla/test2', 'test2') }
111
+ assert_nothing_raised { @item3 = make_dir_item('bla/bla/test3', 'test3') }
112
+ assert_nothing_raised { @item4 = make_file_item('bla/bla/test4', 'test4') }
91
113
 
92
114
  @@policy.copies = 3
93
115
  @@policy.save
94
116
 
95
117
  # wait for copy
96
118
  sleep 2
97
- puts 'Check copy' if @debug
98
- [1, 2, 3].each do |i|
99
- ['b', 'c'].each do |j|
100
- assert_equal `du -sb /tmp/host1-sda/bla/bla/test$i 2>&1`.to_i, `du -sb /tmp/host$i-sd$j/bla/bla/test$i 2>&1`.to_i
119
+ puts 'Check copy' if @@debug
120
+ [1, 2, 3, 4].each do |i|
121
+ %w(b c).each do |j|
122
+ src_size = `du -sb /tmp/host$i-sda/bla/bla/test$i 2>&1`.to_i
123
+ dst_size = `du -sb /tmp/host$i-sd$j/bla/bla/test$i 2>&1`.to_i
124
+ assert_equal src_size, dst_size
101
125
  end
102
126
  end
103
- assert_equal @@errors_count, FC::Error.where.count, "new errors in errors table"
127
+ assert_equal @@errors_count, FC::Error.where.count, 'new errors in errors table'
104
128
 
105
129
  @@policy.copies = 2
106
130
  @@policy.save
@@ -109,24 +133,41 @@ class DaemonTest < Test::Unit::TestCase
109
133
  item_storage.save
110
134
 
111
135
  sleep 2
112
- puts 'Check delete' if @debug
136
+ puts 'Check delete' if @@debug
113
137
  assert_equal 0, `du -sb /tmp/host1-sdc/bla/bla/test1 2>&1`.to_i
114
- assert_equal @@errors_count, FC::Error.where.count, "new errors in errors table"
138
+ assert_equal @@errors_count, FC::Error.where.count, 'new errors in errors table'
115
139
 
116
- @item1.mark_deleted
117
- FC::ItemStorage.where('item_id = ?', @item2.id).each do |item_storage|
118
- item_storage.status = 'error'
119
- item_storage.save
140
+ @item1.immediate_delete
141
+ @item4.mark_deleted
142
+ @item2.get_item_storages.each do |ist|
143
+ ist.status = 'error'
144
+ ist.save
120
145
  end
121
146
  @item3.status = 'error'
122
147
  @item3.save
123
148
 
124
149
  sleep 6
125
- puts 'Check mark_deleted' if @debug
126
- assert_raise(RuntimeError, "Item not deleted after mark_deleted") {@item1.reload}
127
- assert_equal 0, FC::ItemStorage.where('item_id = ?', @item2.id).count, "ItemStorages not deleted after status='error'"
150
+ puts 'Check immediate_delete' if @@debug
151
+ assert_raise(RuntimeError, 'Item not deleted after mark_deleted') { @item1.reload }
152
+ assert_equal 0, @item2.get_item_storages.count, "ItemStorages not deleted after status='error'"
128
153
  @item3.reload
129
- assert_equal 'delete', @item3.status, "ItemStorages not deleted after status='error'"
130
- assert_equal @@errors_count, FC::Error.where.count, "new errors in errors table"
154
+ assert_equal 'delete', @item3.status, "ItemStorages not deleted after status='error'"
155
+ assert_equal @@errors_count, FC::Error.where.count, 'new errors in errors table'
156
+ assert_equal 'deferred_delete', @item4.status, 'Item not deferred_delete after mark_deleted'
157
+ assert_same_elements %w(ready ready ready), @item4.get_item_storages.map(&:status)
158
+
159
+ sleep 6
160
+ puts 'Check mark_deleted' if @@debug
161
+ assert_raise(RuntimeError, 'Item not deleted after mark_deleted') { @item4.reload }
162
+ end
163
+
164
+ private
165
+
166
+ def make_file_item(name, tag)
167
+ FC::Item.create_from_local(@@test_file_path, name, @@policy, :tag => tag)
168
+ end
169
+
170
+ def make_dir_item(name, tag)
171
+ FC::Item.create_from_local(@@test_dir_path, name, @@policy, :tag => tag)
131
172
  end
132
- end
173
+ end
@@ -71,8 +71,9 @@ class DbTest < Test::Unit::TestCase
71
71
  assert_nil FC::DB.connect, 'FC::DB.connect is not empty after close call'
72
72
 
73
73
  FC::DB.stubs(:options_yml_path).returns(db_config_file)
74
- FC::DB.connect_by_yml
74
+ FC::DB.connect_by_yml('test' => 'test')
75
75
  assert_true FC::DB.connect.ping, 'Not connected after connect_by_yml'
76
+ assert_equal FC::DB.options[:test], 'test', 'options keys is not symbolized'
76
77
 
77
78
  FC::DB.close
78
79
  FC::DB.reconnect
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
 
3
3
  class FunctionalTest < Test::Unit::TestCase
4
- class << self
4
+ class << self
5
5
  def startup
6
6
  # tmp fake storages dirs
7
7
  `rm -rf /tmp/host*-sd*`
@@ -155,4 +155,25 @@ class FunctionalTest < Test::Unit::TestCase
155
155
  assert_equal false, File.exists?(tmp_file_path)
156
156
  File.unstub(:delete)
157
157
  end
158
+
159
+ should 'item create_from_local with block for choose storage' do
160
+ item = FC::Item.create_from_local(@@test_file_path,
161
+ '/bla/bla/test7',
162
+ @@policies[0],
163
+ :tag => 'test') do |storages|
164
+ storages.select { |s| s.name == 'host2-sda' }
165
+ end
166
+ assert_kind_of FC::Item, item
167
+ assert_equal `du -sb /tmp/host2-sda/bla/bla/test7 2>&1`.to_i, item.size
168
+ assert_equal 'ready', item.status
169
+ item_storages = item.get_item_storages
170
+ assert_equal 1, item_storages.count
171
+ assert_equal 'ready', item_storages.first.status
172
+ assert_equal 'host2-sda', item_storages.first.storage_name
173
+ item = FC::Item.create_from_local(@@test_file_path,
174
+ '/bla/bla/test8',
175
+ @@policies[0],
176
+ :tag => 'test') { [@@storages[4]] }
177
+ assert_equal 'host3-sda', item.get_item_storages.first.storage_name
178
+ end
158
179
  end
@@ -1,5 +1,6 @@
1
1
  $:.unshift File.expand_path('../lib', File.dirname(__FILE__))
2
2
 
3
+ require 'ostruct'
3
4
  require "test/unit"
4
5
  require "shoulda-context"
5
6
  require "filecluster"
@@ -16,6 +16,7 @@ class ItemTest < Test::Unit::TestCase
16
16
  item_storage
17
17
  end
18
18
  @@storages << FC::Storage.new(:name => 'rec3-sda', :host => 'rec3', :url => 'http://rec3/sda/')
19
+ @@storages[2].save
19
20
  end
20
21
  def shutdown
21
22
  FC::DB.query("DELETE FROM items_storages")
@@ -24,8 +25,7 @@ class ItemTest < Test::Unit::TestCase
24
25
  end
25
26
  end
26
27
 
27
- should "create_from_local" do
28
- policy = FC::Policy.new
28
+ should "create_from_local" do policy = FC::Policy.new
29
29
  assert_raise(ArgumentError) { FC::Item.create_from_local }
30
30
  assert_raise(ArgumentError) { FC::Item.create_from_local '/bla/bla' }
31
31
  assert_raise(ArgumentError) { FC::Item.create_from_local '/bla/bla', 'test' }
@@ -33,42 +33,50 @@ class ItemTest < Test::Unit::TestCase
33
33
  assert_raise() { FC::Item.create_from_local '/bla/bla/bla', 'test', policy}
34
34
  end
35
35
 
36
- should "mark_deleted" do
37
- @@item.mark_deleted
36
+ should "immediate_delete" do
37
+ @@item.immediate_delete
38
38
  @@item.reload
39
39
  assert_equal 'delete', @@item.status
40
40
  @@item_storages.each do |item_storage|
41
41
  item_storage.reload
42
42
  assert_equal 'delete', item_storage.status
43
+ item_storage.status = 'ready'
44
+ item_storage.save
45
+ end
46
+ @@item.status = 'ready'
47
+ @@item.save
48
+ end
49
+
50
+ should 'mark_deleted' do @@item.mark_deleted
51
+ @@item.reload
52
+ assert_equal 'deferred_delete', @@item.status
53
+ @@item_storages.each do |item_storage|
54
+ item_storage.reload
55
+ assert_equal 'ready', item_storage.status
43
56
  end
44
57
  end
45
58
 
46
- should "make_item_storage" do
47
- storage_size = @@storages[2].size.to_i
59
+ should "make_item_storage" do storage_size = @@storages[2].size.to_i
48
60
  assert_kind_of FC::ItemStorage, @@item.make_item_storage(@@storages[2])
49
61
  assert_equal storage_size+@@item.size, @@storages[2].size
50
62
  end
51
63
 
52
- should "get_item_storages" do
53
- assert_same_elements @@item_storages.map(&:id), @@item.get_item_storages.map(&:id)
64
+ should "get_item_storages" do assert_same_elements @@item_storages.map(&:id), @@item.get_item_storages.map(&:id)
54
65
  end
55
66
 
56
- should "item get_available_storages" do
57
- @@storages.each{|s| s.check_time = 0; s.save}
67
+ should "item get_available_storages" do @@storages.each{|s| s.check_time = 0; s.save}
58
68
  @@storages[0].update_check_time
59
69
  assert_equal 1, @@item.get_available_storages.count
60
70
  assert_equal @@storages[0].name, @@item.get_available_storages.first.name
61
71
  end
62
72
 
63
- should "item urls" do
64
- @@storages.each{|s| s.check_time = 0; s.save}
73
+ should "item urls" do @@storages.each{|s| s.check_time = 0; s.save}
65
74
  assert_equal 0, @@item.urls.count
66
75
  @@storages.each(&:update_check_time)
67
76
  assert_same_elements ["http://rec1/sda/test item", "http://rec2/sda/test item"], @@item.urls
68
77
  end
69
78
 
70
- should "item url by url_weight" do
71
- @@storages.each(&:update_check_time)
79
+ should "item url by url_weight" do @@storages.each(&:update_check_time)
72
80
  @@storages.each{|s| s.url_weight = -1; s.save}
73
81
  assert_raise(RuntimeError) { @@item.url }
74
82
 
@@ -39,7 +39,9 @@ class StorageSyncTest < Test::Unit::TestCase
39
39
  assert_nothing_raised { @item3 = FC::Item.create_from_local(@@test_file_path, 'a/b/c/test3', @@policy, {:tag => 'test'}) }
40
40
  assert_nothing_raised { @item4 = FC::Item.create_from_local(@@test_file_path, 'a/b/c/d/test4', @@policy, {:tag => 'test'}) }
41
41
  assert_nothing_raised { @item5 = FC::Item.create_from_local(@@test_file_path, 'a/del_file', @@policy, {:tag => 'test'}) }
42
- @item5.mark_deleted
42
+ assert_nothing_raised { @item6 = FC::Item.create_from_local(@@test_file_path, 'a/differed_del_file', @@policy, {:tag => 'test'}) }
43
+ @item5.immediate_delete
44
+ @item6.mark_deleted
43
45
  `mv /tmp/host1-sda/a/test1 /tmp/host1-sda/test1`
44
46
  `mv /tmp/host1-sda/a/b/c/d/test4 /tmp/host1-sda/a/b/c/d/test5`
45
47
  `mkdir /tmp/host1-sda/test_dir`
@@ -52,10 +54,12 @@ class StorageSyncTest < Test::Unit::TestCase
52
54
  @item2.reload
53
55
  @item3.reload
54
56
  @item4.reload
57
+ @item6.reload
55
58
  assert_equal 'error', @item1.status
56
59
  assert_equal 'ready', @item2.status
57
60
  assert_equal 'ready', @item3.status
58
61
  assert_equal 'error', @item4.status
62
+ assert_equal 'deferred_delete', @item6.status
59
63
  size = `du -sb #{@@test_file_path} 2>&1`.to_i
60
64
  assert_equal 0, `du -sb /tmp/host1-sda/test1 2>&1`.to_i
61
65
  assert_equal size, `du -sb /tmp/host1-sda/a/b/test2 2>&1`.to_i
@@ -63,7 +67,8 @@ class StorageSyncTest < Test::Unit::TestCase
63
67
  assert_equal 0, `du -sb /tmp/host1-sda/a/b/c/d/test5 2>&1`.to_i
64
68
  assert_equal 0, `du -sb /tmp/host1-sda/a/b/c/d 2>&1`.to_i
65
69
  assert_equal 0, `du -sb /tmp/host1-sda/test_dir 2>&1`.to_i
66
- assert_equal 0, @item5.get_item_storages.size
70
+ assert_equal 0, @item5.get_item_storages.count
67
71
  assert_equal 0, `du -sb /tmp/host1-sda/a/del_file 2>&1`.to_i
72
+ assert_equal size, `du -sb /tmp/host1-sda/a/differed_del_file 2>&1`.to_i
68
73
  end
69
- end
74
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filecluster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - sh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-07 00:00:00.000000000 Z
11
+ date: 2016-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mysql2
@@ -174,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
174
  version: '0'
175
175
  requirements: []
176
176
  rubyforge_project:
177
- rubygems_version: 2.4.3
177
+ rubygems_version: 2.4.8
178
178
  signing_key:
179
179
  specification_version: 4
180
180
  summary: Distributed storage