Skip to content

Commit 13e1419

Browse files
committed
draft
Signed-off-by: Wenqi Mou <[email protected]>
1 parent c508e4b commit 13e1419

File tree

11 files changed

+689
-26
lines changed

11 files changed

+689
-26
lines changed

br/pkg/checkpoint/BUILD.bazel

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ go_library(
88
"external_storage.go",
99
"log_restore.go",
1010
"manager.go",
11+
"name.go",
1112
"restore.go",
1213
"storage.go",
1314
"ticker.go",
@@ -43,12 +44,15 @@ go_library(
4344
go_test(
4445
name = "checkpoint_test",
4546
timeout = "short",
46-
srcs = ["checkpoint_test.go"],
47+
srcs = [
48+
"checkpoint_test.go",
49+
"name_test.go",
50+
],
51+
embed = [":checkpoint"],
4752
flaky = True,
4853
race = "on",
4954
shard_count = 13,
5055
deps = [
51-
":checkpoint",
5256
"//br/pkg/gluetidb",
5357
"//br/pkg/pdutil",
5458
"//br/pkg/storage",

br/pkg/checkpoint/checkpoint_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import (
3636
"github.com/tikv/client-go/v2/oracle"
3737
)
3838

39+
const tableSuffix string = "foo"
40+
3941
func TestCheckpointMetaForBackup(t *testing.T) {
4042
ctx := context.Background()
4143
base := t.TempDir()

br/pkg/checkpoint/log_restore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ type TaskInfoForLogRestore struct {
187187
Progress RestoreProgress
188188
}
189189

190-
func TryToGetCheckpointTaskInfo(
190+
func GetCheckpointTaskInfo(
191191
ctx context.Context,
192192
snapshotManager SnapshotMetaManagerT,
193193
logManager LogMetaManagerT,

br/pkg/checkpoint/manager.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ import (
2727
"github.com/pingcap/tidb/pkg/parser/ast"
2828
)
2929

30+
// SnapshotMetaManagerT is a type alias for MetaManager interface specialized for snapshot restoration
3031
type SnapshotMetaManagerT = MetaManager[
3132
RestoreKeyType, RestoreValueType, RestoreValueType, CheckpointMetadataForSnapshotRestore,
3233
]
34+
35+
// LogMetaManagerT is a type alias for LogMetaManager interface specialized for log restoration
3336
type LogMetaManagerT = LogMetaManager[
3437
LogRestoreKeyType, LogRestoreValueType, LogRestoreValueMarshaled, CheckpointMetadataForLogRestore,
3538
]
@@ -48,6 +51,8 @@ func DefaultTickDurationConfig() tickDurationConfig {
4851
}
4952
}
5053

54+
// MetaManager defines the interface for checkpoint metadata operations
55+
// It handles loading, saving, and checking the existence of checkpoint data
5156
type MetaManager[K KeyType, SV, LV ValueType, M any] interface {
5257
fmt.Stringer
5358

@@ -67,6 +72,8 @@ type MetaManager[K KeyType, SV, LV ValueType, M any] interface {
6772
Close()
6873
}
6974

75+
// LogMetaManager extends MetaManager with additional operations specific to log restoration
76+
// This includes handling checkpoint progress and ingest index repair SQLs
7077
type LogMetaManager[K KeyType, SV, LV ValueType, M any] interface {
7178
MetaManager[K, SV, LV, M]
7279

@@ -79,6 +86,8 @@ type LogMetaManager[K KeyType, SV, LV ValueType, M any] interface {
7986
ExistsCheckpointIngestIndexRepairSQLs(context.Context) (bool, error)
8087
}
8188

89+
// TableMetaManager implements the MetaManager interface using database tables for storage
90+
// It stores checkpoint data in tables within the TiDB database
8291
type TableMetaManager[K KeyType, SV, LV ValueType, M any] struct {
8392
se glue.Session
8493
runnerSe glue.Session
@@ -90,6 +99,7 @@ func NewLogTableMetaManager(
9099
g glue.Glue,
91100
dom *domain.Domain,
92101
dbName string,
102+
id uint64,
93103
) (LogMetaManagerT, error) {
94104
se, err := g.CreateSession(dom.Store())
95105
if err != nil {
@@ -105,14 +115,15 @@ func NewLogTableMetaManager(
105115
se: se,
106116
runnerSe: runnerSe,
107117
dom: dom,
108-
dbName: dbName,
118+
dbName: fmt.Sprintf("%s_%d", dbName, id),
109119
}, nil
110120
}
111121

112122
func NewSnapshotTableMetaManager(
113123
g glue.Glue,
114124
dom *domain.Domain,
115125
dbName string,
126+
id uint64,
116127
) (SnapshotMetaManagerT, error) {
117128
se, err := g.CreateSession(dom.Store())
118129
if err != nil {
@@ -128,7 +139,7 @@ func NewSnapshotTableMetaManager(
128139
se: se,
129140
runnerSe: runnerSe,
130141
dom: dom,
131-
dbName: dbName,
142+
dbName: fmt.Sprintf("%s_%d", dbName, id),
132143
}, nil
133144
}
134145

@@ -145,7 +156,7 @@ func (manager *TableMetaManager[K, SV, LV, M]) Close() {
145156
}
146157
}
147158

148-
// load the whole checkpoint range data and retrieve the metadata of restored ranges
159+
// LoadCheckpointData loads the whole checkpoint range data and retrieve the metadata of restored ranges
149160
// and return the total time cost in the past executions
150161
func (manager *TableMetaManager[K, SV, LV, M]) LoadCheckpointData(
151162
ctx context.Context,
@@ -281,14 +292,15 @@ func NewSnapshotStorageMetaManager(
281292
cipher *backuppb.CipherInfo,
282293
clusterID uint64,
283294
prefix string,
295+
id uint64,
284296
) SnapshotMetaManagerT {
285297
return &StorageMetaManager[
286298
RestoreKeyType, RestoreValueType, RestoreValueType, CheckpointMetadataForSnapshotRestore,
287299
]{
288300
storage: storage,
289301
cipher: cipher,
290302
clusterID: fmt.Sprintf("%d", clusterID),
291-
taskName: fmt.Sprintf("%d/%s", clusterID, prefix),
303+
taskName: fmt.Sprintf("%d/%s_%d", clusterID, prefix, id),
292304
}
293305
}
294306

@@ -297,14 +309,15 @@ func NewLogStorageMetaManager(
297309
cipher *backuppb.CipherInfo,
298310
clusterID uint64,
299311
prefix string,
312+
id uint64,
300313
) LogMetaManagerT {
301314
return &StorageMetaManager[
302315
LogRestoreKeyType, LogRestoreValueType, LogRestoreValueMarshaled, CheckpointMetadataForLogRestore,
303316
]{
304317
storage: storage,
305318
cipher: cipher,
306319
clusterID: fmt.Sprintf("%d", clusterID),
307-
taskName: fmt.Sprintf("%d/%s", clusterID, prefix),
320+
taskName: fmt.Sprintf("%d/%s_%d", clusterID, prefix, id),
308321
}
309322
}
310323

br/pkg/restore/log_client/client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ type LogClient struct {
213213

214214
logFilesStat logFilesStatistic
215215
restoreStat restoreStatistics
216+
217+
checkpointTableSuffix string
216218
}
217219

218220
type restoreStatistics struct {

0 commit comments

Comments
 (0)