Merge pull request #39351 from ninja-/reduce_fileclient_latency

Reduce fileclient latency by merging _file_hash and _find_file
This commit is contained in:
Mike Place 2017-02-14 11:55:22 -07:00 committed by GitHub
commit 370b3409ad
2 changed files with 5 additions and 23 deletions

View File

@ -1277,10 +1277,10 @@ class RemoteClient(Client):
hash_type = self.opts.get('hash_type', 'md5')
ret['hsum'] = salt.utils.get_hash(path, form=hash_type)
ret['hash_type'] = hash_type
return ret
return ret, list(os.stat(path))
load = {'path': path,
'saltenv': saltenv,
'cmd': '_file_hash'}
'cmd': '_file_hash_and_stat'}
return self.channel.send(load)
def hash_file(self, path, saltenv='base'):
@ -1289,33 +1289,14 @@ class RemoteClient(Client):
master file server prepend the path with salt://<file on server>
otherwise, prepend the file with / for a local file.
'''
return self.__hash_and_stat_file(path, saltenv)
return self.__hash_and_stat_file(path, saltenv)[0]
def hash_and_stat_file(self, path, saltenv='base'):
'''
The same as hash_file, but also return the file's mode, or None if no
mode data is present.
'''
hash_result = self.hash_file(path, saltenv)
try:
path = self._check_proto(path)
except MinionError as err:
if not os.path.isfile(path):
return hash_result, None
else:
try:
return hash_result, list(os.stat(path))
except Exception:
return hash_result, None
load = {'path': path,
'saltenv': saltenv,
'cmd': '_file_find'}
fnd = self.channel.send(load)
try:
stat_result = fnd.get('stat')
except AttributeError:
stat_result = None
return hash_result, stat_result
return self.__hash_and_stat_file(path, saltenv)
def list_env(self, saltenv='base'):
'''

View File

@ -971,6 +971,7 @@ class AESFuncs(object):
self._serve_file = self.fs_.serve_file
self._file_find = self.fs_._find_file
self._file_hash = self.fs_.file_hash
self._file_hash_and_stat = self.fs_.file_hash_and_stat
self._file_list = self.fs_.file_list
self._file_list_emptydirs = self.fs_.file_list_emptydirs
self._dir_list = self.fs_.dir_list