CUBRID Engine  latest
broker_tester.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  * broker_tester.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 <assert.h>
31 
32 #if defined(WINDOWS)
33 #include <process.h>
34 #include "porting.h"
35 #include <sys/timeb.h>
36 #else /* WINDOWS */
37 #include <sys/time.h>
38 #endif /* WINDOWS */
39 
40 #include "broker_config.h"
41 #include "broker_util.h"
42 #include "broker_config.h"
43 #include "broker_shm.h"
44 #include "broker_filename.h"
45 #include "cas_protocol.h"
46 #include "cas_common.h"
47 #include "cubrid_getopt.h"
48 #include "cas_cci.h"
49 
50 #if defined(WINDOWS)
51 #include "broker_wsa_init.h"
52 #endif /* WINDOWS */
53 
54 #include "ini_parser.h"
55 
56 #define TESTER_ERR_MSG_SIZE 1024
57 #define TIME_BUF_SIZE 50
58 #define MAX_DISPLAY_LENGTH 20
59 
60 #define DEFAULT_EMPTY_STRING "\0"
61 #define DEFAULT_CUB_USER_NAME "PUBLIC"
62 #define DEFAULT_ORACLE_USER_NAME "scott"
63 #define DEFAULT_ORACLE_PASSWORD "tiger"
64 #define DEFAULT_MYSQL_USER_NAME "root"
65 
66 #define RESULT_FORMAT "%-15s"
67 #define SHARD_ID_FORMAT "%-10d"
68 #define STR_SHARD_ID_FORMAT "%-10s"
69 #define ROWCOUNT_FORMAT "%-15d"
70 #define QUERY_FORMAT "%s"
71 #define STR_ROWCOUNT_FORMAT "%-15s"
72 #define TIME_FORMAT "%-20s"
73 
74 #define PRINT_CCI_ERROR(...) \
75  do { \
76  if (br_tester_info.verbose_mode) \
77  { \
78  if (out_file_fp != NULL) \
79  { \
80  fprintf (out_file_fp , "<Error>\n");\
81  fprintf (out_file_fp , __VA_ARGS__); \
82  } \
83  fprintf (stderr, "<Error>\n"); \
84  fprintf (stderr, __VA_ARGS__); \
85  } \
86  } while(0)
87 
88 #define PRINT_RESULT(...) \
89  do { \
90  if (out_file_fp != NULL) \
91  { \
92  fprintf (out_file_fp ,__VA_ARGS__); \
93  } \
94  fprintf (stdout, __VA_ARGS__); \
95  } while (0)
96 
97 #define PRINT_TITLE(n, ...) \
98  do { \
99  if (out_file_fp != NULL) \
100  { \
101  fprintf (out_file_fp ,__VA_ARGS__); \
102  } \
103  n += fprintf (stdout, __VA_ARGS__); \
104  } while (0)
105 
106 static const char SECTION_NAME[] = "broker";
107 
108 static FILE *out_file_fp;
109 
111 
112 typedef struct
113 {
114  char *db_name;
115  char *db_user;
116  char *db_passwd;
117  char *command;
125 } TESTER_INFO;
126 
128 
129 static int init_tester_info (char *broker_name);
130 static void init_default_conn_info (int appl_server_type);
131 
132 static int get_master_shm_id (void);
133 static void get_time (struct timeval *start_time, char *time, int buf_len);
134 
135 static int execute_test_with_query (int conn_handle, char *query, int shard_flag);
136 static int execute_test (int conn_handle, int shard_flag);
137 
138 static void print_usage (void);
139 static void print_conn_result (char *broker_name, int conn_hd_id);
140 static void print_shard_result (void);
141 static void print_title (int shard_flag);
142 static void print_result (int row_count, int err_code, int shard_flag, int shard_id, char *time, char *query);
143 static int print_result_set (int req, T_CCI_ERROR * err_buf, T_CCI_COL_INFO * col_info, int col_count);
144 static void print_query_test_result (int ret);
145 static void print_line (const char *ch, int num);
146 
147 static void free_br_tester_info (void);
148 static bool is_number_type (T_CCI_U_TYPE type);
149 
150 static int
152 {
153  int i;
154  int master_shm_id = 0;
156  T_SHM_PROXY *shm_proxy = NULL;
157  T_BROKER_INFO *broker_info_p = NULL;
158 
159  master_shm_id = get_master_shm_id ();
160  if (master_shm_id <= 0)
161  {
162  return -1;
163  }
164 
165  shm_br = (T_SHM_BROKER *) uw_shm_open (master_shm_id, SHM_BROKER, SHM_MODE_MONITOR);
166  if (shm_br == NULL)
167  {
168  fprintf (stderr, "master shared memory open error[0x%x]\n", master_shm_id);
169  return -1;
170  }
171 
172  for (i = 0; i < shm_br->num_broker; i++)
173  {
174  if (strcasecmp (broker_name, shm_br->br_info[i].name) == 0)
175  {
176  broker_info_p = &shm_br->br_info[i];
177  break;
178  }
179  }
180 
181  if (broker_info_p == NULL)
182  {
183 
184  fprintf (stderr, "Cannot find Broker [%s]\n", broker_name);
185  uw_shm_detach (shm_br);
186  return -1;
187  }
188 
189  br_tester_info.broker_port = broker_info_p->port;
190  br_tester_info.shard_flag = broker_info_p->shard_flag;
191 
192  if (broker_info_p->shard_flag == ON)
193  {
194  shm_proxy = (T_SHM_PROXY *) uw_shm_open (broker_info_p->proxy_shm_id, SHM_PROXY, SHM_MODE_MONITOR);
195  if (shm_proxy == NULL)
196  {
197  uw_shm_detach (shm_br);
198  fprintf (stderr, "proxy shared memory open error[0x%x]\n", broker_info_p->proxy_shm_id);
199  return -1;
200  }
201  br_tester_info.num_shard = shm_proxy->shm_shard_conn.num_shard_conn;
202 
203  uw_shm_detach (shm_proxy);
204 
205  if (br_tester_info.db_name == NULL)
206  {
207  br_tester_info.db_name = strdup (broker_info_p->shard_db_name);
208  }
209 
210  if (br_tester_info.db_user == NULL)
211  {
212  br_tester_info.db_user = strdup (broker_info_p->shard_db_user);
213  }
214 
215  if (br_tester_info.db_passwd == NULL)
216  {
217  br_tester_info.db_passwd = strdup (broker_info_p->shard_db_password);
218  }
219  }
220 
221  init_default_conn_info (broker_info_p->appl_server);
222 
223  uw_shm_detach (shm_br);
224 
225  return 0;
226 }
227 
228 static void
229 init_default_conn_info (int appl_server_type)
230 {
231  const char *user_name;
232  const char *user_password;
233 
234  if (br_tester_info.db_name == NULL)
235  {
236  br_tester_info.db_name = strdup (DEFAULT_EMPTY_STRING);
237  }
238 
239  switch (appl_server_type)
240  {
241  case APPL_SERVER_CAS:
242  user_name = DEFAULT_CUB_USER_NAME;
243  user_password = DEFAULT_EMPTY_STRING;
244  break;
245 
247  user_name = DEFAULT_ORACLE_USER_NAME;
248  user_password = DEFAULT_ORACLE_PASSWORD;
249  break;
250 
252  user_name = DEFAULT_MYSQL_USER_NAME;
253  user_password = DEFAULT_EMPTY_STRING;
254  break;
255 
256  default:
257  user_name = DEFAULT_EMPTY_STRING;
258  user_password = DEFAULT_EMPTY_STRING;
259  }
260 
261  if (br_tester_info.db_user == NULL)
262  {
263  br_tester_info.db_user = strdup (user_name);
264 
265  FREE_MEM (br_tester_info.db_passwd);
266  br_tester_info.db_passwd = strdup (user_password);
267  }
268 
269  if (br_tester_info.db_passwd == NULL)
270  {
271  br_tester_info.db_passwd = strdup (DEFAULT_EMPTY_STRING);
272  }
273 
274  return;
275 }
276 
277 static int
279 {
280  int master_shm_id = 0;
281  struct stat stat_buf;
282  INI_TABLE *ini = NULL;
283  const char *conf_file;
284  char conf_file_path[BROKER_PATH_MAX];
285 
286  conf_file = envvar_get ("BROKER_CONF_FILE");
287 
288  if (conf_file != NULL)
289  {
290  strncpy_bufsize (conf_file_path, conf_file);
291  }
292  else
293  {
295  }
296 
297  if (stat (conf_file_path, &stat_buf) == 0)
298  {
299  ini = ini_parser_load (conf_file_path);
300  if (ini == NULL)
301  {
302  fprintf (stderr, "cannot open conf file %s\n", conf_file_path);
303  return -1;
304  }
305 
306  if (!ini_findsec (ini, SECTION_NAME))
307  {
308  fprintf (stderr, "cannot find [%s] section in conf file %s\n", SECTION_NAME, conf_file_path);
309  ini_parser_free (ini);
310  return -1;
311  }
312 
313  master_shm_id = ini_gethex (ini, SECTION_NAME, "MASTER_SHM_ID", 0, NULL);
314  if (master_shm_id <= 0)
315  {
316  fprintf (stderr, "cannot find MASTER_SHM_ID in [%s] section\n", SECTION_NAME);
317  }
318  }
319 
320  ini_parser_free (ini);
321 
322  return master_shm_id;
323 }
324 
325 static void
326 get_time (struct timeval *start_time, char *time, int buf_len)
327 {
328  struct timeval end_time;
329  struct timeval elapsed_time;
330 
331  assert (time);
332  assert (start_time);
333 
334  gettimeofday (&end_time, NULL);
335 
336  elapsed_time.tv_sec = end_time.tv_sec - start_time->tv_sec;
337  elapsed_time.tv_usec = end_time.tv_usec - start_time->tv_usec;
338  if (elapsed_time.tv_usec < 0)
339  {
340  elapsed_time.tv_sec--;
341  elapsed_time.tv_usec += 1000000;
342  }
343  snprintf (time, buf_len, "%ld.%06ld sec", elapsed_time.tv_sec, elapsed_time.tv_usec);
344  return;
345 }
346 
347 static int
348 execute_test_with_query (int conn_handle, char *query, int shard_flag)
349 {
350  int shard_id = 0;
351  int err_num = 0;
352  int ret, req, col_count;
353  char time[TIME_BUF_SIZE];
354  char query_with_hint[LINE_MAX];
355  struct timeval start_time;
356  T_CCI_ERROR err_buf;
357  T_CCI_SQLX_CMD cmd_type;
358  T_CCI_COL_INFO *col_info = NULL;
359 
360  do
361  {
362  memset (tester_err_msg, 0, sizeof (tester_err_msg));
363 
364  if (br_tester_info.shard_flag == ON && !br_tester_info.single_shard)
365  {
366  snprintf (query_with_hint, sizeof (query_with_hint), "%s /*+ shard_id(%d) */ /* broker_tester */", query,
367  shard_id);
368  }
369  else
370  {
371  snprintf (query_with_hint, sizeof (query_with_hint), "%s /* broker_tester */", query);
372  }
373 
374  gettimeofday (&start_time, NULL);
375 
376  req = cci_prepare (conn_handle, query_with_hint, 0, &err_buf);
377  if (req < 0)
378  {
379  snprintf_dots_truncate (tester_err_msg, sizeof (tester_err_msg) - 1, "ERROR CODE : %d\n%s\n\n",
380  err_buf.err_code, err_buf.err_msg);
381  ret = -1;
382  err_num++;
383  goto end_tran;
384  }
385 
386  ret = cci_execute (req, 0, 0, &err_buf);
387  if (ret < 0)
388  {
389  snprintf_dots_truncate (tester_err_msg, sizeof (tester_err_msg) - 1, "ERROR CODE : %d\n%s\n\n",
390  err_buf.err_code, err_buf.err_msg);
391  err_num++;
392  goto end_tran;
393  }
394 
395  if (br_tester_info.shard_flag == ON && br_tester_info.single_shard)
396  {
397  int ret;
398 
399  ret = cci_get_shard_id_with_req_handle (req, &shard_id, &err_buf);
400  if (ret < 0)
401  {
402  snprintf_dots_truncate (tester_err_msg, sizeof (tester_err_msg) - 1, "ERROR CODE : %d\n%s\n\n",
403  err_buf.err_code, err_buf.err_msg);
404  err_num++;
405  goto end_tran;
406  }
407  }
408 
409  if (br_tester_info.verbose_mode)
410  {
411  col_info = cci_get_result_info (req, &cmd_type, &col_count);
412  if (cmd_type == CUBRID_STMT_SELECT && col_info == NULL)
413  {
414  snprintf_dots_truncate (tester_err_msg, sizeof (tester_err_msg) - 1, "ERROR CODE : %d\n%s\n\n",
415  err_buf.err_code, err_buf.err_msg);
416  ret = -1;
417  err_num++;
418  }
419  }
420 
421  end_tran:
422  get_time (&start_time, time, sizeof (time));
423 
424  print_result (ret, err_buf.err_code, shard_flag, shard_id, time, query);
425 
426  if (ret >= 0 && br_tester_info.verbose_mode && cmd_type == CUBRID_STMT_SELECT)
427  {
428  ret = print_result_set (req, &err_buf, col_info, col_count);
429  if (ret < 0)
430  {
431  err_num++;
432  }
433  }
434 
435  cci_close_req_handle (req);
436 
437  cci_end_tran (conn_handle, CCI_TRAN_ROLLBACK, &err_buf);
438 
439  if (br_tester_info.shard_flag == OFF || br_tester_info.single_shard)
440  {
441  break;
442  }
443  }
444  while (++shard_id < br_tester_info.num_shard);
445 
446  return (-1 * err_num);
447 }
448 
449 static int
450 execute_test (int conn_handle, int shard_flag)
451 {
452  char query[LINE_MAX];
453  char *p;
454  int ret = 0;
455  int err_num = 0;
456  FILE *file = NULL;
457 
458  file = fopen (br_tester_info.input_file_name, "r");
459  if (file == NULL)
460  {
461  fprintf (stderr, "cannot open input file %s\n", br_tester_info.input_file_name);
462  return -1;
463  }
464 
465  print_title (shard_flag);
466 
467  while (fgets (query, LINE_MAX - 1, file) != NULL)
468  {
469  trim (query);
470 
471  p = strchr (query, '#');
472 
473  if (p != NULL)
474  {
475  *p = '\0';
476  }
477 
478  if (query[0] == '\0')
479  {
480  continue;
481  }
482 
483  ret = execute_test_with_query (conn_handle, query, shard_flag);
484  if (ret < 0)
485  {
486  err_num++;
487  }
488  }
489 
490  fclose (file);
491 
492  return (-1 * err_num);
493 }
494 
495 static void
496 print_line (const char *ch, int num)
497 {
498  int i;
499 
500  if (num <= 0)
501  {
502  return;
503  }
504 
505  for (i = 0; i < num; i++)
506  {
507  PRINT_RESULT (ch);
508  }
509 }
510 
511 static void
513 {
514  printf
515  ("broker_tester <broker_name> [-D <database_name>] [-u <user_name>] [-p <user_password>] [-c <SQL_command>] [-i <input_file>] [-o <output_file>] [-v] [-s]\n");
516  printf ("\t-D database-name\n");
517  printf ("\t-u alternate user name\n");
518  printf ("\t-p password string, give \"\" for none\n");
519  printf ("\t-c SQL-command\n");
520  printf ("\t-i input-file-name\n");
521  printf ("\t-o ouput-file-name\n");
522  printf ("\t-v verbose mode\n");
523  printf ("\t-s single shard database\n");
524 }
525 
526 static void
527 print_title (int shard_flag)
528 {
529  int title_len = 0;
530 
531  PRINT_TITLE (title_len, RESULT_FORMAT, "RESULT");
532 
533  if (shard_flag == ON)
534  {
535  PRINT_TITLE (title_len, STR_SHARD_ID_FORMAT, "SHARD_ID");
536  }
537 
538  PRINT_TITLE (title_len, STR_ROWCOUNT_FORMAT, "ROW COUNT");
539 
540  PRINT_TITLE (title_len, TIME_FORMAT, "EXECUTION TIME");
541 
542  PRINT_TITLE (title_len, QUERY_FORMAT, "QUERY\n");
543 
544  print_line ("=", title_len);
545 
546  PRINT_RESULT ("\n");
547 }
548 
549 static void
550 print_conn_result (char *broker_name, int conn_hd_id)
551 {
552  if (conn_hd_id < 0)
553  {
554  PRINT_RESULT ("@ [FAIL] ");
555  }
556  else
557  {
558  PRINT_RESULT ("@ [OK] ");
559  }
560 
561  PRINT_RESULT ("CONNECT %s DB [%s] USER [%s]\n\n", broker_name, br_tester_info.db_name, br_tester_info.db_user);
562  return;
563 }
564 
565 static void
567 {
568  if (ret < 0)
569  {
570  PRINT_RESULT ("@ [FAIL] ");
571  }
572  else
573  {
574  PRINT_RESULT ("@ [OK] ");
575  }
576 
577  PRINT_RESULT ("QUERY TEST\n");
578 
579  return;
580 }
581 
582 static void
584 {
585  PRINT_RESULT ("@ SHARD ");
586 
587  if (br_tester_info.shard_flag == ON)
588  {
589  PRINT_RESULT ("ON\n\n");
590  }
591  else
592  {
593  PRINT_RESULT ("OFF\n\n");
594  }
595 
596  return;
597 }
598 
599 static void
600 print_result (int row_count, int err_code, int shard_flag, int shard_id, char *time, char *query)
601 {
602  if (row_count >= 0)
603  {
604  PRINT_RESULT (RESULT_FORMAT, "OK");
605  }
606  else
607  {
608  char result_buf[15];
609 
610  snprintf (result_buf, sizeof (result_buf), "FAIL(%d) ", err_code);
611  row_count = -1;
612  PRINT_RESULT (RESULT_FORMAT, result_buf);
613  }
614 
615  if (shard_flag == ON)
616  {
617  PRINT_RESULT (SHARD_ID_FORMAT, (row_count < 0) ? -1 : shard_id);
618  }
619 
620  PRINT_RESULT (ROWCOUNT_FORMAT, row_count);
621 
622  PRINT_RESULT (TIME_FORMAT, time);
623 
624  PRINT_RESULT (QUERY_FORMAT, query);
625  PRINT_RESULT ("\n");
626 
627  if (tester_err_msg[0] != '\0')
628  {
630  }
631 
632  return;
633 }
634 
635 static int
636 print_result_set (int req, T_CCI_ERROR * err_buf, T_CCI_COL_INFO * col_info, int col_count)
637 {
638  int i;
639  int ind;
640  int ret = 0;
641  int title_len = 0;
642  int malloc_size = 0;
643  int *col_size_arr;
644  char *data;
645  char *col_name;
646  char *data_with_quot = NULL;
647  T_CCI_U_EXT_TYPE *col_type_arr;
648 
649  col_size_arr = (int *) malloc (sizeof (int) * col_count);
650  if (col_size_arr == NULL)
651  {
652  fprintf (stderr, "malloc error\n");
653  return -1;
654  }
655 
656  col_type_arr = (T_CCI_U_EXT_TYPE *) malloc (sizeof (T_CCI_U_EXT_TYPE) * col_count);
657  if (col_type_arr == NULL)
658  {
659  FREE_MEM (col_size_arr);
660 
661  fprintf (stderr, "malloc error\n");
662  return -1;
663  }
664 
665  PRINT_RESULT ("<Result of SELECT Command>\n");
666 
667  for (i = 1; i < col_count + 1; i++)
668  {
669  col_name = CCI_GET_RESULT_INFO_NAME (col_info, i);
670  col_size_arr[i - 1] = MIN (MAX_DISPLAY_LENGTH, CCI_GET_RESULT_INFO_PRECISION (col_info, i));
671  col_size_arr[i - 1] = MAX (col_size_arr[i - 1], (int) strlen (col_name));
672  col_type_arr[i - 1] = CCI_GET_RESULT_INFO_TYPE (col_info, i);
673 
674  PRINT_TITLE (title_len, " %-*s", col_size_arr[i - 1], col_name);
675  }
676  PRINT_RESULT ("\n");
677 
678  print_line ("-", title_len);
679 
680  PRINT_RESULT ("\n");
681 
682  while (1)
683  {
684  ret = cci_cursor (req, 1, CCI_CURSOR_CURRENT, err_buf);
685  if (ret == CCI_ER_NO_MORE_DATA)
686  {
687  ret = 0;
688  break;
689  }
690 
691  if (ret < 0)
692  {
693  PRINT_CCI_ERROR ("ERROR CODE : %d\n%s\n\n", err_buf->err_code, err_buf->err_msg);
694  goto end;
695  }
696 
697  ret = cci_fetch (req, err_buf);
698  if (ret < 0)
699  {
700  PRINT_CCI_ERROR ("ERROR CODE : %d\n%s\n\n", err_buf->err_code, err_buf->err_msg);
701  goto end;
702  }
703 
704  for (i = 1; i < col_count + 1; i++)
705  {
706  ret = cci_get_data (req, i, CCI_A_TYPE_STR, &data, &ind);
707  if (ret < 0)
708  {
709  PRINT_CCI_ERROR ("ERROR CODE : %d\n%s\n\n", err_buf->err_code, err_buf->err_msg);
710  goto end;
711  }
712 
713  if (is_number_type ((T_CCI_U_TYPE) col_type_arr[i - 1]))
714  {
715  PRINT_RESULT (" %-*s", col_size_arr[i - 1], data);
716  }
717  else
718  {
719  int len = (int) strlen (data) + 3;
720  if (malloc_size < len)
721  {
722  FREE_MEM (data_with_quot);
723  malloc_size = len;
724  data_with_quot = (char *) malloc (malloc_size);
725  if (data_with_quot == NULL)
726  {
727  fprintf (stderr, "malloc error\n");
728  ret = -1;
729  goto end;
730  }
731  }
732  snprintf (data_with_quot, len, "'%s'", data);
733 
734  PRINT_RESULT (" %-*s", col_size_arr[i - 1], data_with_quot);
735  }
736  }
737  PRINT_RESULT ("\n");
738  }
739  PRINT_RESULT ("\n");
740 
741 end:
742 
743  FREE_MEM (data_with_quot);
744  FREE_MEM (col_size_arr);
745  FREE_MEM (col_type_arr);
746 
747  return ret;
748 }
749 
750 static bool
751 is_number_type (T_CCI_U_TYPE type)
752 {
753  switch (type)
754  {
755  case CCI_U_TYPE_INT:
756  case CCI_U_TYPE_SHORT:
757  case CCI_U_TYPE_FLOAT:
758  case CCI_U_TYPE_DOUBLE:
759  case CCI_U_TYPE_BIGINT:
760  return true;
761  default:
762  return false;
763  }
764 
765  return false;
766 }
767 
768 static void
770 {
771  FREE_MEM (br_tester_info.db_name);
772  FREE_MEM (br_tester_info.db_user);
773  FREE_MEM (br_tester_info.db_passwd);
774  FREE_MEM (br_tester_info.command);
775  FREE_MEM (br_tester_info.input_file_name);
776  FREE_MEM (br_tester_info.output_file_name);
777 }
778 
779 int
780 main (int argc, char *argv[])
781 {
782  int ret = 0;
783  int opt;
784  int conn_handle = -1;
786  char conn_url[LINE_MAX];
787  T_CCI_ERROR err_buf;
788 
789  if (argc < 2)
790  {
791  print_usage ();
792  return -1;
793  }
794 
795  memset (&br_tester_info, 0, sizeof (br_tester_info));
796 
797  strncpy (broker_name, argv[1], sizeof (broker_name) - 1);
798 
799  while ((opt = getopt (argc, argv, "D:u:p:c:i:o:sv")) != -1)
800  {
801  switch (opt)
802  {
803  case 'D':
804  br_tester_info.db_name = strdup (optarg);
805  break;
806  case 'u':
807  br_tester_info.db_user = strdup (optarg);
808  break;
809  case 'p':
810  br_tester_info.db_passwd = strdup (optarg);
811  break;
812  case 'c':
813  br_tester_info.command = strdup (optarg);
814  break;
815  case 'i':
816  br_tester_info.input_file_name = strdup (optarg);
817  break;
818  case 'o':
819  br_tester_info.output_file_name = strdup (optarg);
820  break;
821  case 'v':
822  br_tester_info.verbose_mode = true;
823  break;
824  case 's':
825  br_tester_info.single_shard = true;
826  break;
827  default:
828  print_usage ();
829  return -1;
830  }
831  }
832 
833  ret = init_tester_info (broker_name);
834  if (ret < 0)
835  {
836  return -1;
837  }
838 
839  snprintf (conn_url, sizeof (conn_url), "cci:cubrid:localhost:%u:%s:::", br_tester_info.broker_port,
840  br_tester_info.db_name);
841  conn_handle = cci_connect_with_url_ex (conn_url, br_tester_info.db_user, br_tester_info.db_passwd, &err_buf);
842 
843  print_conn_result (broker_name, conn_handle);
844 
845  if (conn_handle < 0)
846  {
847  PRINT_CCI_ERROR ("ERROR CODE : %d\n%s\n\n", err_buf.err_code, err_buf.err_msg);
849  return -1;
850  }
851 
852  ret = cci_set_autocommit (conn_handle, CCI_AUTOCOMMIT_FALSE);
853  if (ret < 0)
854  {
855  fprintf (stderr, "cannot set autocommit mode\n");
856  goto end;
857  }
858 
859  if (br_tester_info.output_file_name != NULL)
860  {
861  out_file_fp = fopen (br_tester_info.output_file_name, "w");
862  if (out_file_fp == NULL)
863  {
864  fprintf (stderr, "cannot open output file %s\n", br_tester_info.input_file_name);
865  goto end;
866  }
867  }
868 
870 
871  if (br_tester_info.command != NULL)
872  {
873  print_title (br_tester_info.shard_flag);
874 
875  ret = execute_test_with_query (conn_handle, br_tester_info.command, br_tester_info.shard_flag);
876  }
877  else if (br_tester_info.input_file_name != NULL)
878  {
879  ret = execute_test (conn_handle, br_tester_info.shard_flag);
880  }
881  else
882  {
883  goto end;
884  }
885 
887 
888 end:
889  if (conn_handle >= 0)
890  {
891  cci_disconnect (conn_handle, &err_buf);
892  }
893 
894  if (out_file_fp != NULL)
895  {
896  fclose (out_file_fp);
897  }
898 
900 
901  return ret;
902 }
#define APPL_SERVER_CAS
Definition: broker_config.h:34
char * trim(char *str)
Definition: porting.c:2260
DllImport char * optarg
static void print_title(int shard_flag)
T_BROKER_INFO br_info[1]
Definition: broker_shm.h:661
static int print_result_set(int req, T_CCI_ERROR *err_buf, T_CCI_COL_INFO *col_info, int col_count)
int ini_gethex(INI_TABLE *ini, const char *sec, const char *key, int def, int *lineno)
Definition: ini_parser.c:993
char * output_file_name
int getopt(int, char *const *, const char *)
static const char SECTION_NAME[]
static int execute_test_with_query(int conn_handle, char *query, int shard_flag)
#define SHM_BROKER
Definition: broker_shm.h:64
int argc
Definition: dynamic_load.c:951
static void print_line(const char *ch, int num)
static void print_result(int row_count, int err_code, int shard_flag, int shard_id, char *time, char *query)
#define BROKER_PATH_MAX
Definition: broker_config.h:91
#define DEFAULT_ORACLE_PASSWORD
Definition: broker_tester.c:63
#define MAX_DISPLAY_LENGTH
Definition: broker_tester.c:58
char broker_name[BROKER_NAME_LEN]
Definition: cas.c:148
static void print_conn_result(char *broker_name, int conn_hd_id)
TESTER_INFO br_tester_info
#define SHM_PROXY
Definition: broker_shm.h:65
#define DEFAULT_MYSQL_USER_NAME
Definition: broker_tester.c:64
char * db_user
void ini_parser_free(INI_TABLE *ini)
Definition: ini_parser.c:683
INI_TABLE * ini_parser_load(const char *ininame)
Definition: ini_parser.c:569
#define TESTER_ERR_MSG_SIZE
Definition: broker_tester.c:56
char shard_db_name[SRV_CON_DBNAME_SIZE]
char * get_cubrid_file(T_CUBRID_FILE_ID fid, char *buf, size_t len)
#define APPL_SERVER_CAS_MYSQL
Definition: broker_config.h:37
#define APPL_SERVER_CAS_ORACLE
Definition: broker_config.h:35
static int init_tester_info(char *broker_name)
#define TIME_BUF_SIZE
Definition: broker_tester.c:57
#define DEFAULT_ORACLE_USER_NAME
Definition: broker_tester.c:62
static void init_default_conn_info(int appl_server_type)
int ini_findsec(INI_TABLE *ini, const char *sec)
Definition: ini_parser.c:697
#define assert(x)
#define PRINT_CCI_ERROR(...)
Definition: broker_tester.c:74
static void print_query_test_result(int ret)
static FILE * out_file_fp
static bool is_number_type(T_CCI_U_TYPE type)
#define DEFAULT_EMPTY_STRING
Definition: broker_tester.c:60
void uw_shm_detach(void *p)
Definition: broker_shm.c:700
#define TIME_FORMAT
Definition: broker_tester.c:72
#define DEFAULT_CUB_USER_NAME
Definition: broker_tester.c:61
#define PRINT_RESULT(...)
Definition: broker_tester.c:88
static int execute_test(int conn_handle, int shard_flag)
#define NULL
Definition: freelistheap.h:34
#define strncpy_bufsize(buf, str)
Definition: porting.h:340
#define BROKER_NAME_LEN
Definition: broker_config.h:87
static void get_time(struct timeval *start_time, char *time, int buf_len)
static char tester_err_msg[TESTER_ERR_MSG_SIZE]
#define PRINT_TITLE(n,...)
Definition: broker_tester.c:97
#define FREE_MEM(PTR)
Definition: cas_common.h:58
static int get_master_shm_id(void)
static struct timeval start_time
static void print_usage(void)
T_SHM_SHARD_CONN shm_shard_conn
Definition: broker_shm.h:542
static T_SHM_BROKER * shm_br
Definition: broker.c:310
const char * envvar_get(const char *name)
#define ROWCOUNT_FORMAT
Definition: broker_tester.c:69
#define snprintf_dots_truncate(dest, max_len,...)
Definition: porting.h:323
char shard_db_password[SRV_CON_DBPASSWD_SIZE]
#define QUERY_FORMAT
Definition: broker_tester.c:70
char * db_name
const char ** argv
Definition: dynamic_load.c:952
#define strlen(s1)
Definition: intl_support.c:43
char shard_db_user[SRV_CON_DBUSER_SIZE]
char name[BROKER_NAME_LEN]
#define SHARD_ID_FORMAT
Definition: broker_tester.c:67
int i
Definition: dynamic_load.c:954
char * strdup(const char *str)
Definition: porting.c:901
#define STR_ROWCOUNT_FORMAT
Definition: broker_tester.c:71
int main(int argc, char *argv[])
char * input_file_name
void * uw_shm_open(int shm_key, int which_shm, T_SHM_MODE shm_mode)
Definition: broker_shm.c:139
char * command
static void print_shard_result(void)
#define STR_SHARD_ID_FORMAT
Definition: broker_tester.c:68
#define RESULT_FORMAT
Definition: broker_tester.c:66
char * db_passwd
static void free_br_tester_info(void)
const char ** p
Definition: dynamic_load.c:945