Table is a convenience class for encapsulating table related operations.

ScalienDB uses databases and tables to manage key value namespaces.

Exemplo n.º 1
0
 public void ListTests(Table tbl, uint num)
 {
     ListTest1(tbl, num);
     ListTest2(tbl, num);
     ListTest3(tbl, num);
     ListTest4(tbl, num);
     ListTest5(tbl, num);
     ListTest6(tbl, num);
     ListTest7(tbl, num);
     ListTest8(tbl, num);
     ListTest9(tbl, num);
     ListTest10(tbl, num);
     ListTest11(tbl, num);
     ListTest12(tbl, num);
     ListTest13(tbl, num);
     ListTest14(tbl, num);
     ListTest15(tbl, num);
     ListTest16(tbl, num);
     ListTest17(tbl, num);
     ListTest18(tbl, num);
     ListTest19(tbl, num);
     ListTest20(tbl, num);
     ListTest21(tbl, num);
     ListTest22(tbl, num);
     ListTest23(tbl, num);
     ListTest24(tbl, num);
     ListTest25(tbl, num);
     ListTest26(tbl, num);
     ListTest27(tbl, num);
     ListTest28(tbl, num);
     ListTest29(tbl, num);
 }
Exemplo n.º 2
0
        public void PerformListTest(Table tbl, StringRangeParams ps, uint expected)
        {
            int cnt;

            cnt = 0;
            foreach (String key in tbl.GetKeyIterator(ps))
            {
                //Console.WriteLine(key);
                cnt++;
            }
            Console.WriteLine("Expecting {0}, received {1}", expected, cnt);
            Assert.IsTrue(expected == cnt);

            cnt = 0;
            foreach (KeyValuePair<string, string> kv in tbl.GetKeyValueIterator(ps))
            {
                cnt++;
            }
            Console.WriteLine("Expecting {0}, received {1}", expected, cnt);
            Assert.IsTrue(expected == cnt);
        }
Exemplo n.º 3
0
        public void ListTest7(Table tbl, uint num)
        {
            uint count = 1234;

            StringRangeParams ps = new StringRangeParams();
            ps.Backward();
            ps.Count(count);

            uint expected = count;
            PerformListTest(tbl, ps, expected);
        }
Exemplo n.º 4
0
        public void ListTest9(Table tbl, uint num)
        {
            StringRangeParams ps = new StringRangeParams();
            ps.EndKey(Utils.Id(15000));
            ps.Backward();

            uint expected = num - 15000 - 1;
            PerformListTest(tbl, ps, expected);
        }
Exemplo n.º 5
0
        public void ListTest3(Table tbl, uint num)
        {
            uint count = 100;

            StringRangeParams ps = new StringRangeParams();
            ps.StartKey(Utils.Id(100));
            ps.Count(count);
            ps.Backward();

            uint expected = count;
            PerformListTest(tbl, ps, expected);
        }
Exemplo n.º 6
0
 public void ListTest5(Table tbl, uint num)
 {
     StringRangeParams ps = new StringRangeParams();
     ps.Backward();
     PerformListTest(tbl, ps, num);
 }
Exemplo n.º 7
0
        public void ListTest27(Table tbl, uint num)
        {
            for (uint i = num; i > 0; i -= 1000)
            {
                StringRangeParams ps = new StringRangeParams();
                ps.StartKey(Utils.Id(i));
                ps.EndKey(Utils.Id(i - 1000));
                ps.Backward();

                uint expected;
                if (i == 22000)
                    expected = 999;
                else
                    expected = 1000;
                PerformListTest(tbl, ps, expected);
            }
        }
Exemplo n.º 8
0
        public void ListTest29(Table tbl, uint num)
        {
            for (uint i = 0; i < (num/1000); i++)
            {
                StringRangeParams ps = new StringRangeParams();
                ps.Prefix("00000000" + i.ToString("D2"));
                ps.Backward();

                uint expected = 1000;
                PerformListTest(tbl, ps, expected);
            }
        }
Exemplo n.º 9
0
        public void ListTest25(Table tbl, uint num)
        {
            StringRangeParams ps = new StringRangeParams();
            ps.StartKey(Utils.Id(22000));
            ps.EndKey(Utils.Id(18000));
            ps.Backward();

            uint expected = 3999;
            PerformListTest(tbl, ps, expected);
        }
Exemplo n.º 10
0
        public void ListTest26(Table tbl, uint num)
        {
            for (uint i = 0; i < num; i += 1000)
            {
                StringRangeParams ps = new StringRangeParams();
                ps.StartKey(Utils.Id(i));
                ps.EndKey(Utils.Id(i + 1000));

                uint expected = 1000;
                PerformListTest(tbl, ps, expected);
            }
        }
Exemplo n.º 11
0
        public void ListTest22(Table tbl, uint num)
        {
            StringRangeParams ps = new StringRangeParams();
            ps.StartKey(Utils.Id(10000));
            ps.EndKey(Utils.Id(13000));

            uint expected = 3000;
            PerformListTest(tbl, ps, expected);
        }
Exemplo n.º 12
0
        public void ListTest19(Table tbl, uint num)
        {
            StringRangeParams ps = new StringRangeParams();
            ps.StartKey(Utils.Id(12000));
            ps.Prefix("0000000013");
            ps.Backward();

            uint expected = 0;
            PerformListTest(tbl, ps, expected);
        }
Exemplo n.º 13
0
        public void ListTest17(Table tbl, uint num)
        {
            StringRangeParams ps = new StringRangeParams();
            ps.Prefix("000000002");
            ps.Backward();

            uint expected = 2000;
            PerformListTest(tbl, ps, expected);
        }
Exemplo n.º 14
0
        public static void FixDiffs(Client client, List<ConfigState.ShardServer> shardServers, Int64 tableID, List<string> diffs)
        {
            var i = 0;
            foreach (var key in diffs)
            {
                i += 1;
                byte[] startKey = Utils.StringToByteArray(key);
                byte[] endKey = Utils.NextKey(startKey);
                var serverKeyValues = ConfigStateHelpers.ParallelFetchTableKeyValuesHTTP(shardServers, tableID, startKey, endKey, true);

                if (Array.TrueForAll(serverKeyValues, val => (val.Count == 1 && Utils.ByteArraysEqual(val.First().Key, serverKeyValues[0].First().Key))))
                    continue;

                foreach (var keyValue in serverKeyValues)
                {
                    if (keyValue == null || keyValue.Count == 0)
                        continue;

                    if (keyValue.First().Value.Length > 0)
                    {
                        Assert.IsTrue(Utils.ByteArraysEqual(Utils.StringToByteArray(key), keyValue.First().Key));

                        Console.WriteLine("Setting key {0}", key);
                        Table table = new Table(client, null, (ulong)tableID, "");
                        table.Set(startKey, keyValue.First().Value);
                        client.Submit();
                    }
                }
            }
        }
Exemplo n.º 15
0
        private void OpenDB()
        {
            try
            {
                db = clients[client_index].GetDatabase(dbname);
            }
            catch (SDBPException)
            {
                db = clients[client_index].CreateDatabase(dbname);
            }

            db = Utils.GetOrCreateEmptyDatabase(clients[client_index], dbname);

            try
            {
                indices = db.GetTable("indices");
            }
            catch (SDBPException)
            {
                indices = db.CreateTable("indices");
            }
            userIDs = indices.GetSequence("userIDs");

            try
            {
                table = db.GetTable(tablename);
            }
            catch (SDBPException)
            {
                table = db.CreateTable(tablename);
            }

            try
            {
                tableByNick = db.GetTable(tablename + "ByNick");
            }
            catch (SDBPException)
            {
                tableByNick = db.CreateTable(tablename + "ByNick");
            }

            try
            {
                tableByBirth = db.GetTable(tablename + "ByBirth");
            }
            catch (SDBPException)
            {
                tableByBirth = db.CreateTable(tablename + "ByBirth");
            }

            try
            {
                tableByLastLogin = db.GetTable(tablename + "ByLastLogin");
            }
            catch (SDBPException)
            {
                tableByLastLogin = db.CreateTable(tablename + "ByLastLogin");
            }
        }