Skip to content
Snippets Groups Projects
  1. Dec 02, 2024
    • Antoine Lambert's avatar
      config: Add LRU cache to get_swh_backend_* functions · 2b8ce87b
      Antoine Lambert authored
      I noticed tests in other SWH packages were really slow to execute
      since recently and it turned out that the root cause of these
      slowdowns is that pytest fixtures like the swh_storage one end up
      calling the get_swh_backend_module from swh.core.config.
      
      As that function reads Python package entry points from disk, this
      slows down tests execution as it is called before each test using
      a fixture as described above.
      
      So add LRU cache to these functions to restore previous execution
      times in SWH package tests.
      2b8ce87b
  2. Nov 19, 2024
  3. Nov 07, 2024
    • David Douard's avatar
      cli/db: Make the db init process a bit more (config) error resilient · 582eba15
      David Douard authored
      We used to run all the sql init scripts before trying to determine the
      backend's version, only to gather this piece of information at time we
      want to write it in the dbversion table.
      
      However, the presence of the dbversion is actually used to determine
      whether a db has been initialized or not.
      
      So if the configuration for the backend prevent it from being
      instantiated, which is done to retrieve the backend version, then this
      last initialization step will fail preventing any future 'swh db' handling
      operation from working properly.
      
      In this change, we move the backend version identification logic before
      attempting any actual db initialization process so this situation does
      not occur.
      582eba15
  4. Nov 06, 2024
    • Antoine Lambert's avatar
      api: Add an optional requests retry feature to the RPC client · ce0d4b72
      Antoine Lambert authored
      Add a new enable_requests_retry flag to the swh.core.api.RPCClient
      class, default to False, allowing to retry requests sent by the
      client when encountering specific errors. Default policy is to retry
      when connection errors and transient remote exceptions are raised.
      Subclasses can change that policy by overriding the retry_policy
      method. Such failed requests will be retry at most five times with a
      delay of 10 seconds between each.
      ce0d4b72
    • Antoine Lambert's avatar
      api: Add an optional requests retry feature to the RPC client · 77bbafca
      Antoine Lambert authored
      Add a new enable_requests_retry flag to the swh.core.api.RPCClient
      class, default to False, allowing to retry requests sent by the
      client when encountering specific errors. Default policy is to retry
      when connection errors and transient remote exceptions are raised.
      Subclasses can change that policy by overriding the retry_policy
      method. Such failed requests will be retry at most five times with a
      delay of 10 seconds between each.
      77bbafca
    • David Douard's avatar
      cli/db: show the actual error that occurred during sql script execution, if any · 7fd221da
      David Douard authored
      When executing a `swh db init` command, the executed sql files for the
      package may fail, but the 'swh db' tool would eat the error reported by
      sqlsh. Make these errors shown as output of the process if such an error
      occurred.
      
      e.g.:
      
        $ swh db init test:fail
      
        Error during database setup
        Command '['psql', '--quiet', '--no-psqlrc', '-v', 'ON_ERROR_STOP=1', '-d', 'postgresql://postgres@127.0.0.1:24370/tests', '-f', '/venv/swh-environment/swh-core/swh/core/db/tests/data/test/fail/sql/40-funcs.sql']' returned non-zero exit status 3.
        Process output:
        psql:/venv/swh-environment/swh-core/swh/core/db/tests/data/test/fail/sql/40-funcs.sql:6: ERROR:  function public.digest(text, unknown) does not exist
        LINE 5:     select encode(public.digest($1, 'sha1'), 'hex')
                                ^
        HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
      
        Aborted!
      7fd221da
  5. Nov 04, 2024
  6. Oct 30, 2024
  7. Oct 29, 2024
  8. Oct 22, 2024
  9. Oct 21, 2024
    • David Douard's avatar
      db_utils: make swh_set_db_module() update the dbmodule entry in the db · 46f6153c
      David Douard authored
      and use it from populate_database_from_packae() so it's fixed when
      running commands like `swh db init` and `swh dn updrade`.
      46f6153c
    • David Douard's avatar
      test/db/test_cli: use raw yaml instead of dumping nested dicts · 4e0d4fa1
      David Douard authored
      It is IMHO easier to read.
      4e0d4fa1
    • David Douard's avatar
      Make most 'swh db xxx' commands support reading the db cnx string from anywhere in the config file · fc2936da
      David Douard authored
      Allow db commands (create, init-admin, init, version, upgrade) get the
      db connection string from anywhere in the config file.
      For example, it can be used like:
      
      $ cat conf.yml
      storage:
        cls: pipeline
        steps:
          - cls: masking
            masking_db: postgresql:///?service=swh-masking-proxy
          - cls: buffer
          - cls: postgresql
            db: postgresql://user:passwd@pghost:5433/swh-storage
            objstorage:
              cls: memory
      
      $ swh db -C conf.yml init storage:steps:0:masking_db
      
      This de facto deprecates the usage of the --module-config-key option.
      
      Also add a -a/--all option to these commands allowing to execute the given
      command to all matching configuration entries in the config file; this
      should help deployment in testing environments like docker.
      
      For example:
      
        $ swh db version -a storage
      
        module: storage.proxies.masking
        current code version: 194
        version: 194
      
        module: storage
        flavor: default
        current code version: 193
        version: 193
      
      This change also make the module name stored in the dbmodule table an
      fully qualified module instead of shortened version, i.e. it will now
      store 'swh.storage.postgresql.storage' instead of just 'storage',
      so there is less "implicit logic" (like removing "swh.", etc.)
      when filling/using this piece of information.
      
      We add a bw compat support in get_sql_for_package to ease the transition
      until the dbmodule tables are updated. This bw compat logic will
      look for the 'sql/' directory not only in the package directly for the
      module, but also in parent directories. This allows to keep the code
      compatible with current version of swh.storage (in which the sql/
      directory and the actual backend submodule do not match).
      
      Doing this, we also stop defining a hardwritten dbname ('softwareheritage-dev')
      as default value for the '--dbname' option in 'swh db create' command.
      
      Warning: for the 'create' and 'init-admin' db commands, looking for the
      connection string in the config file is mainly useful for test environments
      in which the user used to access the backend database have superuser
      permissions on the database. In production-like environments, you most
      certainly will prefer using an explicit --dbname argument with a
      connection with enough permission to handle the job.
      fc2936da
    • David Douard's avatar
      db/test: improve assert for cli_runner results · 47e8cbd4
      David Douard authored
      Show the full traceback of the exception that occurred in the cli_runner
      execution, if any.
      47e8cbd4
    • David Douard's avatar
      db: lower a warning statement to an info · 5a3a8906
      David Douard authored
      5a3a8906
    • David Douard's avatar
      cli: replace '--all' option in 'db version' with '--history' · 45ca8d29
      David Douard authored
      It better captures the semantic of the option and makes the '--all'
      option free for a common usage to handle the 'operate on all db backends
      in the configuration file' semantic (i.e. replace '--initialize-all' and
      '--upgrade-all' options) in the future.
      45ca8d29
  10. Sep 24, 2024
  11. Sep 18, 2024
  12. Aug 30, 2024
  13. Aug 28, 2024
  14. Aug 27, 2024
  15. Jul 17, 2024
  16. Jul 11, 2024
    • Jérémy Bobbio (Lunar)'s avatar
      config: keep dicts in config ordered · 32e534f1
      Jérémy Bobbio (Lunar) authored
      YAML mappings are converted in Python as dict. The order
      of the keys in dicts returned by `load_from_envvar()` were
      not stable from one Python run to the next.
      
      Since Python 3.6, dicts are ordered by default, and `yaml.safe_load()`
      will always return keys in the same order. The culprit was
      `merge_configs` which created a set (which are unordered) of keys
      to perform the merge.
      32e534f1
  17. Jun 28, 2024
Loading