Esempio n. 1
0
        /// <summary>
        /// split function "Setup" into `LoadData` and `LoadWorkloads`
        /// </summary>
        /// <param name="dataFile"></param>
        internal void LoadData(string dataFile, int loadCountMax = -1)
        {
            // step1: clear the database
            this.versionDb.Clear();
            Console.WriteLine("Cleared the database");

            // step2: create version table
            versionDb.CreateVersionTable(TABLE_ID, REDIS_DB_INDEX);
            Console.WriteLine("Created version table {0}", TABLE_ID);

            // step3: load data
            using (StreamReader reader = new StreamReader(dataFile))
            {
                string line;
                int    count = 0;
                while ((line = reader.ReadLine()) != null)
                {
                    string[]   fields   = this.ParseCommandFormat(line);
                    TxWorkload workload = new TxWorkload(fields[0], TABLE_ID, fields[2], fields[3]);
                    count++;

                    ACTION(Tuple.Create(workload, this.versionDb));
                    if (count % 1000 == 0)
                    {
                        Console.WriteLine("Loaded {0} records", count);
                    }
                    if (count == loadCountMax)
                    {
                        break;
                    }
                }
                Console.WriteLine("Load records successfully, {0} records in total", count);
            }
        }
Esempio n. 2
0
        void loadWithOneThread(int tid, int s, int e, List <string> lines, List <VersionDb> vdbList, int[] finishedCnt)
        {
            string line;

            for (int i = s; i < e; i++)
            {
                line = lines[i];
                string[]   fields   = this.ParseCommandFormat(line);
                TxWorkload workload = new TxWorkload(fields[0], TABLE_ID, fields[2], fields[3]);
                ACTION(Tuple.Create(workload, vdbList[tid]));
                finishedCnt[tid] += 1;
            }
        }
Esempio n. 3
0
 internal void LoadWorkloads(string opFile)
 {
     // step 4: fill workers' queue
     using (StreamReader reader = new StreamReader(opFile))
     {
         string line;
         for (int worker_index = 0; worker_index < this.workerCount; worker_index++)
         {
             for (int i = 0; i < this.taskCountPerWorker; i++)
             {
                 line = reader.ReadLine();
                 string[]   fields   = this.ParseCommandFormat(line);
                 TxWorkload workload = new TxWorkload(fields[0], TABLE_ID, fields[2], fields[3]);
                 this.workers[worker_index].EnqueueTxTask(new TxTask(ACTION, Tuple.Create(workload, this.versionDb)));
             }
         }
     }
 }
Esempio n. 4
0
        internal void LoadWorkloads(string opFile, List <VersionDb> vdbList)
        {
            if (vdbList.Count < this.workerCount)
            {
                throw new Exception("not enough version db");
            }

            // step 4: fill workers' queue
            using (StreamReader reader = new StreamReader(opFile))
            {
                string line;
                for (int worker_index = 0; worker_index < this.workerCount; worker_index++)
                {
                    for (int i = 0; i < this.taskCountPerWorker; i++)
                    {
                        line = reader.ReadLine();
                        string[]   fields   = this.ParseCommandFormat(line);
                        TxWorkload workload = new TxWorkload(fields[0], TABLE_ID, fields[2], fields[3]);
                        this.workers[worker_index].EnqueueTxTask(new TxTask(ACTION, Tuple.Create(workload, vdbList[worker_index])));
                    }
                }
            }
        }
Esempio n. 5
0
        internal void Setup(string dataFile, string operationFile)
        {
            // step1: clear the database
            this.versionDb.Clear();
            Console.WriteLine("Cleared the database");

            // step2: create version table
            versionDb.CreateVersionTable(TABLE_ID, REDIS_DB_INDEX);
            Console.WriteLine("Created version table {0}", TABLE_ID);

            // step3: load data
            using (StreamReader reader = new StreamReader(dataFile))
            {
                string line;
                int    count = 0;
                while ((line = reader.ReadLine()) != null)
                {
                    string[]   fields   = this.ParseCommandFormat(line);
                    TxWorkload workload = new TxWorkload(fields[0], TABLE_ID, fields[2], fields[3]);
                    count++;

                    ACTION(Tuple.Create(workload, this.versionDb));
                    if (count % 10000 == 0)
                    {
                        Console.WriteLine("Loaded {0} records", count);
                    }
                    if (count == 2000000)
                    //if (count == 5000)
                    {
                        break;
                    }
                }
                Console.WriteLine("Load records successfully, {0} records in total", count);
            }

            //this.versionDb.ClearTxTable();

            //preload to make txtable and txqueue full.
            //for (int worker_index = 0; worker_index < this.workerCount; worker_index++)
            //{
            //    for (int i = 0; i < TxRange.range; i++)
            //    {
            //        this.versionDb.InsertNewTx(i + worker_index * TxRange.range);
            //        this.executors[worker_index].GarbageQueueTxId.Enqueue(i + worker_index * TxRange.range);
            //        this.executors[worker_index].GarbageQueueFinishTime.Enqueue(0);
            //    }
            //}

            // step 4: fill workers' queue
            using (StreamReader reader = new StreamReader(operationFile))
            {
                string line;
                for (int worker_index = 0; worker_index < this.workerCount; worker_index++)
                {
                    for (int i = 0; i < this.taskCountPerWorker; i++)
                    {
                        line = reader.ReadLine();
                        string[]   fields   = this.ParseCommandFormat(line);
                        TxWorkload workload = new TxWorkload(fields[0], TABLE_ID, fields[2], fields[3]);
                        this.workers[worker_index].EnqueueTxTask(new TxTask(ACTION, Tuple.Create(workload, this.versionDb)));
                        //this.workers[worker_index].EnqueueTxTask(new TxTask(ACTION_1, Tuple.Create(workload, this.executors[worker_index], this.transactions[worker_index])));
                    }
                }
            }
        }