BaseQuery * TPCCQueryGenerator::gen_payment(uint64_t home_partition) { TPCCQuery * query = new TPCCQuery; set<uint64_t> partitions_accessed; query->txn_type = TPCC_PAYMENT; uint64_t home_warehouse; if (FIRST_PART_LOCAL) { while(wh_to_part(home_warehouse = URand(1, g_num_wh)) != home_partition) {} } else home_warehouse = URand(1, g_num_wh); query->w_id = home_warehouse; query->d_w_id = home_warehouse; partitions_accessed.insert(wh_to_part(query->w_id)); query->d_id = URand(1, g_dist_per_wh); query->h_amount = URand(1, 5000); query->rbk = false; double x = (double)(rand() % 10000) / 10000; int y = URand(1, 100); //if(x > g_mpr) { if(x > 0.15) { // home warehouse query->c_d_id = query->d_id; query->c_w_id = query->w_id; } else { // remote warehouse query->c_d_id = URand(1, g_dist_per_wh); if(g_num_wh > 1) { while((query->c_w_id = URand(1, g_num_wh)) == query->w_id) {} if (wh_to_part(query->w_id) != wh_to_part(query->c_w_id)) { partitions_accessed.insert(wh_to_part(query->c_w_id)); } } else query->c_w_id = query->w_id; } if(y <= 60) { // by last name query->by_last_name = true; Lastname(NURand(255,0,999),query->c_last); } else { // by cust id query->by_last_name = false; query->c_id = NURand(1023, 1, g_cust_per_dist); } query->partitions.init(partitions_accessed.size()); for(auto it = partitions_accessed.begin(); it != partitions_accessed.end(); ++it) { query->partitions.add(*it); } return query; }
void tpcc_query::gen_payment(uint64_t thd_id) { type = TPCC_PAYMENT; if (FIRST_PART_LOCAL) w_id = thd_id % g_num_wh + 1; else w_id = URand(1, g_num_wh); d_w_id = w_id; uint64_t part_id = wh_to_part(w_id); part_to_access[0] = part_id; part_num = 1; d_id = URand(1, DIST_PER_WARE); h_amount = URand(1, 5000); int x = URand(1, 100); int y = URand(1, 100); if(x <= 85) { // home warehouse c_d_id = d_id; c_w_id = w_id; } else { // remote warehouse c_d_id = URand(1, DIST_PER_WARE); if(g_num_wh > 1) { while((c_w_id = URand(1, g_num_wh)) == w_id) {} if (wh_to_part(w_id) != wh_to_part(c_w_id)) { part_to_access[1] = wh_to_part(c_w_id); part_num = 2; } } else c_w_id = w_id; } if(y <= 60) { // by last name by_last_name = true; Lastname(NURand(255,0,999),c_last); } else { // by cust id by_last_name = false; c_id = NURand(1023, 1, g_cust_per_dist); } }
void tpcc_query::gen_order_status(uint64_t thd_id) { type = TPCC_ORDER_STATUS; if (FIRST_PART_LOCAL) w_id = thd_id % g_num_wh + 1; else w_id = URand(1, g_num_wh); d_id = URand(1, DIST_PER_WARE); c_w_id = w_id; c_d_id = d_id; int y = URand(1, 100); if(y <= 60) { // by last name by_last_name = true; Lastname(NURand(255,0,999),c_last); } else { // by cust id by_last_name = false; c_id = NURand(1023, 1, g_cust_per_dist); } }
/* * prepare data and execute order status transaction */ static int do_ordstat (int t_num) { int c_num; int byname,i,ret; clock_t clk1,clk2; double rt; struct timespec tbuf1; struct timespec tbuf2; int w_id, d_id, c_id; char c_last[16]; if(num_node==0){ w_id = RandomNumber(1, num_ware); }else{ c_num = ((num_node * t_num)/num_conn); /* drop moduls */ w_id = RandomNumber(1 + (num_ware * c_num)/num_node, (num_ware * (c_num + 1))/num_node); } d_id = RandomNumber(1, DIST_PER_WARE); c_id = NURand(1023, 1, CUST_PER_DIST); Lastname(NURand(255,0,999), c_last); if (RandomNumber(1, 100) <= 60) { byname = 1; /* select by last name */ }else{ byname = 0; /* select by customer id */ } clk1 = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tbuf1 ); for (i = 0; i < MAX_RETRY; i++) { ret = ordstat(t_num, w_id, d_id, byname, c_id, c_last); clk2 = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tbuf2 ); if(ret){ rt = (double)(tbuf2.tv_sec * 1000.0 + tbuf2.tv_nsec/1000000.0-tbuf1.tv_sec * 1000.0 - tbuf1.tv_nsec/1000000.0); if(rt > max_rt[2]) max_rt[2]=rt; hist_inc(2, rt); if(counting_on){ if( rt < RTIME_ORDSTAT ){ success[2]++; success2[2][t_num]++; }else{ late[2]++; late2[2][t_num]++; } } return (1); /* end */ }else{ if(counting_on){ retry[2]++; retry2[2][t_num]++; } } } if(counting_on){ retry[2]--; retry2[2][t_num]--; failure[2]++; failure2[2][t_num]++; } return (0); }
/* * Loads Customer Table * Also inserts corresponding history record * * id - customer id * d_id - district id * w_id - warehouse id */ int Customer(long d_id, long w_id ) { long c_id; long c_d_id; long c_w_id; char c_first[17]; char c_middle[3]; char c_last[17]; char c_street_1[21]; char c_street_2[21]; char c_city[21]; char c_state[3]; char c_zip[10]; char c_phone[17]; char c_since[12]; char c_credit[3]; long c_credit_lim; float c_discount; float c_balance; char c_data[501]; float h_amount; char h_data[25]; int err; printf("Loading Customer for DID=%ld, WID=%ld\n",d_id,w_id); for (c_id=1; c_id<=CUST_PER_DIST; c_id++) { DBT key, data; CUSTOMER_PRIMARY_KEY c_key; CUSTOMER_PRIMARY_DATA c_primdata; HISTORY_PRIMARY_KEY h_key; memset(&c_key, 0, sizeof(CUSTOMER_PRIMARY_KEY)); memset(&c_primdata, 0, sizeof(CUSTOMER_PRIMARY_DATA)); memset(&h_key, 0, sizeof(HISTORY_PRIMARY_KEY)); /* Generate Customer Data */ c_d_id=d_id; c_w_id=w_id; MakeAlphaString( 8, 16, c_first ); c_middle[0]='O'; c_middle[1]='E'; c_middle[2] = '\0'; if (c_id <= 1000) Lastname(c_id-1,c_last); else Lastname(NURand(255,0,999),c_last); MakeAddress( c_street_1, c_street_2, c_city, c_state, c_zip ); MakeNumberString( 16, 16, c_phone ); if (random1(0L,1L)) c_credit[0]='G'; else c_credit[0]='B'; c_credit[1]='C'; c_credit[2]='\0'; c_credit_lim=50000; c_discount=((float)random1(0L,50L))/100.0; c_balance= -10.0; MakeAlphaString(300,500,c_data); /* Prepare for putting into the database */ c_key.C_W_ID = c_w_id; c_key.C_D_ID = c_d_id; c_key.C_ID = c_id; memcpy(&c_primdata.C_FIRST, &c_first, 17); memcpy(&c_primdata.C_MIDDLE, &c_middle, 3); memcpy(&c_primdata.C_LAST, &c_last, 17); memcpy(&c_primdata.C_STREET_1, &c_street_1, 21); memcpy(&c_primdata.C_STREET_2, &c_street_2, 21); memcpy(&c_primdata.C_CITY, &c_city, 21); memcpy(&c_primdata.C_STATE, &c_state, 3); memcpy(&c_primdata.C_ZIP, &c_zip, 10); memcpy(&c_primdata.C_PHONE, &c_phone, 17); memcpy(&c_primdata.C_DATA, &c_data, 501); memcpy(&c_primdata.C_CREDIT, &c_credit, 3); memcpy(c_primdata.C_CREDIT, &c_credit, 3); c_primdata.C_DISCOUNT = c_discount; c_primdata.C_BALANCE = c_balance; memset(&key, 0, sizeof(DBT)); key.data = &c_key; key.size = sizeof(CUSTOMER_PRIMARY_KEY); memset(&data, 0, sizeof(DBT)); data.data = &c_primdata; data.size = sizeof(CUSTOMER_PRIMARY_DATA); if((err=dbp_customer->put(dbp_customer, 0, &key, &data, 0))) { db_error("DB->put", err); return -1; } h_amount = 10.0; MakeAlphaString(12,24,h_data); memset(&key, 0, sizeof(DBT)); key.data = &h_key; key.size = sizeof(HISTORY_PRIMARY_KEY); memset(&data, 0, sizeof(DBT)); h_key.H_C_ID = c_id; h_key.H_C_D_ID = c_d_id; h_key.H_C_W_ID = c_w_id; h_key.H_W_ID = c_w_id; h_key.H_D_ID = c_d_id; h_key.H_AMOUNT = h_amount; memcpy(&h_key.H_DATE, ×tamp, 26); memcpy(&h_key.H_DATA, &h_data, 24); if((err=dbp_history->put(dbp_history, 0, &key, &data, 0))) { db_error("DB->put", err); return -1; } if ( option_debug ) printf( "CID = %ld, LST = %s, P# = %s\n", c_id, c_last, c_phone ); if ( !(c_id % 100) ) { printf("."); if ( !(c_id % 1000) ) printf(" %ld\n",c_id); } } printf("Customer Done.\n"); return 0; }
void tpcc_wl::init_tab_cust(uint64_t did, uint64_t wid) { assert(g_cust_per_dist >= 1000); for (UInt32 cid = 1; cid <= g_cust_per_dist; cid++) { row_t * row; uint64_t row_id; t_customer->get_new_row(row, 0, row_id); row->set_primary_key(cid); row->set_value(C_ID, cid); row->set_value(C_D_ID, did); row->set_value(C_W_ID, wid); char c_last[LASTNAME_LEN]; if (cid <= 1000) Lastname(cid - 1, c_last); else Lastname(NURand(255,0,999), c_last); row->set_value(C_LAST, c_last); #if !TPCC_SMALL char * tmp = "OE"; row->set_value(C_MIDDLE, tmp); char c_first[FIRSTNAME_LEN]; MakeAlphaString(FIRSTNAME_MINLEN, sizeof(c_first), c_first); row->set_value(C_FIRST, c_first); char street[20]; MakeAlphaString(10, 20, street); row->set_value(C_STREET_1, street); MakeAlphaString(10, 20, street); row->set_value(C_STREET_2, street); MakeAlphaString(10, 20, street); row->set_value(C_CITY, street); char state[2]; MakeAlphaString(2, 2, state); /* State */ row->set_value(C_STATE, state); char zip[9]; MakeNumberString(9, 9, zip); /* Zip */ row->set_value(C_ZIP, zip); char phone[16]; MakeNumberString(16, 16, phone); /* Zip */ row->set_value(C_PHONE, phone); row->set_value(C_SINCE, 0); row->set_value(C_CREDIT_LIM, 50000); row->set_value(C_DELIVERY_CNT, 0); char c_data[500]; MakeAlphaString(300, 500, c_data); row->set_value(C_DATA, c_data); #endif if (RAND(10) == 0) { char tmp[] = "GC"; row->set_value(C_CREDIT, tmp); } else { char tmp[] = "BC"; row->set_value(C_CREDIT, tmp); } row->set_value(C_DISCOUNT, (double)RAND(5000) / 10000); row->set_value(C_BALANCE, -10.0); row->set_value(C_YTD_PAYMENT, 10.0); row->set_value(C_PAYMENT_CNT, 1); uint64_t key; key = custNPKey(c_last, did, wid); index_insert(i_customer_last, key, row, wh_to_part(wid)); key = custKey(cid, did, wid); index_insert(i_customer_id, key, row, wh_to_part(wid)); } }