filecluster 0.0.9 → 0.1.0

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.
@@ -39,7 +39,8 @@ end
39
39
 
40
40
  def update_storages
41
41
  $log.debug('Update storages')
42
- $storages = FC::Storage.where('host = ?', FC::Storage.curr_host)
42
+ $all_storages = FC::Storage.where
43
+ $storages = $all_storages.select{|s| s.host == FC::Storage.curr_host}
43
44
  end
44
45
 
45
46
  def storages_check
@@ -29,7 +29,7 @@ class TaskThread < BaseThread
29
29
  storage = $storages.detect{|s| s.name == item_storage.storage_name}
30
30
  item = FC::Item.find(item_storage.item_id)
31
31
  src_item_storage = FC::ItemStorage.where("item_id = ? AND status = 'ready'", item.id).sample
32
- src_storage = $storages.detect{|s| s.name == src_item_storage.storage_name}
32
+ src_storage = $all_storages.detect{|s| s.name == src_item_storage.storage_name}
33
33
  item.copy_item_storage(src_storage, storage, item_storage)
34
34
  rescue Exception => e
35
35
  error "Copy item_storage error: #{e.message}; #{e.backtrace.join(', ')}", :item_id => item_storage.item_id, :item_storage_id => item_storage.id
@@ -21,10 +21,7 @@ module FC
21
21
  end
22
22
 
23
23
  def self.connect=(connect, options = {})
24
- @options = connect.query_options.merge(options)
25
- @prefix = @options[:prefix].to_s
26
- @connects = {}
27
- @connects[Thread.current.object_id] = connect
24
+ self.connect_by_config connect.query_options.merge(options).merge(:as => :hash)
28
25
  end
29
26
 
30
27
  def self.close
@@ -52,7 +49,7 @@ module FC
52
49
  time int DEFAULT NULL,
53
50
  copies int NOT NULL DEFAULT 0,
54
51
  PRIMARY KEY (id), UNIQUE KEY (name(255), policy_id),
55
- KEY (outer_id), KEY (time, status), KEY (status), KEY (copies, status, policy_id)
52
+ KEY (outer_id), KEY (time, status), KEY (status, policy_id, copies), KEY (copies, status, policy_id)
56
53
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
57
54
  })
58
55
  proc_time = %{
@@ -23,16 +23,18 @@ module FC
23
23
  raise 'Zero size path' if item_params[:size] == 0
24
24
 
25
25
  if local_path.include?(item_name)
26
- storage = policy.get_create_storages.detect{|s| local_path.index(s.path) == 0 && local_path.sub(s.path, '') == item_params[:name]}
26
+ storage = policy.get_create_storages.detect do |s|
27
+ s.host == FC::Storage.curr_host && local_path.index(s.path) == 0 && local_path.sub(s.path, '') == item_params[:name]
28
+ end
27
29
  FC::Error.raise "local_path #{local_path} is not valid path for policy ##{policy.id}" unless storage
28
30
  end
29
31
 
30
32
  # new item?
31
33
  item = FC::Item.where('name=? AND policy_id=?', item_params[:name], policy.id).first
32
34
  if item
33
- if options[:replace]
35
+ if options[:replace] || storage
34
36
  # mark delete item_storages on replace
35
- FC::DB.connect.query("UPDATE #{FC::ItemStorage.table_name} SET status='delete' WHERE item_id = #{item.id}")
37
+ FC::DB.connect.query("UPDATE #{FC::ItemStorage.table_name} SET status='delete' WHERE item_id = #{item.id}") if options[:replace] && !storage
36
38
  # replace all fields
37
39
  item_params.each{|key, val| item.send("#{key}=", val)}
38
40
  else
@@ -32,7 +32,13 @@ module FC
32
32
 
33
33
  # get available storage for copy by copy_id and size
34
34
  def get_proper_storage_for_copy(size, copy_id = nil, exclude = [])
35
- storages = get_copy_storages.select do |storage|
35
+ storages = get_copy_storages
36
+ start_storage_index = nil
37
+ storages.each_with_index do |s, i|
38
+ start_storage_index = i if copy_id.to_i == s.copy_id.to_i
39
+ end
40
+ storages = storages[start_storage_index..-1]+storages[0..start_storage_index-1] if storages.size > 0 && start_storage_index
41
+ storages = storages.select do |storage|
36
42
  !exclude.include?(storage.name) && storage.up? && storage.size + size < storage.size_limit
37
43
  end
38
44
  storage = storages.detect{|s| copy_id.to_i == s.copy_id.to_i}
@@ -1,3 +1,3 @@
1
1
  module FC
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -77,5 +77,11 @@ class PolicyTest < Test::Unit::TestCase
77
77
  @@policy.copy_storages = 'rec2-sda,rec3-sda,rec1-sda'
78
78
  @@policy.save
79
79
  assert_equal 'rec2-sda', @@policy.get_proper_storage_for_copy(1, 4).name, 'storage by copy_id'
80
+
81
+ @@policy.copy_storages = 'rec3-sda,rec1-sda,rec2-sda,'
82
+ @@policy.save
83
+ @@storages[0].check_time = 0
84
+ @@storages[0].save
85
+ assert_equal 'rec2-sda', @@policy.get_proper_storage_for_copy(1, 1).name, 'storage by copy_id'
80
86
  end
81
87
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filecluster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
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-04-15 00:00:00.000000000 Z
12
+ date: 2013-04-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rb-readline
@@ -186,7 +186,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
186
  version: '0'
187
187
  segments:
188
188
  - 0
189
- hash: -919880063
189
+ hash: 2418971618198205266
190
190
  required_rubygems_version: !ruby/object:Gem::Requirement
191
191
  none: false
192
192
  requirements:
@@ -195,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
195
  version: '0'
196
196
  segments:
197
197
  - 0
198
- hash: -919880063
198
+ hash: 2418971618198205266
199
199
  requirements: []
200
200
  rubyforge_project:
201
201
  rubygems_version: 1.8.24