Commit Graph

356 Commits

Author SHA1 Message Date
Rodrigo Zhou
f3ebe4f99f Optimize Visibility PostgreSQL upgrade schema v1.14 (#11599)
## What changed?
Apply same optimizations in
https://github.com/temporalio/temporal/pull/10371 for v1.14.

## Why?
Better upgrade script.

## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [x] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)

## Potential risks
2026-08-17 15:32:07 -07:00
Rodrigo Zhou
afdffd76a4 Combine PostgreSQL Visibility schema upgrades from v1.10 through v1.13 (#10371)
## What changed?
Combine PostgreSQL Visibility schema upgrades from v1.10 through v1.13

## Why?
Adding one column at a time requires scanning the entire table. So,
combining all the schema changes in v1.30.0 release into a single SQL
upgrade file.

https://github.com/temporalio/temporal/issues/10358

## How did you test it?
- [x] built
- [x] run locally and tested manually
- [x] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)

## Potential risks
2026-06-04 22:36:09 +00:00
Vladyslav Simonenko
400e2ad37f Add external payload size and count to Visibility Schema (#9007)
## What changed?
Added TemporalExternalPayloadSizeBytes and TemporalExternalPayloadCount
to Visibility Schema as pre-defined search attribute.

## Why?
We are planning to expose external payload size and count as the search
attributes. They are pre-defined, rather than system, because they won't
be set on every single workflow, but only ones which store large
payloads externally (e.g. in S3).

## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [ ] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)

## Potential risks
Incorrectly modified schema
2026-01-23 11:42:08 -08:00
Yichao Yang
558682652a CHASM: SQL separate ID spaces (#8915)
## What changed?
- Support separate ID spaces for different archetypes in SQL
persistence.

## Why?
- Separate ID space workstream

## How did you test it?
- [x] built
- [ ] run locally and tested manually
- [x] covered by existing tests
- [x] added new unit test(s)
- [ ] added new functional test(s)
2026-01-14 20:48:36 -08:00
Shahab Tajik
882268cc71 Add TemporalUsedWorkerDeploymentVersions SA (#8886)
## What changed?
Add `TemporalUsedWorkerDeploymentVersions` search attribute to contain
all the Deployment Versions that completed at least one workflow tasks
for the execution.

This Search Attribute replaces, now deprecated, `BuildIds` Search
attribute.

## Why?
Needed a replacement for `BuildIds` Search attribute which holds
internal values and prefixes.

## How did you test it?
- [x] built
- [ ] run locally and tested manually
- [x] covered by existing tests
- [x] added new unit test(s)
- [x] added new functional test(s)

## Potential risks
None.
2026-01-04 21:36:44 -05:00
Alan Wu
b319d94ed8 Support CHASM Count Group By Filtering (#8754)
Support CHASM Count "Group By" Filtering.

## What changed?
* Adds implementation of CHASM Count Executions `Group By` Filter
support.
* Unifies `visibility_store.go` implementation to get count execution
info.
* Adds functional tests for validation.

## Why?
Needed to unblock standalone activities, and fully support CHASM Count
Execution requirements.

## How did you test it?
- [X] built
- [X] run locally and tested manually
- [X] covered by existing tests
- [X] added new unit test(s)
- [X] added new functional test(s)
2025-12-05 20:10:29 -05:00
Alan Wu
c2da806973 Update Visibility Schema with new TemporalLowCardinalityKeyword01 column (#8729)
## What changed?
Update Visibility Schema with new TemporalLowCardinalityKeyword01
column.

## Why?
Allocate additional column/ES mapping for CHASM Low Cardinality Keyword
search attribute, meant for CHASM Archetype execution status.

TemporalLowCardinalityKeyword fields are stored no differently than
Keyword fields, but have a user requirement that values are from a low
cardinal set, eg. Enums, since they support GROUP BY filtering. Normal
Keyword fields do not support GROUP BY query filters.

Each archetype can track its own execution status as any CHASM Low
Cardinality Keyword field.

## How did you test it?
- [X] built
- [X] run locally and tested manually
- [X] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)
2025-12-05 17:49:03 +00:00
Alan Wu
a288d1e446 Remove transient dependencies on persistence in the chasm package (#8673)
## What changed?
Remove transient dependencies on persistence in the chasm package. 

## How did you test it?
- [X] built
- [X] run locally and tested manually
- [X] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)
2025-11-21 14:01:59 -05:00
Alan Wu
19ac3385fc Add Archetype search attributes for CHASM Visibility (#8390)
## What changed?
Adds Archetype search attributes schema for CHASM Visibility. Functions
similarly to custom search attributes, where pre-allocated column names
or explicit properties, called field names, will map to user aliased
Archetype search attributes.

Adds Archetype search attributes to ClusterMetadata to save all
pre-allocated field name to type mappings in the Cassandra backed
ClusterMetadata store.

## Why?
Required for CHASM Visibility support. Component authors will register a
component with tagged attribute values for querying (List, Count APIs
for now), and executions of the registered component will be tagged with
these attributes.

Archetype name used for querying is left out of this schema change, may
require further discussion.

## How did you test it?
- [X] built
- [X] run locally and tested manually
- [ ] added new unit test(s)
- [ ] added new functional test(s)
2025-10-31 15:24:26 -04:00
Sean Kane
bb1589e040 Degraded workflow visibility (#8223)
## What changed? 
Add a new search attribute `TemporalReportedProblems` when a workflow
task fails or timeouts N consecutive times

## Why?
Enables users to easily discover workflows that are not making progress.
After a workflow task fails or times out N consecutive times a Search
Attribute, `TemporalReportedProblems` a `KeywordList`, will be added
with two entries, a `cause` and a `category`. These search attributes
will be queryable by users with queries like:
* `TemporalReportedProblems IS NOT NULL`
* `TemporalReportedProblems IN ('category=WorkflowTaskFailed')` or
`TemporalReportedProblems IN ('category=WorkflowTaskTimedout')`
* `'TemporalReportedProblems IN ("cause=UnhandledApplicationFailure")'
OR 'TemporalReportedProblems IN ("cause=ScheduleToCloseTimeout")'`

## How did you test it?
- [ ] built
- [X] run locally and tested manually
- [ ] covered by existing tests
- [ ] added new unit test(s)
- [X] added new functional test(s)
- [x] added new xdc test(s)

## Potential risks
Flapping _could_ happen with this change, but is unlikely. There's a
possibility of overloading the visibility system, but these changes are
protected with a dynamic config.

---------

Co-authored-by: Roey Berman <roey@temporal.io>
2025-10-08 14:51:09 -06:00
Rob Holland
389d1ab7d1 Fix command line flag argument parsing for elasticsearch-tool. (#8445)
## What changed?
Reverts to urlfav/cli v1 as per other tools and uses shared flag aliases
where appropriate for more consistency with the other tools.

Works around Go embed's lack of support for symlinks by hard coding the
path to the index template to use. Adds a test to ensure this doesn't
get out of sync with the latest.

## Why?
Better consistency with other tools and being able to actually find the
index template :)

## How did you test it?
- [x] built
- [x] run locally and tested manually
- [ ] covered by existing tests
- [x] added new unit test(s)
- [ ] added new functional test(s)
2025-10-08 07:49:42 +01:00
Rodrigo Zhou
13dcce531a Server Visibility config and preallocate custom search attributes (#8397)
## What changed?
Add a top-level Visibility config in the server config file.
Option to overwrite the default number of preallocated custom search
attributes in the server config
(`visibility.persistenceCustomSearchAttributes`).
Register the preallocated custom search attributes when using custom
Visibility store.
The config can be changed at any point: increasing the number of custom
search attributes will register additional custom search attributes in
the cluster metadata; decreasing the number of custom search attributes
is no-op.

Replace struct validator library with
`github.com/go-playground/validator`.

## Why?
Be able to add more custom search attributes when using SQL Visibility
store.

## How did you test it?
- [x] built
- [x] run locally and tested manually
- [x] covered by existing tests
- [x] added new unit test(s)
- [ ] added new functional test(s)

## Potential risks
2025-10-07 20:57:55 +00:00
Rob Holland
1dc6264f4f Add Elasticsearch CLI tool (#8296)
## What changed?

- Revive and update original PR #2977 for Elasticsearch CLI tool

Replaces manual curl invocations with a proper CLI tool that leverages
Temporal's built-in Elasticsearch auth providers and provides better
error handling and logging.

## How did you test it?
- [x] built
- [x] run locally and tested manually
- [ ] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)

## Potential risks

None, net new.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Introduces `temporal-elasticsearch-tool` for ES schema/index
management and ping, extends ES client APIs, embeds ES schema, and
updates Makefile to use the tool.
> 
> - **Tools**:
> - New `temporal-elasticsearch-tool` CLI with commands: `setup-schema`,
`update-schema`, `create-index`, `drop-index`, `ping`; supports AWS auth
and uses embedded schema files.
> - Adds entrypoint `cmd/tools/elasticsearch`, README, and basic tests.
> - **Elasticsearch Client**:
> - Extends `CLIClient` with `ClusterPutSettings`, `IndexPutTemplate`,
`IndexPutMapping`, `Ping` and implements them (v7) using raw requests
where needed; allows custom HTTP client from config (e.g., AWS-signed).
> - **Schema**:
> - Embeds ES v7 cluster settings and index template
(`schema.Embedded...` accessors).
> - **Build/Makefile**:
> - Adds build target and binary cleanup for
`temporal-elasticsearch-tool`; updates `install-schema-es` and
`install-schema-xdc` to use the CLI instead of curl.
> - Includes binary in `.goreleaser.yml`; excludes it in
`.dockerignore`.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
b37864809a. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-10-02 10:52:21 +01:00
Daniel Kim
98e4a9022e fix(schema): check for extension before creating (#7002)
## What changed?
`CREATE EXTENSION` sql query is replaced with a pgsql script that checks
for the existence of the extension programatically.

## Why?
`CREATE EXTENSION` can cause issues in environment where creating
extensions are limited to certain users. (e.g. Azure)

## How did you test it?
I've ran the updated schema setup in both environments where btree_gin
is installed and and not installed.

## Potential risks
Regression in visibility database setup.

## Documentation
Not needed.

## Is hotfix candidate?
No

---------

Co-authored-by: Rodrigo Zhou <rodrigo.zhou@gmail.com>
2025-09-29 13:02:22 -05:00
David Reiss
1b8dbb4039 Matching task fairness SQL support (#8099)
## What changed?
Add SQL support for matching task fairness.

Based on #8043 with some changes to reduce code duplication (can be
applied to cassandra later).

## Why?
Support all persistence implementations.

## How did you test it?
- [x] covered by existing tests
- [x] added new unit test(s)

---------

Co-authored-by: sivagirish81 <siva.girish@temporal.io>
2025-07-31 05:01:00 -07:00
Stephan Behnke
b157875c3e tdbg for list fairness tasks (#8010)
## What changed?
Added new flag to tdbg's `list-tasks` command to query the fairness
table instead.

## Why?
Allow operation on fairness table, too.

## How did you test it?
- [ ] built
- [x] run locally and tested manually
- [ ] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)

```
./tdbg taskqueue list-tasks --task-queue-type TASK_QUEUE_TYPE_WORKFLOW --task-queue test --min-pass 1
```

It's late ... I didn't manage to see a result, though. But it didn't
fail and I saw the query being executed in the debugger.
2025-07-22 16:38:22 +01:00
David Reiss
49c43bdd4a Matching fairness: update persistence and protos (#7950)
## What changed?
- Add FairLevel to some protos.
- Implement pass handling in task store v2.
- Remove TTLs from task store v2.
- Add some error checking to prevent misuse.
- Add support for using LIMIT in the GetTasks query.
- Rename some things.

## Why?
Start implementing matching task fairness.

## How did you test it?
- [x] built
- [x] covered by existing tests
2025-07-22 16:37:47 +01:00
Stephan Behnke
db0a208f65 Task fairness schema (#7627)
## What changed?
Added new schema for task table that supports fairness scheduling.

* split `matching_task_store.go` into v1 (pre-fairness) and v2
(fairness) - clean copy seemed safest
* inject two task stores, `PhysicalTaskQueueManager` picks the one it
needs
2025-07-22 16:37:42 +01:00
David Reiss
ef2effbb74 Small matching cleanups (#7948)
## What changed?
- Consolidate task ids into `writeTaskRequest` instead of separate
slice.
- Factor out some common code in `newPhysicalTaskQueueManager`.
- Factor out `taskResponse.err()`.
- Move code out of select in `getTasksPump`.
- Add a `UseCassandraPersistence` test helper.
- Remove some obsolete structs and functions.
- Rename some test functions.
- Update some comments.

## Why?
These are a bunch of small changes from the fairness feature branch that
can apply to main immediately, which will make reviewing/merging that
branch easier.

## How did you test it?
- [x] built
- [x] run locally and tested manually
- [x] covered by existing tests
2025-06-23 17:36:47 -07:00
Stephan Behnke
aa1efb6049 Remove encodingType from Serializer interface (#7942)
## What changed?

Removes the `encodingType` from the `Serializer` interface.

## Why?

The parameter is superfluous since it always set to
`enumspb.ENCODING_TYPE_PROTO3`. There are no plans to move to a
different encoding scheme. An encoding parameter for existing/new
methods can be added (back) as needed.

The next steps will be:

1. a codec for the serializer to allow customizing the encoding globally
1. an env variable to customize the encoding to be JSON (for
debugging/developing purposes)

## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [x] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)
2025-06-20 11:30:31 -07:00
Alex Shtin
91893f1064 Remove license header from every file (#7689)
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.

## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
2025-05-01 18:50:21 -07:00
Gary Lee
20156eb1ad Fix sql tool error in windows (#7519)
## What changed?
Use `path.Join()` instead of `filepath.Join()`

## Why?
#7454

## How did you test it?
Tested locally

## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->
None

## Documentation
<!-- Have you made sure this change doesn't falsify anything currently
stated in `docs/`? If significant
new behavior is added, have you described that in `docs/`? -->
None

## Is hotfix candidate?
<!-- Is this PR a hotfix candidate or does it require a notification to
be sent to the broader community? (Yes/No) -->
No
2025-04-11 18:51:14 +00:00
Lina Jodoin
3e95968b61 [CHASM] Avoid a double-encode by passing Metadata and Data as separate fields (#7507)
## What changed?
- CHASM nodes are now internally represented as split distinctly between
Metadata and Data parts.
- Additional columns were added to SQL plugins, bumping the SQL schema
- No change was made to the Cassandra columns; instead, ExecutionManager
ensures that when running on Cassandra, the entire node continues to be
represented in a single blob, to avoid lowering Cass performance
post-change.

## Why?
Before, a ChasmNode contained both its metadata fields, and the user
data blob. Decoding a ChasmNode would cause an additional (often large,
relative to the metadata) allocation to store the inner data blob, as
well as additional memcpys while encoding/decoding. With this change,
the data field can be passed along as-is, opaquely, while the metadata
field can be decoded without additional penalty from a large data blob.

## How did you test it?
- Updated tests

---------

Co-authored-by: Yichao Yang <yichao@temporal.io>
2025-03-24 17:06:10 +00:00
Lina Jodoin
a35a3891e5 [CHASM] SQL persistence for CHASM nodes (#7455)
## What changed?
SQL persistence support has been added for CHASM nodes. 

- A new `chasm_node_maps` table has been added to SQL schemas
- SQL test suites updated
- SQL execution manager/util updated
- SQL plugins for `chasm_node_map` table

## Why?
- We've landed Cassandra persistence support for CHASM nodes, this
brings SQL support up to parity.

## How did you test it?
- New tests ran on all SQL plugins
- `go test -v ./...`

## Potential risks
- No application paths write chasm_node_maps yet, but change does
involve a schema change

---------

Co-authored-by: Yichao Yang <yichao@temporal.io>
2025-03-18 16:05:44 -07:00
Lina Jodoin
5385b99301 [CHASM] Cassandra Persistence for CHASM nodes (#7414)
## What changed?
CHASM persistence support for Cassandra.

- Cassandra schema version bumped for new fields
- New queries for read/update/delete CHASM nodes on the executions table
- ExecutionManager/Serializer updates for CHASM nodes
- Updates to `persistence_interface`
- Wired in `chasm.Registry` under history's config
- Commented MutableStateImpl callsites, some stuff relies on tree
implementation being merged
- common/persistence tests updated for chasm nodes

## Why?

## How did you test it?
- `make unit-test && make lint`

## Potential risks
- Includes a schema change
- CHASM applications not in Prod (fields won't be exercised in persistence layer)
2025-03-12 16:42:28 +00:00
Rodrigo Zhou
a2c77c073a Fix data_encoding column in current_executions table (#7383)
## What changed?
<!-- Describe what has changed in this PR -->
Fix `data_encoding` column in `current_executions` table in SQL
database.
The column must be `NOT NULL`.

## Why?
<!-- Tell your future self why have you made these changes -->

## How did you test it?
<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->
1. Start Temporal at v1.26.2
2. Upgrade schemas in v1.27.0
3. Restart Temporal at v1.27.0 <-- at this point, Temporal is throwing
errors
4. Rollback Temporal to v1.26.2
5. Upgrade schemas in this PR
6. Restart Temporal at v1.27.0 <-- everything works

Tested with both MySQL and PostgreSQL.

## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->

## Documentation
<!-- Have you made sure this change doesn't falsify anything currently
stated in `docs/`? If significant
new behavior is added, have you described that in `docs/`? -->

## Is hotfix candidate?
<!-- Is this PR a hotfix candidate or does it require a notification to
be sent to the broader community? (Yes/No) -->
2025-02-25 12:07:32 -06:00
Jacob Barzee
06a0b8a06c Add version column to SQLlite, MySQL, and Postgress VisibilityStores (#7350)
## What changed?
Add version column to SQLlite, MySQL, and Postgress VisibilityStores

## Why?
There is no built in support for versioning in SQLlite, MySQL, and
Postgress, which leaves open the possibility for out-of-order updates.
We need to explicitly have a column for version to prevent this.

## How did you test it?
Manually tested that Server can run normally (still some bugs). There
will be more tests with nightly pipelines and mid pipeline version
changes to test backwards compatibility.

## Potential risks
High. A failure during table alteration or in compatibility guarantees
would entirely halt all visibility updates.

## Documentation
Not that I am aware of. We will have to close several github issues
though!

## Is hotfix candidate?
Not for cloud. Aiming for upcoming OSS release.

---------

Co-authored-by: rodrigozhou <rodrigo.zhou@temporal.io>
2025-02-15 22:31:28 -07:00
Carly de Frondeville
8b0d8f08fa Add Worker Deployment Search Attributes (#7199)
## What changed?
Add TemporalWorkerDeploymentVersion, TemporalWorkerDeployment, and
TemporalWorkflowVersioningBehavior Search Attributes

## Why?
To be able to list workflows based on their behavior, deployment, and
most recently used deployment version.

## How did you test it?
<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->

## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->

## Documentation
<!-- Have you made sure this change doesn't falsify anything currently
stated in `docs/`? If significant
new behavior is added, have you described that in `docs/`? -->

## Is hotfix candidate?
<!-- Is this PR a hotfix candidate or does it require a notification to
be sent to the broader community? (Yes/No) -->

---------

Co-authored-by: Shivam Saraf <shivam.saraf@temporal.io>
Co-authored-by: Rodrigo Zhou <2068124+rodrigozhou@users.noreply.github.com>
2025-02-06 13:33:03 -08:00
Rodrigo Zhou
72c62184da Add OnConflictOptions to StartWorkflowExecution (#7080)
## What changed?
<!-- Describe what has changed in this PR -->
Add `OnConflictOptions` to `StartWorkflowExecution`.
- if the workflow id conflict policy is not `USE_EXISTING`, then no-op;
- if the field is nil, then no-op;
- otherwise, then it will add a `WorkflowExecutionOptionsUpdatedEvent`
to the existing running workflow.

## Why?
<!-- Tell your future self why have you made these changes -->
Ability to attach completion callbacks to existing running workflows.

## How did you test it?
<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->
WIP: writing tests

## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->

## Documentation
<!-- Have you made sure this change doesn't falsify anything currently
stated in `docs/`? If significant
new behavior is added, have you described that in `docs/`? -->

## Is hotfix candidate?
<!-- Is this PR a hotfix candidate or does it require a notification to
be sent to the broader community? (Yes/No) -->
2025-02-03 15:53:42 -06:00
Stephan Behnke
d7d8dd2d42 Remove persistence from namespace package (#7155)
## What changed?
<!-- Describe what has changed in this PR -->

Removed dependency of `common/persistence` from `common/namespace`
package.

And removed dependency of `common/namespace` on
`common/namespace/nsreplication`.

## Why?
<!-- Tell your future self why have you made these changes -->

Last step towards using `common/namespace` from `common/dynamicconfig`.
(circular dependency right now)

## How did you test it?
<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->

No behavior changes here.

## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->

## Documentation
<!-- Have you made sure this change doesn't falsify anything currently
stated in `docs/`? If significant
new behavior is added, have you described that in `docs/`? -->

## Is hotfix candidate?
<!-- Is this PR a hotfix candidate or does it require a notification to
be sent to the broader community? (Yes/No) -->
2025-01-24 08:35:38 -08:00
Yuri
faabd96464 Make upgrade script executable (#7111)
## What changed?
<!-- Describe what has changed in this PR -->
change the attributes of upgrade.sh

## Why?
<!-- Tell your future self why have you made these changes -->
Making this script executable allows automation. Most likely this is not
used, but just in case.

## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->
No as I aware

## Documentation
<!-- Have you made sure this change doesn't falsify anything currently
stated in `docs/`? If significant
new behavior is added, have you described that in `docs/`? -->
N/A

## Is hotfix candidate?
<!-- Is this PR a hotfix candidate or does it require a notification to
be sent to the broader community? (Yes/No) -->
Yes
2025-01-17 12:00:57 -08:00
Yuri
082b1fd1ca Add TemporalPauseInfo search attribute (#6741)
## What changed?
Add PausedInfo search attribute

## Why?
To allow users find workflows with paused activities

## How did you test it?
make unit-test.

---------

Co-authored-by: Rodrigo Zhou <2068124+rodrigozhou@users.noreply.github.com>
2024-11-08 12:47:25 -08:00
Rodrigo Zhou
8752a90c5b Add search attributes param to sqlite.NewNamespaceConfig (#6476)
## What changed?
<!-- Describe what has changed in this PR -->
Add search attributes param to sqlite.NewNamespaceConfig.

## Why?
<!-- Tell your future self why have you made these changes -->
Ability to start Temporal from the CLI with custom search attributes.
Address https://github.com/temporalio/temporal/issues/6195

## How did you test it?
<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->
Modified the CLI to not call `registerSearchAttributes`, pass it
directly to `NewNamespaceConfig`.

## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->

## Documentation
<!-- Have you made sure this change doesn't falsify anything currently
stated in `docs/`? If significant
new behavior is added, have you described that in `docs/`? -->

## Is hotfix candidate?
<!-- Is this PR a hotfix candidate or does it require a notification to
be sent to the broader community? (Yes/No) -->
2024-09-16 22:57:41 +00:00
Jacob Barzee
0836b0fff0 Import alignment (#6426)
## What changed?
Make import formatting a part of the build, and test validity with
"ensure-no-changes" target

## Why?
So we never discuss import order again (hopefully)

## How did you test it?
its a build change, so the build will test it!

## Potential risks
As long as build works, the only thing I risk is the ire of coworker who
want imports to be different ;)

## Documentation
N/A

## Is hotfix candidate?
No
2024-08-23 14:48:10 -06:00
Yuri
f7f1911421 Add start_time column to the current execution table. Some refactoring (#6310)
## What changed?
Add "start_time" nullable column to the current_executions table. 
Some refactoring of the existing code - send row as a parameter rather
then every single field of that row.

## Why?
Adding column - to allow fast checking workflow creation time to avoid
noisy workflow restarts. Without it we need to get workflow start time
from a mutable state, which can affect latency.

## Is hotfix candidate?
No
2024-07-24 14:17:46 -07:00
pdoerner
fc2b43fccb Fix Nexus endpoint storage schemas (#6119)
## What changed?
<!-- Describe what has changed in this PR -->
Restored schema scripts for `nexus_incoming_services`
Added new schema revisions to drop `nexus_incoming_services` tables and
create `nexus_endpoint` tables

## Why?
<!-- Tell your future self why have you made these changes -->
OSS v1.24 was released using an older schema change from before incoming
services were renamed to endpoints, so we need to keep that to avoid
breaking schema upgrades
2024-06-13 06:05:13 -07:00
Rodrigo Zhou
00e3981e4b Fix SQL visibility root workflow fields in schema (#6067)
## What changed?
<!-- Describe what has changed in this PR -->
Fix SQL visibility root workflow fields in schema: they are supposed to
be not null.

## Why?
<!-- Tell your future self why have you made these changes -->
The schema set the root workflow fields as nullable, but the code was
assuming to be not null.
GH Issue: https://github.com/temporalio/temporal/issues/6050

## How did you test it?
<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->
Start Temporal v1.23.1, create some workflows, update the schemas in
v1.24.0, upgrade Temporal v1.24.0:
- reproduced the error
- applied this fix, and the error was gone.

## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->

## Documentation
<!-- Have you made sure this change doesn't falsify anything currently
stated in `docs/`? If significant
new behavior is added, have you described that in `docs/`? -->

## Is hotfix candidate?
<!-- Is this PR a hotfix candidate or does it require a notification to
be sent to the broader community? (Yes/No) -->
2024-06-05 13:41:39 -05:00
Tim Deeb-Swihart
797bbdf120 Reconnect to SQL databases when connections fail (#5926)
## What changed?

Both our PostgreSQL and MySQL database backends will now automatically
reconnect to the database when certain errors occur: all errors chosen
have been experienced when testing this behavior through an AWS Aurora
RDS failover of either MySQL or PostgreSQL.

For both backends we will reconnect when we see:
- `ECONNRESET`
- `ECONNABORTED`
- `ECONNREFUSED`
- `io.EOF`
- `io.ErrUnexpectedEOF`
- `database/sql/driver.ErrBadConn`

for postgres we will also reconnect on the following SQLStates:
- `25006` read-only transaction
- `57P03` cannot connect now
- `0A000` feature not supported, but ONLY when the message is `cannot
set transaction read-write mode during recovery`

for mysql we will also reconnect when we see the following error codes:
- `1040` too many connections 
- `1792` read-only transaction (SQLstate `25006`)
- `1836` running in read-only mode

This logic is easily extensible should we discover more failure modes
over time

## Why?

We've had multiple community reports of Temporal problems during RDS
failover. One part of this is the fact that we wouldn't necessarily
reconnect; we were at the whims of our chosen SQL abstraction's
connection pooling logic.

## How did you test it?

I manually tested this functionality in the presence of repeated RDS
failovers: 

- [x] postgres12 plugin with pq driver
- [x] postgres12 plugin with pgx driver
- [x] mysql plugin

Automated testing will be added to our regular testing pipelines once
our infrastructure friends have added the support I need (it's in
progress)

## Potential risks

We're concerned there's a correctness issue in our PostgreSQL backend
that's related to our behavior during an RDS failover. If we merge this
before I figure out what's going on, we could hide the issue and make it
harder to reproduce.

## Documentation
N/A

## Is hotfix candidate?
Yes?
2024-05-17 16:59:15 -07:00
Shahab Tajik
6b92aa58ab Validate build id and reschedule tasks when redirect rule applies (#5681)
## What changed?
<!-- Describe what has changed in this PR -->
- Send BuildIdRedirectInfo from Matching to History on
Record*TaskStarted call containing information about redirect intention.
- History validates the redirect info against current MS and fails the
request if the redirect does not have source build if equal to the
current assigned build of the workflow.
- If redirect is valid, workflow is assigned to the new build id and all
pending but not started task are rescheduled to be sent to the new build
id.

## Why?
<!-- Tell your future self why have you made these changes -->
To prevent the following problems from happening for workflows with
concurrent tasks when redirect rules are deleted or not fully propagated
yet:
1. Assign wf back to an old build id after processing task using a newer
build id
2. Interleaved Starts: for some duration tasks are dispatched to a mix
of old or new build IDs
3. New activity output being fed to old wf
4. Execution gets stuck after being (partially) redirected

## How did you test it?
<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->
Functional test. More unit tests to be added in a followup PR.

## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->
As it is right now, in rare situations when a redirect rule is applied
to a WF with concurrent activities and some of them are in backoff
period due to failure, we may schedule (and start) them on the newer
build without waiting for the backoff to finish. This is planed to be
improved in the futuer.

## Documentation
<!-- Have you made sure this change doesn't falsify anything currently
stated in `docs/`? If significant
new behavior is added, have you described that in `docs/`? -->
None.

## Is hotfix candidate?
<!-- Is this PR a hotfix candidate or does it require a notification to
be sent to the broader community? (Yes/No) -->
No.
2024-05-17 15:49:29 -07:00
Roey Berman
356836020b Nexus Endpoints (#5855)
## What changed?

- Refactored Nexus Registry code to merge incoming and outgoing into one
registry
- Added separate concept of "endpoints" - which is roughly analogous to
what was previously called "services"
- Upgraded the Nexus Go SDK and API dependencies accordingly
- Command handler interface was modified to accept a context given new
requirements
- Note that invoking a worker endpoint is not yet supported, there will
be some minor restructuring required to enable that
- Requires this unmerged API PR
https://github.com/temporalio/api/pull/403. The two PRs should be merged
together.
## Why?

Part of late redesign. See also https://github.com/nexus-rpc/api/pull/5

## How did you test it?

Modified existing and added new tests.
2024-05-09 12:17:52 -07:00
Rodrigo Zhou
0f7c9f7614 Add root workflow execution to visibility (#5697)
## What changed?
<!-- Describe what has changed in this PR -->
Add root workflow execution to Visibility

## Why?
<!-- Tell your future self why have you made these changes -->
Follow up of https://github.com/temporalio/temporal/pull/5520.
Be able to list all workflows based on the root execution.

## How did you test it?
<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->
Modified existing tests to check the root workflow execution.

## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->
No.

## Documentation
<!-- Have you made sure this change doesn't falsify anything currently
stated in `docs/`? If significant
new behavior is added, have you described that in `docs/`? -->

## Is hotfix candidate?
<!-- Is this PR a hotfix candidate or does it require a notification to
be sent to the broader community? (Yes/No) -->
No.
2024-04-15 09:56:01 -05:00
Roey Berman
ec09daac8f Nexus accumulated work (#5225)
This PR is intended to merge 4 months of work in the `nexus` feature
branch into `main`.

The functionality it brings is:
- Dispatching Nexus Tasks by namespace and task queue
- Internal implementation of the Incoming Service Registry - not yet
exposed
- Attaching workflow close callbacks on `StartWorkflowExecutionRequest`
and processing of those callbacks

There's more to come and some of the callback code will be refactored
into a new plugin architecture
(https://github.com/temporalio/temporal/pull/5446) soon.

---------

Co-authored-by: PJ Doerner <pj.doerner@temporal.io>
2024-03-05 22:37:21 +00:00
Rodrigo Zhou
f6937601ef Remove support for standard visibility (#5387)
## What changed?
<!-- Describe what has changed in this PR -->
Remove support for standard visibility

## Why?
<!-- Tell your future self why have you made these changes -->
Standard visibility is deprecated.

## How did you test it?
<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->

## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->

## Is hotfix candidate?
<!-- Is this PR a hotfix candidate or does it require a notification to
be sent to the broader community? (Yes/No) -->
2024-02-29 12:05:20 -06:00
Rodrigo Zhou
2a8a1ae694 Remove support for Cassandra as visibility store (#5237)
## What changed?
<!-- Describe what has changed in this PR -->
Remove support for Cassandra as visibility store.
Updated integration tests that used Cassandra visibility to use
Elasticsearch.

## Why?
<!-- Tell your future self why have you made these changes -->
Deprecating Cassandra visibility.

## How did you test it?
<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->
Updated tests.

## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->
No.

## Is hotfix candidate?
<!-- Is this PR a hotfix candidate or does it require a notification to
be sent to the broader community? (Yes/No) -->
No.
2024-01-29 11:36:00 -06:00
Carly de Frondeville
46e90391f4 support embedded schema for cassandra and sql update-schema and setup-schema (#5195)
## What changed?


This change adds a flag to `temporal-sql-tool` and
`temporal-cassandra-tool`'s `update-schema` and `setup-schema` to
specify an embedded schema instead of a path to the schema directory or
schema file.

```
NAME:
   temporal-cassandra-tool update-schema - update cassandra schema to a specific version

USAGE:
   temporal-cassandra-tool update-schema [command options] [arguments...]

OPTIONS:
   --version value, -v value      target version for the schema update, defaults to latest
   --schema-dir value, -d value   path to directory containing versioned schema
   --schema-name value, -s value  name of embedded versioned schema, one of: [cassandra/temporal cassandra/visibility]
```

```
NAME:
   temporal-sql-tool update-schema - update sql schema to a specific version

USAGE:
   temporal-sql-tool update-schema [command options] [arguments...]

OPTIONS:
   --version value, -v value      target version for the schema update, defaults to latest
   --schema-dir value, -d value   path to directory containing versioned schema
   --schema-name value, -s value  name of embedded versioned schema, one of: [mysql/v57/temporal mysql/v57/visibility mysql/v8/temporal mysql/v8/visibility postgresql/v96/temporal postgresql/v96/visibility postgresql/v12/temporal postgresql/v12/visibility]
```


## Why?
We want to embed the db schemas in the `temporal-sql-tool` and
`temporal-cassandra-tool` with `go:embed` so that customers can simply
specify which schema they want using a flag instead of having to copy
the schema files to wherever they're running the db tool and passing the
path to the schema.

https://github.com/temporalio/temporal/issues/2059

## How did you test it?
I wrote a new unit test for reading the embedded file system, and the
existing codepath of the changed functions are all tested by the
existing unit tests. I also updated the unit test for config validation
to reflect the new changes.

I tested this locally with a locally running Postgres. Since the more
complex changes are in `updatetask.go`, which is shared by the sql and
the cassandra tool, I think there is no need to also test with a real
cassandra db. I also built the cassandra command line tool and confirmed
that the flags and validation checks behaved as expected.

## Potential risks
Schema updates could fail. But the changes are pretty contained to the
new `-s` flag which isn't used anywhere in production yet, so the risk
is very low. The code for the `-d` flag remained basically the same.

## Is hotfix candidate?
No
2023-12-05 12:22:06 -08:00
Rodrigo Zhou
bea663d5fc Add parent execution search attributes to ES mappings (#5137)
<!-- Describe what has changed in this PR -->
**What changed?**
Add parent execution search attributes to ES mappings

<!-- Tell your future self why have you made these changes -->
**Why?**
PR https://github.com/temporalio/temporal/pull/5054 modified the SQL
schemas to add parent execution to visibility. This one does for ES.

<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->
**How did you test it?**
Unit Tests.

<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->
**Potential risks**
No.

<!-- Is this PR a hotfix candidate or require that a notification be
sent to the broader community? (Yes/No) -->
**Is hotfix candidate?**
No.
2023-11-22 12:04:06 -06:00
Prathyush PV
200821151c Adding FOR UPDATE for SelectFromQueueV2Metadata (#5075)
<!-- Describe what has changed in this PR -->
**What changed?**
Adding FOR UPDATE clause when fetching queueV2 metadata and removing
unused field version from queue metadata.

<!-- Tell your future self why have you made these changes -->
**Why?**
If a queueV2 metadata row is fetched in a transaction, we have to place
a lock on that row
to avoid another transaction reading from that line. This can happen
when two threads are trying to
delete messages from the queue. Two of them will update queue metadata
and write it back. This will lead
to a race condition. By adding 'FOR UPDATE' SQL clause, the first
transaction will get an exclusive lock
on the row. The second transaction will wait until the first transaction
is complete or rollback.

Also, removing the version field from QueueV2 metadata table. We will
not be using this field since we are using sql transactions.


<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->
**How did you test it?**
Unit test. Executed through the debugger to make sure
SelectFromQueueV2MetadataForUpdate() is called instead of
SelectFromQueueV2Metadata() when executed inside a trancation.


<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->
**Potential risks**


<!-- Is this PR a hotfix candidate or require that a notification be
sent to the broader community? (Yes/No) -->
**Is hotfix candidate?**
2023-11-04 09:56:35 -07:00
Rodrigo Zhou
595b9cee38 Add parent workflow info to visibility schema (#5054)
<!-- Describe what has changed in this PR -->
**What changed?**
Add parent workflow info to visibibility schema

<!-- Tell your future self why have you made these changes -->
**Why?**


<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->
**How did you test it?**
Unit tests

<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->
**Potential risks**
No.

<!-- Is this PR a hotfix candidate or require that a notification be
sent to the broader community? (Yes/No) -->
**Is hotfix candidate?**
No.
2023-11-03 17:10:16 -05:00
Rodrigo Zhou
64eb57d248 Add ExecutionDuration and StateTransitionCount search attributes to SQL schema (#4961)
<!-- Describe what has changed in this PR -->
**What changed?**
Add ExecutionDuration and StateTransitionCount to SQL visibility
schemas.
Add unit test to validate all system search attributes are mapped to SQL
DB column name.
Moved StateTransitionCount to visibility Close request only.

<!-- Tell your future self why have you made these changes -->
**Why?**
Match features with Elasticsearch.
https://github.com/temporalio/temporal/issues/4942

<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->
**How did you test it?**
Run unit tests.

<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->
**Potential risks**
No.

<!-- Is this PR a hotfix candidate or require that a notification be
sent to the broader community? (Yes/No) -->
**Is hotfix candidate?**
No.
2023-10-20 16:50:12 -05:00
Prathyush PV
293928dedc EnqueueMessage and ReadMessage methods for QueueV2 SQL Implementation (#4937)
<!-- Describe what has changed in this PR -->
**What changed?**
Adding EnqueueMessage() and ReadMessage() methods for SQL version of
persistence.QueueV2, which supersedes the persistence.Queue interface.
The implementations for delete and merge are left out for now and will
be implemented later.


<!-- Tell your future self why have you made these changes -->
**Why?**
We plan on using this for the upcoming history task DLQ project.


<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->
**How did you test it?**
Unit tests.

<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->
**Potential risks**


<!-- Is this PR a hotfix candidate or require that a notification be
sent to the broader community? (Yes/No) -->
**Is hotfix candidate?**
2023-10-10 09:57:37 -07:00