Skip to content

Windows pkg states refresh the pkg repo cache file every single pkg.installed found in an sls for or highstate. #36133

Closed

Description

@UtahDave

Description of Issue/Question

On the carbon branch and develop a pkg.refresh_db() is executed for every single instance of pkg.installed that is found when applying an sls file or a highstate.

Setup

Install Salt from the carbon branch on Windows. I believe this would happen on develop, as well.

Steps to Reproduce Issue

cat /srv/salt/winstates.sls

filezilla:
  pkg.installed

#pidgin:
  #pkg.installed

#vlc:
  #pkg.installed

#ccleaner:
  #pkg.installed

I start out with all but one pkg.installed commented out. Then I run the highstate with test=True and I see the repo get refreshed on the minion once. Each time I uncomment another state roughly another minute is added to the total run time and an extra pkg.refresh_db() is executed.

root@bouchamaster:/srv/salt# time salt davewintest state.highstate test=True
davewintest:
  Name: filezilla - Function: pkg.installed - Result: Differs Started: - 12:38:25.715000 Duration: 78407.0 ms

Summary for davewintest
------------
Succeeded: 1 (unchanged=1)
Failed:    0
------------
Total states run:     1
Total run time:  78.407 s

real    1m34.114s
user    0m1.825s
sys 0m0.216s

root@bouchamaster:/srv/salt# time salt davewintest state.highstate test=True
davewintest:
  Name: filezilla - Function: pkg.installed - Result: Differs Started: - 12:40:15.642000 Duration: 60409.0 ms
  Name: pidgin - Function: pkg.installed - Result: Differs Started: - 12:41:16.051000 Duration: 61219.0 ms

Summary for davewintest
------------
Succeeded: 2 (unchanged=2)
Failed:    0
------------
Total states run:     2
Total run time: 121.628 s

real    2m27.577s
user    0m2.828s
sys 0m0.328s

root@bouchamaster:/srv/salt# time salt davewintest state.highstate test=True
davewintest:
  Name: filezilla - Function: pkg.installed - Result: Differs Started: - 12:43:11.962000 Duration: 62046.0 ms
  Name: pidgin - Function: pkg.installed - Result: Differs Started: - 12:44:14.008000 Duration: 61608.0 ms
  Name: vlc - Function: pkg.installed - Result: Differs Started: - 12:45:15.616000 Duration: 61000.0 ms

Summary for davewintest
------------
Succeeded: 3 (unchanged=3)
Failed:    0
------------
Total states run:     3
Total run time: 184.654 s

real    3m28.154s
user    0m3.999s
sys 0m0.342s

root@bouchamaster:/srv/salt# time salt davewintest state.highstate test=True
davewintest:
  Name: filezilla - Function: pkg.installed - Result: Differs Started: - 14:49:33.975000 Duration: 65417.0 ms
  Name: pidgin - Function: pkg.installed - Result: Differs Started: - 14:50:39.392000 Duration: 63028.0 ms
  Name: vlc - Function: pkg.installed - Result: Differs Started: - 14:51:42.420000 Duration: 62997.0 ms
  Name: ccleaner - Function: pkg.installed - Result: Differs Started: - 14:52:45.417000 Duration: 63372.0 ms

Summary for davewintest
------------
Succeeded: 4 (unchanged=4)
Failed:    0
------------
Total states run:     4
Total run time: 254.814 s

real    4m43.106s
user    0m5.344s
sys 0m0.468s

Versions Report

Carbon

Activity

  1. added
    severity-critical
    on Sep 7, 2016
  2. UtahDave commented on Sep 7, 2016

    @UtahDave
    ContributorAuthor

    @damon-atkins, could you take a look at this, too? I think this may have been affected by the updates you made to the refresh_db function on the win_pkg.py file. I haven't completely figured out the solution yet, but I think we need to let the pkg state decide when to do the refresh_db and not have the win_pkg try to be too clever.

  3. damon-atkins commented on Sep 8, 2016

    @damon-atkins
    Contributor

    See #36088 comments on state/pkg.py This has existing since version 0.11 of salt.
    I can have a look at it.... I don't want it slow. But I was not prepared to change too much of how salt currently works i.e. state/pkg.py which request the refresh_db because its an expected behavior.

  4. UtahDave commented on Sep 8, 2016

    @UtahDave
    ContributorAuthor

    No, that is not true. This is not just updating the cache once per highstate in the init() function. A refresh is now happening for EVERY pkg.installed call wherever they are in the highstate. Salt has never done that. Salt has never done that on Windows. I wrote the Salt package manager for Windows.

  5. damon-atkins commented on Sep 8, 2016

    @damon-atkins
    Contributor

    Hi @UtahDave I do not think I have introduced this issue, I think its existed for a long time. The issues is with state/pkg.py can not see how removing two lines of import and namespace would cause this in pkg.py.

    Anyway we both don't want refresh happen needlessly.
    But I will double check I have not caused it in win_pkg.py because that's the last thing I want to do is introduce issues.

    • I will add some logging to the existing develop/carbon code run it, and show when calling refresh happens
    • I will re-install Salt 2016.3 and add some extra logging and show it calling refresh.

    And this will show the pre and post behavior change.

    Then we can work out a plan to fix it... assuming it is coming from state/pkg.py. Otherwise I will just fix it if its in modules/win_pkg.py

  6. damon-atkins commented on Sep 8, 2016

    @damon-atkins
    Contributor

    Here is the result of 2016.3 test (test_win_pkg contains the same as above)
    Note my logging is setup differently to the default settings.

    As you can see we get the wrong behavior, i.e. refresh is called 4 times instead of once

    Salt Version:
               Salt: 2016.3.3
    C:\salt>salt-call state.sls test_win_pkg  test=True
    [ERROR   ] cmdmod.retcode Command 'Import-Module ServerManager' failed with return code: 1
    [ERROR   ] cmdmod.retcode output: Import-Module : The specified module 'ServerManager' was not loaded because no valid module file was found in any module directory.
    At line:1 char:1
    + Import-Module ServerManager
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ResourceUnavailable: (ServerManager:String) [Import-Module], FileNotFoundException
        + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
    [WARNING ] win_pkg.list_pkgs refresh_db called by list_pkgs
    [WARNING ] win_pkg.refresh_db refresh_db running
    [WARNING ] win_pkg.list_pkgs refresh_db called by list_pkgs
    [WARNING ] win_pkg.refresh_db refresh_db running
    [WARNING ] win_pkg.list_pkgs refresh_db called by list_pkgs
    [WARNING ] win_pkg.refresh_db refresh_db running
    [WARNING ] win_pkg.list_pkgs refresh_db called by list_pkgs
    [WARNING ] win_pkg.refresh_db refresh_db running
    local:
    ----------
              ID: filezilla
        Function: pkg.installed
          Result: None
         Comment: The following packages would be installed/updated: filezilla=3.16.0
         Started: 19:13:23.288000
        Duration: 21979.0 ms
         Changes:
    ----------
              ID: pidgin
        Function: pkg.installed
          Result: None
         Comment: The following packages would be installed/updated: pidgin=2.10.11
         Started: 19:13:45.267000
        Duration: 22610.0 ms
         Changes:
    ----------
              ID: vlc
        Function: pkg.installed
          Result: None
         Comment: The following packages would be installed/updated: vlc=2.2.4
         Started: 19:14:07.877000
        Duration: 24338.0 ms
         Changes:
    ----------
              ID: ccleaner
        Function: pkg.installed
          Result: None
         Comment: The following packages would be installed/updated: ccleaner=5.20
         Started: 19:14:32.215000
        Duration: 22329.0 ms
         Changes:
    
    Summary for local
    ------------
    Succeeded: 4 (unchanged=4)
    Failed:    0
    ------------
    Total states run:     4
    Total run time:  91.256 s
    

    Now the same thing but with "latest". As you can see we get the expected behavior i.e. refresh is called once

    C:\salt>salt-call state.sls test_win_pkg_latest  test=True
    [ERROR   ] cmdmod.retcode Command 'Import-Module ServerManager' failed with return code: 1
    [ERROR   ] cmdmod.retcode output: Import-Module : The specified module 'ServerManager' was not loaded because no valid module file was found in any module directory.
    At line:1 char:1
    + Import-Module ServerManager
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ResourceUnavailable: (ServerManager:String) [Import-Module], FileNotFoundException
        + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
    [WARNING ] win_pkg.latest_version refresh_db called by latest_version
    [WARNING ] win_pkg.refresh_db refresh_db running
    local:
    ----------
              ID: filezilla
        Function: pkg.latest
          Result: None
         Comment: The following packages would be installed/upgraded: filezilla
         Started: 19:21:45.397000
        Duration: 21970.0 ms
         Changes:
    ----------
              ID: pidgin
        Function: pkg.latest
          Result: None
         Comment: The following packages would be installed/upgraded: pidgin
         Started: 19:22:07.367000
        Duration: 360.0 ms
         Changes:
    ----------
              ID: vlc
        Function: pkg.latest
          Result: None
         Comment: The following packages would be installed/upgraded: vlc
         Started: 19:22:07.727000
        Duration: 376.0 ms
         Changes:
    ----------
              ID: ccleaner
        Function: pkg.latest
          Result: None
         Comment: The following packages would be installed/upgraded: ccleaner
         Started: 19:22:08.103000
        Duration: 416.0 ms
         Changes:
    
    Summary for local
    ------------
    Succeeded: 4 (unchanged=4)
    Failed:    0
    ------------
    Total states run:     4
    Total run time:  23.122 s
    

    from list_pkgs, therefore states/pkg.py is calling this with refresh=True and therefore is the root cause

        if kwargs.get('refresh', False):
            # _get_name_map() needs a refresh_db if cache is not present
            log.warning('refresh_db called by list_pkgs')
            refresh_db()
    
  7. added this to the Approved milestone on Sep 8, 2016
  8. added
    P3
    Platform
    on Sep 8, 2016
  9. damon-atkins commented on Sep 9, 2016

    @damon-atkins
    Contributor

    See also PR #34768 2015.8 Aug 2 - Makes sure that pkg.installed works in accordance with the docs when it comes to refreshing the pkg db in Windows. Even if, for some reason, it's not a perfect fix it will only improve things, and it shouldn't break anything non-Windows

  10. modified the milestones: C 4, Approved on Sep 9, 2016
  11. damon-atkins commented on Sep 13, 2016

    @damon-atkins
    Contributor

    At the end of the run the refresh file should not exist

    C:\salt>dir var\cache\salt\minion
     Volume in drive C is win8 SSD
     Volume Serial Number is 3C03-452D
    
     Directory of C:\salt\var\cache\salt\minion
    
    13/09/2016  12:11 PM    <DIR>          .
    13/09/2016  12:11 PM    <DIR>          ..
    09/09/2016  11:58 AM    <DIR>          accumulator
    13/09/2016  04:39 AM    <DIR>          extmods
    12/09/2016  02:10 AM    <DIR>          extrn_files
    12/09/2016  02:17 AM    <DIR>          files
    13/09/2016  02:34 PM               271 highstate.cache.p
    13/09/2016  04:39 AM                 0 module_refresh
    13/09/2016  12:11 PM                 0 pkg_refresh
    13/09/2016  02:33 PM    <DIR>          proc
    13/09/2016  02:34 PM               850 sls.p
                   4 File(s)          1,121 bytes
                   7 Dir(s)  98,549,645,312 bytes free
    C:\salt>
    
  12. damon-atkins commented on Sep 13, 2016

    @damon-atkins
    Contributor

    Diffs link here remove as out of date

  13. damon-atkins commented on Sep 13, 2016

    @damon-atkins
    Contributor

    Diffs link here remove as out of date

  14. UtahDave commented on Sep 13, 2016

    @UtahDave
    ContributorAuthor

    #36222 seems to fix this bug.

  15. modified the milestones: C 3, C 4 on Sep 19, 2016
  16. damon-atkins commented on Sep 27, 2016

    @damon-atkins
    Contributor

    As part of #36222 which included
    states/pkg.py Fixes

    • Fixes installed() in states/pkg.py which was calling calling refresh DB to much. This involved replacing the current code with a new function called _refresh_tag_file()
    • latest() in states/pkgpy change to use the new function _refresh_tag_file()
    • remove windows specific code around refreshing db

    This should resolve this issue for Carbon going forward. Previous release will need this fix i.e. _refresh_tag_file() changes in states/pkg.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Execution-ModuleP3PlatformWindowsseverity-critical

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions