diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-01-28 16:02:26 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-01-28 16:02:26 -0800 |
commit | a24cd5c8e29161c5dbf707f65ec0d64b2a75dc1b (patch) | |
tree | 9f9c94f975426a67e0766578206a7a42492d2151 | |
parent | e482442c5c46ab67d5db5206e8dea66d2e5c4dc9 (diff) | |
download | mogilefs-client-a24cd5c8e29161c5dbf707f65ec0d64b2a75dc1b.tar.gz |
Domains and devices may be added/changed at any time, so there's a risk of cache misses in case something got added before our cache refresh interval. Always retry if we have a cache miss.
-rw-r--r-- | lib/mogilefs/mysql.rb | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/mogilefs/mysql.rb b/lib/mogilefs/mysql.rb index b6760a4..ccfee0d 100644 --- a/lib/mogilefs/mysql.rb +++ b/lib/mogilefs/mysql.rb @@ -30,8 +30,7 @@ class MogileFS::Mysql # +after+ is nil the list starts at the beginning. def _list_keys(domain, prefix = '', after = '', limit = 1000, &block) # this code is based on server/lib/MogileFS/Worker/Query.pm - dmid = refresh_domain[domain] or \ - raise MogileFS::Backend::DomainNotFoundError + dmid = get_dmid(domain) # don't modify passed arguments limit ||= 1000 @@ -66,8 +65,7 @@ class MogileFS::Mysql ## # Returns the size of +key+. def _size(domain, key) - dmid = refresh_domain[domain] or \ - raise MogileFS::Backend::DomainNotFoundError + dmid = get_dmid(domain) sql = <<-EOS SELECT length FROM file @@ -85,8 +83,7 @@ class MogileFS::Mysql def _get_paths(params = {}) zone = params[:zone] noverify = (params[:noverify] == 1) # TODO this is unused atm - dmid = refresh_domain[params[:domain]] or \ - raise MogileFS::Backend::DomainNotFoundError + dmid = get_dmid(params[:domain]) devices = refresh_device or raise MogileFS::Backend::NoDevicesError urls = [] sql = <<-EOS @@ -100,7 +97,11 @@ class MogileFS::Mysql fid = res[0] sql = "SELECT devid FROM file_on WHERE fid = '#{@my.quote(fid)}'" query(sql).each do |devid,| - devinfo = devices[devid.to_i] + unless devinfo = devices[devid.to_i] + devices = refresh_device(true) + devinfo = devices[devid.to_i] or next + end + port = devinfo[:http_get_port] host = zone && zone == 'alt' ? devinfo[:altip] : devinfo[:hostip] nfid = '%010u' % fid @@ -157,4 +158,9 @@ class MogileFS::Mysql @cache_domain = tmp.freeze end + def get_dmid(domain) + refresh_domain[domain] || refresh_domain(true)[domain] or \ + raise MogileFS::Backend::DomainNotFoundError, domain + end + end |