class SyncWrap::LVMCache
Provision a cache using a fast drive (like an SSD) over a slow drive (magnetic or network attached) via LVM's cache-pool mechanism and dm-cache.
Host component dependencies: <Distro>
Attributes
The target size of the cache volume as a string. This may either express a percentage (via -l) or a real size (via -L, ex: '30G') Default: '100%FREE'
The name of the cache volume Default: #lv_cache_target + '_cache'
The target volume name in the same volume group to cache. (required)
The target size of the cache metadata volume as a string. The dm-cache guidelines are 1/1000th of the cache volume size and a minimum of 8M (MiB). Default: '8M'
The fast raw device to use as the cache, i.e. '/dev/xvdb' (required)
A volume group instance number compatible with the naming used by MDRaid. The cache and cache-meta volumes must all be under the same volume group as the #lv_cache_target volume. Default: 0 -> 'vg0'
Array of additional flags to vgextend Default: ['-y']
Public Class Methods
# File lib/syncwrap/components/lvm_cache.rb, line 76 def initialize( opts = {} ) @meta_size = '8M' @cache_size = '100%FREE' @vg_instance = 0 @raw_device = nil @lv_cache_target = nil @lv_cache = nil @vgextend_flags = %w[ -y ] super raise "LVMCache#raw_device not set" unless raw_device raise "LVMCache#lv_cache_target not set" unless lv_cache_target end
Public Instance Methods
# File lib/syncwrap/components/lvm_cache.rb, line 90 def install if distro.is_a?( Debian ) dist_install( "lvm2", "thin-provisioning-tools", minimal: true ) else dist_install( "lvm2", minimal: true ) end sudo_if( "! lvs /dev/#{vg}/#{lv_cache}" ) do unmount_device( raw_device ) sudo <<-SH vgextend #{vgextend_flags.join ' '} #{vg} #{raw_device} lvcreate -L #{meta_size} -n #{lv_cache_meta} #{vg} #{raw_device} lvcreate #{cache_size_flag} -n #{lv_cache} #{vg} #{raw_device} lvconvert --yes --type cache-pool --cachemode writethrough \ --poolmetadata #{vg}/#{lv_cache_meta} #{vg}/#{lv_cache} lvconvert --yes --type cache --cachepool #{vg}/#{lv_cache} \ #{vg}/#{lv_cache_target} SH end end
Protected Instance Methods
# File lib/syncwrap/components/lvm_cache.rb, line 112 def cache_size_flag if cache_size =~ /%/ "-l #{cache_size}" else "-L #{cache_size}" end end
# File lib/syncwrap/components/lvm_cache.rb, line 62 def lv_cache @lv_cache || ( lv_cache_target + '_cache' ) end
# File lib/syncwrap/components/lvm_cache.rb, line 66 def lv_cache_meta lv_cache + '_meta' end
# File lib/syncwrap/components/lvm_cache.rb, line 70 def vg "vg#{vg_instance}" end