示例#1
0
        public override void Start()
        {
            // init
            this.output          = new TPCCWorkloadOutput();
            output.txFinalStatus = TxFinalStatus.UNKNOWN;

            // the first step
            // determine c_id
            this.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?
            }

            this.currentState = PaymentState.ReadC;
            var cpk = new CustomerPkey
            {
                C_ID   = C_ID,
                C_D_ID = input.C_D_ID,
                C_W_ID = input.C_W_ID
            };

            this.cpkStr = cpk.ToString();
            this.AddReq(this.cpkStr);
        }
示例#2
0
        public override void ReadCallback(string tableId, object recordKey, object payload)
        {
            switch (this.currentState)
            {
            case NewOrderState.ReadItems:
                if (payload == null)
                {
                    this.Close("read item failed");
                    break;
                }
                items[i++] = JsonConvert.DeserializeObject <ItemPayload>(payload as string);
                if (this.i < this.olCount)
                {
                    ReadItem();
                }
                else
                {
                    this.currentState = NewOrderState.ReadW;
                    WarehousePkey wpk = new WarehousePkey {
                        W_ID = input.W_ID
                    };
                    this.AddReq(wpk.ToString());
                }
                break;

            case NewOrderState.ReadW:
                if (payload == null)
                {
                    this.Close("read W fail");
                    break;
                }
                WarehousePayload wpl = JsonConvert.DeserializeObject <WarehousePayload>(payload as string);
                this.W_TAX        = wpl.W_TAX;
                this.currentState = NewOrderState.ReadD;
                DistrictPkey dpk = new DistrictPkey {
                    D_ID = input.D_ID, D_W_ID = input.W_ID
                };
                this.dpkStr = dpk.ToString();
                this.AddReq(this.dpkStr);
                break;

            case NewOrderState.ReadD:
                if (payload == null)
                {
                    this.Close("read D fail");
                    break;
                }
                this.dpl          = JsonConvert.DeserializeObject <DistrictPayload>(payload as string);
                this.D_NEXT_O_ID  = dpl.D_NEXT_O_ID;
                this.currentState = NewOrderState.ReadC;
                CustomerPkey cpk = new CustomerPkey {
                    C_ID = input.C_ID, C_D_ID = input.D_ID, C_W_ID = input.W_ID
                };
                this.AddReq(cpk.ToString());
                break;

            case NewOrderState.ReadC:
                if (payload == null)
                {
                    this.Close("read C fail");
                    break;
                }
                this.cpl        = JsonConvert.DeserializeObject <CustomerPayload>(payload as string);
                this.C_DISCOUNT = cpl.C_DISCOUNT;
                //
                this.currentState = NewOrderState.ReadInitO;
                OrderPkey opk = new OrderPkey
                {
                    O_ID   = D_NEXT_O_ID,
                    O_D_ID = input.D_ID,
                    O_W_ID = input.W_ID
                };
                this.opkStr = opk.ToString();
                this.AddReq(this.opkStr, null, OperationType.InitiRead);
                break;

            case NewOrderState.ReadInitO:
                if (payload != null)
                {
                    this.Close("read init O fail");
                    break;
                }
                this.currentState = NewOrderState.InsertO;
                // all local or not
                bool allLocal = true;
                for (i = 0; i < this.olCount; i++)
                {
                    allLocal = allLocal & input.OL_I_IDs[i] == input.W_ID;
                }
                OrderPayload opl = new OrderPayload
                {
                    O_C_ID       = input.C_ID,
                    O_ENTRY_D    = input.O_ENTRY_D,
                    O_CARRIER_ID = Constants.NullCarrierID,
                    O_OL_CNT     = (uint)input.OL_I_IDs.Length,
                    O_ALL_LOCAL  = Convert.ToUInt32(allLocal)
                };
                AddReq(this.opkStr, JsonConvert.SerializeObject(opl), OperationType.Insert);
                break;

            case NewOrderState.ReadInitNO:
                if (payload != null)
                {
                    this.Close("read init NO fail");
                    break;
                }
                this.currentState = NewOrderState.InsertNO;
                this.AddReq(this.nopkStr, Constants.PlaceHolders, OperationType.Insert);
                break;

            case NewOrderState.InsertOLsReadS:
                if (payload == null)
                {
                    this.Close("insert OL read S fail");
                    break;
                }
                this.currentState = NewOrderState.InsertOLsUpdateS;
                this.spl          = JsonConvert.DeserializeObject <StockPayload>(payload as string);
                uint OL_QUANTITY = input.OL_QUANTITYs[i];
                this.spl.S_YTD += OL_QUANTITY;
                if (spl.S_QUANTITY >= OL_QUANTITY + 10)
                {
                    spl.S_QUANTITY -= (int)OL_QUANTITY;
                }
                else
                {
                    spl.S_QUANTITY += 91 - (int)OL_QUANTITY;
                }
                spl.S_ORDER_CNT += 1;
                if (input.OL_SUPPLY_W_IDs[i] != input.W_ID)
                {
                    spl.S_REMOTE_CNT += 1;
                }
                this.AddReq(this.spkStr, JsonConvert.SerializeObject(spl), OperationType.Update);
                break;

            case NewOrderState.InsertOLsReadInitOL:
                if (payload != null)
                {
                    this.Close("insert OL read init OL fail");
                    break;
                }
                this.currentState = NewOrderState.InsertOLsInsertOL;
                double OL_AMOUNT = input.OL_QUANTITYs[i] * items[i].I_PRICE;
                this.totalFee += OL_AMOUNT;
                OrderLinePayload olpl = new OrderLinePayload
                {
                    OL_I_ID        = input.OL_I_IDs[i],
                    OL_SUPPLY_W_ID = input.OL_SUPPLY_W_IDs[i],
                    OL_DELIVERY_D  = null,
                    OL_QUANTITY    = input.OL_QUANTITYs[i],
                    OL_AMOUNT      = OL_AMOUNT,
                    OL_DIST_INFO   = spl.S_DIST_01          // TODO, assign to S_DIST_XX, where XX equals to D_ID
                };
                this.AddReq(this.olpkStr, JsonConvert.SerializeObject(olpl), OperationType.Insert);
                break;

            default:
                this.Close("exception read");
                break;
            }

            this.StoreCurrentState();
        }