Skip to content

Commit d2f7c42

Browse files
authored
Merge pull request #16 from innogames/issue15
Fix client timeout and some side improvements
2 parents f1e59f0 + e5d979e commit d2f7c42

File tree

695 files changed

+261990
-50
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

695 files changed

+261990
-50
lines changed

Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ endef
99
GO_FILES = $(shell find -name '*.go')
1010
PKG_FILES = build/$(NAME)_$(VERSION)_amd64.deb build/$(NAME)-$(VERSION)-1.x86_64.rpm
1111
SUM_FILES = build/sha256sum build/md5sum
12+
MODULE = github.com/innogames/$(NAME)
1213

14+
GO ?= go
15+
export GOFLAGS += -mod=vendor
16+
export GO111MODULE := on
1317

1418
.PHONY: all clean docker test version
1519

@@ -27,8 +31,8 @@ rebuild: clean all
2731

2832
# Run tests
2933
test:
30-
go vet $(GO_FILES)
31-
go test $(GO_FILES)
34+
$(GO) vet $(MODULE)
35+
$(GO) test $(MODULE)
3236

3337
build: | $(NAME)
3438
mkdir build
@@ -38,7 +42,7 @@ docker:
3842
docker build -t innogames/$(NAME):latest -f docker/$(NAME)/Dockerfile .
3943

4044
$(NAME): $(NAME).go
41-
go build -ldflags "-X 'main.version=$(VERSION)'" -o $@ .
45+
$(GO) build -ldflags "-X 'main.version=$(VERSION)'" -o $@ .
4246

4347
#########################################################
4448
# Prepare artifact directory and set outputs for upload #
@@ -73,7 +77,7 @@ build/pkg: build/$(NAME) build/config.toml.example
7377
cp -l config.toml.example pkg/etc/$(NAME)
7478

7579
build/$(NAME): $(NAME).go
76-
GOOS=linux GOARCH=amd64 go build -ldflags "-X 'main.version=$(VERSION)'" -o $@ .
80+
GOOS=linux GOARCH=amd64 $(GO) build -ldflags "-X 'main.version=$(VERSION)'" -o $@ .
7781

7882
build/config.toml.example: build/$(NAME)
7983
./build/$(NAME) --print-defaults > $@

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ To launch the container run the following command on the host with a running Cli
3333
* Daemon mode is preferable over one-shot script for the normal work
3434
* It's safe to run it on the cluster hosts
3535
* You could either run it on the one of replicated host or just over the all hosts
36-
* If you have big partitions (month or something like this) and will get exceptions about timeout, then you need to adjust `receive_timeout` parameter in DSN
36+
* There are two different parameters in DSN, that should be adjusted together to fix timeouts for big partitions (month or something like this) optimizing:
37+
* `read_timeout` - `clickhouse-go` parameter. Controls the timeout between the `graphite-ch-optimizer` and ClickHouse server.
38+
* `receive_timeout` - ClickHouse parameter, used when the OPTIMIZE query is applied in the cluster. See [comment](https://github.com/ClickHouse/ClickHouse/issues/4831#issuecomment-708721042) in the issue.
3739
* `optimize_throw_if_noop=1` is not mandatory, but good to have.
3840
* The next picture demonstrates the result of running the daemon for the first time on ~3 years old GraphiteMergeTree table:
3941
<img src="./docs/result.jpg" alt="example"/>
@@ -160,7 +162,7 @@ Default config:
160162
```toml
161163
[clickhouse]
162164
optimize-interval = "72h0m0s"
163-
server-dsn = "tcp://localhost:9000?&optimize_throw_if_noop=1&receive_timeout=3600&debug=true"
165+
server-dsn = "tcp://localhost:9000?&optimize_throw_if_noop=1&receive_timeout=3600&debug=true&read_timeout=3600"
164166

165167
[daemon]
166168
dry-run = false
@@ -180,7 +182,7 @@ Usage of graphite-ch-optimizer:
180182
--print-defaults Print default config values and exit
181183
-v, --version Print version and exit
182184
--optimize-interval duration The partition will be merged after having no writes for more than the given duration (default 72h0m0s)
183-
-s, --server-dsn string DSN to connect to ClickHouse server (default "tcp://localhost:9000?&optimize_throw_if_noop=1&receive_timeout=3600&debug=true")
185+
-s, --server-dsn string DSN to connect to ClickHouse server (default "tcp://localhost:9000?&optimize_throw_if_noop=1&receive_timeout=3600&debug=true&read_timeout=3600")
184186
-n, --dry-run Will print how many partitions would be merged without actions
185187
--loop-interval duration Daemon will check if there partitions to merge once per this interval (default 1h0m0s)
186188
--one-shot Program will make only one optimization instead of working in the loop (true if dry-run)

go.mod

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ module github.com/innogames/graphite-ch-optimizer
33
go 1.13
44

55
require (
6-
github.com/ClickHouse/clickhouse-go v1.3.13
7-
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
8-
github.com/pelletier/go-toml v1.6.0
9-
github.com/sirupsen/logrus v1.4.2
10-
github.com/spf13/afero v1.2.2 // indirect
6+
github.com/ClickHouse/clickhouse-go v1.4.3
7+
github.com/fsnotify/fsnotify v1.4.9 // indirect
8+
github.com/magiconair/properties v1.8.4 // indirect
9+
github.com/mitchellh/mapstructure v1.3.3 // indirect
10+
github.com/pelletier/go-toml v1.8.1
11+
github.com/sirupsen/logrus v1.7.0
12+
github.com/spf13/afero v1.4.1 // indirect
1113
github.com/spf13/cast v1.3.1 // indirect
1214
github.com/spf13/jwalterweatherman v1.1.0 // indirect
1315
github.com/spf13/pflag v1.0.5
14-
github.com/spf13/viper v1.6.2
15-
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82 // indirect
16-
golang.org/x/text v0.3.2 // indirect
17-
gopkg.in/ini.v1 v1.51.1 // indirect
18-
gopkg.in/yaml.v2 v2.2.8 // indirect
16+
github.com/spf13/viper v1.7.1
17+
golang.org/x/sys v0.0.0-20201027140754-0fcbb8f4928c // indirect
18+
gopkg.in/ini.v1 v1.62.0 // indirect
19+
gopkg.in/yaml.v2 v2.3.0 // indirect
1920
)

0 commit comments

Comments
 (0)