filecluster 0.5.7 → 0.5.8

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fc/storage.rb +31 -19
  3. data/lib/fc/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 513efeda9b8bc064c2ac65cff2b96f96ab3f2a13
4
- data.tar.gz: a91430765fbf496273b7c25bed7c0f3fb1b89172
3
+ metadata.gz: fc12e92010113085a66dea7bfbac267f67768247
4
+ data.tar.gz: 80afdcb6ec68e4b282e359bd75cc46975787a22b
5
5
  SHA512:
6
- metadata.gz: c452b42e5e0ef6ff4611b7d111a3b9f07ad351411636ebef0b50389463457a7d9796c3a104759da9d53bf66e48cb47ecde7ccc643cfb47303b9073fd5fd51416
7
- data.tar.gz: 35a68af5f2165b48310777dcd9f1f5de141fee06e5625b1c77831859d6c07392879cd6f11f54e95489a5ffa0be80a1df3b0220919043a187fc112605d7d87c3c
6
+ metadata.gz: b67df5a734df911038c68f9b2780f355357adfec7865af7cacb55c661c09cb719dbec6f7d038d2cccb79dd9dee423391898efdcf9b98236cb6d2b0c01e46fd4e
7
+ data.tar.gz: 1d7eb36494a02a57c786da0a53c65bc60e280d13abd438e391384607a1f25951dc79584579d739d7d96a2c2a863ece8fa8d6dc7bc7dc639a7c5ac51cda9bbf37
@@ -16,7 +16,7 @@ module FC
16
16
  def self.curr_host
17
17
  @uname || @uname = `uname -n`.chomp
18
18
  end
19
-
19
+
20
20
  def self.select_proper_storage_for_create(storages, size, exclude = [])
21
21
  list = storages.select do |storage|
22
22
  !exclude.include?(storage.name) && storage.up? && storage.size + size < storage.size_limit && storage.write_weight.to_i >= 0
@@ -101,23 +101,33 @@ module FC
101
101
  def up?
102
102
  check_time_delay < self.class.check_time_limit
103
103
  end
104
-
104
+
105
+ def self.speed_limit_to_rsync_opt(speed_limit)
106
+ return "--bwlimit=#{(speed_limit.to_f * 125.0).ceil} " if speed_limit.to_f > 0
107
+ ''
108
+ end
109
+
105
110
  # copy local_path to storage
106
111
  def copy_path(local_path, file_name, try_move = false, speed_limit = nil)
107
112
  dst_path = "#{self.path}#{file_name}"
108
113
 
109
- cmd = "rm -rf #{dst_path.shellescape}; mkdir -p #{File.dirname(dst_path).shellescape}"
110
- cmd = self.class.curr_host == host ? cmd : "ssh -q -oBatchMode=yes -oStrictHostKeyChecking=no #{self.host} \"#{cmd}\""
111
- r = `#{cmd} 2>&1`
112
- raise r if $?.exitstatus != 0
113
-
114
- op = try_move && self.class.curr_host == host && File.stat(local_path).dev == File.stat(File.dirname(dst_path)).dev ? 'mv' : 'cp -r'
115
- speed_limit = (speed_limit * 1000).to_i if speed_limit.to_f > 0
116
- cmd = self.class.curr_host == host ?
117
- "#{op} #{local_path.shellescape} #{dst_path.shellescape}" :
118
- "scp -r -q -oBatchMode=yes -oStrictHostKeyChecking=no #{speed_limit.to_i > 0 ? '-l '+speed_limit.to_s : ''} #{local_path.shellescape} #{self.host}:\"#{dst_path.shellescape}\""
119
- r = `#{cmd} 2>&1`
120
- raise r if $?.exitstatus != 0
114
+ recreate_dirs_cmd = "rm -rf #{dst_path.shellescape}; mkdir -p #{File.dirname(dst_path).shellescape}"
115
+
116
+ # recreate dirs anyway if local op
117
+ if try_move && self.class.curr_host == host
118
+ r = `#{recreate_dirs_cmd} 2>&1`
119
+ raise r if $?.exitstatus != 0
120
+ end
121
+ # if we can make mv command
122
+ if try_move && self.class.curr_host == host && File.stat(local_path).dev == File.stat(File.dirname(dst_path)).dev
123
+ r = `mv #{local_path.shellescape} #{dst_path.shellescape} 2>&1`
124
+ raise r if $?.exitstatus != 0
125
+ else
126
+ local_path += '/' if File.stat(local_path).directory?
127
+ cmd = "ionice -c 2 -n 7 rsync -a #{FC::Storage.speed_limit_to_rsync_opt(speed_limit)}--rsync-path=\"#{recreate_dirs_cmd} && ionice -c 2 -n 7 rsync\" #{local_path.shellescape} #{self.host}:\"#{dst_path.shellescape}\""
128
+ r = `#{cmd} 2>&1`
129
+ raise r if $?.exitstatus != 0
130
+ end
121
131
  end
122
132
 
123
133
  # copy object to local_path
@@ -126,11 +136,13 @@ module FC
126
136
 
127
137
  r = `rm -rf #{local_path.shellescape}; mkdir -p #{File.dirname(local_path).shellescape} 2>&1`
128
138
  raise r if $?.exitstatus != 0
129
-
130
- speed_limit = (speed_limit * 1000).to_i if speed_limit.to_f > 0
131
- cmd = self.class.curr_host == host ?
132
- "cp -r #{src_path.shellescape} #{local_path.shellescape}" :
133
- "scp -r -q -oBatchMode=yes -oStrictHostKeyChecking=no #{speed_limit.to_i > 0 ? '-l '+speed_limit.to_s : ''} #{self.host}:\"#{src_path.shellescape}\" #{local_path.shellescape}"
139
+
140
+ # if remote file is directory?
141
+ cmd = "ssh -oStrictHostKeyChecking=no -q #{self.host} \"if [ -d #{src_path.shellescape} ]; then /bin/true; else /bin/false; fi\""
142
+ r = `#{cmd} 2>&1`
143
+ src_path += '/' if $?.exitstatus == 0
144
+
145
+ cmd = "ionice -c 2 -n 7 rsync -a #{FC::Storage.speed_limit_to_rsync_opt(speed_limit)}--rsync-path=\"ionice -c 2 -n 7 rsync\" #{self.host}:\"#{src_path.shellescape}\" #{local_path.shellescape}"
134
146
  r = `#{cmd} 2>&1`
135
147
  raise r if $?.exitstatus != 0
136
148
  end
@@ -1,3 +1,3 @@
1
1
  module FC
2
- VERSION = '0.5.7'.freeze
2
+ VERSION = '0.5.8'.freeze
3
3
  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.7
4
+ version: 0.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - sh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-25 00:00:00.000000000 Z
11
+ date: 2017-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mysql2