/// <summary>
        /// Reads the user's choice of a split point, and creates a new shard with a mapping for the resulting range.
        /// </summary>
        private static void AddShard(int customerid)
        {
            ListShardMap <int> shardMap = TryGetShardMap();

            if (shardMap != null)
            {
                // Here we assume that the ranges start at 0, are contiguous,
                // and are bounded (i.e. there is no range where HighIsMax == true)
                //int currentMaxHighKey = shardMap.GetMappings().Max(m => m.Value.High);
                //int defaultNewHighKey = currentMaxHighKey + 100;

                //Console.WriteLine("A new range with low key {0} will be mapped to the new shard.", currentMaxHighKey);
                //int newHighKey = ConsoleUtils.ReadIntegerInput(
                //    string.Format("Enter the high key for the new range [default {0}]: ", defaultNewHighKey),
                //    defaultNewHighKey,
                //    input => input > currentMaxHighKey);

                //Range<int> range = new Range<int>(currentMaxHighKey, newHighKey);

                //Console.WriteLine();
                //Console.WriteLine("Creating shard for range {0}", range);

                CreateShardSample.CreateShard(shardMap, customerid);
            }
        }
예제 #2
0
        /// <summary>
        /// Creates a shard map manager, creates a shard map, and creates a shard
        /// with a mapping for the full range of 32-bit integers.
        /// </summary>
        private static void CreateShardMapManagerAndShard()
        {
            if (MultiShardConfiguration.objShardMapManager != null)
            {
                ConsoleUtils.WriteWarning("Shard Map Manager already exists");
                return;
            }

            // Create shard map manager database
            if (!SqlDatabaseUtils.ExistsDatabase(MultiShardConfiguration.ShardMapManagerServerName, MultiShardConfiguration.ShardMapManagerDatabaseName))
            {
                SqlDatabaseUtils.CreateDatabase(MultiShardConfiguration.ShardMapManagerServerName, MultiShardConfiguration.ShardMapManagerDatabaseName);
            }

            // Create shard map manager
            string shardMapManagerConnectionString = MultiShardConfiguration.GetConnectionString();

            MultiShardConfiguration.objShardMapManager = ShardManagementUtils.CreateOrGetShardMapManager(shardMapManagerConnectionString);

            // Create shard map
            RangeShardMap <int> shardMap = ShardManagementUtils.CreateOrGetRangeShardMap <int>(
                MultiShardConfiguration.objShardMapManager, MultiShardConfiguration.ShardMapName);

            // Create schema info so that the split-merge service can be used to move data in sharded tables
            // and reference tables.
            CreateSchemaInfo(shardMap.Name);

            // If there are no shards, add two shards: one for [0,100) and one for [100,+inf)
            if (!shardMap.GetShards().Any())
            {
                CreateShardSample.CreateShard(shardMap, new Range <int>(0, 100));
                CreateShardSample.CreateShard(shardMap, new Range <int>(100, 200));
            }
        }