forked from pingcap/tidb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask.go
103 lines (88 loc) · 2.62 KB
/
task.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0.
package export
import "fmt"
// Task is a file dump task for dumpling, it could either be dumping database/table/view metadata, table data
type Task interface {
// Brief is the brief for a dumping task
Brief() string
}
// TaskDatabaseMeta is a dumping database metadata task
type TaskDatabaseMeta struct {
Task
DatabaseName string
CreateDatabaseSQL string
}
// TaskTableMeta is a dumping table metadata task
type TaskTableMeta struct {
Task
DatabaseName string
TableName string
CreateTableSQL string
}
// TaskViewMeta is a dumping view metadata task
type TaskViewMeta struct {
Task
DatabaseName string
ViewName string
CreateTableSQL string
CreateViewSQL string
}
// TaskTableData is a dumping table data task
type TaskTableData struct {
Task
Meta TableMeta
Data TableDataIR
ChunkIndex int
TotalChunks int
}
// NewTaskDatabaseMeta returns a new dumping database metadata task
func NewTaskDatabaseMeta(dbName, createSQL string) *TaskDatabaseMeta {
return &TaskDatabaseMeta{
DatabaseName: dbName,
CreateDatabaseSQL: createSQL,
}
}
// NewTaskTableMeta returns a new dumping table metadata task
func NewTaskTableMeta(dbName, tblName, createSQL string) *TaskTableMeta {
return &TaskTableMeta{
DatabaseName: dbName,
TableName: tblName,
CreateTableSQL: createSQL,
}
}
// NewTaskViewMeta returns a new dumping view metadata task
func NewTaskViewMeta(dbName, tblName, createTableSQL, createViewSQL string) *TaskViewMeta {
return &TaskViewMeta{
DatabaseName: dbName,
ViewName: tblName,
CreateTableSQL: createTableSQL,
CreateViewSQL: createViewSQL,
}
}
// NewTaskTableData returns a new dumping table data task
func NewTaskTableData(meta TableMeta, data TableDataIR, currentChunk, totalChunks int) *TaskTableData {
return &TaskTableData{
Meta: meta,
Data: data,
ChunkIndex: currentChunk,
TotalChunks: totalChunks,
}
}
// Brief implements task.Brief
func (t *TaskDatabaseMeta) Brief() string {
return fmt.Sprintf("meta of dababase '%s'", t.DatabaseName)
}
// Brief implements task.Brief
func (t *TaskTableMeta) Brief() string {
return fmt.Sprintf("meta of table '%s'.'%s'", t.DatabaseName, t.TableName)
}
// Brief implements task.Brief
func (t *TaskViewMeta) Brief() string {
return fmt.Sprintf("meta of view '%s'.'%s'", t.DatabaseName, t.ViewName)
}
// Brief implements task.Brief
func (t *TaskTableData) Brief() string {
db, tbl := t.Meta.DatabaseName(), t.Meta.TableName()
idx, total := t.ChunkIndex, t.TotalChunks
return fmt.Sprintf("data of table '%s'.'%s'(%d/%d)", db, tbl, idx, total)
}