@@ -37,10 +37,10 @@ import (
37
37
"github.com/uber/cadence/service/matching/event"
38
38
)
39
39
40
- // TaskMatcher matches a task producer with a task consumer
40
+ // taskMatcherImpl matches a task producer with a task consumer
41
41
// Producers are usually rpc calls from history or taskReader
42
42
// that drains backlog from db. Consumers are the task list pollers
43
- type TaskMatcher struct {
43
+ type taskMatcherImpl struct {
44
44
log log.Logger
45
45
// synchronous task channel to match producer/consumer for any isolation group
46
46
// tasks having no isolation requirement are added to this channel
@@ -81,7 +81,7 @@ func newTaskMatcher(
81
81
isolationGroups []string ,
82
82
log log.Logger ,
83
83
tasklist * Identifier ,
84
- tasklistKind types.TaskListKind ) * TaskMatcher {
84
+ tasklistKind types.TaskListKind ) TaskMatcher {
85
85
dPtr := config .TaskDispatchRPS
86
86
limiter := quotas .NewRateLimiter (& dPtr , config .TaskDispatchRPSTTL , config .MinTaskThrottlingBurstSize ())
87
87
isolatedTaskC := make (map [string ]chan * InternalTask )
@@ -91,7 +91,7 @@ func newTaskMatcher(
91
91
92
92
cancelCtx , cancelFunc := context .WithCancel (context .Background ())
93
93
94
- return & TaskMatcher {
94
+ return & taskMatcherImpl {
95
95
log : log ,
96
96
limiter : limiter ,
97
97
scope : scope ,
@@ -108,7 +108,7 @@ func newTaskMatcher(
108
108
}
109
109
110
110
// DisconnectBlockedPollers gradually disconnects pollers which are blocked on long polling
111
- func (tm * TaskMatcher ) DisconnectBlockedPollers () {
111
+ func (tm * taskMatcherImpl ) DisconnectBlockedPollers () {
112
112
tm .cancelFunc ()
113
113
}
114
114
@@ -141,7 +141,7 @@ func (tm *TaskMatcher) DisconnectBlockedPollers() {
141
141
// - ratelimit is exceeded (does not apply to query task)
142
142
// - context deadline is exceeded
143
143
// - task is matched and consumer returns error in response channel
144
- func (tm * TaskMatcher ) Offer (ctx context.Context , task * InternalTask ) (bool , error ) {
144
+ func (tm * taskMatcherImpl ) Offer (ctx context.Context , task * InternalTask ) (bool , error ) {
145
145
startT := time .Now ()
146
146
if ! task .IsForwarded () {
147
147
err := tm .ratelimit (ctx )
@@ -213,15 +213,16 @@ func (tm *TaskMatcher) Offer(ctx context.Context, task *InternalTask) (bool, err
213
213
task .IsForwarded () { // task came from a child partition
214
214
// a forwarded backlog task from a child partition, block trying
215
215
// to match with a poller until ctx timeout
216
- return tm .offerOrTimeout (ctx , startT , task )
216
+ return tm .OfferOrTimeout (ctx , startT , task )
217
217
}
218
218
}
219
219
220
220
return false , nil
221
221
}
222
222
}
223
223
224
- func (tm * TaskMatcher ) offerOrTimeout (ctx context.Context , startT time.Time , task * InternalTask ) (bool , error ) {
224
+ // OfferOrTimeout offers a task to a poller and blocks until a poller picks up the task or context timeouts
225
+ func (tm * taskMatcherImpl ) OfferOrTimeout (ctx context.Context , startT time.Time , task * InternalTask ) (bool , error ) {
225
226
select {
226
227
case tm .getTaskC (task ) <- task : // poller picked up the task
227
228
if task .ResponseC != nil {
@@ -242,7 +243,7 @@ func (tm *TaskMatcher) offerOrTimeout(ctx context.Context, startT time.Time, tas
242
243
// OfferQuery will either match task to local poller or will forward query task.
243
244
// Local match is always attempted before forwarding is attempted. If local match occurs
244
245
// response and error are both nil, if forwarding occurs then response or error is returned.
245
- func (tm * TaskMatcher ) OfferQuery (ctx context.Context , task * InternalTask ) (* types.QueryWorkflowResponse , error ) {
246
+ func (tm * taskMatcherImpl ) OfferQuery (ctx context.Context , task * InternalTask ) (* types.QueryWorkflowResponse , error ) {
246
247
select {
247
248
case tm .queryTaskC <- task :
248
249
<- task .ResponseC
@@ -278,7 +279,7 @@ func (tm *TaskMatcher) OfferQuery(ctx context.Context, task *InternalTask) (*typ
278
279
279
280
// MustOffer blocks until a consumer is found to handle this task
280
281
// Returns error only when context is canceled, expired or the ratelimit is set to zero (allow nothing)
281
- func (tm * TaskMatcher ) MustOffer (ctx context.Context , task * InternalTask ) error {
282
+ func (tm * taskMatcherImpl ) MustOffer (ctx context.Context , task * InternalTask ) error {
282
283
e := event.E {
283
284
TaskListName : tm .tasklist .GetName (),
284
285
TaskListType : tm .tasklist .GetType (),
@@ -390,7 +391,7 @@ forLoop:
390
391
// On success, the returned task could be a query task or a regular task
391
392
// Returns ErrNoTasks when context deadline is exceeded
392
393
// Returns ErrMatcherClosed when matching is closed
393
- func (tm * TaskMatcher ) Poll (ctx context.Context , isolationGroup string ) (* InternalTask , error ) {
394
+ func (tm * taskMatcherImpl ) Poll (ctx context.Context , isolationGroup string ) (* InternalTask , error ) {
394
395
startT := time .Now ()
395
396
isolatedTaskC , ok := tm .isolatedTaskC [isolationGroup ]
396
397
if ! ok && isolationGroup != "" {
@@ -429,7 +430,7 @@ func (tm *TaskMatcher) Poll(ctx context.Context, isolationGroup string) (*Intern
429
430
// PollForQuery blocks until a *query* task is found or context deadline is exceeded
430
431
// Returns ErrNoTasks when context deadline is exceeded
431
432
// Returns ErrMatcherClosed when matching is closed
432
- func (tm * TaskMatcher ) PollForQuery (ctx context.Context ) (* InternalTask , error ) {
433
+ func (tm * taskMatcherImpl ) PollForQuery (ctx context.Context ) (* InternalTask , error ) {
433
434
startT := time .Now ()
434
435
// try local match first without blocking until context timeout
435
436
if task , err := tm .pollNonBlocking (ctx , nil , nil , tm .queryTaskC ); err == nil {
@@ -443,7 +444,7 @@ func (tm *TaskMatcher) PollForQuery(ctx context.Context) (*InternalTask, error)
443
444
}
444
445
445
446
// UpdateRatelimit updates the task dispatch rate
446
- func (tm * TaskMatcher ) UpdateRatelimit (rps * float64 ) {
447
+ func (tm * taskMatcherImpl ) UpdateRatelimit (rps * float64 ) {
447
448
if rps == nil {
448
449
return
449
450
}
@@ -457,11 +458,11 @@ func (tm *TaskMatcher) UpdateRatelimit(rps *float64) {
457
458
}
458
459
459
460
// Rate returns the current rate at which tasks are dispatched
460
- func (tm * TaskMatcher ) Rate () float64 {
461
+ func (tm * taskMatcherImpl ) Rate () float64 {
461
462
return float64 (tm .limiter .Limit ())
462
463
}
463
464
464
- func (tm * TaskMatcher ) pollOrForward (
465
+ func (tm * taskMatcherImpl ) pollOrForward (
465
466
ctx context.Context ,
466
467
startT time.Time ,
467
468
isolationGroup string ,
@@ -546,7 +547,7 @@ func (tm *TaskMatcher) pollOrForward(
546
547
}
547
548
}
548
549
549
- func (tm * TaskMatcher ) poll (
550
+ func (tm * taskMatcherImpl ) poll (
550
551
ctx context.Context ,
551
552
startT time.Time ,
552
553
isolatedTaskC <- chan * InternalTask ,
@@ -610,7 +611,7 @@ func (tm *TaskMatcher) poll(
610
611
}
611
612
}
612
613
613
- func (tm * TaskMatcher ) pollLocalWait (
614
+ func (tm * taskMatcherImpl ) pollLocalWait (
614
615
ctx context.Context ,
615
616
isolatedTaskC <- chan * InternalTask ,
616
617
taskC <- chan * InternalTask ,
@@ -670,7 +671,7 @@ func (tm *TaskMatcher) pollLocalWait(
670
671
}
671
672
}
672
673
673
- func (tm * TaskMatcher ) pollNonBlocking (
674
+ func (tm * taskMatcherImpl ) pollNonBlocking (
674
675
ctx context.Context ,
675
676
isolatedTaskC <- chan * InternalTask ,
676
677
taskC <- chan * InternalTask ,
@@ -736,21 +737,21 @@ func (tm *TaskMatcher) pollNonBlocking(
736
737
}
737
738
}
738
739
739
- func (tm * TaskMatcher ) fwdrPollReqTokenC (isolationGroup string ) <- chan * ForwarderReqToken {
740
+ func (tm * taskMatcherImpl ) fwdrPollReqTokenC (isolationGroup string ) <- chan * ForwarderReqToken {
740
741
if tm .fwdr == nil {
741
742
return noopForwarderTokenC
742
743
}
743
744
return tm .fwdr .PollReqTokenC (isolationGroup )
744
745
}
745
746
746
- func (tm * TaskMatcher ) fwdrAddReqTokenC () <- chan * ForwarderReqToken {
747
+ func (tm * taskMatcherImpl ) fwdrAddReqTokenC () <- chan * ForwarderReqToken {
747
748
if tm .fwdr == nil {
748
749
return noopForwarderTokenC
749
750
}
750
751
return tm .fwdr .AddReqTokenC ()
751
752
}
752
753
753
- func (tm * TaskMatcher ) ratelimit (ctx context.Context ) error {
754
+ func (tm * taskMatcherImpl ) ratelimit (ctx context.Context ) error {
754
755
err := tm .limiter .Wait (ctx )
755
756
if errors .Is (err , clock .ErrCannotWait ) {
756
757
// "err != ctx.Err()" may also be correct, as that would mean "gave up due to context".
@@ -763,11 +764,11 @@ func (tm *TaskMatcher) ratelimit(ctx context.Context) error {
763
764
return err // nil if success, non-nil if canceled
764
765
}
765
766
766
- func (tm * TaskMatcher ) isForwardingAllowed () bool {
767
+ func (tm * taskMatcherImpl ) isForwardingAllowed () bool {
767
768
return tm .fwdr != nil
768
769
}
769
770
770
- func (tm * TaskMatcher ) getTaskC (task * InternalTask ) chan <- * InternalTask {
771
+ func (tm * taskMatcherImpl ) getTaskC (task * InternalTask ) chan <- * InternalTask {
771
772
taskC := tm .taskC
772
773
if isolatedTaskC , ok := tm .isolatedTaskC [task .isolationGroup ]; ok && task .isolationGroup != "" {
773
774
taskC = isolatedTaskC
0 commit comments