CUBRID Engine  latest
cas_runner.c
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 
20 /*
21  * cas_runner.c -
22  */
23 
24 #ident "$Id$"
25 
26 #include <stdio.h>
27 #include <string.h>
28 #include <stdlib.h>
29 #include <errno.h>
30 #include <signal.h>
31 #include <math.h>
32 #if defined(WINDOWS)
33 #include <winsock2.h>
34 #include <windows.h>
35 #include <process.h>
36 #include <sys/timeb.h>
37 #else
38 #include <pthread.h>
39 #include <unistd.h>
40 #endif
41 
42 #include "cubrid_getopt.h"
43 #include "cas_common.h"
44 #include "porting.h"
45 #include "cas_cci.h"
46 #include "broker_log_util.h"
47 
48 #define PRINT_CCI_ERROR(ERRCODE, CCI_ERROR, result_fp) \
49  do { \
50  T_CCI_ERROR *cci_error_p = CCI_ERROR; \
51  if ((ERRCODE) == CCI_ER_DBMS && cci_error_p != NULL) { \
52  if (!ignore_error(cci_error_p->err_code)) { \
53  cas_error_flag = 1; \
54  if (cubrid_manager_run) { \
55  fprintf(cas_error_fp, "server error : (%d) %s\n", cci_error_p->err_code, cci_error_p->err_msg); \
56  } \
57  else { \
58  if (result_fp) { \
59  fprintf(result_fp, "%s: server error : %d %s\n", exec_script_file, cci_error_p->err_code, cci_error_p->err_msg); \
60  } \
61  fprintf(cas_error_fp, "%s: server error : %d %s\n", exec_script_file, cci_error_p->err_code, cci_error_p->err_msg); \
62  } \
63  } \
64  } \
65  else if ((ERRCODE) < 0) { \
66  char msgbuf[1024] = ""; \
67  cas_error_flag = 1; \
68  if (cubrid_manager_run) { \
69  cci_get_error_msg(ERRCODE, NULL, msgbuf, sizeof(msgbuf)); \
70  fprintf(cas_error_fp, "%s\n", msgbuf); \
71  } \
72  else { \
73  cci_get_error_msg(ERRCODE, NULL, msgbuf, sizeof(msgbuf)); \
74  if (result_fp) { \
75  fprintf(result_fp, "%s: cci_error : %d %s\n", exec_script_file, (ERRCODE), msgbuf); \
76  } \
77  fprintf(cas_error_fp, "%s: cci_error : %d %s\n", exec_script_file, (ERRCODE), msgbuf); \
78  } \
79  } \
80  } while (0)
81 
82 #define FREE_BIND_INFO(NUM_BIND, BIND_INFO) \
83  do { \
84  int i; \
85  for (i=0 ; i < NUM_BIND ; i++) { \
86  FREE_MEM(BIND_INFO[i].value); \
87  } \
88  NUM_BIND = 0; \
89  } while (0)
90 
91 #define MAX_NODE_INFO 100
92 #define MAX_IGN_SRV_ERR 100
93 
94 #if defined(WINDOWS)
95 #define strcasecmp(X, Y) _stricmp(X, Y)
96 #ifdef THREAD_FUNC
97 #undef THREAD_FUNC
98 #endif
99 #define THREAD_FUNC unsigned __stdcall
100 #define SLEEP_SEC(X) Sleep((X) * 1000)
101 #define SLEEP_MILISEC(sec, msec) Sleep((sec) * 1000 + (msec))
102 #else
103 #define THREAD_FUNC void*
104 #define SLEEP_SEC(X) sleep(X)
105 #define SLEEP_MILISEC(sec, msec) \
106  do { \
107  struct timeval sleep_time_val; \
108  sleep_time_val.tv_sec = sec; \
109  sleep_time_val.tv_usec = (msec) * 1000; \
110  select(0, 0, 0, 0, &sleep_time_val); \
111  } while(0)
112 #endif
113 
114 #define STRDUP(TARGET, SOURCE) \
115  do { \
116  if(TARGET != NULL) free(TARGET); \
117  TARGET = strdup (SOURCE); \
118  } while(0)
119 
120 #define SERVER_HANDLE_ALLOC_SIZE (MAX_SERVER_H_ID + 1)
121 
122 typedef struct t_bind_info T_BIND_INFO;
124 {
125  char *value;
126  int type;
127  int len;
128 };
129 
130 typedef struct t_node_info T_NODE_INFO;
132 {
133  char *node_name;
134  char *dbname;
135  char *ip;
136  char *dbuser;
137  char *dbpasswd;
138  int port;
139 };
140 
141 static double calc_stddev (double *t, double avg, int count);
142 static double calc_avg (double *t, int count);
143 static void calc_min_max (double *t, int count, double *min, double *max);
144 static int get_args (int argc, char *argv[]);
145 static int read_conf (void);
146 static void cas_runner (FILE * fp, FILE * result_fp, double *ret_exec_time, double *ret_prepare_time);
147 static THREAD_FUNC thr_main (void *arg);
148 static int process_execute (char *msg, int *req_h, int num_bind, T_BIND_INFO * bind_info, FILE * result_fp,
149  double *sum_execute_time);
150 static int process_bind (char *msg, int *num_bind_p, T_BIND_INFO * bind_info);
151 static int process_endtran (int con_h, int *req_h, FILE * result_fp);
152 static int process_close_req (char *linebuf, int *req_h, FILE * result_fp);
153 static void print_result (int cci_res, int req_id, FILE * fp);
154 static void free_node (T_NODE_INFO * node);
155 static int make_node_info (T_NODE_INFO * node, char *node_name, char *info_str);
156 static int set_args_with_node_info (char *node_name);
157 static int ignore_error (int code);
158 static char *make_sql_stmt (char *src);
159 
160 const char *cci_client_name = "JDBC";
161 
162 static char *broker_host = NULL;
163 static int broker_port = 0;
164 static char *dbname = NULL;
165 static char *dbuser = NULL;
166 static char *dbpasswd = NULL;
167 static int num_thread = 1;
168 static int repeat_count = 1;
169 static char *exec_script_file;
170 static int batch_mode = 0;
171 static char *result_file = NULL;
172 static char *cas_err_file = NULL;
173 static int fork_delay = 0;
174 static char *node_name = NULL;
175 static int think_time = 0;
176 static int qa_test_flag = 0;
177 static int num_replica = 1;
178 static int dump_query_plan = 0;
179 static int autocommit_mode = 0;
180 static int statdump_mode = 0;
181 
182 static double *run_time_exec;
183 static FILE *cas_error_fp;
184 static int cas_error_flag = 0;
185 static int cubrid_manager_run = 0;
186 
188 static int num_node = 0;
190 static int num_ign_srv_err = 0;
191 
192 int
193 main (int argc, char *argv[])
194 {
195  pthread_t *thr_id;
196  int i;
197  const char *err_str = "-";
198  double avg;
199  double stddev;
200  double min, max;
201  char *cm_out_msg_fname = NULL;
202  FILE *cm_out_msg_fp = NULL;
203 
204 #if !defined(WINDOWS)
205  signal (SIGPIPE, SIG_IGN);
206 #endif
207 
208  if (read_conf () < 0)
209  {
210  return -1;
211  }
212 
213  if (get_args (argc, argv) < 0)
214  return -1;
215 
216  cm_out_msg_fname = getenv ("CUBRID_MANAGER_OUT_MSG_FILE");
217  if (cm_out_msg_fname != NULL)
218  {
219  cubrid_manager_run = 1;
220  }
221 
222  if (node_name != NULL)
223  {
225  {
226  fprintf (stderr, "error:node (%s)\n", node_name);
227  return -1;
228  }
229  }
230 
231  if (broker_host == NULL || broker_host[0] == '\0')
232  {
233  fprintf (stderr, "error:broker_host\n");
234  return -1;
235  }
236  if (broker_port <= 0)
237  {
238  fprintf (stderr, "error:broker_port(%d)\n", broker_port);
239  return -1;
240  }
241  if (dbname == NULL || dbname[0] == '\0')
242  {
243  fprintf (stderr, "errorr:dbname\n");
244  return -1;
245  }
246  if (dbuser == NULL)
247  dbuser = (char *) "PUBLIC";
248  if (dbpasswd == NULL)
249  dbpasswd = (char *) "";
250 
251  cas_error_fp = fopen (cas_err_file, (batch_mode ? "a" : "w"));
252  if (cas_error_fp == NULL)
253  {
254  fprintf (stderr, "fopen error [%s]\n", cas_err_file);
255  return -1;
256  }
257 
258 #ifdef DUP_RUN
259  num_thread = 1;
260 #endif
261 
262  if (repeat_count < 1)
263  repeat_count = 1;
264  if (num_thread < 1)
265  num_thread = 1;
266  if (num_replica < 1)
267  num_replica = 1;
268 
270  {
271  fprintf (stdout, "broker_host = %s\n", broker_host);
272  fprintf (stdout, "broker_port = %d\n", broker_port);
273  fprintf (stdout, "num_thread = %d\n", num_thread);
274  fprintf (stdout, "repeat = %d\n", repeat_count);
275  fprintf (stdout, "dbname = %s\n", dbname);
276  fprintf (stdout, "dbuser = %s\n", dbuser);
277  fprintf (stdout, "dbpasswd = %s\n", dbpasswd);
278  if (result_file)
279  {
280  fprintf (stdout, "result_file = %s\n", result_file);
281  }
282  }
283 
284  thr_id = (pthread_t *) malloc (sizeof (pthread_t) * num_thread);
285  if (thr_id == NULL)
286  {
287  fprintf (stderr, "malloc error\n");
288  return -1;
289  }
290  run_time_exec = (double *) malloc (sizeof (double) * num_thread * repeat_count);
291  if (run_time_exec == NULL)
292  {
293  FREE_MEM (thr_id);
294  fprintf (stderr, "malloc error\n");
295  return -1;
296  }
297 
298  cci_init ();
299 
300  if (qa_test_flag == 1)
301  {
302  int *con_handle;
303  T_CCI_ERROR cci_error;
304  con_handle = (int *) malloc (sizeof (int) * num_thread);
305  if (con_handle == NULL)
306  {
307  FREE_MEM (thr_id);
308  fprintf (stderr, "malloc error\n");
309  return -1;
310  }
311  for (i = 0; i < num_thread; i++)
312  {
313  con_handle[i] = cci_connect (broker_host, broker_port, dbname, dbuser, dbpasswd);
314  cci_get_db_version (con_handle[i], NULL, 0);
315  }
316  for (i = 0; i < num_thread; i++)
317  {
318  cci_disconnect (con_handle[i], &cci_error);
319  }
320  FREE_MEM (con_handle);
321  }
322 
323  for (i = 0; i < num_thread; i++)
324  {
325  if (i > 0 && fork_delay > 0)
326  {
328  }
329 
330  if (pthread_create (&thr_id[i], NULL, thr_main, (void *) &i) < 0)
331  {
332  FREE_MEM (thr_id);
333  perror ("Error:cannot create thread");
334  return -1;
335  }
336  }
337 
338  for (i = 0; i < num_thread; i++)
339  {
340  if (pthread_join (thr_id[i], NULL) < 0)
341  {
342  perror ("pthread_join");
343  }
344  }
345 
346  if (cm_out_msg_fname != NULL)
347  {
348  cm_out_msg_fp = fopen (cm_out_msg_fname, "w");
349  }
350 
351  if (cm_out_msg_fp == NULL)
352  {
353  cm_out_msg_fp = stdout;
354  }
355 
356  fclose (cas_error_fp);
357  if (cas_error_flag)
358  {
359  FILE *err_fp;
360  if (cm_out_msg_fname != NULL)
361  {
362  err_fp = cm_out_msg_fp;
363  }
364  else
365  {
366  err_fp = stderr;
367  }
368  err_str = "ERR";
369  fprintf (err_fp, "\n");
370  fprintf (err_fp, "********************************\n");
371  if (!cubrid_manager_run)
372  {
373  fprintf (err_fp, "cas error : %s\n", cas_err_file);
374  }
375  if (!batch_mode)
376  {
377  char buf[1024];
378  FILE *fp;
379  size_t readlen;
380  fp = fopen (cas_err_file, "r");
381  if (fp != NULL)
382  {
383  while ((readlen = fread (buf, 1, sizeof (buf), fp)) > 0)
384  {
385  if (readlen > sizeof (buf))
386  {
387  readlen = sizeof (buf);
388  }
389  fwrite (buf, 1, readlen, err_fp);
390  }
391  fclose (fp);
392  }
393  }
394  fprintf (err_fp, "********************************\n");
395  }
396  else
397  {
398  if (!batch_mode)
399  unlink (cas_err_file);
400  }
401 
402  avg = calc_avg (run_time_exec, num_thread * repeat_count);
403  stddev = calc_stddev (run_time_exec, avg, num_thread * repeat_count);
404 
405  if (cubrid_manager_run)
406  {
407  calc_min_max (run_time_exec, num_thread * repeat_count, &min, &max);
408  fprintf (cm_out_msg_fp, "min : %.6f\n", min);
409  fprintf (cm_out_msg_fp, "max : %.6f\n", max);
410  fprintf (cm_out_msg_fp, "avg : %.6f\n", avg);
411  fprintf (cm_out_msg_fp, "stddev : %.6f\n", stddev);
412  }
413  else
414  {
415  fprintf (stdout, "%.6f %.6f %s\n", avg, stddev, err_str);
416  }
417 
418  if (cm_out_msg_fname != NULL)
419  {
420  fflush (cm_out_msg_fp);
421  if (cm_out_msg_fp != stdout)
422  {
423  fclose (cm_out_msg_fp);
424  }
425  }
426  FREE_MEM (thr_id);
428 
429  return 0;
430 }
431 
432 static void
433 calc_min_max (double *t, int count, double *min, double *max)
434 {
435  int i;
436  if (count <= 0)
437  {
438  *min = 0;
439  *max = 0;
440  return;
441  }
442  *min = t[0];
443  *max = t[0];
444  for (i = 1; i < count; i++)
445  {
446  if (*min > t[i])
447  *min = t[i];
448  if (*max < t[i])
449  *max = t[i];
450  }
451 }
452 
453 static double
454 calc_avg (double *t, int count)
455 {
456  double sum = 0;
457  int i;
458  for (i = 0; i < count; i++)
459  {
460  sum += t[i];
461  }
462  return (sum / count);
463 }
464 
465 static double
466 calc_stddev (double *t, double avg, int count)
467 {
468  double sum = 0;
469  int i;
470  for (i = 0; i < count; i++)
471  {
472  sum += ((t[i] - avg) * (t[i] - avg));
473  }
474  sum /= count;
475  return (sqrt (sum));
476 }
477 
478 static int
479 get_args (int argc, char *argv[])
480 {
481  int c;
482 
483  while ((c = getopt (argc, argv, "saQbqI:P:d:u:p:t:r:o:e:f:n:h:R:")) != EOF)
484  {
485  switch (c)
486  {
487  case 's':
488  statdump_mode = 1;
489  break;
490  case 'a':
491  autocommit_mode = 1;
492  break;
493  case 'b':
494  batch_mode = 1;
495  break;
496  case 'q':
497  qa_test_flag = 1;
498  break;
499  case 'I':
501  break;
502  case 'P':
503  broker_port = atoi (optarg);
504  break;
505  case 'd':
506  dbname = optarg;
507  break;
508  case 'u':
509  dbuser = optarg;
510  break;
511  case 'p':
513 #if defined (LINUX)
514  memset (optarg, '*', strlen (optarg));
515 #endif
516  break;
517  case 't':
518  num_thread = atoi (optarg);
519  if (num_thread < 1)
520  num_thread = 1;
521  break;
522  case 'r':
523  repeat_count = atoi (optarg);
524  if (repeat_count < 1)
525  repeat_count = 1;
526  break;
527  case 'o':
529  break;
530  case 'e':
532  break;
533  case 'f':
534  fork_delay = atoi (optarg);
535  break;
536  case 'n':
537  node_name = optarg;
538  break;
539  case 'h':
540  think_time = atoi (optarg);
541  break;
542  case 'R':
543  num_replica = atoi (optarg);
544  break;
545  case 'Q':
546  dump_query_plan = 1;
547  break;
548  case '?':
549  goto getargs_err;
550  }
551  }
552 
553  if (optind >= argc)
554  {
555  goto getargs_err;
556  }
557 
558  exec_script_file = argv[optind];
559 
560  if (batch_mode)
561  {
562  if (result_file != NULL && strcmp (result_file, "stdout") == 0)
563  result_file = NULL;
564  }
565 
566  return 0;
567 
568 getargs_err:
569  fprintf (stderr,
570  "usage : %s [OPTION] exec_script_file\n" "\n" "valid options:\n" " -I broker host\n"
571  " -P broker port\n" " -d database name\n" " -u user name\n" " -p user password\n"
572  " -t the number of thread\n" " -r the number of times to execute entire query by each thread\n"
573  " -Q enable to print a plan per query\n" " -o result file\n"
574  " -s enable to print a statdump per query\n" " -a enable auto commit mode\n", argv[0]);
575  return -1;
576 }
577 
578 static THREAD_FUNC
579 thr_main (void *arg)
580 {
581  int id = *(int *) arg;
582  FILE *fp;
583  int i;
584  FILE *result_fp;
585 
586  fp = fopen (exec_script_file, "r");
587  if (fp == NULL)
588  {
589  fprintf (stderr, "fopen error [%s]\n", exec_script_file);
590  goto end;
591  }
592 
593  if (result_file == NULL)
594  {
595  result_fp = NULL;
596  }
597  else if (strcmp (result_file, "stdout") == 0)
598  {
599  result_fp = stdout;
600  }
601  else if (strcmp (result_file, "stderr") == 0)
602  {
603  result_fp = stderr;
604  }
605  else
606  {
607  char result_filename[256];
608  sprintf (result_filename, "%s.%d", result_file, id);
609  result_fp = fopen (result_filename, "w");
610  }
611 
612 #ifndef DUP_RUN
613  if (repeat_count > 1)
614  {
615  cas_runner (fp, result_fp, NULL, NULL);
616  fseek (fp, 0, SEEK_SET);
617  }
618 #endif
619 
620  for (i = 0; i < repeat_count; i++)
621  {
622  double e, p;
623  cas_runner (fp, result_fp, &e, &p);
624  run_time_exec[id * repeat_count + i] = e;
625  fseek (fp, 0, SEEK_SET);
626  if (think_time > 0)
628  }
629 
630  fclose (fp);
631  if (result_fp != NULL && result_fp != stderr && result_fp != stdout)
632  fclose (result_fp);
633 
634 end:
635 #if defined(WINDOWS)
636  return 0;
637 #else
638  return NULL;
639 #endif
640 }
641 
642 static void
643 cas_runner (FILE * fp, FILE * result_fp, double *ret_exec_time, double *ret_prepare_time)
644 {
645  char *sql_stmt = NULL;
646  int con_h = -1;
647  T_CCI_ERROR cci_error;
648  int num_bind = 0;
649  double prepare_time = 0;
650  double sum_execute_time = 0;
651  double sum_prepare_time = 0;
652  char *linebuf = NULL;
653  char *data = NULL;
654  T_BIND_INFO *bind_info = NULL;
655  int *req_h = NULL;
656  int req_stat_h = -1;
657  int error;
658  int ind;
659  int i;
660  T_STRING *linebuf_tstr = NULL;
661 #ifdef DUP_RUN
662  int dup_con_h;
663  int *dup_req_h = NULL;
664 #endif
665 
666  linebuf_tstr = t_string_make (1000);
667  req_h = (int *) malloc (sizeof (int) * SERVER_HANDLE_ALLOC_SIZE);
668  bind_info = (T_BIND_INFO *) malloc (sizeof (T_BIND_INFO) * MAX_BIND_VALUE);
669 #ifdef DUP_RUN
670  dup_req_h = (int *) malloc (sizeof (int) * SERVER_HANDLE_ALLOC_SIZE);
671 #endif
672 
673  if (linebuf_tstr == NULL || req_h == NULL || bind_info == NULL
674 #ifdef DUP_RUN
675  || dup_req_h == NULL
676 #endif
677  )
678  {
679  fprintf (stderr, "malloc error\n");
680  goto end_cas_runner;
681  }
682  memset (req_h, 0, sizeof (int) * SERVER_HANDLE_ALLOC_SIZE);
683  memset (bind_info, 0, sizeof (T_BIND_INFO) * MAX_BIND_VALUE);
684 #ifdef DUP_RUN
685  memset (dup_req_h, 0, sizeof (int) * SERVER_HANDLE_ALLOC_SIZE);
686 #endif
687 
688  con_h = cci_connect (broker_host, broker_port, dbname, dbuser, dbpasswd);
689  if (con_h < 0)
690  {
691  PRINT_CCI_ERROR (con_h, NULL, result_fp);
692  goto end_cas_runner;
693  }
694 #ifdef DUP_RUN
695  dup_con_h = cci_connect (broker_host, broker_port, dbname, dbuser, dbpasswd);
696  if (dup_con_h < 0)
697  {
698  fprintf (stderr, "DUP_RUN cci_connect error\n");
699  goto end_cas_runner;
700  }
701 #endif
702 
703  if (autocommit_mode)
704  {
705  if (cci_set_autocommit (con_h, CCI_AUTOCOMMIT_TRUE) < 0)
706  {
707  fprintf (stderr, "cannot set autocommit mode");
708  goto end_cas_runner;
709  }
710 #ifdef DUP_RUN
711  if (cci_set_autocommit (dup_con_h, CCI_AUTOCOMMIT_TRUE) < 0)
712  {
713  fprintf (stderr, "DUP_RUN cannot set autocommit mode");
714  goto end_cas_runner;
715  }
716 #endif
717  }
718 
719  if (statdump_mode)
720  {
721  req_stat_h = cci_prepare (con_h, "set @collect_exec_stats = 1", 0, &cci_error);
722  if (req_stat_h < 0)
723  {
724  fprintf (stderr, "cci_prepare error\n");
725  }
726  else
727  {
728  int res;
729  error = cci_execute (req_stat_h, 0, 0, &cci_error);
730 
731  res = cci_close_req_handle (req_stat_h);
732  if (res < 0)
733  {
734  fprintf (stderr, "cci_close_req_error\n");
735  req_stat_h = -1;
736  }
737 
738  if (error < 0)
739  {
740  fprintf (stderr, "cci_execute error\n");
741  }
742  else
743  {
744  req_stat_h = cci_prepare (con_h, "show exec statistics", 0, &cci_error);
745  if (req_stat_h < 0)
746  {
747  fprintf (stderr, "cci_prepare error\n");
748  }
749  }
750  }
751  }
752 
753  while (1)
754  {
755  if (ut_get_line (fp, linebuf_tstr, NULL, NULL) < 0)
756  {
757  fprintf (stderr, "malloc error\n");
758  goto end_cas_runner;
759  }
760  if (t_string_len (linebuf_tstr) <= 0)
761  break;
762  linebuf = t_string_str (linebuf_tstr);
763 
764  if (linebuf[strlen (linebuf) - 1] == '\n')
765  linebuf[strlen (linebuf) - 1] = '\0';
766 
767  if (linebuf[0] == 'Q')
768  {
769  FREE_MEM (sql_stmt);
770  sql_stmt = make_sql_stmt (linebuf + 2);
771  if (sql_stmt == NULL)
772  {
773  goto end_cas_runner;
774  }
775 
776  if (result_fp)
777  {
778  fprintf (result_fp, "-------------- query -----------------\n");
779  fprintf (result_fp, "%s\n", sql_stmt);
780  }
781  }
782  else if (linebuf[0] == 'P')
783  {
784  int req_id, prepare_flag;
785  struct timeval begin, end;
786 
787  if (sscanf (linebuf + 2, "%d %d", &req_id, &prepare_flag) < 2)
788  {
789  fprintf (stderr, "file format error : %s\n", linebuf);
790  FREE_MEM (sql_stmt);
791  goto end_cas_runner;
792  }
793  if (req_id < 0 || req_id >= SERVER_HANDLE_ALLOC_SIZE)
794  {
795  fprintf (stderr, "request id error : %d (valid range 0-%d)\n", req_id, SERVER_HANDLE_ALLOC_SIZE - 1);
796  FREE_MEM (sql_stmt);
797  goto end_cas_runner;
798  }
799  gettimeofday (&begin, NULL);
800  req_h[req_id] = cci_prepare (con_h, sql_stmt, prepare_flag, &cci_error);
801  gettimeofday (&end, NULL);
802  prepare_time = ut_diff_time (&begin, &end);
803  sum_prepare_time += prepare_time;
804 
805  if (result_fp)
806  {
807  fprintf (result_fp, "cci_prepare elapsed time : %.3f \n", prepare_time);
808  }
809 
810  if (req_h[req_id] < 0)
811  {
812  fprintf (cas_error_fp, "prepare error\n%s\nrequest id %d\n", linebuf, req_id);
813  PRINT_CCI_ERROR (req_h[req_id], &cci_error, result_fp);
814  }
815 #ifdef DUP_RUN
816  dup_req_h[req_id] = cci_prepare (dup_con_h, sql_stmt, prepare_flag, &cci_error);
817 #endif
818  FREE_MEM (sql_stmt);
819  }
820  else if (linebuf[0] == 'B')
821  {
822  if (process_bind (linebuf, &num_bind, bind_info) < 0)
823  {
824  FREE_BIND_INFO (num_bind, bind_info);
825  goto end_cas_runner;
826  }
827  }
828  else if (linebuf[0] == 'E')
829  {
830  int res;
831  res = process_execute (linebuf, req_h, num_bind, bind_info, result_fp, &sum_execute_time);
832 #ifdef DUP_RUN
833  process_execute (linebuf, dup_req_h, num_bind, bind_info, result_fp, NULL);
834 #endif
835  FREE_BIND_INFO (num_bind, bind_info);
836  num_bind = 0;
837  if (res < 0)
838  goto end_cas_runner;
839  }
840  else if (linebuf[0] == 'C')
841  {
842  if (process_close_req (linebuf, req_h, result_fp) < 0)
843  goto end_cas_runner;
844 #ifdef DUP_RUN
845  process_close_req (linebuf, dup_req_h, result_fp);
846 #endif
847  }
848  else if (linebuf[0] == 'T')
849  {
850  if (process_endtran (con_h, req_h, result_fp) < 0)
851  goto end_cas_runner;
852 #ifdef DUP_RUN
853  if (process_endtran (dup_con_h, dup_req_h, result_fp) < 0)
854  {
855  fprintf (stderr, "DUP_RUN end_transaction error\n");
856  }
857 #endif
858  if (statdump_mode && req_stat_h > 0)
859  {
860  error = cci_execute (req_stat_h, 0, 0, &cci_error);
861  if (error < 0)
862  {
863  fprintf (cas_error_fp, "execute error\nshow exec statistics\nrequest id %d\n", req_stat_h);
864  continue;
865  }
866  if (result_fp)
867  {
868  fprintf (result_fp, "SHOW EXEC STATISTICS\n");
869  }
870 
871  while (1)
872  {
873  error = cci_cursor (req_stat_h, 1, CCI_CURSOR_CURRENT, &cci_error);
874 
875  if (error == CCI_ER_NO_MORE_DATA)
876  {
877  break;
878  }
879 
880  if (error < 0)
881  {
882  fprintf (cas_error_fp, "cursor error\nrequest id %d\n", req_stat_h);
883  PRINT_CCI_ERROR (error, &cci_error, result_fp);
884  break;
885  }
886 
887  error = cci_fetch (req_stat_h, &cci_error);
888  if (error < 0)
889  {
890  fprintf (cas_error_fp, "fetch error\nrequest id %d\n", req_stat_h);
891  PRINT_CCI_ERROR (error, &cci_error, result_fp);
892  break;
893  }
894  for (i = 1; i <= 2; i++)
895  {
896  error = cci_get_data (req_stat_h, i, CCI_A_TYPE_STR, &data, &ind);
897  if (error < 0)
898  {
899  fprintf (cas_error_fp, "get data error\nrequest id %d\n", req_stat_h);
900  PRINT_CCI_ERROR (error, NULL, result_fp);
901  break;
902  }
903  if (ind < 0 || data == NULL)
904  {
905  if (result_fp)
906  {
907  fprintf (result_fp, "<NULL>\t|");
908  }
909  }
910  else
911  {
912  if (result_fp)
913  {
914  fprintf (result_fp, "%s\t|", data);
915  }
916  }
917  }
918  if (result_fp)
919  {
920  fprintf (result_fp, "\n");
921  }
922  }
923  }
924  }
925  else
926  {
927  fprintf (stderr, "file format error : %s\n", linebuf);
928  }
929  }
930 
931 end_cas_runner:
932  if (req_stat_h > 0)
933  {
934  cci_close_req_handle (req_stat_h);
935  }
936 
937  if (con_h > 0)
938  {
939  cci_disconnect (con_h, &cci_error);
940  }
941 #ifdef DUP_RUN
942  if (dup_con_h > 0)
943  {
944  cci_disconnect (dup_con_h, &cci_error);
945  }
946 #endif
947 
948  FREE_MEM (req_h);
949  FREE_MEM (bind_info);
950  if (linebuf_tstr)
951  t_string_free (linebuf_tstr);
952 #ifdef DUP_RUN
953  FREE_MEM (dup_req_h);
954 #endif
955  FREE_MEM (sql_stmt);
956 
957  if (ret_exec_time)
958  *ret_exec_time = sum_execute_time;
959  if (ret_prepare_time)
960  *ret_prepare_time = sum_prepare_time;
961 }
962 
963 static int
964 read_conf (void)
965 {
966  FILE *fp;
967  char read_buf[1024];
968  char buf1[1024], buf2[1024], buf3[1024];
969  int lineno = 0;
970  const char *conf_file;
971  int num_token;
972  char *p;
973 
974  /* set initial error file name */
975  if (cas_err_file == NULL)
976  {
977  cas_err_file = strdup ("cas_error");
978  }
979 
980  conf_file = getenv (CAS_RUNNER_CONF_ENV);
981  if (conf_file == NULL)
982  conf_file = CAS_RUNNER_CONF;
983 
984  fp = fopen (conf_file, "r");
985  if (fp == NULL)
986  {
987  /*
988  * fprintf(stderr, "fopen error [%s]\n", CAS_RUNNER_CONF); return -1; */
989  return 0;
990  }
991 
992  while (fgets (read_buf, sizeof (read_buf), fp))
993  {
994  lineno++;
995 
996  p = strchr (read_buf, '#');
997  if (p)
998  {
999  *p = '\0';
1000  }
1001  num_token = sscanf (read_buf, "%1023s %1023s %1023s", buf1, buf2, buf3);
1002  if (num_token < 2)
1003  {
1004  continue;
1005  }
1006 
1007  if (num_token == 3)
1008  {
1009  if (strcasecmp (buf1, "node") == 0)
1010  {
1011  if (num_node >= MAX_NODE_INFO)
1012  {
1013  goto error;
1014  }
1015  if (make_node_info (&node_table[num_node], buf2, buf3) < 0)
1016  {
1017  continue;
1018  }
1019  num_node++;
1020  }
1021  }
1022  else
1023  {
1024  if (strcasecmp (buf1, "CAS_IP") == 0)
1025  {
1026  STRDUP (broker_host, buf2);
1027  }
1028  else if (strcasecmp (buf1, "CAS_PORT") == 0)
1029  {
1030  broker_port = atoi (buf2);
1031  }
1032  else if (strcasecmp (buf1, "DBNAME") == 0)
1033  {
1034  STRDUP (dbname, buf2);
1035  }
1036  else if (strcasecmp (buf1, "NUM_THREAD") == 0)
1037  {
1038  num_thread = atoi (buf2);
1039  }
1040  else if (strcasecmp (buf1, "DBUSER") == 0)
1041  {
1042  STRDUP (dbuser, buf2);
1043  }
1044  else if (strcasecmp (buf1, "DBPASSWD") == 0)
1045  {
1046  STRDUP (dbpasswd, buf2);
1047  }
1048  else if (strcasecmp (buf1, "REPEAT") == 0)
1049  {
1050  repeat_count = atoi (buf2);
1051  }
1052  else if (strcasecmp (buf1, "RESULT_FILE") == 0)
1053  {
1054  STRDUP (result_file, buf2);
1055  }
1056  else if (strcasecmp (buf1, "CAS_ERROR_FILE") == 0)
1057  {
1058  STRDUP (cas_err_file, buf2);
1059  }
1060  else if (strcasecmp (buf1, "FORK_DELAY") == 0)
1061  {
1062  fork_delay = atoi (buf2);
1063  }
1064  else if (strcasecmp (buf1, "IGNORE_SERVER_ERROR") == 0)
1065  {
1066  int ign_err = atoi (buf2);
1067  if (ign_err < 0)
1068  {
1070  goto error;
1071  ign_srv_err_list[num_ign_srv_err++] = ign_err;
1072  }
1073  }
1074  else
1075  goto error;
1076  }
1077  }
1078 
1079  fclose (fp);
1080  return 0;
1081 
1082 error:
1083  fprintf (stderr, "%s : error [%d] line\n", CAS_RUNNER_CONF, lineno);
1084  fclose (fp);
1085  return -1;
1086 }
1087 
1088 static int
1089 process_bind (char *linebuf, int *num_bind_p, T_BIND_INFO * bind_info)
1090 {
1091  char *p;
1092  int num_bind = *num_bind_p;
1093 
1094  if (num_bind >= MAX_BIND_VALUE)
1095  {
1096  fprintf (stderr, "bind buffer overflow[%d]\n", num_bind);
1097  return -1;
1098  }
1099 
1100  bind_info[num_bind].type = atoi (linebuf + 2);
1101  p = strchr (linebuf + 2, ' ');
1102  if (p == NULL)
1103  {
1104  fprintf (stderr, "file format error : %s\n", linebuf);
1105  return -1;
1106  }
1107 
1108  if ((bind_info[num_bind].type == CCI_U_TYPE_CHAR) || (bind_info[num_bind].type == CCI_U_TYPE_STRING)
1109  || (bind_info[num_bind].type == CCI_U_TYPE_NCHAR) || (bind_info[num_bind].type == CCI_U_TYPE_VARNCHAR)
1110  || (bind_info[num_bind].type == CCI_U_TYPE_BIT) || (bind_info[num_bind].type == CCI_U_TYPE_VARBIT)
1111  || (bind_info[num_bind].type == CCI_U_TYPE_ENUM) || (bind_info[num_bind].type == CCI_U_TYPE_JSON))
1112  {
1113  bind_info[num_bind].len = atoi (p + 1);
1114  p = strchr (p + 1, ' ');
1115  if (p == NULL)
1116  {
1117  fprintf (stderr, "file format error : %s\n", linebuf);
1118  return -1;
1119  }
1120  }
1121  else if (bind_info[num_bind].type == CCI_U_TYPE_BLOB || bind_info[num_bind].type == CCI_U_TYPE_CLOB)
1122  {
1123  fprintf (stderr, "binding BLOB/CLOB is not implemented : %s\nreplaced with NULL value.\n", p + 1);
1124  bind_info[num_bind].type = CCI_U_TYPE_NULL;
1125  }
1126 
1127  bind_info[num_bind].value = strdup (p + 1);
1128  if (bind_info[num_bind].value == NULL)
1129  {
1130  fprintf (stderr, "malloc error\n");
1131  return -1;
1132  }
1133  *num_bind_p = num_bind + 1;
1134  return 0;
1135 }
1136 
1137 static int
1138 process_execute (char *linebuf, int *req_h, int num_bind, T_BIND_INFO * bind_info, FILE * result_fp,
1139  double *sum_execute_time)
1140 {
1141  int req_id, exec_flag;
1142  T_CCI_ERROR cci_error;
1143  struct timeval begin, end;
1144  double elapsed_time = 0;
1145 
1146  if (sscanf (linebuf + 2, "%d %d", &req_id, &exec_flag) < 2)
1147  {
1148  fprintf (stderr, "file format error : %s\n", linebuf);
1149  return -1;
1150  }
1151  if (req_id < 0 || req_id >= SERVER_HANDLE_ALLOC_SIZE)
1152  {
1153  fprintf (stderr, "request id error : %d (valid range 0-%d)\n", req_id, SERVER_HANDLE_ALLOC_SIZE - 1);
1154  return -1;
1155  }
1156 
1157  if (num_replica > 1)
1158  {
1159  exec_flag |= CCI_EXEC_QUERY_ALL;
1160  }
1161 
1162  if (req_h[req_id] > 0)
1163  {
1164  int res;
1165  if (num_bind > 0)
1166  {
1167  int i, k;
1168  for (k = 0; k < num_replica; k++)
1169  {
1170  for (i = 0; i < num_bind; i++)
1171  {
1172  if ((bind_info[i].type == CCI_U_TYPE_VARBIT) || (bind_info[i].type == CCI_U_TYPE_BIT))
1173  {
1174  T_CCI_BIT vptr;
1175  memset ((char *) &vptr, 0x00, sizeof (T_CCI_BIT));
1176  vptr.size = bind_info[i].len;
1177  vptr.buf = (char *) bind_info[i].value;
1178  res =
1179  cci_bind_param (req_h[req_id], (k * num_bind) + i + 1, CCI_A_TYPE_BIT, (void *) &(vptr),
1180  (T_CCI_U_TYPE) bind_info[i].type, CCI_BIND_PTR);
1181  }
1182  else
1183  {
1184  res =
1185  cci_bind_param (req_h[req_id], (k * num_bind) + i + 1, CCI_A_TYPE_STR, bind_info[i].value,
1186  (T_CCI_U_TYPE) bind_info[i].type, 0);
1187  }
1188  if (res < 0)
1189  {
1190  fprintf (cas_error_fp, "bind error\n%s\nrequest id %d bind %d\n", linebuf, req_id, i);
1191  PRINT_CCI_ERROR (res, NULL, result_fp);
1192  }
1193  }
1194  }
1195  }
1196 
1197  if (dump_query_plan)
1198  exec_flag |= CCI_EXEC_QUERY_INFO;
1199 
1200  gettimeofday (&begin, NULL);
1201  res = cci_execute (req_h[req_id], exec_flag, 0, &cci_error);
1202  gettimeofday (&end, NULL);
1203  elapsed_time = ut_diff_time (&begin, &end);
1204  if (!batch_mode && !cubrid_manager_run)
1205  {
1206  fprintf (stdout, "exec_time : %.3f \n", elapsed_time);
1207  }
1208 
1209  if (result_fp)
1210  {
1211  fprintf (result_fp, "cci_execute elapsed_time : %.3f \n", elapsed_time);
1212  }
1213 
1214  if (res < 0)
1215  {
1216  fprintf (cas_error_fp, "execute error\n%s\nrequest id %d\n", linebuf, req_id);
1217  PRINT_CCI_ERROR (res, &cci_error, result_fp);
1218  }
1219  else
1220  {
1221  print_result (res, req_h[req_id], result_fp);
1222  }
1223  }
1224  if (sum_execute_time)
1225  *sum_execute_time += elapsed_time;
1226 
1227  return 0;
1228 }
1229 
1230 static int
1231 process_close_req (char *linebuf, int *req_h, FILE * result_fp)
1232 {
1233  int req_id, res;
1234 
1235  req_id = atoi (linebuf + 2);
1236  if (req_id < 0 || req_id >= SERVER_HANDLE_ALLOC_SIZE)
1237  {
1238  fprintf (cas_error_fp, "close error\n%s\nrequest id %d\n", linebuf, req_id);
1239  PRINT_CCI_ERROR (CCI_ER_REQ_HANDLE, NULL, result_fp);
1240  return 0;
1241  }
1242  if (req_h[req_id] > 0)
1243  {
1244  res = cci_close_req_handle (req_h[req_id]);
1245  if (res < 0)
1246  {
1247  fprintf (cas_error_fp, "close error\n%s\nrequest id %d\n", linebuf, req_id);
1248  PRINT_CCI_ERROR (res, NULL, result_fp);
1249  }
1250  }
1251  req_h[req_id] = 0;
1252  return 0;
1253 }
1254 
1255 static int
1256 process_endtran (int con_h, int *req_h, FILE * result_fp)
1257 {
1258  int res, i;
1259  T_CCI_ERROR cci_error;
1260 
1261  struct timeval begin, end;
1262  double commit_time;
1263 
1264  if (!autocommit_mode)
1265  {
1266  gettimeofday (&begin, NULL);
1267  res = cci_end_tran (con_h, CCI_TRAN_ROLLBACK, &cci_error);
1268  gettimeofday (&end, NULL);
1269  commit_time = ut_diff_time (&begin, &end);
1270 
1271  if (result_fp)
1272  {
1273  fprintf (result_fp, "cci_end_tran elapsed_time : %.3f \n", commit_time);
1274  }
1275 
1276  if (res < 0)
1277  {
1278  fprintf (cas_error_fp, "end tran error\nconnection handle id %d\n", con_h);
1279  }
1280  PRINT_CCI_ERROR (res, &cci_error, result_fp);
1281  }
1282 
1283  for (i = 0; i < SERVER_HANDLE_ALLOC_SIZE; i++)
1284  {
1285  req_h[i] = 0;
1286  }
1287 
1288  return 0;
1289 }
1290 
1291 static void
1292 print_result (int cci_res, int req_id, FILE * result_fp)
1293 {
1294  int column_count;
1295  int res;
1296  int i;
1297  int ind;
1298  char *buffer;
1299  T_CCI_ERROR cci_error;
1300  int num_tuple = 0;
1301  T_CCI_CUBRID_STMT cmd_type;
1302  char *plan;
1303 
1304  if (result_fp == NULL)
1305  return;
1306 
1307  fprintf (result_fp, "cci_execute:%d\n", cci_res);
1308 
1309  if (dump_query_plan)
1310  {
1311  if (cci_get_query_plan (req_id, &plan) >= 0)
1312  {
1313  fprintf (result_fp, "---------- query plan --------------\n");
1314  fprintf (result_fp, "%s\n", (plan ? plan : ""));
1315  cci_query_info_free (plan);
1316  }
1317  }
1318 
1319 
1320  cci_get_result_info (req_id, &cmd_type, &column_count);
1321 
1322 /*
1323  if (cmd_type == CUBRID_STMT_CALL_SP) {
1324  column_count = cci_get_bind_num(req_id);
1325  printf("col cnt = %d\n", column_count);
1326  }
1327 */
1328 
1329  res = cci_cursor (req_id, 1, CCI_CURSOR_FIRST, &cci_error);
1330  if (res == CCI_ER_NO_MORE_DATA || column_count <= 0)
1331  return;
1332  if (res < 0)
1333  {
1334  fprintf (cas_error_fp, "cursor error\nrequest id %d\n", req_id);
1335  PRINT_CCI_ERROR (res, &cci_error, result_fp);
1336  return;
1337  }
1338 
1339  fprintf (result_fp, "---------- query result --------------\n");
1340 
1341  while (1)
1342  {
1343  res = cci_fetch (req_id, &cci_error);
1344  if (res < 0)
1345  {
1346  fprintf (cas_error_fp, "fetch error\nrequest id %d\n", req_id);
1347  PRINT_CCI_ERROR (res, &cci_error, result_fp);
1348  break;
1349  }
1350  for (i = 0; i < column_count; i++)
1351  {
1352  res = cci_get_data (req_id, i + 1, CCI_A_TYPE_STR, &buffer, &ind);
1353  if (res < 0)
1354  {
1355  fprintf (cas_error_fp, "get data error\nrequest id %d\n", req_id);
1356  PRINT_CCI_ERROR (res, NULL, result_fp);
1357  break;
1358  }
1359  if (ind < 0 || buffer == NULL)
1360  fprintf (result_fp, "<NULL>|");
1361  else
1362  fprintf (result_fp, "%s|", buffer);
1363  }
1364  fprintf (result_fp, "\n");
1365  num_tuple++;
1366 
1367  if (cmd_type == CUBRID_STMT_CALL_SP)
1368  {
1369  break;
1370  }
1371  else
1372  {
1373  res = cci_cursor (req_id, 1, CCI_CURSOR_CURRENT, &cci_error);
1374  if (res == CCI_ER_NO_MORE_DATA)
1375  break;
1376  if (res < 0)
1377  {
1378  fprintf (cas_error_fp, "cursor error\nrequest id %d\n", req_id);
1379  PRINT_CCI_ERROR (res, NULL, result_fp);
1380  break;
1381  }
1382  }
1383  }
1384 
1385  fprintf (result_fp, "-- %d rows ----------------------------\n", num_tuple);
1386 }
1387 
1388 static int
1389 make_node_info (T_NODE_INFO * node, char *node_name, char *info_str)
1390 {
1391  char *p;
1392  char *str = NULL;
1393  int i;
1394  char *token[5];
1395 
1396  memset (node, 0, sizeof (T_NODE_INFO));
1397 
1398  trim (node_name);
1399 
1400  info_str = strdup (info_str);
1401  if (info_str == NULL)
1402  {
1403  fprintf (stderr, "malloc error\n");
1404  return -1;
1405  }
1406  trim (info_str);
1407 
1408  str = info_str;
1409  token[0] = str;
1410  for (i = 1; i < 5; i++)
1411  {
1412  p = strchr (str, ':');
1413  if (p == NULL)
1414  goto err;
1415  *p = '\0';
1416  str = p + 1;
1417  token[i] = str;
1418  }
1419 
1420  node->node_name = strdup (node_name);
1421  node->dbname = strdup (token[0]);
1422  node->ip = strdup (token[1]);
1423  node->port = atoi (token[2]);
1424  node->dbuser = strdup (token[3]);
1425  node->dbpasswd = strdup (token[4]);
1426 
1427  if (node->node_name == NULL || node->dbname == NULL || node->ip == NULL || node->dbuser == NULL
1428  || node->dbpasswd == NULL)
1429  {
1430  goto err;
1431  }
1432 
1433  FREE_MEM (info_str);
1434  return 0;
1435 
1436 err:
1437  FREE_MEM (info_str);
1438  free_node (node);
1439  fprintf (stderr, "invalid node format (%s)\n", info_str);
1440  return -1;
1441 }
1442 
1443 static void
1445 {
1446  FREE_MEM (node->node_name);
1447  FREE_MEM (node->dbname);
1448  FREE_MEM (node->ip);
1449  FREE_MEM (node->dbuser);
1450  FREE_MEM (node->dbpasswd);
1451 }
1452 
1453 static int
1455 {
1456  int i;
1457  T_NODE_INFO *node;
1458 
1459  node = NULL;
1460  for (i = 0; i < num_node; i++)
1461  {
1462  if (strcasecmp (node_table[i].node_name, node_name) == 0)
1463  {
1464  node = &node_table[i];
1465  break;
1466  }
1467  }
1468  if (node == NULL)
1469  return -1;
1470 
1471  if (dbname == NULL)
1472  dbname = node->dbname;
1473  if (broker_host == NULL)
1474  broker_host = node->ip;
1475  if (broker_port == 0)
1476  broker_port = node->port;
1477  if (dbuser == NULL)
1478  dbuser = node->dbuser;
1479  if (dbpasswd == NULL)
1480  dbpasswd = node->dbpasswd;
1481  return 0;
1482 }
1483 
1484 static int
1485 ignore_error (int code)
1486 {
1487  int i;
1488  for (i = 0; i < num_ign_srv_err; i++)
1489  {
1490  if (ign_srv_err_list[i] == code)
1491  return 1;
1492  }
1493  return 0;
1494 }
1495 
1496 static char *
1497 make_sql_stmt (char *src)
1498 {
1499  char *p;
1500  char *tmp;
1501  int query_len;
1502  char *query;
1503 
1504  tmp = (char *) malloc (strlen (src) + 3);
1505  if (tmp == NULL)
1506  {
1507  fprintf (stderr, "malloc error\n");
1508  return NULL;
1509  }
1510  strcpy (tmp, src);
1511  for (p = tmp; *p; p++)
1512  {
1513  if (*p == 1)
1514  *p = '\n';
1515  }
1516 
1517  if (cubrid_manager_run)
1518  {
1519  query_len = (int) strlen (tmp);
1520  }
1521  else
1522  {
1523  trim (tmp);
1524  query_len = (int) strlen (tmp);
1525  if (query_len > 0)
1526  {
1527  if (tmp[query_len - 1] != ';')
1528  {
1529  tmp[query_len++] = ';';
1530  }
1531  tmp[query_len++] = '\n';
1532  tmp[query_len] = '\0';
1533  }
1534  }
1535 
1536  if (num_replica == 1)
1537  {
1538  query = tmp;
1539  }
1540  else
1541  {
1542  int i;
1543  int offset = 0;
1544  query = (char *) malloc ((query_len + 1) * num_replica);
1545  if (query == NULL)
1546  {
1547  fprintf (stderr, "malloc error\n");
1548  FREE_MEM (tmp);
1549  return NULL;
1550  }
1551  for (i = 0; i < num_replica; i++)
1552  {
1553  strcpy (query + offset, tmp);
1554  offset += query_len;
1555  }
1556  FREE_MEM (tmp);
1557  }
1558  return query;
1559 }
DllImport int optind
char * trim(char *str)
Definition: porting.c:2260
DllImport char * optarg
char * ip
Definition: cas_runner.c:135
static int make_node_info(T_NODE_INFO *node, char *node_name, char *info_str)
Definition: cas_runner.c:1389
#define CAS_RUNNER_CONF_ENV
Definition: cas_common.h:42
static char * dbuser
Definition: cas_runner.c:165
int getopt(int, char *const *, const char *)
static int process_close_req(char *linebuf, int *req_h, FILE *result_fp)
Definition: cas_runner.c:1231
int argc
Definition: dynamic_load.c:951
static int process_endtran(int con_h, int *req_h, FILE *result_fp)
Definition: cas_runner.c:1256
static int broker_port
Definition: cas_runner.c:163
static char * exec_script_file
Definition: cas_runner.c:169
#define MAX_IGN_SRV_ERR
Definition: cas_runner.c:92
static int num_replica
Definition: cas_runner.c:177
static int fork_delay
Definition: cas_runner.c:173
static THREAD_FUNC thr_main(void *arg)
Definition: cas_runner.c:579
static int ign_srv_err_list[MAX_IGN_SRV_ERR]
Definition: cas_runner.c:189
void t_string_free(T_STRING *t_str)
static int set_args_with_node_info(char *node_name)
Definition: cas_runner.c:1454
static int num_ign_srv_err
Definition: cas_runner.c:190
static char * dbname
Definition: cas_runner.c:164
int t_string_len(T_STRING *t_str)
static int think_time
Definition: cas_runner.c:175
#define MAX_NODE_INFO
Definition: cas_runner.c:91
static void cas_runner(FILE *fp, FILE *result_fp, double *ret_exec_time, double *ret_prepare_time)
Definition: cas_runner.c:643
char * dbpasswd
Definition: cas_runner.c:137
static double calc_avg(double *t, int count)
Definition: cas_runner.c:454
static int cubrid_manager_run
Definition: cas_runner.c:185
static int autocommit_mode
Definition: cas_runner.c:179
static FILE * cas_error_fp
Definition: cas_runner.c:183
static char * node_name
Definition: cas_runner.c:174
char * value
Definition: cas_runner.c:125
#define THREAD_FUNC
Definition: cas_runner.c:103
int main(int argc, char *argv[])
Definition: cas_runner.c:193
char * t_string_str(T_STRING *t_str)
char * dbname
Definition: cas_runner.c:134
static double calc_stddev(double *t, double avg, int count)
Definition: cas_runner.c:466
static void calc_min_max(double *t, int count, double *min, double *max)
Definition: cas_runner.c:433
static int read_conf(void)
Definition: cas_runner.c:964
static int process_bind(char *msg, int *num_bind_p, T_BIND_INFO *bind_info)
Definition: cas_runner.c:1089
#define min(a, b)
static void print_result(int cci_res, int req_id, FILE *fp)
Definition: cas_runner.c:1292
#define SERVER_HANDLE_ALLOC_SIZE
Definition: cas_runner.c:120
#define NULL
Definition: freelistheap.h:34
#define FREE_MEM(PTR)
Definition: cas_common.h:58
#define err(fd,...)
Definition: porting.h:431
static double * run_time_exec
Definition: cas_runner.c:182
#define MAX_BIND_VALUE
Definition: cas_common.h:39
static int num_node
Definition: cas_runner.c:188
int count(int &result, const cub_regex_object &reg, const std::string &src, const int position, const INTL_CODESET codeset)
static int process_execute(char *msg, int *req_h, int num_bind, T_BIND_INFO *bind_info, FILE *result_fp, double *sum_execute_time)
Definition: cas_runner.c:1138
static int statdump_mode
Definition: cas_runner.c:180
#define max(a, b)
static void error(const char *msg)
Definition: gencat.c:331
static int repeat_count
Definition: cas_runner.c:168
#define STRDUP(TARGET, SOURCE)
Definition: cas_runner.c:114
char * node_name
Definition: cas_runner.c:133
static int dump_query_plan
Definition: cas_runner.c:178
static int qa_test_flag
Definition: cas_runner.c:176
const char ** argv
Definition: dynamic_load.c:952
static char * cas_err_file
Definition: cas_runner.c:172
#define strlen(s1)
Definition: intl_support.c:43
static void free_node(T_NODE_INFO *node)
Definition: cas_runner.c:1444
static int num_thread
Definition: cas_runner.c:167
static char * broker_host
Definition: cas_runner.c:162
#define CAS_RUNNER_CONF
Definition: cas_common.h:41
double ut_diff_time(struct timeval *begin, struct timeval *end)
int i
Definition: dynamic_load.c:954
static T_NODE_INFO node_table[MAX_NODE_INFO]
Definition: cas_runner.c:187
#define PRINT_CCI_ERROR(ERRCODE, CCI_ERROR, result_fp)
Definition: cas_runner.c:48
T_STRING * t_string_make(int init_size)
static int batch_mode
Definition: cas_runner.c:170
char * strdup(const char *str)
Definition: porting.c:901
static int ignore_error(int code)
Definition: cas_runner.c:1485
const char * cci_client_name
Definition: cas_runner.c:160
static char * result_file
Definition: cas_runner.c:171
char * dbuser
Definition: cas_runner.c:136
static char * dbpasswd
Definition: cas_runner.c:166
static int get_args(int argc, char *argv[])
Definition: cas_runner.c:479
static char * make_sql_stmt(char *src)
Definition: cas_runner.c:1497
int ut_get_line(FILE *fp, T_STRING *t_str, char **out_str, int *lineno)
#define SLEEP_SEC(X)
Definition: cas_runner.c:104
const char ** p
Definition: dynamic_load.c:945
#define FREE_BIND_INFO(NUM_BIND, BIND_INFO)
Definition: cas_runner.c:82
static int cas_error_flag
Definition: cas_runner.c:184