Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Add RoleGrantee to provide meta-service key for RoleMgr #14752

Merged
merged 2 commits into from
Feb 27, 2024

Conversation

drmingdrmer
Copy link
Member

@drmingdrmer drmingdrmer commented Feb 27, 2024

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

refactor: Add RoleGrantee to provide meta-service key for RoleMgr

Encapsulate the logic of encoding/decoding role-grantee key into
RoleGrantee. RoleGrantee is a standard kvapi::Key implementation
so that the export program could rely on the kvapi::Key API to
traverse meta-data to fetch all data that belongs to a tenant.

Legacy issue:

  • For OwnershipObject::Database{ catalog_name, db_id }, catalog_name
    is not encoded into the key, we have to be compatible with this. The
    solution is to encode a "default" catalog with
    database-by-id/<db-id> prefix, and encode a non-default catalog with
    database-by-catalog-id/<catalog>/<db-id> prefix.

    The same for the OwnershipObject::Table{ catalog_name, ... }.

  • For OwnershipObject::Table{ catalog_name, db_id, table_id }, db_id
    is not encoded into the key. Thus kvapi::Key::from_str_key() can not
    be implemented because db_id is absent.

  • In this version, only "default" catalog is allowed. Using other
    catalog will panic. This restrict will be removed if it is confirmed
    there is no other catalog in our meta-data.


Changelog

  • Improvement

Related Issues


This change is Reviewable

@github-actions github-actions bot added the pr-refactor this PR changes the code base without new features or bugfix label Feb 27, 2024
@drmingdrmer drmingdrmer marked this pull request as ready for review February 27, 2024 01:55
Encapsulate the logic of encoding/decoding role-grantee key into
`RoleGrantee`. `RoleGrantee` is a standard `kvapi::Key` implementation
so that the export program could rely on the `kvapi::Key` API to
traverse meta-data to fetch all data that belongs to a tenant.

Legacy issue:

- For `OwnershipObject::Database{ catalog_name, db_id }`, `catalog_name`
  is not encoded into the key, we have to be compatible with this. The
  solution is to encode a `"default"` catalog with
  `database-by-id/<db-id>` prefix, and encode a non-default catalog with
  `database-by-catalog-id/<catalog>/<db-id>` prefix.

  The same for the `OwnershipObject::Table{ catalog_name, ... }`.

- For `OwnershipObject::Table{ catalog_name, db_id, table_id }`, `db_id`
  is not encoded into the key. Thus `kvapi::Key::from_str_key()` can not
  be implemented because `db_id` is absent.

- In this version, only `"default"` catalog is allowed. Using other
  catalog will panic. This restrict will be removed if it is confirmed
  there is no other catalog in our meta-data.

---

- Part of databendlabs#14738
@drmingdrmer drmingdrmer merged commit eb46c30 into databendlabs:main Feb 27, 2024
71 of 72 checks passed
@drmingdrmer drmingdrmer deleted the 34-tenant-key branch February 27, 2024 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-refactor this PR changes the code base without new features or bugfix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants