common/persistence/nosql/nosqlplugin/cassandra/workflow_cql.go (566 lines of code) (raw):
// Copyright (c) 2021 Uber Technologies, Inc.
// Portions of the Software are attributed to Copyright (c) 2020 Temporal Technologies Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package cassandra
const (
templateWorkflowExecutionType = `{` +
`domain_id: ?, ` +
`workflow_id: ?, ` +
`run_id: ?, ` +
`first_run_id: ?, ` +
`parent_domain_id: ?, ` +
`parent_workflow_id: ?, ` +
`parent_run_id: ?, ` +
`initiated_id: ?, ` +
`completion_event_batch_id: ?, ` +
`completion_event: ?, ` +
`completion_event_data_encoding: ?, ` +
`task_list: ?, ` +
`workflow_type_name: ?, ` +
`workflow_timeout: ?, ` +
`decision_task_timeout: ?, ` +
`execution_context: ?, ` +
`state: ?, ` +
`close_status: ?, ` +
`last_first_event_id: ?, ` +
`last_event_task_id: ?, ` +
`next_event_id: ?, ` +
`last_processed_event: ?, ` +
`start_time: ?, ` +
`last_updated_time: ?, ` +
`create_request_id: ?, ` +
`signal_count: ?, ` +
`history_size: ?, ` +
`decision_version: ?, ` +
`decision_schedule_id: ?, ` +
`decision_started_id: ?, ` +
`decision_request_id: ?, ` +
`decision_timeout: ?, ` +
`decision_attempt: ?, ` +
`decision_timestamp: ?, ` +
`decision_scheduled_timestamp: ?, ` +
`decision_original_scheduled_timestamp: ?, ` +
`cancel_requested: ?, ` +
`cancel_request_id: ?, ` +
`sticky_task_list: ?, ` +
`sticky_schedule_to_start_timeout: ?,` +
`client_library_version: ?, ` +
`client_feature_version: ?, ` +
`client_impl: ?, ` +
`auto_reset_points: ?, ` +
`auto_reset_points_encoding: ?, ` +
`attempt: ?, ` +
`has_retry_policy: ?, ` +
`init_interval: ?, ` +
`backoff_coefficient: ?, ` +
`max_interval: ?, ` +
`expiration_time: ?, ` +
`max_attempts: ?, ` +
`non_retriable_errors: ?, ` +
`event_store_version: ?, ` +
`branch_token: ?, ` +
`cron_schedule: ?, ` +
`expiration_seconds: ?, ` +
`search_attributes: ?, ` +
`memo: ?, ` +
`partition_config: ? ` +
`}`
templateTransferTaskType = `{` +
`domain_id: ?, ` +
`workflow_id: ?, ` +
`run_id: ?, ` +
`visibility_ts: ?, ` +
`task_id: ?, ` +
`target_domain_id: ?, ` +
`target_domain_ids: ?,` +
`target_workflow_id: ?, ` +
`target_run_id: ?, ` +
`target_child_workflow_only: ?, ` +
`task_list: ?, ` +
`type: ?, ` +
`schedule_id: ?, ` +
`record_visibility: ?, ` +
`version: ?` +
`}`
templateCrossClusterTaskType = templateTransferTaskType
templateReplicationTaskType = `{` +
`domain_id: ?, ` +
`workflow_id: ?, ` +
`run_id: ?, ` +
`task_id: ?, ` +
`type: ?, ` +
`first_event_id: ?,` +
`next_event_id: ?,` +
`version: ?,` +
`scheduled_id: ?, ` +
`event_store_version: ?, ` +
`branch_token: ?, ` +
`new_run_event_store_version: ?, ` +
`new_run_branch_token: ?, ` +
`created_time: ? ` +
`}`
templateTimerTaskType = `{` +
`domain_id: ?, ` +
`workflow_id: ?, ` +
`run_id: ?, ` +
`visibility_ts: ?, ` +
`task_id: ?, ` +
`type: ?, ` +
`timeout_type: ?, ` +
`event_id: ?, ` +
`schedule_attempt: ?, ` +
`version: ?` +
`}`
templateActivityInfoType = `{` +
`version: ?, ` +
`schedule_id: ?, ` +
`scheduled_event_batch_id: ?, ` +
`scheduled_event: ?, ` +
`scheduled_time: ?, ` +
`started_id: ?, ` +
`started_event: ?, ` +
`started_time: ?, ` +
`activity_id: ?, ` +
`request_id: ?, ` +
`details: ?, ` +
`schedule_to_start_timeout: ?, ` +
`schedule_to_close_timeout: ?, ` +
`start_to_close_timeout: ?, ` +
`heart_beat_timeout: ?, ` +
`cancel_requested: ?, ` +
`cancel_request_id: ?, ` +
`last_hb_updated_time: ?, ` +
`timer_task_status: ?, ` +
`attempt: ?, ` +
`task_list: ?, ` +
`started_identity: ?, ` +
`has_retry_policy: ?, ` +
`init_interval: ?, ` +
`backoff_coefficient: ?, ` +
`max_interval: ?, ` +
`expiration_time: ?, ` +
`max_attempts: ?, ` +
`non_retriable_errors: ?, ` +
`last_failure_reason: ?, ` +
`last_worker_identity: ?, ` +
`last_failure_details: ?, ` +
`event_data_encoding: ?` +
`}`
templateTimerInfoType = `{` +
`version: ?, ` +
`timer_id: ?, ` +
`started_id: ?, ` +
`expiry_time: ?, ` +
`task_id: ?` +
`}`
templateChildExecutionInfoType = `{` +
`version: ?, ` +
`initiated_id: ?, ` +
`initiated_event_batch_id: ?, ` +
`initiated_event: ?, ` +
`started_id: ?, ` +
`started_workflow_id: ?, ` +
`started_run_id: ?, ` +
`started_event: ?, ` +
`create_request_id: ?, ` +
`event_data_encoding: ?, ` +
`domain_id: ?, ` +
`domain_name: ?, ` +
`workflow_type_name: ?, ` +
`parent_close_policy: ?` +
`}`
templateRequestCancelInfoType = `{` +
`version: ?,` +
`initiated_id: ?, ` +
`initiated_event_batch_id: ?, ` +
`cancel_request_id: ? ` +
`}`
templateSignalInfoType = `{` +
`version: ?, ` +
`initiated_id: ?, ` +
`initiated_event_batch_id: ?, ` +
`signal_request_id: ?, ` +
`signal_name: ?, ` +
`input: ?, ` +
`control: ?` +
`}`
templateChecksumType = `{` +
`version: ?, ` +
`flavor: ?, ` +
`value: ? ` +
`}`
templateUpdateCurrentWorkflowExecutionQuery = `UPDATE executions USING TTL 0 ` +
`SET current_run_id = ?, ` +
`execution = {run_id: ?, create_request_id: ?, state: ?, close_status: ?}, ` +
`workflow_last_write_version = ?, ` +
`workflow_state = ? ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? ` +
`IF current_run_id = ? `
templateUpdateCurrentWorkflowExecutionForNewQuery = templateUpdateCurrentWorkflowExecutionQuery +
`and workflow_last_write_version = ? ` +
`and workflow_state = ? `
templateCreateCurrentWorkflowExecutionQuery = `INSERT INTO executions (` +
`shard_id, type, domain_id, workflow_id, run_id, visibility_ts, task_id, current_run_id, execution, workflow_last_write_version, workflow_state) ` +
`VALUES(?, ?, ?, ?, ?, ?, ?, ?, {run_id: ?, create_request_id: ?, state: ?, close_status: ?}, ?, ?) IF NOT EXISTS USING TTL 0 `
templateCreateWorkflowExecutionWithVersionHistoriesQuery = `INSERT INTO executions (` +
`shard_id, domain_id, workflow_id, run_id, type, execution, next_event_id, visibility_ts, task_id, version_histories, version_histories_encoding, checksum, workflow_last_write_version, workflow_state) ` +
`VALUES(?, ?, ?, ?, ?, ` + templateWorkflowExecutionType + `, ?, ?, ?, ?, ?, ` + templateChecksumType + `, ?, ?) IF NOT EXISTS `
templateCreateTransferTaskQuery = `INSERT INTO executions (` +
`shard_id, type, domain_id, workflow_id, run_id, transfer, visibility_ts, task_id) ` +
`VALUES(?, ?, ?, ?, ?, ` + templateTransferTaskType + `, ?, ?)`
templateCreateCrossClusterTaskQuery = `INSERT INTO executions (` +
`shard_id, type, domain_id, workflow_id, run_id, cross_cluster, visibility_ts, task_id) ` +
`VALUES(?, ?, ?, ?, ?, ` + templateCrossClusterTaskType + `, ?, ?)`
templateCreateReplicationTaskQuery = `INSERT INTO executions (` +
`shard_id, type, domain_id, workflow_id, run_id, replication, visibility_ts, task_id) ` +
`VALUES(?, ?, ?, ?, ?, ` + templateReplicationTaskType + `, ?, ?)`
templateCreateTimerTaskQuery = `INSERT INTO executions (` +
`shard_id, type, domain_id, workflow_id, run_id, timer, visibility_ts, task_id) ` +
`VALUES(?, ?, ?, ?, ?, ` + templateTimerTaskType + `, ?, ?)`
templateUpdateLeaseQuery = `UPDATE executions ` +
`SET range_id = ? ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? ` +
`IF range_id = ?`
// TODO: remove replication_state after all 2DC workflows complete
templateGetWorkflowExecutionQuery = `SELECT execution, replication_state, activity_map, timer_map, ` +
`child_executions_map, request_cancel_map, signal_map, signal_requested, buffered_events_list, ` +
`buffered_replication_tasks_map, version_histories, version_histories_encoding, checksum ` +
`FROM executions ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ?`
templateGetCurrentExecutionQuery = `SELECT current_run_id, execution, workflow_last_write_version ` +
`FROM executions ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ?`
templateListCurrentExecutionsQuery = `SELECT domain_id, workflow_id, run_id, current_run_id, workflow_state ` +
`FROM executions ` +
`WHERE shard_id = ? ` +
`and type = ?`
templateIsWorkflowExecutionExistsQuery = `SELECT shard_id, type, domain_id, workflow_id, run_id, visibility_ts, task_id ` +
`FROM executions ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ?`
templateListWorkflowExecutionQuery = `SELECT run_id, execution, version_histories, version_histories_encoding ` +
`FROM executions ` +
`WHERE shard_id = ? ` +
`and type = ?`
templateUpdateWorkflowExecutionWithVersionHistoriesQuery = `UPDATE executions ` +
`SET execution = ` + templateWorkflowExecutionType +
`, next_event_id = ? ` +
`, version_histories = ? ` +
`, version_histories_encoding = ? ` +
`, checksum = ` + templateChecksumType +
`, workflow_last_write_version = ? ` +
`, workflow_state = ? ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? ` +
`IF next_event_id = ? `
templateUpdateActivityInfoQuery = `UPDATE executions ` +
`SET activity_map[ ? ] = ` + templateActivityInfoType + ` ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? `
templateResetActivityInfoQuery = `UPDATE executions ` +
`SET activity_map = ? ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? `
templateUpdateTimerInfoQuery = `UPDATE executions ` +
`SET timer_map[ ? ] = ` + templateTimerInfoType + ` ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? `
templateResetTimerInfoQuery = `UPDATE executions ` +
`SET timer_map = ? ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? `
templateUpdateChildExecutionInfoQuery = `UPDATE executions ` +
`SET child_executions_map[ ? ] = ` + templateChildExecutionInfoType + ` ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? `
templateResetChildExecutionInfoQuery = `UPDATE executions ` +
`SET child_executions_map = ?` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? `
templateUpdateRequestCancelInfoQuery = `UPDATE executions ` +
`SET request_cancel_map[ ? ] = ` + templateRequestCancelInfoType + ` ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? `
templateResetRequestCancelInfoQuery = `UPDATE executions ` +
`SET request_cancel_map = ?` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? `
templateUpdateSignalInfoQuery = `UPDATE executions ` +
`SET signal_map[ ? ] = ` + templateSignalInfoType + ` ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? `
templateResetSignalInfoQuery = `UPDATE executions ` +
`SET signal_map = ? ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? `
templateUpdateSignalRequestedQuery = `UPDATE executions ` +
`SET signal_requested = signal_requested + ? ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? `
templateResetSignalRequestedQuery = `UPDATE executions ` +
`SET signal_requested = ? ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? `
templateAppendBufferedEventsQuery = `UPDATE executions ` +
`SET buffered_events_list = buffered_events_list + ? ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? `
templateDeleteBufferedEventsQuery = `UPDATE executions ` +
`SET buffered_events_list = [] ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? `
templateDeleteActivityInfoQuery = `DELETE activity_map[ ? ] ` +
`FROM executions ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? `
templateDeleteTimerInfoQuery = `DELETE timer_map[ ? ] ` +
`FROM executions ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? `
templateDeleteChildExecutionInfoQuery = `DELETE child_executions_map[ ? ] ` +
`FROM executions ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? `
templateDeleteRequestCancelInfoQuery = `DELETE request_cancel_map[ ? ] ` +
`FROM executions ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? `
templateDeleteSignalInfoQuery = `DELETE signal_map[ ? ] ` +
`FROM executions ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? `
templateDeleteWorkflowExecutionMutableStateQuery = `DELETE FROM executions ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? `
templateDeleteWorkflowExecutionCurrentRowQuery = templateDeleteWorkflowExecutionMutableStateQuery + " if current_run_id = ? "
templateDeleteWorkflowExecutionSignalRequestedQuery = `UPDATE executions ` +
`SET signal_requested = signal_requested - ? ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ? `
templateGetTransferTasksQuery = `SELECT transfer ` +
`FROM executions ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id > ? ` +
`and task_id <= ?`
templateGetCrossClusterTasksQuery = `SELECT cross_cluster ` +
`FROM executions ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id > ? ` +
`and task_id <= ?`
templateGetReplicationTasksQuery = `SELECT replication ` +
`FROM executions ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id > ? ` +
`and task_id <= ?`
templateGetDLQSizeQuery = `SELECT count(1) as count ` +
`FROM executions ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ?`
templateCompleteTransferTaskQuery = `DELETE FROM executions ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id = ?`
templateRangeCompleteTransferTaskQuery = `DELETE FROM executions ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id > ? ` +
`and task_id <= ?`
templateCompleteCrossClusterTaskQuery = templateCompleteTransferTaskQuery
templateRangeCompleteCrossClusterTaskQuery = templateRangeCompleteTransferTaskQuery
templateCompleteReplicationTaskBeforeQuery = `DELETE FROM executions ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ? ` +
`and run_id = ? ` +
`and visibility_ts = ? ` +
`and task_id <= ?`
templateCompleteReplicationTaskQuery = templateCompleteTransferTaskQuery
templateRangeCompleteReplicationTaskQuery = templateRangeCompleteTransferTaskQuery
templateGetTimerTasksQuery = `SELECT timer ` +
`FROM executions ` +
`WHERE shard_id = ? ` +
`and type = ?` +
`and domain_id = ? ` +
`and workflow_id = ?` +
`and run_id = ?` +
`and visibility_ts >= ? ` +
`and visibility_ts < ?`
templateCompleteTimerTaskQuery = `DELETE FROM executions ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ?` +
`and run_id = ?` +
`and visibility_ts = ? ` +
`and task_id = ?`
templateRangeCompleteTimerTaskQuery = `DELETE FROM executions ` +
`WHERE shard_id = ? ` +
`and type = ? ` +
`and domain_id = ? ` +
`and workflow_id = ?` +
`and run_id = ?` +
`and visibility_ts >= ? ` +
`and visibility_ts < ?`
)