Update Gitlab::Database::Count to work with decomposed database
What does this MR do and why?
When counting records with Gitlab::Database::Count
split models by database so that we can wrap usage of PgClass
in Gitlab::Database::SharedModel.using_connection
using the correct connection.
Also use model.connection
instead of ActiveRecord::Base.connection
.
Related to #345279 (closed).
How to set up and validate locally
- Setup your environment for multiple databases as described in https://docs.gitlab.com/ee/development/database/multiple_databases.html#configdatabaseyml.
- Load the schema, e.g.
gdk psql -d my_ci_database < db/structure.sql
. - Connect to the
ci
database -gdk psql -d my_ci_database
. - Create some
ci_instance_variables
records:insert into ci_instance_variables values (1, 1, false, false, 'TEST_DECOMPOSED_1', null, null), (2, 1, false, false, 'TEST_DECOMPOSED_2', null, null);
- Analyze
ci_instance_variables
-analyze ci_instance_variables;
-
@alipniagov : also run similar analyze on your primary DB, so
pg_class
would have data.
-
@alipniagov : also run similar analyze on your primary DB, so
- While on master open Rails console with
GITLAB_USE_MODEL_LOAD_BALANCING=true bundle exec rails console
- Check counts with
Gitlab::Database::Count.approximate_counts([Ci::InstanceVariable], strategies: [Gitlab::Database::Count::ReltuplesCountStrategy])
, you should see0
as a count. - Switch to this branch -
git checkout 345279-decomposed-db-count
- open Rails console with
GITLAB_USE_MODEL_LOAD_BALANCING=true bundle exec rails console
- Check counts with
Gitlab::Database::Count.approximate_counts([Ci::InstanceVariable], strategies: [Gitlab::Database::Count::ReltuplesCountStrategy])
, this time you should see2
as a count.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Aleksei Lipniagov