Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce random sleep before clickhouse loads #4193

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions warehouse/integrations/clickhouse/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"errors"
"fmt"
"io"
"math/rand"
"net/url"
"os"
"path"
Expand Down Expand Up @@ -160,6 +161,7 @@
numWorkersDownloadLoadFiles int
s3EngineEnabledWorkspaceIDs []string
slowQueryThreshold time.Duration
randomLoadDelay func(string) time.Duration
}
}

Expand Down Expand Up @@ -234,6 +236,16 @@
ch.config.numWorkersDownloadLoadFiles = conf.GetInt("Warehouse.clickhouse.numWorkersDownloadLoadFiles", 8)
ch.config.s3EngineEnabledWorkspaceIDs = conf.GetStringSlice("Warehouse.clickhouse.s3EngineEnabledWorkspaceIDs", nil)
ch.config.slowQueryThreshold = conf.GetDuration("Warehouse.clickhouse.slowQueryThreshold", 5, time.Minute)
r := rand.New(rand.NewSource(time.Now().UnixNano()))
ch.config.randomLoadDelay = func(workspaceID string) time.Duration {
maxDelay := conf.GetDurationVar(
0,
time.Second,
fmt.Sprintf("Warehouse.clickhouse.%s.maxLoadDelay", workspaceID),
"Warehouse.clickhouse.maxLoadDelay",
)
return time.Duration(float64(maxDelay) * (1 - r.Float64()))
}

return ch
}
Expand Down Expand Up @@ -491,6 +503,11 @@

// loadTable loads table to clickhouse from the load files
func (ch *Clickhouse) loadTable(ctx context.Context, tableName string, tableSchemaInUpload model.TableSchema) (err error) {
if delay := ch.config.randomLoadDelay(ch.Warehouse.WorkspaceID); delay > 0 {
if err = misc.SleepCtx(ctx, delay); err != nil {
return
}

Check warning on line 509 in warehouse/integrations/clickhouse/clickhouse.go

View check run for this annotation

Codecov / codecov/patch

warehouse/integrations/clickhouse/clickhouse.go#L507-L509

Added lines #L507 - L509 were not covered by tests
}
if ch.UseS3CopyEngineForLoading() {
return ch.loadByCopyCommand(ctx, tableName, tableSchemaInUpload)
}
Expand Down