Azure / elastic-db-tools

Elastic database tools client library allows ADO.NET developers to create applications that implement and use the pattern known as database sharding in Azure SQL Database.
MIT License
145 stars 102 forks source link

CodeFirst Shard DB Creation missing Sharding Schema/SPs #147

Open ConX-Ryan opened 8 years ago

ConX-Ryan commented 8 years ago

Exception thrown "Could not find stored procedure '__ShardManagement.spBulkOperationShardMappingsLocal'"

When ListShardMap.CreatePointMapping is called on the freshly created Shard DB.

I can confirm that the EF schemas have been created properly but all the sharding schemas and SPs are not present.

Seems to occur more often we dropping and recreating a shard with the same name using the same Shard Manager DB

client version 1.3.3 please let me know if you require more info.

jaredmoo commented 8 years ago

Before deleting a shard database, you should remove it from the shard map manager using ShardMap.DeleteShard. This is the safe way to delete because before allowing the shard to be deleted, the shard map manager will check that there are no mappings to the shard (and if there are no mappings to the shard, then hopefully that shard should be empty of sharded data - although that last part is your responsibility, shard map manager cannot verify that for you).

At this point since you already deleted the database, you can instead remove the shard db from the shard map manager using RecoveryManager.DetachShard. This is normally dangerous to do, since all mappings to that shard will deleted, which is why DeleteShard is preferred.

So then if you create a new database with the same name, you need to call ShardMap.CreateShard to create sharding schemas on that shard db and add that shard db to the shard map manager. However you didn't call this, so the sharding schema wasn't created. (Note that CreateShard will fail if you didn't call DeleteShard or DetachShard earlier.)

ConX-Ryan commented 8 years ago

Thanks very much for your explanation!

jaredmoo commented 8 years ago

Cheers. Hope this fixes your problem :)