Skip to content

Commit

Permalink
clickhouse: set mutations_sync 2 for delete version (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
chapsuk authored Jan 27, 2023
1 parent 32ad603 commit ad90652
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 59 deletions.
2 changes: 1 addition & 1 deletion dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func (m ClickHouseDialect) migrationSQL() string {
}

func (m ClickHouseDialect) deleteVersionSQL() string {
return fmt.Sprintf("ALTER TABLE %s DELETE WHERE version_id = $1", TableName())
return fmt.Sprintf("ALTER TABLE %s DELETE WHERE version_id = $1 SETTINGS mutations_sync = 2", TableName())
}

////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.17

require (
github.com/ClickHouse/clickhouse-go/v2 v2.2.0
github.com/avast/retry-go/v4 v4.3.2
github.com/denisenkom/go-mssqldb v0.12.3
github.com/go-sql-driver/mysql v1.7.0
github.com/jackc/pgx/v4 v4.17.2
Expand Down Expand Up @@ -56,6 +55,7 @@ require (
github.com/remyoudompheng/bigfft v0.0.0-20220927061507-ef77025ab5aa // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/stretchr/testify v1.8.1 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw=
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/avast/retry-go/v4 v4.3.2 h1:x4sTEu3jSwr7zNjya8NTdIN+U88u/jtO/q3OupBoDtM=
github.com/avast/retry-go/v4 v4.3.2/go.mod h1:rg6XFaiuFYII0Xu3RDbZQkxCofFwruZKW8oEF1jpWiU=
github.com/bkaradzic/go-lz4 v1.0.0/go.mod h1:0YdlkowM3VswSROI7qDxhRvJ3sLhlFrRRwjwegp5jy4=
github.com/cenkalti/backoff/v4 v4.1.3 h1:cFAlzYUlVYDysBEH2T5hyJZMh3+5+WCBvSnK6Q8UtC4=
github.com/cenkalti/backoff/v4 v4.1.3/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
Expand Down
55 changes: 0 additions & 55 deletions tests/clickhouse/clickhouse_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package clickhouse_test

import (
"database/sql"
"errors"
"path/filepath"
"testing"
"time"

"github.com/avast/retry-go/v4"
"github.com/pressly/goose/v3"
"github.com/pressly/goose/v3/internal/check"
"github.com/pressly/goose/v3/internal/testdb"
Expand All @@ -23,16 +20,6 @@ func TestClickUpDownAll(t *testing.T) {

check.NoError(t, goose.SetDialect("clickhouse"))

retryCheckTableMutation := func(table string) func() error {
return func() error {
ok := checkTableMutation(t, db, table)
if !ok {
return errors.New("mutation not done for table: " + table)
}
return nil
}
}

/*
This test applies all up migrations, asserts we have all the entries in
the versions table, applies all down migration and asserts we have zero
Expand Down Expand Up @@ -69,11 +56,6 @@ func TestClickUpDownAll(t *testing.T) {

err = goose.DownTo(db, migrationDir, 0)
check.NoError(t, err)
err = retry.Do(
retryCheckTableMutation(goose.TableName()),
retry.Delay(1*time.Second),
)
check.NoError(t, err)

currentVersion, err = goose.GetDBVersion(db)
check.NoError(t, err)
Expand Down Expand Up @@ -170,40 +152,3 @@ func TestRemoteImportMigration(t *testing.T) {
check.NoError(t, err)
check.Number(t, count, 265)
}

func checkTableMutation(t *testing.T, db *sql.DB, tableName string) bool {
t.Helper()
rows, err := db.Query(
`select mutation_id, command, is_done, create_time from system.mutations where table=$1`,
tableName,
)
check.NoError(t, err)

type result struct {
mutationID string `db:"mutation_id"`
command string `db:"command"`
isDone int64 `db:"is_done"`
createTime time.Time `db:"create_time"`
}
var results []result
for rows.Next() {
var r result
err = rows.Scan(&r.mutationID, &r.command, &r.isDone, &r.createTime)
check.NoError(t, err)
results = append(results, r)
}
check.NoError(t, rows.Close())
check.NoError(t, rows.Err())
// No results means there are no mutations. Assume they are all done.
if len(results) == 0 {
return true
}
// Loop through all the mutations, if at least one of them is
// not done, return false.
for _, r := range results {
if r.isDone != 1 {
return false
}
}
return true
}

0 comments on commit ad90652

Please sign in to comment.