Support claiming of unique model attributes across Cells
What this is
This is part of https://handbook.gitlab.com/handbook/engineering/architecture/design-documents/cells/topology_service_transactional_behavior/
The intention of this issue is to implement reusable code/library that we can use to claim attributes for models.
Currently everything is tested and implemented in:
- Rails: gitlab-org/gitlab!200701
- Topology service: gitlab-org/cells/topology-service!308
Status
Latest status update in this comment: #365 (comment 2810908345)
Previous description
Based on the POC MR we can work on a concern that can be reused by each clusterwide ActiveRecord, like User, Email, Route to easily claim any unique attribute across the whole cluster.
By having such a generic reusable claim, we can integrate this concern into any model with code that looks like this
class Email < MainClusterwide::ApplicationRecord
.....
include CellsUniqueness
cell_cluster_unique_attributes :email,
sharding_key_object: -> { self },
claim_type: Gitlab::Cells::ClaimType::Emails,
owner_type: Gitlab::Cells::OwnerType::User
Notes
- The enums here are provided by the GRPC generated Ruby Client.
- Global Service API is not finalized yet. Check the draft MR and gitlab-org/gitlab!145944 (merged).
Functional Requirements
- If the claim was taken already, we need to add error to the attribute
- This should also work for changing the attribute name. For example, if a User change their
username, we should drop the claim on the old username (after save), and check the claim on the new username (on validation). - This should also work on destroying records. They should also drop the claims on
after_destroy
Implementation Detail
-
Create a claimstable uniquely indexed by( claim_record.bucket, claim_record.value ) -
Import ClaimServiceruby client exposingClaimRecordandOwnerTypeENUMs -
Global unique attribute concern module
Edited by Lin Jen-Shin