Exemplo n.º 1
0
        public static void CheckDatabaseWithNumericKeys(string databaseName, string tableName)
        {
            var client = new Client(Utils.GetConfigNodes());
            var jsonConfigState = client.GetJSONConfigState();
            var configState = Utils.JsonDeserialize<ConfigState>(System.Text.Encoding.UTF8.GetBytes(jsonConfigState));
            var shardServers = new List<ConfigState.ShardServer>();
            Int64 tableID = 0;
            foreach (var database in configState.databases)
            {
                if (database.name == databaseName)
                {
                    foreach (var table in configState.tables)
                    {
                        if (table.databaseID == database.databaseID && table.name == tableName)
                        {
                            shardServers = ConfigStateHelpers.GetShardServersByTable(table, configState);
                            tableID = table.tableID;
                            break;
                        }
                    }
                }
                if (tableID != 0)
                    break;
            }

            Assert.IsTrue(tableID != 0);

            ulong num = 50 * 1000 * 1000;
            CompareNumericTableKeysHTTP(shardServers, tableID, num);
            CompareNumericTableKeysBackwardsHTTP(shardServers, tableID, num);
        }
Exemplo n.º 2
0
        public static ConfigState GetFullConfigState(Client client, int controllerHttpPort = 8080)
        {
            var jsonConfigState = client.GetJSONConfigState();

            if (jsonConfigState == null)
            {
                return(null);
            }
            var configState = Utils.JsonDeserialize <ConfigState>(System.Text.Encoding.UTF8.GetBytes(jsonConfigState));
            var master      = configState.master;

            if (master < 0)
            {
                return(null);
            }
            var masterHost = client.Nodes[master].Split(new char[] { ':' })[0];
            var url        = "http://" + masterHost + ":" + controllerHttpPort + "/json/getconfigstate";
            var bytes      = Utils.HTTP.BinaryGET(url);

            return(Utils.JsonDeserialize <ConfigState>(bytes));
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        public void CheckConfigStateConsistency()
        {
            Console.WriteLine("\nChecking config state consistency...\n");

            var client = new Client(Utils.GetConfigNodes());
            var jsonConfigState = client.GetJSONConfigState();
            var clientConfigState = Utils.JsonDeserialize<ConfigState>(System.Text.Encoding.UTF8.GetBytes(jsonConfigState));
            var master = clientConfigState.master;
            var controllers = GetControllersHTTPEndpoint(Utils.GetConfigNodes());
            foreach (var controller in controllers)
            {
                var url = controller + "json/getconfigstate";
                jsonConfigState = Utils.HTTP.GET(url, COUNT_TIMEOUT);
                var configState = Utils.JsonDeserialize<ConfigState>(System.Text.Encoding.UTF8.GetBytes(jsonConfigState));
                Assert.IsTrue(configState.master == -1 || configState.master == master);
            }
        }
Exemplo n.º 5
0
        public void CheckClusterConsistencyByKeyValues()
        {
            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("\nComparing shard key-values on shard " + shard.shardID);

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

                    CompareTableKeyValuesHTTP(shardServers, tableID, startKey, endKey);

                    System.Console.WriteLine("Shard " + shard.shardID + " is consistent.\n");
                }
            }
        }
Exemplo n.º 6
0
        public void TestNoPrimaryException()
        {
            try
            {
                // ensure that there is no master
                Client client = new Client(new string[] { "192.168.2.118:7080", "192.168.2.119:7080", "192.168.2.120:7080" });
                client.SetMasterTimeout(5 * 1000);
                client.SetGlobalTimeout(10 * 1000);
                Client.SetTrace(true);
                string configState = client.GetJSONConfigState();
                Database db = client.GetDatabase("test_db");
                Table table = db.GetTable("test_table");
                for (int i = 0; i < 100; i++)
                {
                    table.Set("a", "1");
                    client.Submit();
                    Thread.Sleep(500);
                }
            }
            catch (SDBPException e)
            {
                Assert.IsTrue(e.Status == Status.SDBP_FAILURE);
                return;
            }

            Assert.Fail();
        }
Exemplo n.º 7
0
        public void TestNoMasterException()
        {
            // This test is not working, because it always throws Status.SDBP_NOCONNECTION
            try
            {
                // ensure that there is no master
                Client client = new Client(new string[] { "192.168.2.118:7080", "192.168.2.119:7080", "192.168.2.120:7080" });
                client.SetMasterTimeout(5 * 1000);
                client.SetGlobalTimeout(10 * 1000);
                string configState = client.GetJSONConfigState();
            }
            catch (SDBPException e)
            {
                Assert.IsTrue(e.Status == Status.SDBP_NOMASTER);
                return;
            }

            Assert.Fail();
        }
Exemplo n.º 8
0
        public void TestNoConnectionException()
        {
            try
            {
                // bad port
                Client client = new Client(new string[] { "127.0.0.1:1" });
                client.SetMasterTimeout(5 * 1000);
                client.SetGlobalTimeout(10 * 1000);
                string configState = client.GetJSONConfigState();
            }
            catch (SDBPException e)
            {
                Assert.IsTrue(e.Status == Status.SDBP_NOCONNECTION);
                return;
            }

            Assert.Fail();
        }
Exemplo n.º 9
0
        public void Killer(Object param)
        {
            string victim;
            Int64 vix;
            string url;
            ConfigState cstate;

            List<KillerConf> actions;
            if (param is KillerConf)
            {
                actions = new List<KillerConf>();
                actions.Add((KillerConf)param);
            }
            else
            {
                actions = (List<KillerConf>)param;
            }
            Client client = new Client(Utils.GetConfigNodes());

            vix = 0;
            victim = null;

            while (actions.Count > 0)
            {
                Thread.Sleep(actions[0].timeout);

                cstate = Utils.JsonDeserialize<ConfigState>(System.Text.Encoding.UTF8.GetBytes(client.GetJSONConfigState()));
                if (cstate.quorums.Count < 1) Assert.Fail("No quorum in ConfigState");

                // select victim and next timeout
                switch (actions[0].mode)
                {
                    case KillMode.KILL_ONE_RANDOMLY:
                        if (cstate.quorums[0].inactiveNodes.Count > 0)
                        {
                            System.Console.WriteLine("Cluster pardoned");
                            continue; // this mode kills only one
                        }

                        vix = cstate.quorums[0].activeNodes[Utils.RandomNumber.Next(cstate.quorums[0].activeNodes.Count)];

                        foreach (ConfigState.ShardServer shardsrv in cstate.shardServers)
                            if (shardsrv.nodeID == vix)
                            {
                                victim = shardsrv.endpoint;
                                break;
                            }

                        break;

                    case KillMode.KILL_ONE_PRIMARY:
                        if (cstate.quorums[0].inactiveNodes.Count > 0)
                        {
                            System.Console.WriteLine("Cluster pardoned");
                            continue; // this mode kills only one
                        }

                        if (cstate.quorums[0].hasPrimary)
                        {
                            vix = cstate.quorums[0].primaryID;

                            foreach (ConfigState.ShardServer shardsrv in cstate.shardServers)
                                if (shardsrv.nodeID == vix)
                                {
                                    victim = shardsrv.endpoint;
                                    break;
                                }
                        }
                        break;

                    case KillMode.KILL_MAJORITY:
                        if (cstate.quorums[0].activeNodes.Count < 2)
                        {
                            System.Console.WriteLine("Cluster pardoned");
                            continue; // keep one alive
                        }

                        vix = cstate.quorums[0].activeNodes[Utils.RandomNumber.Next(cstate.quorums[0].activeNodes.Count)];

                        foreach (ConfigState.ShardServer shardsrv in cstate.shardServers)
                            if (shardsrv.nodeID == vix)
                            {
                                victim = shardsrv.endpoint;
                                break;
                            }

                        break;

                    case KillMode.KILL_REPETITIVELY:
                        if (cstate.quorums[0].inactiveNodes.Count > 0)
                        {
                            System.Console.WriteLine("Cluster pardoned");
                            continue; // this mode kills only one
                        }

                        if (victim == null)
                        {
                            // choose the only victim and kill always him
                            vix = cstate.quorums[0].activeNodes[Utils.RandomNumber.Next(cstate.quorums[0].activeNodes.Count)];

                            foreach (ConfigState.ShardServer shardsrv in cstate.shardServers)
                                if (shardsrv.nodeID == vix)
                                {
                                    victim = shardsrv.endpoint;
                                    break;
                                }
                        }
                        break;
                }

                if (victim != null)
                {
                    string action_string = "";

                    switch (actions[0].action)
                    {
                        case KillActionType.KILL_USING_SLEEP:
                            action_string = "/debug?sleep=25";
                            break;
                        case KillActionType.KILL_USING_CRASH:
                            action_string = "/debug?crash";
                            break;
                        case KillActionType.KILL_USING_BOTH_RANDOMLY:
                            if (Utils.RandomNumber.Next(10) < 5)
                                action_string = "/debug?sleep=25";
                            else
                                action_string = "/debug?crash";
                            break;
                    }

                    victim = victim.Substring(0, victim.Length - 4) + "8090";
                    url = "http://" + victim + action_string;
                    System.Console.WriteLine("Shard action(" + vix + "): " + url);

                    System.Console.WriteLine(Utils.HTTP.GET(url, 3000));
                }

                if (actions[0].repeat == 0)
                {
                    actions.Remove(actions[0]); // remove action
                    victim = null;
                    continue;
                }

                if (actions[0].repeat > 0) actions[0].repeat--;
            }
        }
Exemplo n.º 10
0
        public void TestConfigState()
        {
            Client client = new Client(Utils.GetConfigNodes());

            client.SetGlobalTimeout(15000);

            string config_string = client.GetJSONConfigState();
            System.Console.WriteLine(config_string);

            ConfigState conf = Utils.JsonDeserialize<ConfigState>(System.Text.Encoding.UTF8.GetBytes(config_string));
        }