Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Commit

Permalink
cherry pick #1141 to release-2.0 (#1154)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Oct 13, 2020
1 parent 9a02110 commit 01cdcf8
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/chaos-mesh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ jobs:
env:
KUBECONFIG: /etc/rancher/k3s/k3s.yaml
- name: Export KUBECONFIG environment variable
run: echo "::set-env name=KUBECONFIG::/etc/rancher/k3s/k3s.yaml"
run: |
echo 'KUBECONFIG=/etc/rancher/k3s/k3s.yaml' >> $GITHUB_ENV
shell: bash
- name: Print cluster information
run: |
Expand Down Expand Up @@ -239,7 +240,7 @@ jobs:
- name: Encode chaos-mesh action
run: |
echo "::set-env name=CFG_BASE64::$(base64 -w 0 $GITHUB_WORKSPACE/chaos/manifests/${{ matrix.chaos-obj }}.yaml)"
echo CFG_BASE64=$(base64 -w 0 $GITHUB_WORKSPACE/chaos/manifests/${{ matrix.chaos-obj }}.yaml) >> $GITHUB_ENV
- name: Run chaos mesh action
uses: chaos-mesh/chaos-mesh-action@master
Expand Down
59 changes: 59 additions & 0 deletions chaos/cases/instance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2020 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"context"

config2 "github.com/pingcap/dm/dm/config"
"github.com/pingcap/dm/pkg/conn"
)

var (
// go-sqlsmith may generate some SQLs with
// `psefyz timestamp DEFAULT '1969-12-31 01:18:34': Error 1067: Invalid default value for 'psefyz'`
// so we set lesser sql_mode.
mustExecSQLs = []string{
`SET @@GLOBAL.SQL_MODE="NO_ENGINE_SUBSTITUTION"`,
}
)

// setInstancesState sets the state (like global sql_mode) for upstream and downstream DB instances.
func setInstancesState(ctx context.Context, targetCfg config2.DBConfig, sourcesCfg ...config2.DBConfig) error {
targetDB, err := conn.DefaultDBProvider.Apply(targetCfg)
if err != nil {
return err
}
for _, query := range mustExecSQLs {
_, err = targetDB.DB.ExecContext(ctx, query)
if err != nil {
return err
}
}

for _, cfg := range sourcesCfg {
sourceDB, err2 := conn.DefaultDBProvider.Apply(cfg)
if err2 != nil {
return err2
}
for _, query := range mustExecSQLs {
_, err2 = sourceDB.DB.ExecContext(ctx, query)
if err2 != nil {
return err2
}
}
}

return nil
}
7 changes: 7 additions & 0 deletions chaos/cases/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ func main() {
os.Exit(2)
}

// set upstream and downstream instances state.
err = setInstancesState(ctx, cfg.Target, cfg.Source1, cfg.Source2)
if err != nil {
log.L().Error("fail to set instances state", zap.Error(err))
os.Exit(2)
}

// context for the duration of running.
ctx3, cancel3 := context.WithTimeout(ctx, cfg.Duration)
defer cancel3()
Expand Down

0 comments on commit 01cdcf8

Please sign in to comment.