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
Common cycle manager #3025
Common cycle manager #3025
Conversation
a5872bf
to
e561dfd
Compare
c.commitLogMaintenance = cyclemanager.NewMulti(commitlogMaintenanceTicker) | ||
c.tombstoneCleanup = cyclemanager.NewMulti(tombstoneCleanupTicker) | ||
|
||
c.commitLogMaintenance.Start() |
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.
c.commitLogMaintenance or c.tombstoneCleanup one of them could be nil
I think we need to check for nil pointer before calling start
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.
cyclemanager.NewMulti()
method always returns instance. so at that point both of cycle managers are inited and safe to use
tombstoneCleanupStop <- nil | ||
}() | ||
|
||
commitlogMaintenanceStopErr := <-commitlogMaintenanceStop |
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.
the main goroutine blocks anyway. I would rather use a wait group instead of using two channels
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.
Right, refactored to use WaitGroup
. Also extracted to separate method to be reused in Shutdown
method
} | ||
c.lock.Unlock() | ||
|
||
c.commitLogMaintenance.Start() |
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.
Same as before we need to check for nit pointers
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.
as explained above. method returns earlier if instance is not inited.
commitlogMaintenanceStop := make(chan error) | ||
tombstoneCleanupStop := make(chan error) | ||
go func() { | ||
if err := c.commitLogMaintenance.StopAndWait(ctx); err != nil { |
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.
check nil for nil pointer
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.
Check whether commitLogMaintenance
and tombstoneCleanup
are nils is done at the beginning of the method. If so, method returns earlier.
I've extracted the check to separate method, as it was used couple of times already, and changed condition to consider instance inited if both cycle managers are created, not just one.
(change of condition was purely cosmetic, cause both cycle managers are created at the same time. So either both or none will be created)
commitlogMaintenanceStop <- nil | ||
}() | ||
go func() { | ||
if err := c.tombstoneCleanup.StopAndWait(ctx); err != nil { |
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.
here as well
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.
as explained above. method returns earlier if instance is not inited.
|
||
eg := errgroup.Group{} | ||
eg.Go(func() error { | ||
if err := c.commitLogMaintenance.StopAndWait(ctx); err != nil { |
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.
check nil for nil pointer
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.
as explained above. method returns earlier if instance is not inited.
entities/cyclemanager/callbacks.go
Outdated
counter: 0, | ||
states: map[uint32]*callbackState{}, | ||
keys: []uint32{}, | ||
canceledCtx: canceledCtx, |
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 is not clear to me why are we returning cancelled context canceledCtx
(see line 41)
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.
I used contexts to track if callback is being currently executed. Active context means callback is running, expired context means callback finished execution or was not yet started.
This particular canceled (expired) context was meant to be used as const context, for all newly added callbacks to mark them as not running.
I've changed the implementation to use nil to mark not yet run callbacks instead of expired ctx.
continue | ||
case <-ctx.Done(): | ||
// in case both context are ready, but incoming ctx was selected | ||
// check again running ctx as priority one |
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.
I would consider using if runningCtx.Err() != nil
instead of the select
because it is more simple
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.
Good point. Changed to error check.
"github.com/weaviate/weaviate/entities/storagestate" | ||
) | ||
|
||
func TestStoreBackup_PauseCompaction(t *testing.T) { |
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.
Maybe it would be also useful to include in all tests a scenario where we create n-buckets in store? now we create in each test only 1 bucket.
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.
added tests for 1, 2 and 5 buckets
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.
great! looks good
// h.tombstoneCleanupCycle.Start() | ||
// h.commitLogMaintenanceCycle.Start() |
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.
why is this commented?
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.
good catch. removed
066ddf0
to
54ccdce
Compare
What's being changed:
Addresses #2983
Instead creating multiple cycle managers, separate for each bucket, geo prop etc, common cycle managers are created for different usecases:
Review checklist