Skip to content
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ Before starting the implementation or review of any request, you MUST REVIEW the
- Update API proto: `make update-go-api`
- Always include `-tags test_dep` when running tests. Include the `integration` tag only for integration tests.

## Code Conventions

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just something that i observed an agent do :)


- Keep receiver methods in their existing implementation files and unit tests in the corresponding owner test files. Do not create feature files that mix methods or test suites from unrelated owners.
- Use getter methods for reads whenever available, including protobuf fields. Use direct field access for assignments.

## Development Workflow

1. Inspect surrounding code, tests, and configuration before making changes.
Expand Down
35 changes: 24 additions & 11 deletions api/historyservice/v1/request_response.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions api/persistence/v1/executions.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 21 additions & 7 deletions api/persistence/v1/tasks.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions common/persistence/cassandra/matching_task_store_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ func (d *taskQueueStore) UpdateTaskQueue(

if d.version == matchingTaskVersion1 && request.TaskQueueKind == enumspb.TASK_QUEUE_KIND_STICKY {
// V1 TTL logic - only applies to V1
if request.ExpiryTime == nil {
return nil, serviceerror.NewInternal("ExpiryTime cannot be nil for sticky task queue")
expiryTTL, ttlErr := taskQueueMetadataTTL(request, time.Now())
if ttlErr != nil {
return nil, ttlErr
}
expiryTTL := min(convert.Int64Ceil(time.Until(timestamp.TimeValue(request.ExpiryTime)).Seconds()), maxCassandraTTL)
batch := d.Session.NewBatch(gocql.LoggedBatch).WithContext(ctx)

batch.Query(switchTasksTable(templateUpdateTaskQueueQueryWithTTLPart1, d.version),
Expand Down Expand Up @@ -251,6 +251,16 @@ func (d *taskQueueStore) UpdateTaskQueue(
return &p.UpdateTaskQueueResponse{}, nil
}

func taskQueueMetadataTTL(request *p.InternalUpdateTaskQueueRequest, now time.Time) (int64, error) {
if request.SingleSessionAssigned {
return 0, nil
}
if request.ExpiryTime == nil {
return 0, serviceerror.NewInternal("ExpiryTime cannot be nil for sticky task queue")
}
return min(convert.Int64Ceil(timestamp.TimeValue(request.ExpiryTime).Sub(now).Seconds()), maxCassandraTTL), nil
}

func (d *taskQueueStore) ListTaskQueue(
_ context.Context,
_ *p.ListTaskQueueRequest,
Expand Down
40 changes: 40 additions & 0 deletions common/persistence/cassandra/matching_task_store_queue_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package cassandra

import (
"testing"
"time"

"github.com/stretchr/testify/require"
"go.temporal.io/server/common/persistence"
"google.golang.org/protobuf/types/known/timestamppb"
)

func TestTaskQueueMetadataTTL(t *testing.T) {
t.Parallel()
now := time.Unix(1000, 0)
for _, tc := range []struct {
name string
assigned bool
expiry *timestamppb.Timestamp
ttl int64
invalid bool
}{
{name: "assigned metadata has no ttl", assigned: true},
{name: "assignment removes existing ttl", assigned: true, expiry: timestamppb.New(now.Add(time.Hour))},
{name: "ordinary sticky requires expiry", invalid: true},
{name: "ordinary sticky keeps ttl", expiry: timestamppb.New(now.Add(time.Hour)), ttl: 3600},
{name: "fractional ttl rounds up", expiry: timestamppb.New(now.Add(time.Second + time.Millisecond)), ttl: 2},
{name: "ttl is capped", expiry: timestamppb.New(now.Add(time.Duration(maxCassandraTTL+3600) * time.Second)), ttl: maxCassandraTTL},
} {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
ttl, err := taskQueueMetadataTTL(&persistence.InternalUpdateTaskQueueRequest{SingleSessionAssigned: tc.assigned, ExpiryTime: tc.expiry}, now)
if tc.invalid {
require.ErrorContains(t, err, "ExpiryTime cannot be nil")
return
}
require.NoError(t, err)
require.Equal(t, tc.ttl, ttl)
})
}
}
5 changes: 3 additions & 2 deletions common/persistence/persistence_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,9 @@ type (
RangeID int64
TaskQueueInfo *commonpb.DataBlob

TaskQueueKind enumspb.TaskQueueKind
ExpiryTime *timestamppb.Timestamp
TaskQueueKind enumspb.TaskQueueKind
ExpiryTime *timestamppb.Timestamp
SingleSessionAssigned bool
Comment thread
Shivs11 marked this conversation as resolved.
Resolved

PrevRangeID int64
}
Expand Down
Loading
Loading