Exemplo n.º 1
0
        public void LoadPaymentWorkload(string filepath)
        {
            Console.WriteLine("Loading PAYMENT workload...");
            var    csvReader = new System.IO.StreamReader(filepath);
            string line      = null;
            int    lineNum   = 0;

            line = csvReader.ReadLine();    // ignore the first line: header

            int workloadTotal = workerCount * workloadCountPerWorker;

            int instanceIndex = 0;

            for (int i = 0; i < workerCount; i++)
            {
                RedisClient redisClient = new RedisClient(Constants.RedisHost, Constants.RedisPort);   // for payment to create `c_last` index
                redisClient.ChangeDb(Constants.RedisIndexDbN);

                Queue <TransactionRequest> reqQueue = new Queue <TransactionRequest>();
                for (int k = 0; k < workloadCountPerWorker; k++)
                {
                    line = csvReader.ReadLine();
                    lineNum++;
                    if (line == null)
                    {
                        throw new Exception("there is no enough workload");
                    }

                    string[] columns = line.Split(new string[] { Constants.WorkloadDelimiter }, StringSplitOptions.None);
                    for (int j = 0; j < columns.Length; j++)
                    {
                        columns[j] = columns[j].Substring(1);
                    }
                    columns[columns.Length - 1] = columns[columns.Length - 1].Substring(0, columns[columns.Length - 1].Length - 1); // remove `"`

                    var pm = new PaymentInParameters
                    {
                        timestamp = columns[0],
                        C_ID      = (columns[1] == "" ? 0 : Convert.ToUInt32(columns[1])),
                        C_LAST    = columns[2], // may be ""
                        H_DATE    = columns[3],
                        C_D_ID    = Convert.ToUInt32(columns[4]),
                        D_ID      = Convert.ToUInt32(columns[5]),
                        W_ID      = Convert.ToUInt32(columns[6]),
                        C_W_ID    = Convert.ToUInt32(columns[7]),
                        H_AMOUNT  = Convert.ToDouble(columns[8])
                    };

                    TPCCPaymentStoredProcedure pmsp = new TPCCPaymentStoredProcedure(lineNum.ToString(), pm, redisClient);
                    // TODO: should adopt to the lastest storedprocedure rule
                    // TransactionRequest req = new TransactionRequest(lineNum.ToString(), pmsp);
                    TransactionRequest req = null;
                    reqQueue.Enqueue(req);
                }

                List <Tuple <string, int> > executorInstances = instanceIndex >= this.partitionedInstances.Count ? null :
                                                                this.partitionedInstances[instanceIndex++];
                this.executorList.Add(new TransactionExecutor(this.redisVersionDb, null, reqQueue, i, i));
            }
        }
Exemplo n.º 2
0
 public TPCCPaymentStoredProcedure(string sessionId, PaymentInParameters inParams, RedisClient redisClient)
 {
     this.pid          = int.Parse(sessionId);
     this.sessionId    = sessionId;
     this.input        = inParams;
     this.currentState = PaymentState.ToStart;
     this.redisClient  = redisClient;
 }
Exemplo n.º 3
0
        object ExecuteStoredProcedure(SyncExecution exec, WorkloadParam param)
        {
            PaymentInParameters input = (PaymentInParameters)param;

            // Transaction tx = new Transaction(null, vdb);

            // warehouse, district
            this.wpk.Set(W_ID: input.W_ID);
            // var wpl = JsonConvert.DeserializeObject<WarehousePayload>((string)tx.Read(Constants.DefaultTbl, wpk.ToString()));
            WarehousePayload wpl;

            if (exec.ReadCopy(this.wpk, out wpl).IsAborted())
            {
                return(null);
            }
            wpl.W_YTD += input.H_AMOUNT;
            // tx.Update(Constants.DefaultTbl, wpk.ToString(), JsonConvert.SerializeObject(wpl));
            if (exec.Update(this.wpk, wpl).IsAborted())
            {
                return(null);
            }

            this.dpk.Set(D_ID: input.D_ID, D_W_ID: input.W_ID);
            // var dpl = JsonConvert.DeserializeObject<DistrictPayload>((string)tx.Read(Constants.DefaultTbl, dpk.ToString()));
            DistrictPayload dpl;

            if (exec.ReadCopy(this.dpk, out dpl).IsAborted())
            {
                return(null);
            }
            dpl.D_YTD += input.H_AMOUNT;
            // tx.Update(Constants.DefaultTbl, dpk.ToString(), JsonConvert.SerializeObject(dpl));
            if (exec.Update(this.dpk, dpl).IsAborted())
            {
                return(null);
            }

            // determine c_id
            var C_ID = input.C_ID;

            // if (C_ID == 0)  // by c_last
            // {
            //     var k = CustomerPayload.GetLastNameIndexKey(input.C_W_ID, input.C_D_ID, input.C_LAST);
            //     var ids = redisClient.GetAllItemsFromList(k);
            //     C_ID = Convert.ToUInt32(ids[ids.Count / 2]);    // TODO order by c_first?
            // }
            if (C_ID == 0)
            {
                // var lastNameKey = new LastNameIndexKey(
                //     input.C_W_ID, input.C_D_ID, input.C_LAST);
                this.lastNameKey.Set(
                    C_W_ID: input.C_W_ID,
                    C_D_ID: input.C_D_ID,
                    C_LAST: input.C_LAST);
                CustomerLastNamePayloads lastNamePayload;
                if (exec.Read(this.lastNameKey, out lastNamePayload).IsAborted())
                {
                    return(null);
                }
                C_ID = lastNamePayload.GetRequiredId();
            }

            this.cpk.Set(
                C_ID: C_ID,
                C_D_ID: input.C_D_ID,
                C_W_ID: input.C_W_ID);
            // var cpl = JsonConvert.DeserializeObject<CustomerPayload>((string)tx.Read(Constants.DefaultTbl, cpk.ToString()));
            CustomerPayload cpl;

            if (exec.ReadCopy(this.cpk, out cpl).IsAborted())
            {
                return(null);
            }
            cpl.C_BALANCE     -= input.H_AMOUNT;
            cpl.C_YTD_PAYMENT += input.H_AMOUNT;
            cpl.C_PAYMENT_CNT += 1;
            //var C_DATA = cpl.C_DATA;

            // credit info
            if (cpl.C_CREDIT == Constants.BadCredit)
            {
                uint[] tmp     = { C_ID, input.C_D_ID, input.C_W_ID, input.D_ID, input.W_ID };
                var    newData = string.Join(" ", tmp) + " " + input.H_AMOUNT + "|" + cpl.C_DATA;
                if (newData.Length > Constants.Max_C_DATA)
                {
                    newData = newData.Substring(0, Constants.Max_C_DATA);
                }
                cpl.C_DATA = newData;
            }
            // tx.Update(Constants.DefaultTbl, cpk.ToString(), JsonConvert.SerializeObject(cpl));
            if (exec.Update(this.cpk, cpl).IsAborted())
            {
                return(null);
            }

            /*
             * // history
             * var hpl = new HistoryPayload
             * {
             *  H_C_ID = C_ID,
             *  H_C_D_ID = this.cpk.C_D_ID,
             *  H_C_W_ID = this.cpk.C_W_ID,
             *  H_D_ID = input.D_ID,
             *  H_W_ID = input.W_ID,
             *  H_DATA = wpl.W_NAME + "    " + dpl.D_NAME,
             *  H_AMOUNT = input.H_AMOUNT,
             *  H_DATE = input.timestamp
             * };
             * var hpk = HistoryPKey.New();
             * // tx.ReadAndInitialize(Constants.DefaultTbl, hpk);
             * // tx.Insert(Constants.DefaultTbl, hpk, JsonConvert.SerializeObject(hpl));
             * if (false && exec.Insert(hpk, hpl).IsAborted())
             * {
             *  return null;
             * }
             */
            // tx.Commit();
            if (exec.Commit().IsAborted())
            {
                return(null);
            }

            // to return
            this.pmOutput.wpl = wpl;
            this.pmOutput.dpl = dpl;
            this.pmOutput.cpl = cpl;  // TODO C_ID may be null in input

            return(this.pmOutput);
        }