Skip to content

Add a class to facilitate sharing an SQL connection pool between services

Adam Coldrick requested to merge sotk/refactoring/shared-sql-provider into master

Before raising this MR, consider whether the following are required, and complete if so:

  • Unit tests
  • Metrics
  • Documentation update(s)

If not required, please explain in brief why not.

Description

Currently, each SQL-related service in a BuildGrid instance (eg. a scheduler configured using !sql-scheduler, or a CAS index using !sql-index) sets up its own individual pool of connections to use. This means that a BuildGrid containing eg. both an SQL CAS and SQL scheduler could have available connections in one pool not being used, whilst the other is at capacity. As we look to add SQL functionality to the Bots service, this problem will only get worse with a third service needing its own pool.

Additionally, the SQL CAS index and SQL data store contain a bunch of duplicated code regarding setting up the database connections and managing sessions. As currently implemented, we'll need to add the same code in a third place to add SQL support to the Bots service.

This MR solves these problems by refactoring the SQL connection management into a new class, SqlProvider. This class is used by both the SQL CAS index and the SQL data store to access the database, allowing the duplicated code to be consolidated and the separate connection pools to be replaced with a single shared pool if desired.

Validation

Run BuildGrid with any of the example configs and verify that things are working.

Merge request reports