Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' into kennytm/disk-quota
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytm committed Jan 19, 2021
2 parents 3af075d + 90dbfe3 commit dc5b5b7
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 35 deletions.
40 changes: 29 additions & 11 deletions lightning/backend/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,34 @@ loopWrite:
for errCnt < maxRetryTimes {
log.L().Debug("ingest meta", zap.Reflect("meta", meta))
var resp *sst.IngestResponse
resp, err = local.Ingest(ctx, meta, region)
failpoint.Inject("FailIngestMeta", func(val failpoint.Value) {
// only inject the error once
switch val.(string) {
case "notleader":
resp = &sst.IngestResponse{
Error: &errorpb.Error{
NotLeader: &errorpb.NotLeader{
RegionId: region.Region.Id,
Leader: region.Leader,
},
},
}
case "epochnotmatch":
resp = &sst.IngestResponse{
Error: &errorpb.Error{
EpochNotMatch: &errorpb.EpochNotMatch{
CurrentRegions: []*metapb.Region{region.Region},
},
},
}
}
if resp != nil {
err = nil
}
})
if resp == nil {
resp, err = local.Ingest(ctx, meta, region)
}
if err != nil {
if errors.Cause(err) == context.Canceled {
return nil, err
Expand All @@ -1178,16 +1205,7 @@ loopWrite:
errCnt++
continue
}
failpoint.Inject("FailIngestMeta", func(val failpoint.Value) {
switch val.(string) {
case "notleader":
resp.Error.NotLeader = &errorpb.NotLeader{
RegionId: region.Region.Id, Leader: region.Leader}
case "epochnotmatch":
resp.Error.EpochNotMatch = &errorpb.EpochNotMatch{
CurrentRegions: []*metapb.Region{region.Region}}
}
})

var retryTy retryType
var newRegion *split.RegionInfo
retryTy, newRegion, err = local.isIngestRetryable(ctx, resp, region, meta)
Expand Down
4 changes: 0 additions & 4 deletions lightning/backend/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"bytes"
"context"
"encoding/binary"
"fmt"
"math"
"math/rand"
"os"
Expand Down Expand Up @@ -379,16 +378,13 @@ func testLocalWriter(c *C, needSort bool, partitialSort bool) {
}

func (s *localSuite) TestLocalWriterWithSort(c *C) {
fmt.Println("TestLocalWriterWithSort")
testLocalWriter(c, false, false)
}

func (s *localSuite) TestLocalWriterWithIngest(c *C) {
fmt.Println("TestLocalWriterWithIngest")
testLocalWriter(c, true, false)
}

func (s *localSuite) TestLocalWriterWithIngestUnsort(c *C) {
fmt.Println("TestLocalWriterWithIngestUnsort")
testLocalWriter(c, true, true)
}
15 changes: 8 additions & 7 deletions lightning/backend/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,14 @@ func (enc *tidbEncoder) appendSQL(sb *strings.Builder, datum *types.Datum, col *
value := strconv.AppendFloat(buffer[:0], datum.GetFloat64(), 'g', -1, 64)
sb.Write(value)
case types.KindString:
if enc.mode.HasStrictMode() {
d, err := table.CastValue(enc.se, *datum, col.ToInfo(), false, false)
if err != nil {
return errors.Trace(err)
}
datum = &d
}
// See: https://github.com/pingcap/tidb-lightning/issues/550
//if enc.mode.HasStrictMode() {
// d, err := table.CastValue(enc.se, *datum, col.ToInfo(), false, false)
// if err != nil {
// return errors.Trace(err)
// }
// datum = &d
//}

enc.appendSQLBytes(sb, datum.GetBytes())
case types.KindBytes:
Expand Down
3 changes: 2 additions & 1 deletion lightning/backend/tidb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ func (s *mysqlSuite) TestWriteRowsErrorOnDup(c *C) {
c.Assert(err, IsNil)
}

func (s *mysqlSuite) TestStrictMode(c *C) {
// TODO: temporarily disable this test before we fix strict mode
func (s *mysqlSuite) testStrictMode(c *C) {
ft := *types.NewFieldType(mysql.TypeVarchar)
ft.Charset = charset.CharsetUTF8MB4
col0 := &model.ColumnInfo{ID: 1, Name: model.NewCIStr("s0"), State: model.StatePublic, Offset: 0, FieldType: ft}
Expand Down
2 changes: 2 additions & 0 deletions lightning/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ type Security struct {
CAPath string `toml:"ca-path" json:"ca-path"`
CertPath string `toml:"cert-path" json:"cert-path"`
KeyPath string `toml:"key-path" json:"key-path"`
// RedactInfoLog indicates that whether enabling redact log
RedactInfoLog bool `toml:"redact-info-log" json:"redact-info-log"`
}

// RegistersMySQL registers (or deregisters) the TLS config with name "cluster"
Expand Down
8 changes: 4 additions & 4 deletions lightning/config/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ func LoadGlobalConfig(args []string, extraFlags func(*flag.FlagSet)) (*GlobalCon

logLevel := flagext.ChoiceVar(fs, "L", "", `log level: info, debug, warn, error, fatal (default info)`, "", "info", "debug", "warn", "warning", "error", "fatal")
logFilePath := fs.String("log-file", "", "log file path")
redactLog := fs.Bool("redact-log", false, "whether to redact sensitive info in log")
tidbHost := fs.String("tidb-host", "", "TiDB server host")
tidbPort := fs.Int("tidb-port", 0, "TiDB server port (default 4000)")
tidbUser := fs.String("tidb-user", "", "TiDB user name to connect")
Expand All @@ -163,6 +162,7 @@ func LoadGlobalConfig(args []string, extraFlags func(*flag.FlagSet)) (*GlobalCon
tlsCAPath := fs.String("ca", "", "CA certificate path for TLS connection")
tlsCertPath := fs.String("cert", "", "certificate path for TLS connection")
tlsKeyPath := fs.String("key", "", "private key path for TLS connection")
redactInfoLog := fs.Bool("redact-info-log", false, "whether to redact sensitive info in log")

statusAddr := fs.String("status-addr", "", "the Lightning server address")
serverMode := fs.Bool("server-mode", false, "start Lightning in server mode, wait for multiple tasks instead of starting immediately")
Expand Down Expand Up @@ -199,9 +199,6 @@ func LoadGlobalConfig(args []string, extraFlags func(*flag.FlagSet)) (*GlobalCon
if *logFilePath != "" {
cfg.App.Config.File = *logFilePath
}
if *redactLog {
cfg.App.Config.RedactLog = *redactLog
}
// "-" is a special config for log to stdout
if cfg.App.Config.File == "-" {
cfg.App.Config.File = ""
Expand Down Expand Up @@ -271,6 +268,9 @@ func LoadGlobalConfig(args []string, extraFlags func(*flag.FlagSet)) (*GlobalCon
if *tlsKeyPath != "" {
cfg.Security.KeyPath = *tlsKeyPath
}
if *redactInfoLog {
cfg.Security.RedactInfoLog = *redactInfoLog
}
if len(filter) > 0 {
cfg.Mydumper.Filter = filter
}
Expand Down
2 changes: 2 additions & 0 deletions lightning/lightning.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ func New(globalCfg *config.GlobalConfig) *Lightning {
log.L().Fatal("failed to load TLS certificates", zap.Error(err))
}

log.InitRedact(globalCfg.Security.RedactInfoLog)

ctx, shutdown := context.WithCancel(context.Background())
return &Lightning{
globalCfg: globalCfg,
Expand Down
4 changes: 0 additions & 4 deletions lightning/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ type Config struct {
FileMaxDays int `toml:"max-days" json:"max-days"`
// Maximum number of old log files to retain.
FileMaxBackups int `toml:"max-backups" json:"max-backups"`
// Redact sensitive logs during the whole process
RedactLog bool `toml:"redact-log" json:"redact-log"`
}

func (cfg *Config) Adjust() {
Expand Down Expand Up @@ -100,8 +98,6 @@ func InitLogger(cfg *Config, tidbLoglevel string) error {
appLogger = Logger{logger.WithOptions(zap.AddStacktrace(zap.DPanicLevel))}
appLevel = props.Level

InitRedact(cfg.RedactLog)

return nil
}

Expand Down
4 changes: 2 additions & 2 deletions tests/local_backend/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ENGINE_COUNT=6
rm -f "$TEST_DIR/lightning-local.log"
rm -f "/tmp/tidb_lightning_checkpoint_local_backend_test.pb"
run_sql 'DROP DATABASE IF EXISTS cpeng;'
export GO_FAILPOINTS='github.com/pingcap/tidb-lightning/lightning/backend/local/FailIngestMeta=return("notleader")'
export GO_FAILPOINTS='github.com/pingcap/tidb-lightning/lightning/backend/FailIngestMeta=1*return("notleader")'

run_lightning --backend local --enable-checkpoint=1 --log-file "$TEST_DIR/lightning-local.log" --config "tests/$TEST_NAME/config.toml"

Expand All @@ -40,7 +40,7 @@ check_contains 'sum(c): 46'
run_sql 'DROP DATABASE cpeng;'
rm -f "/tmp/tidb_lightning_checkpoint_local_backend_test.pb"

export GO_FAILPOINTS='github.com/pingcap/tidb-lightning/lightning/backend/local/FailIngestMeta=return("epochnotmatch")'
export GO_FAILPOINTS='github.com/pingcap/tidb-lightning/lightning/backend/FailIngestMeta=2*return("epochnotmatch")'

run_lightning --backend local --enable-checkpoint=1 --log-file "$TEST_DIR/lightning-local.log" --config "tests/$TEST_NAME/config.toml"

Expand Down
4 changes: 2 additions & 2 deletions tidb-lightning.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ file = "tidb-lightning.log"
max-size = 128 # MB
max-days = 28
max-backups = 14
# If set to true, lightning will redact sensitive infomation in log.
redact-log = false

[security]
# specifies certificates and keys for TLS connections within the cluster.
Expand All @@ -52,6 +50,8 @@ redact-log = false
# cert-path = "/path/to/lightning.pem"
# private key of this service.
# key-path = "/path/to/lightning.key"
# If set to true, lightning will redact sensitive infomation in log.
# redact-info-log = false

[checkpoint]
# Whether to enable checkpoints.
Expand Down

0 comments on commit dc5b5b7

Please sign in to comment.