Exemple #1
0
        public void CheckClusterConsistencyByCount()
        {
            var client          = new Client(Utils.GetConfigNodes());
            var jsonConfigState = client.GetJSONConfigState();
            var configState     = Utils.JsonDeserialize <ConfigState>(System.Text.Encoding.UTF8.GetBytes(jsonConfigState));

            foreach (var table in configState.tables)
            {
                var shards = ConfigStateHelpers.GetTableShards(table, configState.shards);
                foreach (var shard in shards)
                {
                    System.Console.WriteLine("\nCounting shard " + shard.shardID);

                    var tableID      = shard.tableID;
                    var startKey     = shard.firstKey;
                    var endKey       = shard.lastKey;
                    var quorum       = ConfigStateHelpers.GetQuorum(configState, shard.quorumID);
                    var shardServers = ConfigStateHelpers.GetQuorumActiveShardServers(configState, quorum);

                    ParallelTableCountHTTP(shardServers, tableID, startKey, endKey);

                    System.Console.WriteLine("Shard " + shard.shardID + " is consistent.\n");
                }
            }
        }
Exemple #2
0
        public void CheckConfigStateShardConsistency()
        {
            Console.WriteLine("\nChecking config state shard consistency...\n");

            var client          = new Client(Utils.GetConfigNodes());
            var jsonConfigState = client.GetJSONConfigState();
            var configState     = Utils.JsonDeserialize <ConfigState>(System.Text.Encoding.UTF8.GetBytes(jsonConfigState));

            foreach (var table in configState.tables)
            {
                System.Console.WriteLine("\nChecking table {0}", table.tableID);

                var shards   = ConfigStateHelpers.GetTableShards(table, configState.shards);
                var shardMap = new Dictionary <string, ConfigState.Shard>();

                // build a map of shards by firstkey
                foreach (var shard in shards)
                {
                    ConfigState.Shard testShard;
                    Assert.IsFalse(shardMap.TryGetValue(shard.firstKey, out testShard));
                    shardMap.Add(shard.firstKey, shard);
                }

                // walk the map of shards by the last key of the shard
                var firstKey = "";
                int count    = 0;
                ConfigState.Shard tmpShard;
                while (shardMap.TryGetValue(firstKey, out tmpShard))
                {
                    count += 1;
                    if (tmpShard.lastKey == "")
                    {
                        break;
                    }
                    firstKey = tmpShard.lastKey;
                }

                Assert.IsTrue(count == shards.Count);
            }
        }