Files
tasks/common/worker_versioning/version_membership_cache.go
zeekay 40351cce6f rip: delete temporal fork — native ZAP-only tasksd
Goes from 135 MB binary with 1153 files importing go.temporal.io and 224
importing google.golang.org/grpc to a 10 MB native binary with ZERO of
either.

Deleted:
- tasks/, tasktests/, service/, chasm/, client/, api/, proto/, tools/
- cmd/tools/, components/, docker/
- schema/{cassandra,elasticsearch,mysql,postgresql,sqlite}/
- 40 tainted common/ subdirs + 7 top-level common files
- tests/testutils (no longer referenced after surviving deps drop common)

New cmd/tasksd (~100 lines) boots tasks.Embed (zap.Node) + http.Server.
New pkg/tasks/embed.go registers ZAP handlers for the SDK opcode surface
(0x0060-0x00A5). Workflow handlers return a 501 "not yet implemented"
envelope; native engine lands behind this contract.

Build:  go build ./cmd/tasksd → 10 MB
Vet:    go vet ./... → clean
Boot:   tasksd --zap-port 9999 --http :7243
Probes: /healthz, /v1/tasks/health → 200
UI:     /_/tasks/, / → 200 (embedded Vite bundle)
ZAP:    _tasks._tcp on :9999 (mDNS disabled; direct connect)

go.mod: tidy. No go.temporal.io. No google.golang.org/grpc.
2026-04-26 14:06:21 -07:00

130 lines
4.4 KiB
Go

//nolint:staticcheck
package worker_versioning
import (
enumspb "go.temporal.io/api/enums/v1"
"go.temporal.io/server/common/cache"
"go.temporal.io/server/common/metrics"
)
// VersionMembershipAndReactivationStatusCache caches results of Matching's
// CheckTaskQueueVersionMembership calls. It stores three pieces of information per version:
// - isMember: whether the task queue exists in the version (used for pinned override validation).
// - shouldSkipReactivation: true when the version's current status is CURRENT, RAMPING,
// or DRAINING, in which case the caller skips the reactivation signal. The zero value
// (false) is the safe default and covers unknown / not-found / old-matching cases.
// - revisionNumber: the version's current revision per matching's view. Used as part of the
// reactivation signal's RequestId so that all history pods targeting the same version at
// the same revision compose the same dedup key. Zero means unknown (old matching server or
// legacy DeploymentVersionData format with no revision_number field).
//
// Implementations are expected to be safe for concurrent use.
type (
VersionMembershipAndReactivationStatusCache interface {
Get(
namespaceID string,
taskQueue string,
taskQueueType enumspb.TaskQueueType,
deploymentName string,
buildID string,
) (isMember bool, shouldSkipReactivation bool, revisionNumber int64, ok bool)
Put(
namespaceID string,
taskQueue string,
taskQueueType enumspb.TaskQueueType,
deploymentName string,
buildID string,
isMember bool,
shouldSkipReactivation bool,
revisionNumber int64,
)
}
versionMembershipCacheKey struct {
namespaceID string
taskQueue string
taskQueueType enumspb.TaskQueueType
deploymentName string
buildID string
}
versionTaskQueueInfoCacheValue struct {
isMember bool
shouldSkipReactivation bool // false = unknown / not-found / eligible-for-reactivation
revisionNumber int64 // 0 = unknown (old matching server or legacy format)
}
VersionMembershipAndReactivationStatusCacheImpl struct {
cache.Cache
metricsHandler metrics.Handler
}
)
// NewVersionMembershipAndReactivationStatusCache wraps the provided cache with a typed API and metrics.
func NewVersionMembershipAndReactivationStatusCache(c cache.Cache, metricsHandler metrics.Handler) VersionMembershipAndReactivationStatusCache {
h := metricsHandler.WithTags(metrics.CacheTypeTag(metrics.VersionMembershipCacheTypeTagValue))
return &VersionMembershipAndReactivationStatusCacheImpl{
Cache: c,
metricsHandler: h,
}
}
func (c *VersionMembershipAndReactivationStatusCacheImpl) Get(
namespaceID string,
taskQueue string,
taskQueueType enumspb.TaskQueueType,
deploymentName string,
buildID string,
) (isMember bool, shouldSkipReactivation bool, revisionNumber int64, ok bool) {
handler := c.metricsHandler.WithTags(metrics.OperationTag(metrics.VersionMembershipCacheGetScope), metrics.NamespaceIDTag(namespaceID))
metrics.CacheRequests.With(handler).Record(1)
key := versionMembershipCacheKey{
namespaceID: namespaceID,
taskQueue: taskQueue,
taskQueueType: taskQueueType,
deploymentName: deploymentName,
buildID: buildID,
}
v := c.Cache.Get(key)
if v == nil {
metrics.CacheMissCounter.With(handler).Record(1)
return false, false, 0, false
}
value, ok := v.(versionTaskQueueInfoCacheValue)
if !ok {
// Unexpected type: treat as miss to avoid false positives.
metrics.CacheMissCounter.With(handler).Record(1)
return false, false, 0, false
}
return value.isMember, value.shouldSkipReactivation, value.revisionNumber, true
}
func (c *VersionMembershipAndReactivationStatusCacheImpl) Put(
namespaceID string,
taskQueue string,
taskQueueType enumspb.TaskQueueType,
deploymentName string,
buildID string,
isMember bool,
shouldSkipReactivation bool,
revisionNumber int64,
) {
handler := c.metricsHandler.WithTags(metrics.OperationTag(metrics.VersionMembershipCachePutScope), metrics.NamespaceIDTag(namespaceID))
metrics.CacheRequests.With(handler).Record(1)
key := versionMembershipCacheKey{
namespaceID: namespaceID,
taskQueue: taskQueue,
taskQueueType: taskQueueType,
deploymentName: deploymentName,
buildID: buildID,
}
c.Cache.Put(key, versionTaskQueueInfoCacheValue{
isMember: isMember,
shouldSkipReactivation: shouldSkipReactivation,
revisionNumber: revisionNumber,
})
}