/// <summary> /// Registers the new shard. /// Verify if shard exists for the tenant. If not then create new shard and add tenant details to Tenants table in catalog /// </summary> /// <param name="tenantName">Name of the tenant.</param> /// <param name="tenantId">The tenant identifier.</param> /// <param name="tenantServerConfig">The tenant server configuration.</param> /// <param name="databaseConfig">The database configuration.</param> /// <param name="catalogConfig">The catalog configuration.</param> public static bool RegisterNewShard(string tenantName, int tenantId, TenantServerConfig tenantServerConfig, DatabaseConfig databaseConfig, CatalogConfig catalogConfig) { try { Shard shard; ShardLocation shardLocation = new ShardLocation(tenantServerConfig.TenantServer, tenantName, databaseConfig.SqlProtocol, databaseConfig.DatabaseServerPort); if (!ShardMap.TryGetShard(shardLocation, out shard)) { //create shard if it does not exist shard = ShardMap.CreateShard(shardLocation); } // Register the mapping of the tenant to the shard in the shard map. // After this step, DDR on the shard map can be used PointMapping <int> mapping; if (!ShardMap.TryGetMappingForKey(tenantId, out mapping)) { var pointMapping = ShardMap.CreatePointMapping(tenantId, shard); //convert from int to byte[] as tenantId has been set as byte[] in Tenants entity var key = _helper.ConvertIntKeyToBytesArray(pointMapping.Value); //add tenant to Tenants table var tenant = new Tenants { ServicePlan = catalogConfig.ServicePlan, TenantId = key, TenantName = tenantName }; _tenantsRepository.Add(tenant); } return(true); } catch (Exception ex) { // _logger.LogError(0, ex, "Error in registering new shard."); //throw new ApplicationException("Error in registering new shard."); return(false); } }