Skip to content

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:

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

  1. The enums here are provided by the GRPC generated Ruby Client.
  2. Global Service API is not finalized yet. Check the draft MR and gitlab-org/gitlab!145944 (merged).

Functional Requirements

  1. If the claim was taken already, we need to add error to the attribute
  2. 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).
  3. This should also work on destroying records. They should also drop the claims on after_destroy

Implementation Detail

  • Create a claims table uniquely indexed by ( claim_record.bucket, claim_record.value )
  • Import ClaimService ruby client exposing ClaimRecord and OwnerType ENUMs
  • Global unique attribute concern module
Edited by Lin Jen-Shin
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information