From bc850c3c6462000292e10ffd443c45aae1d30e18 Mon Sep 17 00:00:00 2001 From: Saman Barghi Date: Mon, 15 May 2023 19:50:54 -0400 Subject: [PATCH] Add new error and tail time --- go.mod | 2 +- go.sum | 4 ++-- service/history/workflow/cache/cache.go | 11 +++++------ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index ad91580c822..db346e976ec 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index aa589e6ed93..ecdac2b817a 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/service/history/workflow/cache/cache.go b/service/history/workflow/cache/cache.go index 068df4511c0..8f19598a92c 100644 --- a/service/history/workflow/cache/cache.go +++ b/service/history/workflow/cache/cache.go @@ -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" @@ -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) @@ -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 }