-
Notifications
You must be signed in to change notification settings - Fork 287
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
sorter/leveldb(ticdc): separate write from table sorter #4686
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ed47259
sorter/leveldb(ticdc): separate write from table sorter
overvenus 65957c6
address lints
overvenus fb1e5a7
address comments
overvenus dda0efe
Merge branch 'master' into leveldb-split-write
ti-chi-bot e48970a
Merge branch 'master' into leveldb-split-write
ti-chi-bot 71be3b3
try fix pd breaking change
overvenus edeb755
Merge branch 'leveldb-split-write' of https://github.com/overvenus/ti…
overvenus 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 |
---|---|---|
|
@@ -49,6 +49,8 @@ type System struct { | |
dbs []db.DB | ||
dbSystem *actor.System | ||
DBRouter *actor.Router | ||
WriterSystem *actor.System | ||
WriterRouter *actor.Router | ||
compactSystem *actor.System | ||
compactRouter *actor.Router | ||
compactSched *lsorter.CompactScheduler | ||
|
@@ -64,14 +66,22 @@ type System struct { | |
|
||
// NewSystem returns a system. | ||
func NewSystem(dir string, memPercentage float64, cfg *config.DBConfig) *System { | ||
// A system polles actors that read and write leveldb. | ||
dbSystem, dbRouter := actor.NewSystemBuilder("sorter-db"). | ||
WorkerNumber(cfg.Count).Build() | ||
// A system polles actors that compact leveldb, garbage collection. | ||
compactSystem, compactRouter := actor.NewSystemBuilder("sorter-compactor"). | ||
WorkerNumber(cfg.Count).Build() | ||
// A system polles actors that receive events from Puller and batch send | ||
// writes to leveldb. | ||
writerSystem, writerRouter := actor.NewSystemBuilder("sorter-writer"). | ||
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. we have |
||
WorkerNumber(cfg.Count).Throughput(4, 64).Build() | ||
compactSched := lsorter.NewCompactScheduler(compactRouter) | ||
return &System{ | ||
dbSystem: dbSystem, | ||
DBRouter: dbRouter, | ||
WriterSystem: writerSystem, | ||
WriterRouter: writerRouter, | ||
compactSystem: compactSystem, | ||
compactRouter: compactRouter, | ||
compactSched: compactSched, | ||
|
@@ -85,20 +95,15 @@ func NewSystem(dir string, memPercentage float64, cfg *config.DBConfig) *System | |
} | ||
} | ||
|
||
// ActorID returns an ActorID correspond with tableID. | ||
func (s *System) ActorID(tableID uint64) actor.ID { | ||
// DBActorID returns an DBActorID correspond with tableID. | ||
func (s *System) DBActorID(tableID uint64) actor.ID { | ||
h := fnv.New64() | ||
b := [8]byte{} | ||
binary.LittleEndian.PutUint64(b[:], tableID) | ||
h.Write(b[:]) | ||
return actor.ID(h.Sum64() % uint64(s.cfg.Count)) | ||
} | ||
|
||
// Router returns db actors router. | ||
func (s *System) Router() *actor.Router { | ||
return s.DBRouter | ||
} | ||
|
||
// CompactScheduler returns compaction scheduler. | ||
func (s *System) CompactScheduler() *lsorter.CompactScheduler { | ||
return s.compactSched | ||
|
@@ -131,6 +136,7 @@ func (s *System) Start(ctx context.Context) error { | |
|
||
s.compactSystem.Start(ctx) | ||
s.dbSystem.Start(ctx) | ||
s.WriterSystem.Start(ctx) | ||
captureAddr := config.GetGlobalServerConfig().AdvertiseAddr | ||
totalMemory, err := memory.MemTotal() | ||
if err != nil { | ||
|
@@ -205,6 +211,7 @@ func (s *System) Stop() error { | |
defer cancel() | ||
// Close actors | ||
s.broadcast(ctx, s.DBRouter, message.StopMessage()) | ||
s.broadcast(ctx, s.WriterRouter, message.StopMessage()) | ||
s.broadcast(ctx, s.compactRouter, message.StopMessage()) | ||
// Close metrics goroutine. | ||
close(s.closedCh) | ||
|
@@ -216,6 +223,10 @@ func (s *System) Stop() error { | |
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
err = s.WriterSystem.Stop() | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
err = s.compactSystem.Stop() | ||
if err != nil { | ||
return errors.Trace(err) | ||
|
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
Oops, something went wrong.
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.
It makes the logic complex and unreadable to add so many fields in one struct, some fields are always nil in some cases.
And the
Task
is a part ofMessage
, The size will be larger and larger, maybe we should find a better way to extend theTask
orMessage
.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.
It's good point! Ideally tasks should be an enum type in rust, so tasks can be separated and more readable. Unfortunately, golang does not support it.
Maybe we should make Task be a pointer in Message? Though it makes memory allocation, not sure if it helps performance.
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.
Also see, notes in #4631