go.temporal.io/server@v1.23.0/common/persistence/sql/sqlplugin/history_execution.go (about)

     1  // The MIT License
     2  //
     3  // Copyright (c) 2020 Temporal Technologies Inc.  All rights reserved.
     4  //
     5  // Copyright (c) 2020 Uber Technologies, Inc.
     6  //
     7  // Permission is hereby granted, free of charge, to any person obtaining a copy
     8  // of this software and associated documentation files (the "Software"), to deal
     9  // in the Software without restriction, including without limitation the rights
    10  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    11  // copies of the Software, and to permit persons to whom the Software is
    12  // furnished to do so, subject to the following conditions:
    13  //
    14  // The above copyright notice and this permission notice shall be included in
    15  // all copies or substantial portions of the Software.
    16  //
    17  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    18  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    19  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    20  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    21  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    22  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    23  // THE SOFTWARE.
    24  
    25  package sqlplugin
    26  
    27  import (
    28  	"context"
    29  	"database/sql"
    30  
    31  	enumspb "go.temporal.io/api/enums/v1"
    32  
    33  	enumsspb "go.temporal.io/server/api/enums/v1"
    34  	"go.temporal.io/server/common/primitives"
    35  )
    36  
    37  type (
    38  	// ExecutionsRow represents a row in executions table
    39  	ExecutionsRow struct {
    40  		ShardID          int32
    41  		NamespaceID      primitives.UUID
    42  		WorkflowID       string
    43  		RunID            primitives.UUID
    44  		NextEventID      int64
    45  		LastWriteVersion int64
    46  		Data             []byte
    47  		DataEncoding     string
    48  		State            []byte
    49  		StateEncoding    string
    50  		DBRecordVersion  int64
    51  	}
    52  
    53  	// ExecutionsFilter contains the column names within executions table that
    54  	// can be used to filter results through a WHERE clause
    55  	ExecutionsFilter struct {
    56  		ShardID     int32
    57  		NamespaceID primitives.UUID
    58  		WorkflowID  string
    59  		RunID       primitives.UUID
    60  	}
    61  
    62  	// CurrentExecutionsRow represents a row in current_executions table
    63  	CurrentExecutionsRow struct {
    64  		ShardID          int32
    65  		NamespaceID      primitives.UUID
    66  		WorkflowID       string
    67  		RunID            primitives.UUID
    68  		CreateRequestID  string
    69  		LastWriteVersion int64
    70  		State            enumsspb.WorkflowExecutionState
    71  		Status           enumspb.WorkflowExecutionStatus
    72  	}
    73  
    74  	// CurrentExecutionsFilter contains the column names within current_executions table that
    75  	// can be used to filter results through a WHERE clause
    76  	CurrentExecutionsFilter struct {
    77  		ShardID     int32
    78  		NamespaceID primitives.UUID
    79  		WorkflowID  string
    80  		RunID       primitives.UUID
    81  	}
    82  
    83  	// TODO remove this block in 1.12.x
    84  	ExecutionVersion struct {
    85  		DBRecordVersion int64
    86  		NextEventID     int64
    87  	}
    88  
    89  	// HistoryExecution is the SQL persistence interface for history executions
    90  	HistoryExecution interface {
    91  		InsertIntoExecutions(ctx context.Context, row *ExecutionsRow) (sql.Result, error)
    92  		UpdateExecutions(ctx context.Context, row *ExecutionsRow) (sql.Result, error)
    93  		SelectFromExecutions(ctx context.Context, filter ExecutionsFilter) (*ExecutionsRow, error)
    94  		DeleteFromExecutions(ctx context.Context, filter ExecutionsFilter) (sql.Result, error)
    95  		ReadLockExecutions(ctx context.Context, filter ExecutionsFilter) (int64, int64, error)
    96  		WriteLockExecutions(ctx context.Context, filter ExecutionsFilter) (int64, int64, error)
    97  
    98  		LockCurrentExecutionsJoinExecutions(ctx context.Context, filter CurrentExecutionsFilter) ([]CurrentExecutionsRow, error)
    99  
   100  		InsertIntoCurrentExecutions(ctx context.Context, row *CurrentExecutionsRow) (sql.Result, error)
   101  		UpdateCurrentExecutions(ctx context.Context, row *CurrentExecutionsRow) (sql.Result, error)
   102  		// SelectFromCurrentExecutions returns one or more rows from current_executions table
   103  		// Required params - {shardID, namespaceID, workflowID}
   104  		SelectFromCurrentExecutions(ctx context.Context, filter CurrentExecutionsFilter) (*CurrentExecutionsRow, error)
   105  		// DeleteFromCurrentExecutions deletes a single row that matches the filter criteria
   106  		// If a row exist, that row will be deleted and this method will return success
   107  		// If there is no row matching the filter criteria, this method will still return success
   108  		// Callers can check the output of Result.RowsAffected() to see if a row was deleted or not
   109  		// Required params - {shardID, namespaceID, workflowID, runID}
   110  		DeleteFromCurrentExecutions(ctx context.Context, filter CurrentExecutionsFilter) (sql.Result, error)
   111  		LockCurrentExecutions(ctx context.Context, filter CurrentExecutionsFilter) (*CurrentExecutionsRow, error)
   112  	}
   113  )