Files
tasks/service/history/workflow/query_registry.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

192 lines
4.0 KiB
Go

package workflow
import (
"sync"
querypb "go.temporal.io/api/query/v1"
"go.temporal.io/api/serviceerror"
"go.temporal.io/server/service/history/consts"
historyi "go.temporal.io/server/service/history/interfaces"
)
var (
errQueryNotExists = serviceerror.NewInternal("query does not exist")
)
type (
queryRegistryImpl struct {
sync.RWMutex
buffered map[string]query
completed map[string]query
unblocked map[string]query
failed map[string]query
}
)
func NewQueryRegistry() historyi.QueryRegistry {
return &queryRegistryImpl{
buffered: make(map[string]query),
completed: make(map[string]query),
unblocked: make(map[string]query),
failed: make(map[string]query),
}
}
func (r *queryRegistryImpl) HasBufferedQuery() bool {
r.RLock()
defer r.RUnlock()
return len(r.buffered) > 0
}
func (r *queryRegistryImpl) GetBufferedIDs() []string {
r.RLock()
defer r.RUnlock()
return r.getIDs(r.buffered)
}
func (r *queryRegistryImpl) HasCompletedQuery() bool {
r.RLock()
defer r.RUnlock()
return len(r.completed) > 0
}
func (r *queryRegistryImpl) GetCompletedIDs() []string {
r.RLock()
defer r.RUnlock()
return r.getIDs(r.completed)
}
func (r *queryRegistryImpl) HasUnblockedQuery() bool {
r.RLock()
defer r.RUnlock()
return len(r.unblocked) > 0
}
func (r *queryRegistryImpl) GetUnblockedIDs() []string {
r.RLock()
defer r.RUnlock()
return r.getIDs(r.unblocked)
}
func (r *queryRegistryImpl) HasFailedQuery() bool {
r.RLock()
defer r.RUnlock()
return len(r.failed) > 0
}
func (r *queryRegistryImpl) GetFailedIDs() []string {
r.RLock()
defer r.RUnlock()
return r.getIDs(r.failed)
}
func (r *queryRegistryImpl) GetQueryCompletionCh(id string) (<-chan struct{}, error) {
r.RLock()
defer r.RUnlock()
q, err := r.getQueryNoLock(id)
if err != nil {
return nil, err
}
return q.getCompletionCh(), nil
}
func (r *queryRegistryImpl) GetQueryInput(id string) (*querypb.WorkflowQuery, error) {
r.RLock()
defer r.RUnlock()
q, err := r.getQueryNoLock(id)
if err != nil {
return nil, err
}
return q.getQueryInput(), nil
}
func (r *queryRegistryImpl) GetCompletionState(id string) (*historyi.QueryCompletionState, error) {
r.RLock()
defer r.RUnlock()
q, err := r.getQueryNoLock(id)
if err != nil {
return nil, err
}
return q.GetCompletionState()
}
func (r *queryRegistryImpl) BufferQuery(queryInput *querypb.WorkflowQuery) (string, <-chan struct{}) {
r.Lock()
defer r.Unlock()
q := newQuery(queryInput)
id := q.getID()
r.buffered[id] = q
return id, q.getCompletionCh()
}
func (r *queryRegistryImpl) SetCompletionState(id string, completionState *historyi.QueryCompletionState) error {
r.Lock()
defer r.Unlock()
q, ok := r.buffered[id]
if !ok {
return errQueryNotExists
}
if err := q.setCompletionState(completionState); err != nil {
return err
}
delete(r.buffered, id)
switch completionState.Type {
case QueryCompletionTypeSucceeded:
r.completed[id] = q
case QueryCompletionTypeUnblocked:
r.unblocked[id] = q
case QueryCompletionTypeFailed:
r.failed[id] = q
}
return nil
}
func (r *queryRegistryImpl) RemoveQuery(id string) {
r.Lock()
defer r.Unlock()
delete(r.buffered, id)
delete(r.completed, id)
delete(r.unblocked, id)
delete(r.failed, id)
}
func (r *queryRegistryImpl) Clear() {
r.Lock()
defer r.Unlock()
for id, q := range r.buffered {
_ = q.setCompletionState(&historyi.QueryCompletionState{
Type: QueryCompletionTypeFailed,
Err: consts.ErrBufferedQueryCleared,
})
r.failed[id] = q
}
r.buffered = make(map[string]query)
}
func (r *queryRegistryImpl) getQueryNoLock(id string) (query, error) {
if q, ok := r.buffered[id]; ok {
return q, nil
}
if q, ok := r.completed[id]; ok {
return q, nil
}
if q, ok := r.unblocked[id]; ok {
return q, nil
}
if q, ok := r.failed[id]; ok {
return q, nil
}
return nil, errQueryNotExists
}
func (r *queryRegistryImpl) getIDs(m map[string]query) []string {
result := make([]string, len(m))
index := 0
for id := range m {
result[index] = id
index++
}
return result
}