-
Notifications
You must be signed in to change notification settings - Fork 46
/
Makefile
192 lines (143 loc) · 6.98 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
GIT_REVISION=`git rev-parse --short HEAD`
SPQR_VERSION=`git describe --tags --abbrev=0`
LDFLAGS=-ldflags "-X github.com/pg-sharding/spqr/pkg.GitRevision=${GIT_REVISION} -X github.com/pg-sharding/spqr/pkg.SpqrVersion=${SPQR_VERSION}"
GCFLAGS=-gcflags=all="-N -l"
GOFMT_FILES?=$$(find . -name '*.go' | grep -v vendor | grep -v yacc)
.PHONY : run
.DEFAULT_GOAL := deps
#################### DEPENDENCIES ####################
proto-deps:
go get -u google.golang.org/grpc
go get -u github.com/golang/protobuf/protoc-gen-go
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
yacc-deps:
go get -u golang.org/x/tools/cmd/goyacc
deps:
go mod download
go mod vendor
####################### BUILD #######################
build_balancer:
go build -pgo=auto -o spqr-balancer ./cmd/balancer
build_coorctl:
go build -pgo=auto -o coorctl ./cmd/coordctl
build_coordinator:
go build -pgo=auto -o spqr-coordinator ./cmd/coordinator
build_router:
go build -pgo=auto -o spqr-router $(LDFLAGS) $(GCFLAGS) ./cmd/router
build_mover:
go build -pgo=auto -o spqr-mover ./cmd/mover
build_worldmock:
go build -pgo=auto -o spqr-worldmock ./cmd/worldmock
build_workloadreplay:
go build -pgo=auto -o spqr-workloadreplay ./cmd/workloadreplay
build_spqrdump:
go build -pgo=auto -o spqr-dump ./cmd/spqrdump
build: build_balancer build_coordinator build_coorctl build_router build_mover build_worldmock build_workloadreplay build_spqrdump
build_images:
docker compose build spqr-base-image
@if [ "x" != "${POSTGRES_VERSION}x" ]; then\
echo "building ${POSTGRES_VERSION} version";\
docker compose build --build-arg POSTGRES_VERSION=${POSTGRES_VERSION} spqr-shard-image;\
else\
docker compose build spqr-shard-image;\
fi
save_shard_image:
sudo rm -f spqr-shard-image-*
docker compose build ${IMAGE_SHARD};\
docker save ${IMAGE_SHARD} | gzip -c > ${CACHE_FILE_SHARD};\
clean: clean_feature_test
rm -f spqr-router spqr-coordinator spqr-mover spqr-worldmock spqr-balancer
######################## RUN ########################
run: build_images
docker compose up -d --remove-orphans --build router router2 coordinator shard1 shard2 qdb01
proxy_2sh_run:
./spqr-router run --config ./examples/2shardproxy.yaml -d --proto-debug
proxy_run:
./spqr-router run --config ./examples/router.yaml
coordinator_run:
./spqr-coordinator run --config ./examples/coordinator.yaml
pooler_run:
./spqr-router run --config ./examples/localrouter.yaml
####################### TESTS #######################
unittest:
go test ./cmd/... ./pkg/... ./router/... ./coordinator/... ./yacc/console...
go test -race -count 20 -timeout 30s ./qdb/...
regress_local: proxy_2sh_run
./script/regress_local.sh
regress: build_images
docker compose -f test/regress/docker-compose.yaml down && docker compose -f test/regress/docker-compose.yaml run --build regress
hibernate_regress: build_images
docker compose -f test/drivers/hibernate-regress/docker-compose.yaml up --remove-orphans --force-recreate --exit-code-from regress --build coordinator router shard1 shard2 regress qdb01
jdbc_regress: build_images
docker compose -f test/drivers/jdbc-regress/docker-compose.yaml up --remove-orphans --force-recreate --exit-code-from regress --build coordinator router shard1 shard2 regress qdb01
gorm_regress: build_images
docker compose -f test/drivers/gorm-regress/docker-compose.yaml down && docker compose -f test/drivers/gorm-regress/docker-compose.yaml run --remove-orphans --build regress
xproto_regress: build_images
docker compose -f test/xproto/docker-compose.yaml down && docker compose -f test/xproto/docker-compose.yaml run --remove-orphans --build regress
stress: build_images
docker compose -f test/stress/docker-compose.yaml up --remove-orphans --exit-code-from stress --build router shard1 shard2 stress
split_feature_test_old:
docker compose build slicer
(cd test/feature/features; tar -c .) | docker compose run slicer | (mkdir test/feature/generatedFeatures; cd test/feature/generatedFeatures; tar -x)
split_feature_test:
mkdir test/feature/generatedFeatures && cp test/feature/features/* test/feature/generatedFeatures
clean_feature_test:
rm -rf test/feature/generatedFeatures
feature_test_ci:
@if [ "x" = "${CACHE_FILE_SHARD}x" ]; then\
echo "Rebuild";\
docker compose build spqr-shard-image;\
else\
docker load -i ${CACHE_FILE_SHARD};\
fi
docker compose build spqr-base-image
go build ./test/feature/...
mkdir ./test/feature/logs
(cd test/feature; go test -timeout 150m)
feature_test: clean_feature_test build_images
make split_feature_test
go build ./test/feature/...
rm -rf ./test/feature/logs
mkdir ./test/feature/logs
(cd test/feature; GODOG_FEATURE_DIR=generatedFeatures go test -timeout 150m)
####################### LINTERS #######################
fmt:
gofmt -w $(GOFMT_FILES)
fmtcheck:
@sh -c "'$(CURDIR)/script/gofmtcheck.sh'"
lint:
golangci-lint run --timeout=10m --out-format=colored-line-number --skip-dirs=yacc/console
####################### GENERATE #######################
gogen:
protoc --go_out=./pkg --go_opt=paths=source_relative --go-grpc_out=./pkg --go-grpc_opt=paths=source_relative \
protos/*
mockgen:
mockgen -source=pkg/datatransfers/data_transfers.go -destination=pkg/mock/pgx/mock_pgxconn_iface.go -package=mock
mockgen -source=pkg/datatransfers/pgx_tx_iface.go -destination=pkg/mock/pgx/mock_pgx_tx.go -package=mock
mockgen -source=./pkg/conn/raw.go -destination=./pkg/mock/conn/raw_mock.go -package=mock
mockgen -source=./router/server/server.go -destination=router/mock/server/mock_server.go -package=mock
mockgen -source=./pkg/conn/instance.go -destination=pkg/mock/conn/mock_instance.go -package=mock
mockgen -source=./pkg/shard/shard.go -destination=pkg/mock/shard/mock_shard.go -package=mock
mockgen -source=./pkg/pool/pool.go -destination=pkg/mock/pool/mock_pool.go -package=mock
mockgen -source=./router/client/client.go -destination=./router/mock/client/mock_client.go -package=mock
mockgen -source=./router/poolmgr/pool_mgr.go -destination=./router/mock/poolmgr/mock_pool_mgr.go -package=mock
mockgen -source=./router/qrouter/qrouter.go -destination=./router/mock/qrouter/mock_qrouter.go -package=mock
mockgen -source=./pkg/meta/meta.go -destination=./pkg/mock/meta/mock_meta.go -package=mock
mockgen -source=./pkg/clientinteractor/interactor.go -destination=pkg/mock/clientinteractor/mock_interactor.go -package=mock
mockgen -source=qdb/qdb.go -destination=qdb/mock/qdb.go -package=mock
yaccgen:
make -C ./yacc/console gen
gen: gogen yaccgen mockgen
generate: build_images
docker build -f docker/generator/Dockerfile -t spqr-generator .
docker run --name spqr-generator-1 spqr-generator
docker cp spqr-generator-1:/spqr/pkg/protos/. pkg/protos
docker cp spqr-generator-1:/spqr/yacc/console/. yacc/console
docker cp spqr-generator-1:/spqr/pkg/mock/. pkg/mock
docker cp spqr-generator-1:/spqr/router/mock/. router/mock
docker container rm spqr-generator-1
version = $(shell git describe --tags --abbrev=0)
package:
sed -i 's/SPQR_VERSION/$(version)/g' debian/changelog
dpkg-buildpackage -us -uc
.PHONY: build gen