salt icon indicating copy to clipboard operation
salt copied to clipboard

Copying files from gitfs in file.recurse state fails / is slow

Open martinhoefling opened this issue 11 years ago • 10 comments

In a file.recurse state copying ~250 files, we observe transfer rates of 1 file/sec. These are small text files (a salt state.tree).

2014-12-09 15:23:43,379 [salt.fileclient  ][INFO    ] Fetching file from saltenv 'salt-daily', ** done ** 'ntpd/init.sls'
2014-12-09 15:23:43,800 [salt.fileclient  ][INFO    ] Fetching file from saltenv 'salt-daily', ** done ** 'hostname.sls'
2014-12-09 15:23:44,209 [salt.fileclient  ][INFO    ] Fetching file from saltenv 'salt-daily', ** done ** 'ssh_auth/ubuntu.sls'
2014-12-09 15:23:45,107 [salt.fileclient  ][INFO    ] Fetching file from saltenv 'salt-daily', ** done ** 'governed-salt-master/init.sls'

Often, the highstate fails with a file that could not be copied to the minion:

2014-12-08 16:16:12,947 [salt.state       ][INFO    ] Executing state file.recurse for /srv/pillar
2014-12-08 16:16:20,208 [salt.state       ][ERROR   ] #### /srv/pillar/defaults-elasticsearch.sls ####

Source file salt://|instance-masters/pillar/defaults-elasticsearch.sls not found

We use salt 2014.7.0 / ubuntu packages with gitpython as gitfs provider.

martinhoefling avatar Dec 09 '14 15:12 martinhoefling

I have the same problem, using pygit2 as a provider. Here's a traceback of one of the failed transfers:

2014-12-09 15:57:13,816 [salt.master      ][INFO    ] AES payload received with command _file_hash
2014-12-09 15:57:14,044 [salt.config      ][DEBUG   ] Reading configuration from /etc/salt/master
2014-12-09 15:57:14,052 [salt.config      ][DEBUG   ] Guessing ID. The id can be explicitly in set /etc/salt/minion
2014-12-09 15:57:14,127 [salt.config      ][INFO    ] Found minion id from generate_minion_id(): e4c08e8d91df
2014-12-09 15:57:14,129 [salt.config      ][DEBUG   ] Reading configuration from /etc/salt/master
2014-12-09 15:57:14,367 [salt.loaded.int.grain.core][DEBUG   ] The `dmidecode` binary is not available on the system. GPU grains will not be available.
2014-12-09 15:57:14,381 [salt.master      ][INFO    ] AES payload received with command _file_hash
2014-12-09 15:57:14,723 [salt.loader      ][DEBUG   ] LazyLoaded local_cache.clean_old_jobs
2014-12-09 15:57:14,768 [salt.loaded.int.fileserver.gitfs][DEBUG   ] Fetching from file:///project.git
2014-12-09 15:57:14,974 [salt.master      ][INFO    ] AES payload received with command _file_hash
2014-12-09 15:57:15,112 [salt.loaded.int.fileserver.gitfs][DEBUG   ] Gitfs received 0 objects for remote file:///project.git
2014-12-09 15:57:15,113 [salt.loaded.int.fileserver.gitfs][DEBUG   ] Fetching from file:///project.git
2014-12-09 15:57:15,450 [salt.loaded.int.fileserver.gitfs][DEBUG   ] Gitfs received 0 objects for remote file:///project.git
2014-12-09 15:57:15,451 [salt.loaded.int.fileserver.gitfs][DEBUG   ] Fetching from file:///project.git
2014-12-09 15:57:15,586 [salt.master      ][INFO    ] AES payload received with command _file_hash
2014-12-09 15:57:15,827 [salt.loaded.int.fileserver.gitfs][DEBUG   ] Gitfs received 0 objects for remote file:///project.git
2014-12-09 15:57:15,828 [salt.loaded.int.fileserver.gitfs][DEBUG   ] Fetching from file:///project.git
2014-12-09 15:57:16,257 [salt.loaded.int.fileserver.gitfs][DEBUG   ] Gitfs received 0 objects for remote file:///project.git
2014-12-09 15:57:16,280 [salt.master      ][ERROR   ] Error in function _file_hash:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/salt/master.py", line 1329, in run_func
    ret = getattr(self, func)(load)
  File "/usr/lib/python2.7/dist-packages/salt/fileserver/__init__.py", line 428, in file_hash
    fnd = self.find_file(load['path'], load['saltenv'])
  File "/usr/lib/python2.7/dist-packages/salt/fileserver/__init__.py", line 382, in find_file
    fnd = self.servers[fstr](path, saltenv, **kwargs)
  File "/usr/lib/python2.7/dist-packages/salt/fileserver/gitfs.py", line 1213, in find_file
    with salt.utils.fopen(lk_fn, 'w+') as fp_:
  File "/usr/lib/python2.7/dist-packages/salt/utils/__init__.py", line 1065, in fopen
    fhandle = open(*args, **kwargs)
IOError: [Errno 2] No such file or directory: '/var/cache/salt/master/gitfs/hash/salt-project-daily/common/states/ssh_auth/authorized_keys.lk'```

eyj avatar Dec 09 '14 16:12 eyj

@martinhoefling, @eyj, I have setup two ubuntu 14.04.1 VMs and installed GitPython with pip on the master to try to reproduce this problem without success. If either of you are able to provide a minimal state configuration that reproduces this problem, that would be very helpful. Here's my attempt; please comment if I have omitted anything important.

versions

jmoney-ubuntu-14 ~ master # lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.1 LTS
Release:        14.04
Codename:       trusty
jmoney-ubuntu-14 ~ master # salt --versions
           Salt: 2014.7.0
         Python: 2.7.6 (default, Mar 22 2014, 22:59:56)
         Jinja2: 2.7.2
       M2Crypto: 0.21.1
 msgpack-python: 0.3.0
   msgpack-pure: Not Installed
       pycrypto: 2.6.1
        libnacl: Not Installed
         PyYAML: 3.10
          ioflo: Not Installed
          PyZMQ: 14.0.1
           RAET: Not Installed
            ZMQ: 4.0.4
           Mako: 0.9.1
jmoney-ubuntu-14 ~ master # salt jmoney-ubuntu-14-minion test.version
jmoney-ubuntu-14-minion:
    2014.7.0
jmoney-ubuntu-14 ~ master # pip list | grep -i gitpython
GitPython (0.3.2.1)

setup

jmoney-ubuntu-14 ~ master # cat /etc/salt/master
fileserver_backend:
  - git
  - roots
gitfs_remotes:
  - git://github.com/saltstack/salt.git
gitfs_base: '2014.7'
jmoney-ubuntu-14 ~ master # cat /srv/salt/salt-tests.sls
the-files:
  file.recurse:
    - name: /tmp/salt-tests
    - source: salt://tests/unit

execution

jmoney-ubuntu-14 ~ master # salt jmoney-ubuntu-14-minion run 'rm -fr /tmp/salt-tests'
jmoney-ubuntu-14-minion:

jmoney-ubuntu-14 ~ master # salt jmoney-ubuntu-14-minion state.sls salt-tests
jmoney-ubuntu-14-minion:
----------
          ID: the-files
    Function: file.recurse
        Name: /tmp/salt-tests
      Result: True
     Comment: Recursively updated /tmp/salt-tests
     Started: 14:59:09.734127
    Duration: 2740.085 ms
     Changes:

...

Summary
------------
Succeeded: 1 (changed=1)
Failed:    0
------------
Total states run:     1

result

2014-12-09 14:58:53,430 [salt.loaded.int.fileserver.gitfs][DEBUG   ] Fetching from git://github.com/saltstack/salt.git
2014-12-09 14:58:53,486 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:53,602 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:53,721 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:53,827 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:53,931 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:54,053 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:54,156 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:54,265 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:54,379 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:54,477 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:54,576 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:54,722 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:54,790 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:54,869 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:54,934 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:54,993 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:55,084 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:55,187 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:55,300 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:55,407 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:55,523 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:55,629 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:55,659 [salt.utils.verify][DEBUG   ] This salt-master instance has accepted 1 minion keys.
2014-12-09 14:58:55,763 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:55,890 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:56,002 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:56,102 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:56,241 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:56,389 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:56,515 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:56,689 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:56,871 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:57,039 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:57,217 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:57,385 [salt.master      ][INFO    ] AES payload received with command _file_list
2014-12-09 14:58:57,557 [salt.master      ][INFO    ] AES payload received with command _file_list
...

jfindlay avatar Dec 09 '14 22:12 jfindlay

Could the roundtrip time between saltmaster and salt-minion be an issue? We have sth. around 200msecs. How many roundtrips are required per file copy from gitfs?

martinhoefling avatar Dec 10 '14 12:12 martinhoefling

@martinhoefling, this is a very good point. An easy way to inspect the rate/amount of communication between master and minion is to use the eventlisten.py script.

jfindlay avatar Dec 10 '14 20:12 jfindlay

As far as I could see, the files are not transfered via the event bus.

martinhoefling avatar Jan 19 '15 15:01 martinhoefling

I guess there is a problem in salt/fileserver/gitfs.py.

The logfile update.lk is not checked in find_file so when creating its own logfile in line 1065 (find_file) the directory does not exists, because the directory has been removed during ?parallel? update() in purge_cache().

I think to fix this you could:

  • check for update.lk
  • move the update.lk before the call to purge_cache()

Or introduce another locking mechanism.

If you like I can provide you with a patch.

crasu avatar Jan 27 '15 14:01 crasu

@crasu, a patch would be awesome. Please be sure to ping @cachedout when you do.

Do you think this race condition is related to the slow, lossy transfers @martinhoefling is reporting? If not, will you create a new issue and reference that issue when/if you create a patch, thanks.

jfindlay avatar Jan 27 '15 16:01 jfindlay

Fix was merged, closing.

terminalmage avatar Feb 09 '15 17:02 terminalmage

Thanks!

martinhoefling avatar Feb 22 '15 10:02 martinhoefling

The fix that @crasu made needed to be reverted, so I'm going to reopen this so that we can continue to investigate.

The traceback which @eyj posted is completely unrelated to this. To be honest, I am not sure how this could happen, since the parent directory for the hash file is created in the find_file() function. @eyj, if this continues to happen, please look for other errors in the log file and open a separate issue to investigate. Thanks!

terminalmage avatar Feb 23 '15 04:02 terminalmage