Skip to content

Commit d7004e3

Browse files
committed
bool type support, supervisor, dev/prod mods
1 parent 332be0c commit d7004e3

File tree

11 files changed

+56
-20
lines changed

11 files changed

+56
-20
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ src/.env
99
src/vendor
1010
src/configs/*.json
1111
src/plugins/user/*.go
12-
src/plugins/user/*.so
12+
src/plugins/user/*.so
13+
src/horgh-replicator

Dockerfile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM golang:1.10
22

33
RUN apt-get update
4-
RUN apt-get -y install curl g++ make bzip2 nano unixodbc unixodbc-dev
4+
RUN apt-get -y install curl g++ make bzip2 nano supervisor unixodbc unixodbc-dev
55

66
WORKDIR /go/src/horgh-replicator
77
COPY . .
@@ -11,4 +11,13 @@ RUN tar -xvf /vertica-client.tar.gz -C /
1111

1212
#installing dep and vendors
1313
RUN go get -u github.com/golang/dep/...
14-
CMD ["sh", "-c", "cd /go/src/horgh-replicator/src && dep ensure -update && /bin/bash"]
14+
15+
# dev mode
16+
CMD ["sh", "-c", "cd /go/src/horgh-replicator/src && dep ensure -update && /bin/bash"]
17+
18+
# prod mode
19+
# CMD ["sh", "-c", "cd /go/src/horgh-replicator/src \
20+
# && dep ensure -update \
21+
# && go build main.go \
22+
# && mv main horgh-replicator \
23+
# && /usr/bin/supervisord"]

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,9 @@ Don't forget to set `binlog_do_db=<master_db_name>` and restart MySQL service.
5858
- Set start position of log: `go run main.go set-position <table> <name> <position>`
5959
- Loader for replication testing: `go run main.go load`
6060

61+
### Container mode
62+
63+
Where are 2 modes of docker container in Dockerfile:
64+
65+
- Prod mode: build app and execute app as supervisor process
66+
- Dev mode: provides the opportunity for manual start and debug

docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ services:
66
context: ./
77
tty: true
88
volumes:
9-
- .:/go/src/horgh-replicator
9+
- .:/go/src/horgh-replicator
10+
- ./supervisor:/etc/supervisor/conf.d

examples/user.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"id",
66
"name",
77
"status",
8+
"active",
89
"created"
910
]
1011
},
@@ -32,6 +33,11 @@
3233
]
3334
}
3435
},
36+
{
37+
"name": "active",
38+
"key": false,
39+
"mode": "bool"
40+
},
3541
{
3642
"name": "created",
3743
"key": false,

sql/structure.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CREATE TABLE test.user
66
id INT AUTO_INCREMENT PRIMARY KEY,
77
name VARCHAR(40),
88
status VARCHAR(255),
9+
active bool,
910
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP
1011
) engine=InnoDB;
1112

@@ -23,6 +24,7 @@ CREATE TABLE test.user
2324
id INT AUTO_INCREMENT PRIMARY KEY,
2425
name VARCHAR(40),
2526
status VARCHAR(255),
27+
active bool,
2628
created TIMESTAMP NOT NULL
2729
) engine=InnoDB;
2830

@@ -44,6 +46,7 @@ CREATE TABLE public."user"
4446
id BIGSERIAL PRIMARY KEY,
4547
name VARCHAR(40),
4648
status VARCHAR(255),
49+
active bool,
4750
created TIMESTAMP DEFAULT NULL
4851
);
4952

@@ -58,7 +61,7 @@ CREATE TABLE public.post
5861
/*For ClickHouse Slave*/
5962
CREATE DATABASE test;
6063

61-
CREATE TABLE test.user (id Int32, name FixedString(40), status FixedString(255), created DateTime) ENGINE = MergeTree()
64+
CREATE TABLE test.user (id Int32, name FixedString(40), status FixedString(255), active UInt8, created DateTime) ENGINE = MergeTree()
6265
PARTITION BY id
6366
ORDER BY id;
6467

@@ -73,6 +76,7 @@ CREATE TABLE "user"
7376
id INT,
7477
name VARCHAR,
7578
status VARCHAR,
79+
active bool,
7680
created TIMESTAMP NOT NULL
7781
);
7882

sql/test.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* This queries to test replication user table*/
2-
INSERT INTO test.user (`name`, `status`) VALUE ("Jack", "active");
3-
UPDATE test.user SET `name`='Tommy' ORDER BY RAND() LIMIT 1;
2+
INSERT INTO test.user (`name`, `status`, `active`) VALUE ("Jack", "active", false);
3+
UPDATE test.user SET `name`='Tommy', `status`=true ORDER BY RAND() LIMIT 1;
44
DELETE FROM test.user LIMIT 1;
55

66
/* This queries to test replication post table*/

src/parser/parser.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ func (m *BinlogParser) beforeSave(beforeSave connectors.ConfigBeforeSave, value
6868
func (m *BinlogParser) prepareType(fieldName string, fieldType string, value interface{}, params map[string]interface{}) {
6969
switch fieldType {
7070
case "bool":
71-
params[fieldName] = value.(bool)
71+
if value.(int8) == 1 {
72+
params[fieldName] = true
73+
} else {
74+
params[fieldName] = false
75+
}
7276
case "int":
7377
params[fieldName] = value.(int32)
7478
case "string":
@@ -138,15 +142,6 @@ func (m *BinlogParser) floatHelper(e *canal.RowsEvent, n int, columnName string)
138142
return float64(0)
139143
}
140144

141-
func (m *BinlogParser) boolHelper(e *canal.RowsEvent, n int, columnName string) bool {
142-
143-
val := m.intHelper(e, n, columnName)
144-
if val == 1 {
145-
return true
146-
}
147-
return false
148-
}
149-
150145
func (m *BinlogParser) stringHelper(e *canal.RowsEvent, n int, columnName string) string {
151146

152147
columnId := m.getBinlogIdByName(e, columnName)

src/tools/loader.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const (
1414
// goroutine count. WARNING if you set more 1, may be concurrency problems
1515
ThreadCount = 1
1616
// time to create queries in minutes
17-
LoadTime = 5
17+
LoadTime = 1
1818
)
1919

2020
var CmdLoad = &cobra.Command{
@@ -63,8 +63,8 @@ func randInt(min int, max int) int {
6363

6464
func makeQueries(id int) {
6565
queries := []string{
66-
"INSERT INTO test.user (`name`, `status`) VALUE ('Jack', 'active');",
67-
"UPDATE test.user SET `name`='Tommy', status='dead' ORDER BY RAND() LIMIT 1",
66+
"INSERT INTO test.user (`name`, `status`, `active`) VALUE ('Jack', 'active', false);",
67+
"UPDATE test.user SET `name`='Tommy', status='dead', active=true ORDER BY RAND() LIMIT 1",
6868
"DELETE FROM test.user ORDER BY RAND() LIMIT 1;",
6969
"INSERT INTO test.post (`title`, `text`) VALUE ('Title', 'London is the capital of Great Britain');",
7070
"UPDATE test.post SET title='New title' ORDER BY RAND() LIMIT 1;",

supervisor/bash.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[supervisord]
2+
nodaemon=true
3+
4+
[program:sshd]
5+
command=/bin/bash

0 commit comments

Comments
 (0)