-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: retry write points and print the retried points
- Loading branch information
Showing
9 changed files
with
50 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/bash | ||
go mod tidy | ||
go build -o dataMigrate ./src/ | ||
go build . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module dataMigrate | ||
module github.com/openGemini/dataMigrate | ||
|
||
go 1.16 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ the implementations of the "location" and "KeyCursor" classes in the above file | |
copyright 2023 Qizhi Huang([email protected]) | ||
*/ | ||
|
||
package main | ||
package src | ||
|
||
import ( | ||
"container/heap" | ||
|
@@ -348,35 +348,41 @@ func (s *Scanner) writeBatches(c client.Client, cmd Migrator) error { | |
} | ||
|
||
pt, err := s.nextPoint(cmd) | ||
|
||
if err != nil { | ||
logger.LogString("point read error: "+err.Error(), TOLOGFILE|TOCONSOLE, LEVEL_ERROR) | ||
return err | ||
} | ||
|
||
if pt == nil { | ||
rowsNum := len(bp.Points()) | ||
err := c.Write(bp) | ||
if err != nil { | ||
logger.LogString("insert error: "+err.Error(), TOLOGFILE|TOCONSOLE, LEVEL_ERROR) | ||
return err | ||
} | ||
s.retryWrite(c, bp) | ||
cmd.getStat().rowsRead += rowsNum | ||
break | ||
} | ||
|
||
bp.AddPoint(pt) | ||
count = count + 1 | ||
if count == cmd.getBatchSize() { | ||
err := c.Write(bp) | ||
if err != nil { | ||
logger.LogString("insert error: "+err.Error(), TOLOGFILE|TOCONSOLE, LEVEL_ERROR) | ||
return err | ||
} | ||
s.retryWrite(c, bp) | ||
cmd.getStat().rowsRead += cmd.getBatchSize() | ||
flag = true | ||
count = 0 | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (s *Scanner) retryWrite(c client.Client, bp client.BatchPoints) { | ||
for { | ||
err := c.Write(bp) | ||
if err == nil { | ||
break | ||
} | ||
logger.LogString("insert error: "+err.Error(), TOLOGFILE|TOCONSOLE, LEVEL_ERROR) | ||
points := bp.Points() | ||
if len(points) > 0 { | ||
logger.LogString("retry for points like:"+points[0].String(), TOLOGFILE|TOCONSOLE, LEVEL_ERROR) | ||
} | ||
time.Sleep(3 * time.Second) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package src | ||
|
||
import ( | ||
client "github.com/influxdata/influxdb1-client/v2" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
copyright 2023 Qizhi Huang([email protected]) | ||
*/ | ||
|
||
package main | ||
package src | ||
|
||
import ( | ||
"log" | ||
|
@@ -30,7 +30,7 @@ var LevelPrefixDict map[int]string = map[int]string{ | |
LEVEL_ERROR: "ERROR: ", | ||
} | ||
|
||
type Logger struct { | ||
type Log struct { | ||
logDir string | ||
logName string | ||
fileWriter *os.File | ||
|
@@ -40,12 +40,20 @@ type Logger struct { | |
debug bool | ||
} | ||
|
||
func NewLogger() *Logger { | ||
var Logger *Log | ||
var logger *Log | ||
|
||
func init() { | ||
Logger = NewLogger() | ||
logger = Logger | ||
} | ||
|
||
func NewLogger() *Log { | ||
var err error | ||
tm := time.Unix(0, time.Now().UnixNano()) | ||
timestr := tm.Format("2006-01-02_15-04-05") | ||
filename := "migrate_log_" + timestr + ".log" | ||
l := &Logger{ | ||
l := &Log{ | ||
logDir: "./logs", | ||
logName: filename, | ||
debug: false, | ||
|
@@ -69,15 +77,15 @@ func NewLogger() *Logger { | |
return l | ||
} | ||
|
||
func (l *Logger) SetDebug() { | ||
func (l *Log) SetDebug() { | ||
l.debug = true | ||
} | ||
|
||
func (l *Logger) IsDebug() bool { | ||
func (l *Log) IsDebug() bool { | ||
return l.debug | ||
} | ||
|
||
func (l *Logger) LogString(str string, target int, level int) { | ||
func (l *Log) LogString(str string, target int, level int) { | ||
if level == LEVEL_DEBUG { | ||
if !l.debug { | ||
return | ||
|
@@ -96,12 +104,12 @@ func (l *Logger) LogString(str string, target int, level int) { | |
} | ||
} | ||
|
||
func (l *Logger) LogError(err error) { | ||
func (l *Log) LogError(err error) { | ||
l.fileLogger.Println("ERROR: ", err.Error()) | ||
l.errorLogger.Println("ERROR: ", err) | ||
} | ||
|
||
func (l *Logger) close() { | ||
func (l *Log) Close() { | ||
l.fileLogger = nil | ||
l.fileWriter.Close() | ||
l.consoleLogger = nil | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters