Skip to content

Commit

Permalink
Refactor: rename termCh to completionCh (#3101)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshtin authored Jul 14, 2022
1 parent 8d536bc commit a1ac36f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions service/history/historyEngine.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,11 +797,11 @@ func (e *historyEngineImpl) QueryWorkflow(
scope.IncCounter(metrics.QueryBufferExceededCount)
return nil, consts.ErrConsistentQueryBufferExceeded
}
queryID, termCh := queryReg.BufferQuery(req.GetQuery())
queryID, completionCh := queryReg.BufferQuery(req.GetQuery())
defer queryReg.RemoveQuery(queryID)
weCtx.GetReleaseFn()(nil)
select {
case <-termCh:
case <-completionCh:
completionState, err := queryReg.GetCompletionState(queryID)
if err != nil {
scope.IncCounter(metrics.QueryRegistryInvalidStateCount)
Expand Down
4 changes: 2 additions & 2 deletions service/history/workflow/query_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type (
HasFailedQuery() bool
GetFailedIDs() []string

GetQueryTermCh(string) (<-chan struct{}, error)
GetQueryCompletionCh(string) (<-chan struct{}, error)
GetQueryInput(string) (*querypb.WorkflowQuery, error)
GetCompletionState(string) (*QueryCompletionState, error)

Expand Down Expand Up @@ -125,7 +125,7 @@ func (r *queryRegistryImpl) GetFailedIDs() []string {
return r.getIDs(r.failed)
}

func (r *queryRegistryImpl) GetQueryTermCh(id string) (<-chan struct{}, error) {
func (r *queryRegistryImpl) GetQueryCompletionCh(id string) (<-chan struct{}, error) {
r.RLock()
defer r.RUnlock()
q, err := r.getQueryNoLock(id)
Expand Down
42 changes: 21 additions & 21 deletions service/history/workflow/query_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ func (s *QueryRegistrySuite) SetupTest() {
func (s *QueryRegistrySuite) TestQueryRegistry() {
qr := NewQueryRegistry()
ids := make([]string, 100, 100)
termChans := make([]<-chan struct{}, 100, 100)
completionChs := make([]<-chan struct{}, 100, 100)
for i := 0; i < 100; i++ {
ids[i], termChans[i] = qr.BufferQuery(&querypb.WorkflowQuery{})
ids[i], completionChs[i] = qr.BufferQuery(&querypb.WorkflowQuery{})
}
s.assertBufferedState(qr, ids...)
s.assertHasQueries(qr, true, false, false, false)
s.assertQuerySizes(qr, 100, 0, 0, 0)
s.assertChanState(false, termChans...)
s.assertChanState(false, completionChs...)

for i := 0; i < 25; i++ {
err := qr.SetCompletionState(ids[i], &QueryCompletionState{
Expand All @@ -75,8 +75,8 @@ func (s *QueryRegistrySuite) TestQueryRegistry() {
s.assertBufferedState(qr, ids[25:]...)
s.assertHasQueries(qr, true, true, false, false)
s.assertQuerySizes(qr, 75, 25, 0, 0)
s.assertChanState(true, termChans[0:25]...)
s.assertChanState(false, termChans[25:]...)
s.assertChanState(true, completionChs[0:25]...)
s.assertChanState(false, completionChs[25:]...)

for i := 25; i < 50; i++ {
err := qr.SetCompletionState(ids[i], &QueryCompletionState{
Expand All @@ -89,8 +89,8 @@ func (s *QueryRegistrySuite) TestQueryRegistry() {
s.assertBufferedState(qr, ids[50:]...)
s.assertHasQueries(qr, true, true, true, false)
s.assertQuerySizes(qr, 50, 25, 25, 0)
s.assertChanState(true, termChans[0:50]...)
s.assertChanState(false, termChans[50:]...)
s.assertChanState(true, completionChs[0:50]...)
s.assertChanState(false, completionChs[50:]...)

for i := 50; i < 75; i++ {
err := qr.SetCompletionState(ids[i], &QueryCompletionState{
Expand All @@ -105,8 +105,8 @@ func (s *QueryRegistrySuite) TestQueryRegistry() {
s.assertBufferedState(qr, ids[75:]...)
s.assertHasQueries(qr, true, true, true, true)
s.assertQuerySizes(qr, 25, 25, 25, 25)
s.assertChanState(true, termChans[0:75]...)
s.assertChanState(false, termChans[75:]...)
s.assertChanState(true, completionChs[0:75]...)
s.assertChanState(false, completionChs[75:]...)

for i := 0; i < 75; i++ {
switch i % 3 {
Expand All @@ -132,8 +132,8 @@ func (s *QueryRegistrySuite) TestQueryRegistry() {
s.assertBufferedState(qr, ids[75:]...)
s.assertHasQueries(qr, true, true, true, true)
s.assertQuerySizes(qr, 25, 25, 25, 25)
s.assertChanState(true, termChans[0:75]...)
s.assertChanState(false, termChans[75:]...)
s.assertChanState(true, completionChs[0:75]...)
s.assertChanState(false, completionChs[75:]...)

for i := 0; i < 25; i++ {
qr.RemoveQuery(ids[i])
Expand All @@ -155,15 +155,15 @@ func (s *QueryRegistrySuite) TestQueryRegistry() {
s.assertHasQueries(qr, i < 99, false, false, false)
s.assertQuerySizes(qr, 100-i-1, 0, 0, 0)
}
s.assertChanState(true, termChans[0:75]...)
s.assertChanState(false, termChans[75:]...)
s.assertChanState(true, completionChs[0:75]...)
s.assertChanState(false, completionChs[75:]...)
}

func (s *QueryRegistrySuite) assertBufferedState(qr QueryRegistry, ids ...string) {
for _, id := range ids {
termCh, err := qr.GetQueryTermCh(id)
completionCh, err := qr.GetQueryCompletionCh(id)
s.NoError(err)
s.False(closed(termCh))
s.False(closed(completionCh))
input, err := qr.GetQueryInput(id)
s.NoError(err)
s.NotNil(input)
Expand All @@ -175,9 +175,9 @@ func (s *QueryRegistrySuite) assertBufferedState(qr QueryRegistry, ids ...string

func (s *QueryRegistrySuite) assertCompletedState(qr QueryRegistry, ids ...string) {
for _, id := range ids {
termCh, err := qr.GetQueryTermCh(id)
completionCh, err := qr.GetQueryCompletionCh(id)
s.NoError(err)
s.True(closed(termCh))
s.True(closed(completionCh))
input, err := qr.GetQueryInput(id)
s.NoError(err)
s.NotNil(input)
Expand All @@ -192,9 +192,9 @@ func (s *QueryRegistrySuite) assertCompletedState(qr QueryRegistry, ids ...strin

func (s *QueryRegistrySuite) assertUnblockedState(qr QueryRegistry, ids ...string) {
for _, id := range ids {
termCh, err := qr.GetQueryTermCh(id)
completionCh, err := qr.GetQueryCompletionCh(id)
s.NoError(err)
s.True(closed(termCh))
s.True(closed(completionCh))
input, err := qr.GetQueryInput(id)
s.NoError(err)
s.NotNil(input)
Expand All @@ -209,9 +209,9 @@ func (s *QueryRegistrySuite) assertUnblockedState(qr QueryRegistry, ids ...strin

func (s *QueryRegistrySuite) assertFailedState(qr QueryRegistry, ids ...string) {
for _, id := range ids {
termCh, err := qr.GetQueryTermCh(id)
completionCh, err := qr.GetQueryCompletionCh(id)
s.NoError(err)
s.True(closed(termCh))
s.True(closed(completionCh))
input, err := qr.GetQueryInput(id)
s.NoError(err)
s.NotNil(input)
Expand Down

0 comments on commit a1ac36f

Please sign in to comment.