Skip to content

Commit 0bd85b0

Browse files
author
VadimTk
committed
options for tpcc_load
1 parent ca3c479 commit 0bd85b0

File tree

3 files changed

+64
-53
lines changed

3 files changed

+64
-53
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
`mysql tpcc1000 < add_fkey_idx.sql`
1212
* populate data
1313
- simple step
14-
`tpcc_load 127.0.0.1:3306 tpcc1000 root "" 1000`
14+
`tpcc_load -h127.0.0.1 -d tpcc1000 -u root -p "" -w 1000`
1515
|hostname:port| |dbname| |user| |password| |WAREHOUSES|
1616
ref. tpcc_load --help for all options
1717
- load data in parallel

load.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
export LD_LIBRARY_PATH=/usr/local/mysql/lib/mysql/
22
DBNAME=$1
33
WH=$2
4-
HOST=localhost
4+
HOST=127.0.0.1
55
STEP=100
66

7-
./tpcc_load $HOST $DBNAME root "" $WH 1 1 $WH >> 1.out &
7+
./tpcc_load -h $HOST -d $DBNAME -u root -p "" -w $WH -l 1 -m 1 -n $WH >> 1.out &
88

99
x=1
1010

1111
while [ $x -le $WH ]
1212
do
1313
echo $x $(( $x + $STEP - 1 ))
14-
./tpcc_load $HOST $DBNAME root "" $WH 2 $x $(( $x + $STEP - 1 )) >> 2_$x.out &
15-
./tpcc_load $HOST $DBNAME root "" $WH 3 $x $(( $x + $STEP - 1 )) >> 3_$x.out &
16-
./tpcc_load $HOST $DBNAME root "" $WH 4 $x $(( $x + $STEP - 1 )) >> 4_$x.out &
14+
./tpcc_load -h $HOST -d $DBNAME -u root -p "" -w $WH -l 2 -m $x -n $(( $x + $STEP - 1 )) >> 2_$x.out &
15+
./tpcc_load -h $HOST -d $DBNAME -u root -p "" -w $WH -l 3 -m $x -n $(( $x + $STEP - 1 )) >> 3_$x.out &
16+
./tpcc_load -h $HOST -d $DBNAME -u root -p "" -w $WH -l 4 -m $x -n $(( $x + $STEP - 1 )) >> 4_$x.out &
1717
x=$(( $x + $STEP ))
1818
done
1919

src/load.c

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <stdio.h>
1212
#include <string.h>
13+
#include <unistd.h>
1314
#include <ctype.h>
1415
#include <stdlib.h>
1516
#include <time.h>
@@ -75,70 +76,80 @@ main(argc, argv)
7576
char db_password[DB_STRING_MAX];
7677
int port= 3306;
7778

78-
int i;
79+
int i,c;
7980

8081
MYSQL* resp;
8182

8283
/* initialize */
8384
count_ware = 0;
8485

8586
printf("*************************************\n");
86-
printf("*** ###easy### TPC-C Data Loader ***\n");
87+
printf("*** TPCC-mysql Data Loader ***\n");
8788
printf("*************************************\n");
8889

89-
/* Parse args */
90-
if (argc != 9) {
91-
if (argc != 6) {
92-
fprintf(stderr,
93-
"\n usage: tpcc_load [server] [DB] [user] [pass] [warehouse]\n"
94-
" OR\n"
95-
" tpcc_load [server] [DB] [user] [pass] [warehouse] [part] [min_wh] [max_wh]\n\n"
96-
" * [part]: 1=ITEMS 2=WAREHOUSE 3=CUSTOMER 4=ORDERS\n"
97-
);
98-
exit(1);
99-
}
100-
}else{
90+
/* Parse args */
91+
92+
while ( (c = getopt(argc, argv, "h:P:d:u:p:w:l:m:n:")) != -1) {
93+
switch (c) {
94+
case 'h':
95+
printf ("option h with value '%s'\n", optarg);
96+
strncpy(connect_string, optarg, DB_STRING_MAX);
97+
break;
98+
case 'd':
99+
printf ("option d with value '%s'\n", optarg);
100+
strncpy(db_string, optarg, DB_STRING_MAX);
101+
break;
102+
case 'u':
103+
printf ("option u with value '%s'\n", optarg);
104+
strncpy(db_user, optarg, DB_STRING_MAX);
105+
break;
106+
case 'p':
107+
printf ("option p with value '%s'\n", optarg);
108+
strncpy(db_password, optarg, DB_STRING_MAX);
109+
break;
110+
case 'w':
111+
printf ("option w with value '%s'\n", optarg);
112+
count_ware = atoi(optarg);
113+
break;
114+
case 'l':
115+
printf ("option l with value '%s'\n", optarg);
116+
part_no = atoi(optarg);
101117
particle_flg = 1;
102-
}
103-
104-
if ( strlen(argv[1]) >= DB_STRING_MAX ) {
105-
fprintf(stderr, "\n server phrase is too long\n");
106-
exit(1);
107-
}
108-
if ( strlen(argv[2]) >= DB_STRING_MAX ) {
109-
fprintf(stderr, "\n DBname phrase is too long\n");
110-
exit(1);
111-
}
112-
if ( strlen(argv[3]) >= DB_STRING_MAX ) {
113-
fprintf(stderr, "\n user phrase is too long\n");
114-
exit(1);
115-
}
116-
if ( strlen(argv[4]) >= DB_STRING_MAX ) {
117-
fprintf(stderr, "\n pass phrase is too long\n");
118-
exit(1);
119-
}
120-
if ((count_ware = atoi(argv[5])) <= 0) {
121-
fprintf(stderr, "\n expecting positive number of warehouses\n");
122-
exit(1);
123-
}
124-
//strcpy(connect_string, argv[1]);
125-
parse_host(connect_string, argv[1]);
126-
port= parse_port(argv[1]);
127-
strcpy( db_string, argv[2] );
128-
strcpy( db_user, argv[3] );
129-
strcpy( db_password, argv[4] );
118+
break;
119+
case 'm':
120+
printf ("option m with value '%s'\n", optarg);
121+
min_ware = atoi(optarg);
122+
break;
123+
case 'n':
124+
printf ("option n with value '%s'\n", optarg);
125+
max_ware = atoi(optarg);
126+
break;
127+
case 'P':
128+
printf ("option P with value '%s'\n", optarg);
129+
port = atoi(optarg);
130+
break;
131+
case '?':
132+
printf("Usage: tpcc_load -h server_host -P port -d database_name -u mysql_user -p mysql_password -w warehouses -l part -m min_wh -n max_wh\n");
133+
printf("* [part]: 1=ITEMS 2=WAREHOUSE 3=CUSTOMER 4=ORDERS\n");
134+
exit(0);
135+
default:
136+
printf ("?? getopt returned character code 0%o ??\n", c);
137+
}
138+
}
139+
if (optind < argc) {
140+
printf ("non-option ARGV-elements: ");
141+
while (optind < argc)
142+
printf ("%s ", argv[optind++]);
143+
printf ("\n");
144+
}
130145

131146
if(strcmp(connect_string,"l")==0){
132147
is_local = 1;
133148
}else{
134149
is_local = 0;
135150
}
136151

137-
if(particle_flg==1){
138-
part_no = atoi(argv[6]);
139-
min_ware = atoi(argv[7]);
140-
max_ware = atoi(argv[8]);
141-
}else{
152+
if(particle_flg==0){
142153
min_ware = 1;
143154
max_ware = count_ware;
144155
}

0 commit comments

Comments
 (0)