Class: Pmux::GlusterFSAdapter

Inherits:
StorageAdapter show all
Defined in:
lib/pmux/storage_adapter.rb

Direct Known Subclasses

BBFSAdapter

Constant Summary

Constants inherited from StorageAdapter

StorageAdapter::Adapters

Instance Attribute Summary

Attributes inherited from StorageAdapter

#addrs

Instance Method Summary collapse

Methods inherited from StorageAdapter

create, #init_node_hash, #initialize

Constructor Details

This class inherits a constructor from Pmux::StorageAdapter

Instance Method Details

#connect_to_storage(locator_host, locator_port) ⇒ Object



71
72
73
74
75
76
# File 'lib/pmux/storage_adapter.rb', line 71

def connect_to_storage locator_host, locator_port
  locator_port ||= 7076
  @client = MR::Client.new locator_host, locator_port
  @client.timeout = 3600 #FIXME
  @client
end

#get_files(args, glob_flag = false) ⇒ Object

Raises:

  • (RuntimeError)


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/pmux/storage_adapter.rb', line 78

def get_files args, glob_flag=false
  raise RuntimeError, 'not connected' unless @client
  result = @client.call :get_locations, args, glob_flag
  @locations = result

  # hostname -> addr
  hosts = {}
  for vs in result.values
    for host, path in vs
      hosts[host] = true
    end
  end
  @host2addr = {}
  @addrs = hosts.keys.map {|host| addr = getaddr host
    @host2addr[host] = addr}
  @h = init_node_hash @addrs
  result.keys # files
end

#getaddr(host) ⇒ Object



65
66
67
68
69
# File 'lib/pmux/storage_adapter.rb', line 65

def getaddr host
  sa = Socket.pack_sockaddr_in 0, host
  port, addr = Socket.unpack_sockaddr_in sa
  addr
end

#lookup_file(file) ⇒ Object



97
98
99
100
101
102
103
# File 'lib/pmux/storage_adapter.rb', line 97

def lookup_file file
  if (res = @locations[file])
    res.map {|host, path| [@host2addr[host], path]}
  else
    nil
  end
end