Files
tasks/service/history/queues/action_slice_predicate.go
Alex ShtinandGitHub 8e8f1b0f7c Remove license header from every file (#7689)
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.

## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
2025-05-01 18:50:21 -07:00

95 lines
2.4 KiB
Go

package queues
import (
"go.temporal.io/server/service/history/tasks"
)
const (
moveSliceDefaultReaderMinPendingTaskCount = 50
moveSliceDefaultReaderMinSliceCount = 3
)
var _ Action = (*slicePredicateAction)(nil)
type (
// slicePredicateAction will move all slices in default reader
// with non-universal predicate to the next reader so that upon restart
// task loading for those slices won't blocking loading for other slices
// in the default reader.
//
// Slice.ShrinkScope() will shrink its predicate when there's few
// namespaces left. But those slices may still in the default reader.
// If there are many such slices in the default reader, then upon restart
// task loading for other namespace will be blocked. So we need to move those
// slices to a different reader.
//
// NOTE: When there's no restart/shard movement, this movement won't affect
// anything, as slice with non-universal predicate must have already loaded
// all tasks into memory.
slicePredicateAction struct {
monitor Monitor
maxReaderCount int
}
)
func newSlicePredicateAction(
monitor Monitor,
maxReaderCount int,
) *slicePredicateAction {
return &slicePredicateAction{
monitor: monitor,
maxReaderCount: maxReaderCount,
}
}
func (a *slicePredicateAction) Name() string {
return "slice-predicate"
}
func (a *slicePredicateAction) Run(readerGroup *ReaderGroup) {
reader, ok := readerGroup.ReaderByID(DefaultReaderId)
if !ok {
return
}
if int64(a.maxReaderCount) <= DefaultReaderId+1 {
return
}
sliceCount := a.monitor.GetSliceCount(DefaultReaderId)
pendingTasks := 0
hasNonUniversalPredicate := false
reader.WalkSlices(func(s Slice) {
pendingTasks += a.monitor.GetSlicePendingTaskCount(s)
if !tasks.IsUniverisalPredicate(s.Scope().Predicate) {
hasNonUniversalPredicate = true
}
})
// only move slices when either default reader slice count or
// pending task count is high
if !hasNonUniversalPredicate ||
(pendingTasks < moveSliceDefaultReaderMinPendingTaskCount &&
sliceCount < moveSliceDefaultReaderMinSliceCount) {
return
}
var moveSlices []Slice
reader.SplitSlices(func(s Slice) (remaining []Slice, split bool) {
if tasks.IsUniverisalPredicate(s.Scope().Predicate) {
return []Slice{s}, false
}
moveSlices = append(moveSlices, s)
return nil, true
})
if len(moveSlices) == 0 {
return
}
nextReader := readerGroup.GetOrCreateReader(DefaultReaderId + 1)
nextReader.MergeSlices(moveSlices...)
}