Sharding Key Investigation for keys table
Status Update
The database schema changes for the keys table have been completed via !208105 (merged). The table has been classified as Organization-level (gitlab_main_org) with organization_id as the sharding key.
Completed Work
-
Added organization_idcolumn tokeystable -
Created index on organization_id -
Added foreign key constraint to organizationstable -
Updated db/docs/keys.ymlwithgitlab_schema: gitlab_main_organdsharding_key: organization_id -
Added model association: belongs_to :organization -
Removed sharding_key_issue_urlfrom documentation
Remaining Work
The remaining application-level work is tracked in epic: &19679
Key remaining tasks:
- Backfill
organization_idfor existing records - Add NOT NULL constraint to
organization_id - Handle deploy keys shared across projects
- Update application code to use
organization_id - Testing and validation
- Documentation updates
Original Investigation
Action Required: Classify the keys table
To properly configure the keys table, please choose the one classification below that best fits its data and purpose. This choice will determine the table's database schema and sharding key.
After selecting the best option, remove the sharding_key_issue_url and apply the corresponding configuration.
1. Choose a Classification
Select the most suitable option for the keys table from the following:
A. Org-level with sharding key ✅ SELECTED
This is for data that belongs to an entire organization.
- Action:
- Set
gitlab_schema: gitlab_main_org. - Add the
sharding_keyordesired_sharding_key. - If the key doesn't yet meet
not-nullor foreign key requirements, you can add a temporary exception. Please link to a follow-up issue in a comment next to the exception. -
See an example at
db/docs/epics.yml.
B. Cell-local
This is for data related to cell-specific features.
- Action:
- Set
gitlab_schema: gitlab_main_cell_local. - Ensure there are no foreign key references to or from organization-level tables.
C. User-related
This is for data that is strictly and exclusively owned by a user.
- Action:
- Set
gitlab_schema: gitlab_main_user. - Confirm the table's data belongs only to users.
D. Cell settings
This is for configuration settings that are specific to a single cell.
- Action:
- Set
gitlab_schema: gitlab_main_cell_setting. - Ensure there are no foreign key references to or from organization-level tables.
Note: gitlab_main_clusterwide has been deprecated. If you believe this is the correct classification, please consult the Tenant Scale group for alternatives.
2. Complete the Task
- Add this issue to the epic: &11670
- Review the documentation below for more details.
Documentation
References
- Database changes MR: !208105 (merged) (merged)
- Implementation epic: &19679