-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drainer: Fix #724, Enable drainer to purge old incremental backup data on disk #885
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d530f78
drainer: Fix #724, Enable drainer to purge old incremental backup dat…
suzaku 3edf281
Change return type to the Syncer interface
suzaku 7454403
Move retention-time to the example for when the type is file
suzaku d58980a
Address comment
suzaku 9ae079a
Update pkg/binlogfile/binlogger.go
suzaku 5a0765e
Update pkg/binlogfile/binlogger.go
suzaku File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -14,7 +14,11 @@ | |
package sync | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/pingcap/errors" | ||
"github.com/pingcap/log" | ||
"github.com/pingcap/tidb-binlog/drainer/translator" | ||
"github.com/pingcap/tidb-binlog/pkg/binlogfile" | ||
pb "github.com/pingcap/tidb-binlog/proto/binlog" | ||
|
@@ -24,21 +28,44 @@ import ( | |
var _ Syncer = &pbSyncer{} | ||
|
||
type pbSyncer struct { | ||
binlogger binlogfile.Binlogger | ||
|
||
*baseSyncer | ||
|
||
binlogger binlogfile.Binlogger | ||
cancel func() | ||
} | ||
|
||
// NewPBSyncer sync binlog to files | ||
func NewPBSyncer(dir string, tableInfoGetter translator.TableInfoGetter) (*pbSyncer, error) { | ||
func NewPBSyncer(dir string, retentionDays int, tableInfoGetter translator.TableInfoGetter) (*pbSyncer, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported func NewPBSyncer returns unexported type *sync.pbSyncer, which can be annoying to use |
||
binlogger, err := binlogfile.OpenBinlogger(dir, binlogfile.SegmentSizeBytes) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
|
||
ctx, cancel := context.WithCancel(context.TODO()) | ||
|
||
s := &pbSyncer{ | ||
binlogger: binlogger, | ||
baseSyncer: newBaseSyncer(tableInfoGetter), | ||
cancel: cancel, | ||
} | ||
|
||
if retentionDays > 0 { | ||
// TODO: Add support for human readable format input of times like "7d", "12h" | ||
retentionTime := time.Duration(retentionDays) * 24 * time.Hour | ||
ticker := time.NewTicker(time.Hour) | ||
go func() { | ||
defer ticker.Stop() | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
log.Info("Binlog GC loop stopped") | ||
return | ||
case <-ticker.C: | ||
log.Info("Trying to GC binlog files") | ||
binlogger.GCByTime(retentionTime) | ||
} | ||
} | ||
}() | ||
} | ||
|
||
return s, nil | ||
|
@@ -71,6 +98,8 @@ func (p *pbSyncer) saveBinlog(binlog *pb.Binlog) error { | |
} | ||
|
||
func (p *pbSyncer) Close() error { | ||
p.cancel() | ||
|
||
err := p.binlogger.Close() | ||
p.setErr(err) | ||
close(p.success) | ||
|
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported func NewPBSyncer returns unexported type *sync.pbSyncer, which can be annoying to use