GetSequence() публичный Метод

Retrieve a Scalien.Sequence backed by a key-value in this table.
public GetSequence ( byte key ) : Sequence
key byte The key backing the sequence.
Результат Sequence
Пример #1
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");
            }
        }
Пример #2
0
        public static void ThreadFunc()
        {
            //Client.SetTrace(true);
            //Client.SetLogFile("d:/out.txt");

            //string[] controllers = { "127.0.0.1:7080" };
            string[] controllers = { "192.168.137.110:7080", "192.168.137.111:7080", "192.168.137.112:7080" };
            Client   client      = new Client(controllers);

            Quorum   quorum  = client.GetQuorum("test");
            Database db      = client.GetDatabase("test");
            Table    test    = db.GetTable("test");
            Table    indices = db.GetTable("indices");
            Sequence IDs     = indices.GetSequence("IDs");

            //System.Console.WriteLine("Thread.CurrentThread.ManagedThreadId = {0}", Thread.CurrentThread.ManagedThreadId);

            System.Random random = new System.Random(Thread.CurrentThread.ManagedThreadId);

            var value = "";

            while (value.Length < 10 * 1000)
            {
                value += "" + random.Next();
            }

            //using (client.Transaction(quorum, "foo" + random.Next(100)))
            //{
            //    System.Console.WriteLine("Transaction started.");
            //    for (var j = 0; j < 10*1000; j++)
            //            table.Set("" + j, value);

            //    client.CommitTransaction();
            //    System.Console.WriteLine("Transaction finished.");
            //}
            //return;

            ulong ID;

            //for (var i = 0; i < 1000; i++)
            while (true)
            {
                if (random.Next(3) == 0)
                {
                    try
                    {
                        System.Console.WriteLine("Batch started.");
                        for (var j = 0; j < 10; j++)
                        {
                            if (random.Next(2) == 0)
                            {
                                test.Set("" + random.Next(1000 * 1000), value);
                            }
                            else
                            {
                                test.Delete("" + random.Next(1000 * 1000));
                            }
                        }
                        //for (var j = 0; j < 10 * 1000; j++)
                        //    ID = IDs.GetNext;
                        client.Submit();
                        System.Console.WriteLine("Batch finished.");
                    }
                    catch (SDBPException)
                    {
                        System.Console.WriteLine("Batch failed.");
                    }
                    continue;
                }

                //if (random.Next(2) == 0)
                //{
                //    try
                //    {
                //        System.Console.WriteLine("List started.");
                //        var count = 0;
                //        foreach (KeyValuePair<string, string> kv in test.GetKeyValueIterator(new StringRangeParams().Prefix("1")))
                //        {
                //            count++;
                //            //System.Console.WriteLine(kv.Key + " => " + kv.Value);
                //            if (count == 10)
                //                break;
                //        }
                //        System.Console.WriteLine("List finished.");
                //    }
                //    catch (SDBPException)
                //    {
                //        System.Console.WriteLine("List failed.");
                //        // why does this happen
                //    }
                //    continue;
                //}

                while (true)
                {
                    try
                    {
                        using (client.Transaction(quorum, "foo" + random.Next(100)))
                        {
                            System.Console.WriteLine("Transaction started.");
                            for (var j = 0; j < 10; j++)
                            {
                                if (random.Next(2) == 0)
                                {
                                    test.Set("" + random.Next(1000 * 1000), value);
                                }
                                else
                                {
                                    test.Delete("" + random.Next(1000 * 1000));
                                }
                            }
                            //for (var j = 0; j < 1000; j++)
                            //    ID = IDs.GetNext;
                            if (random.Next(2) == 0)
                            {
                                client.CommitTransaction();
                            }
                            else
                            {
                                client.RollbackTransaction();
                            }
                            System.Console.WriteLine("Transaction finished.");
                            break;
                        }
                    }
                    catch (SDBPException)
                    {
                        //System.Console.WriteLine("Exception.");
                        System.Threading.Thread.Sleep(1);
                    }
                }
            }
        }
Пример #3
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");
            }
        }