Skip to content

Commit

Permalink
Add new error and tail time
Browse files Browse the repository at this point in the history
  • Loading branch information
samanbarghi committed May 16, 2023
1 parent a1af8e8 commit bc850c3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ require (
go.opentelemetry.io/otel/metric v0.36.0
go.opentelemetry.io/otel/sdk v1.13.0
go.opentelemetry.io/otel/sdk/metric v0.36.0
go.temporal.io/api v1.19.1-0.20230511202036-4dee2bb54577
go.temporal.io/api v1.19.1-0.20230515221100-0caa7c878f66
go.temporal.io/sdk v1.22.2
go.temporal.io/version v0.3.0
go.uber.org/atomic v1.10.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1123,8 +1123,8 @@ go.opentelemetry.io/proto/otlp v0.15.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI
go.opentelemetry.io/proto/otlp v0.19.0 h1:IVN6GR+mhC4s5yfcTbmzHYODqvWAp3ZedA2SJPI1Nnw=
go.opentelemetry.io/proto/otlp v0.19.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI405h3+duxN4U=
go.temporal.io/api v1.19.1-0.20230322213042-07fb271d475b/go.mod h1:PLQJqp1YZZikmtGm9jIbzWpP3p6zS39WQjhsO/Hiw30=
go.temporal.io/api v1.19.1-0.20230511202036-4dee2bb54577 h1:BDU+5DlZuQicarZIXLhwXtup1dj8WUk+7XiK6m0brvA=
go.temporal.io/api v1.19.1-0.20230511202036-4dee2bb54577/go.mod h1:uITFvsxpTQT/ZRGMHTzmEXhdDkfA9o8Ik4cgw91TlM4=
go.temporal.io/api v1.19.1-0.20230515221100-0caa7c878f66 h1:nLBDjkSXTJO/aoptKUSGmhVu78qiNIupn0j0RQGTs5M=
go.temporal.io/api v1.19.1-0.20230515221100-0caa7c878f66/go.mod h1:uITFvsxpTQT/ZRGMHTzmEXhdDkfA9o8Ik4cgw91TlM4=
go.temporal.io/sdk v1.22.2 h1:4bGxYekEN+FHAGXkRAxZcHs9k+fNO3RUmBRf97WH3So=
go.temporal.io/sdk v1.22.2/go.mod h1:LqYtPesETgMHktpH98Vk7WegNcikxErmmuaZPNWEnPw=
go.temporal.io/version v0.3.0 h1:dMrei9l9NyHt8nG6EB8vAwDLLTwx2SvRyucCSumAiig=
Expand Down
11 changes: 5 additions & 6 deletions service/history/workflow/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ package cache

import (
"context"
"fmt"
"sync/atomic"
"time"
"unicode/utf8"

"github.com/pborman/uuid"
commonpb "go.temporal.io/api/common/v1"
"go.temporal.io/api/enums/v1"
"go.temporal.io/api/serviceerror"

"go.temporal.io/server/common/cache"
Expand Down Expand Up @@ -200,13 +200,13 @@ func (c *CacheImpl) getOrCreateWorkflowExecutionInternal(
// Consider revisiting this if it causes too much GC activity
releaseFunc := c.makeReleaseFunc(key, workflowCtx, forceClearContext, lockPriority)

const tailTime = 500 * time.Millisecond
var timeout time.Time
if deadline, ok := ctx.Deadline(); ok {
// TODO: what is our tail time?
timeout = deadline
timeout = deadline.Add(-tailTime)
}

if headers.GetCallerInfo(ctx).CallerType == headers.CallerTypeBackground {
if headers.GetCallerInfo(ctx).CallerType != headers.CallerTypeAPI {
timeout = time.Now().Add(500 * time.Millisecond)
}
ctxWithDeadline, cancel := context.WithDeadline(ctx, timeout)
Expand All @@ -217,8 +217,7 @@ func (c *CacheImpl) getOrCreateWorkflowExecutionInternal(
c.Release(key)
handler.Counter(metrics.CacheFailures.GetMetricName()).Record(1)
handler.Counter(metrics.AcquireLockFailedCounter.GetMetricName()).Record(1)
// TODO: what error return here?
return nil, nil, fmt.Errorf("Workflow is busy")
return nil, nil, serviceerror.NewResourceExhausted(enums.RESOURCE_EXHAUSTED_CAUSE_BUSY_WORKFLOW, "Workflow cannot be locked")
}
return workflowCtx, releaseFunc, nil
}
Expand Down

0 comments on commit bc850c3

Please sign in to comment.