This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 188
/
writer.go
66 lines (56 loc) · 2.43 KB
/
writer.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
// Copyright 2019 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 writer
import (
gmysql "github.com/siddontang/go-mysql/mysql"
"github.com/siddontang/go-mysql/replication"
"github.com/pingcap/dm/pkg/gtid"
)
// Result represents a write result.
type Result struct {
Ignore bool // whether the event ignored by the writer
}
// RecoverResult represents a result for a binlog recover operation.
type RecoverResult struct {
// true if recover operation has done and successfully.
// false if no recover operation has done or unsuccessfully.
Recovered bool
// the latest binlog position after recover operation has done.
LatestPos gmysql.Position
// the latest binlog GTID set after recover operation has done.
LatestGTIDs gtid.Set
}
// Writer writes binlog events into disk or any other memory structure.
// The writer should support:
// 1. write binlog events and report the operation result
// 2. skip any obsolete binlog events
// 3. generate dummy events to fill the gap if needed
// 4. rotate binlog(relay) file if needed
// 5. rollback/discard unfinished binlog entries(events or transactions)
type Writer interface {
// Start prepares the writer for writing binlog events.
Start() error
// Close closes the writer and release the resource.
Close() error
// Recover tries to recover the binlog file or any other memory structure associate with this writer.
// It is often used to recover a binlog file with some corrupt/incomplete binlog events/transactions at the end of the file.
// It is not safe for concurrent use by multiple goroutines.
// It should be called before writing to the file.
Recover() (*RecoverResult, error)
// WriteEvent writes an binlog event's data into disk or any other places.
// It is not safe for concurrent use by multiple goroutines.
WriteEvent(ev *replication.BinlogEvent) (*Result, error)
// Flush flushes the buffered data to a stable storage or sends through the network.
// It is not safe for concurrent use by multiple goroutines.
Flush() error
}