Skip to content

Managing sharding databases

Jon P Smith edited this page Aug 14, 2023 · 15 revisions

Since AuthP version 6 when you set the AuthPermissionsOptions's TenantType and added SetupMultiTenantSharding method to register that the multi-tenant is using sharding, then the SetupMultiTenantSharding will register a called IGetSetShardingEntries that provides ways to read / change the sharding entries, and other support methods. The typical things you might to do are:

  • Managing the sharding entries
  • Reading the connection string names
  • List the databases and their tenants

Managing sharding entries

The GetAllShardingEntries method reads the information in the sharding entries. This is used internally but is also useful for the admin user to see what the sharding entries. The screenshot below comes from Example6.MvcWebApp.Sharding web application. If you log in as an application admin user and click the Auth Admin -> List database info.

List sharding entries

The code for these can be found in the ShardingController class of Example6 and Example7

b) Methods to add, update, and remove a sharding entry

These are simple to understand. They alter the sharding entries containing all the sharding entries.

  • AddNewShardingEntry(info) - Adds a new sharding entry to the sharding entries.
  • UpdateShardingEntry(info) - Updates the sharding entry with the given Name.
  • RemoveShardingEntry(name) - Removes the sharding entry with the given Name.

Reading the connection string names

When to create a sharding tenant, then you need to get the connection strings that provide access to the database server to use - see this example of creating a new tenant. The IGetSetShardingEntries service provides a method called GetConnectionStringNames, which have one connection string (one single server), or many connection strings if you have multiple database servers.

NOTE: The mode (hybrid or sharding-only) you will affect what connection string names are shown - see this section about modes for more detail.

List the databases and their tenants

In a hybrid multi-tenant application databases can have multiple tenants in one database. This means that a list of sharding entries doesn't provide all the information you need when changing sharding entries. Therefore the IGetSetShardingEntries service provides a method called GetDatabaseInfoNamesWithTenantNamesAsync which shows each sharding with a list of tenants in each database.

NOTE: This method isn't very useful if you using the sharding-only mode, because each sharding entry has one database, so the "list sharding entries" is a better list.

Additional resources

Articles / Videos

Concepts

Setup

Usage

Admin

SupportCode

Clone this wiki locally