Skip to content

Commit 3d6eb66

Browse files
authored
Merge pull request #12 from guangzhouzhang/feature_add_various_params
Feature add various params
2 parents 6feea08 + 95d378a commit 3d6eb66

3 files changed

Lines changed: 140 additions & 45 deletions

File tree

dbsync/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pgsql_lib_dir := $(shell $(PG_CONFIG) --libdir)
2121
PGXS := $(shell $(PG_CONFIG) --pgxs)
2222
include $(PGXS)
2323

24-
RPATH_LDFLAGS='-Wl,-rpath,$$ORIGIN,-rpath,$(mysql_lib_dir),-rpath,$(pgsql_lib_dir)'
24+
RPATH_LDFLAGS='-Wl,-rpath,$$ORIGIN,-rpath,$$ORIGIN/lib,-rpath,$$ORIGIN/../lib,-rpath,$(mysql_lib_dir),-rpath,$(pgsql_lib_dir)'
2525
export RPATH_LDFLAGS
2626

2727
all: demo.o dbsync-pgsql2pgsql.o mysql2pgsql.o dbsync-mysql2pgsql.o readcfg.o
@@ -31,3 +31,9 @@ all: demo.o dbsync-pgsql2pgsql.o mysql2pgsql.o dbsync-mysql2pgsql.o readcfg.o
3131

3232
clean:
3333
rm -rf *.o pgsql2pgsql mysql2pgsql demo
34+
35+
pkg_mysql2pg:
36+
mkdir -p install
37+
mkdir -p install/bin
38+
mkdir -p install/lib
39+
cp -fr mysql2pgsql install/bin

dbsync/dbsync-mysql2pgsql.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include <unistd.h>
99

1010
extern bool get_ddl_only;
11+
extern bool simple_wo_part;
12+
extern bool first_col_as_dist_key;
13+
extern int buffer_size;
1114

1215
static int load_table_list_file(const char *filename, char*** p_tables, char*** p_queries);
1316

@@ -22,6 +25,7 @@ main(int argc, char **argv)
2225
char *sport = NULL;
2326
//char *tabname = NULL;
2427
int res_getopt = 0;
28+
char *target_schema = NULL;
2529
char *table_list_file = NULL;
2630
char **tables = NULL, **queries = NULL;
2731

@@ -53,7 +57,7 @@ main(int argc, char **argv)
5357

5458
src.port = atoi(sport);
5559

56-
while ((res_getopt = getopt(argc, argv, ":l:j:d")) != -1)
60+
while ((res_getopt = getopt(argc, argv, ":l:j:dnfhs:b:")) != -1)
5761
{
5862
switch (res_getopt)
5963
{
@@ -63,17 +67,34 @@ main(int argc, char **argv)
6367
case 'j':
6468
num_thread = atoi(optarg);
6569
break;
70+
case 'b':
71+
buffer_size = 1024 * atoi(optarg);
72+
break;
73+
case 's':
74+
target_schema = optarg;
75+
break;
6676
case ':':
67-
fprintf(stderr, "No value specified for -%c", optopt);
77+
fprintf(stderr, "No value specified for -%c\n", optopt);
6878
break;
6979
case 'd':
7080
get_ddl_only = true;
7181
break;
82+
case 'n':
83+
simple_wo_part = true;
84+
break;
85+
case 'f':
86+
first_col_as_dist_key = true;
87+
break;
88+
case 'h':
89+
fprintf(stderr, "Usage: -l <table list file> -j <thread number> -d -n -f -s -b -h\n");
90+
fprintf(stderr, " -l specifies a file with table listed;\n -j specifies number of threads to do the job;\n -d means get DDL only without fetching data;\n -n means no partion info in DDLs;\n -f means taking first column as distribution key;\n -s specifies the target schema;\n -b specifies the buffer size in KB used to sending copy data to target db, the default is 0");
91+
return 0;
7292
case '?':
7393
fprintf(stderr, "Unsupported option: %c", optopt);
7494
break;
7595
default:
7696
fprintf(stderr, "Parameter parsing error: %c", res_getopt);
97+
return -1;
7798

7899
}
79100
}
@@ -94,7 +115,7 @@ main(int argc, char **argv)
94115
if (get_ddl_only)
95116
num_thread = 1;
96117

97-
return mysql2pgsql_sync_main(desc , num_thread, &src);
118+
return mysql2pgsql_sync_main(desc , num_thread, &src, target_schema);
98119
}
99120

100121

@@ -212,7 +233,7 @@ int load_table_list_file(const char *filename, char*** p_tables, char*** p_queri
212233
table_array[cur_table] = table_begin;
213234
query_array[cur_table] = query_begin;
214235
cur_table++;
215-
fprintf(stderr, "Adding table: %s\n", table_begin);
236+
fprintf(stderr, "-- Adding table: %s\n", table_begin);
216237
}
217238

218239
table_begin = p + 1;

0 commit comments

Comments
 (0)