go.temporal.io/server@v1.23.0/common/persistence/visibility/store/visibility_store.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 store
    26  
    27  // -aux_files is required here due to Closeable interface being in another file.
    28  //go:generate mockgen -copyright_file ../../../../LICENSE -package $GOPACKAGE -source $GOFILE -destination visibility_store_mock.go -aux_files go.temporal.io/server/common/persistence=../../data_interfaces.go
    29  
    30  import (
    31  	"context"
    32  	"time"
    33  
    34  	commonpb "go.temporal.io/api/common/v1"
    35  	enumspb "go.temporal.io/api/enums/v1"
    36  
    37  	"go.temporal.io/server/common/persistence"
    38  	"go.temporal.io/server/common/persistence/visibility/manager"
    39  )
    40  
    41  type (
    42  	// VisibilityStore is the store interface for visibility
    43  	VisibilityStore interface {
    44  		persistence.Closeable
    45  		GetName() string
    46  		GetIndexName() string
    47  
    48  		// Validate search attributes based on the store constraints. It returns a new map containing
    49  		// only search attributes with valid values. If there are invalid values, an error of type
    50  		// VisibilityStoreInvalidValuesError wraps all invalid values errors.
    51  		ValidateCustomSearchAttributes(searchAttributes map[string]any) (map[string]any, error)
    52  
    53  		// Write APIs.
    54  		RecordWorkflowExecutionStarted(ctx context.Context, request *InternalRecordWorkflowExecutionStartedRequest) error
    55  		RecordWorkflowExecutionClosed(ctx context.Context, request *InternalRecordWorkflowExecutionClosedRequest) error
    56  		UpsertWorkflowExecution(ctx context.Context, request *InternalUpsertWorkflowExecutionRequest) error
    57  		DeleteWorkflowExecution(ctx context.Context, request *manager.VisibilityDeleteWorkflowExecutionRequest) error
    58  
    59  		// Read APIs.
    60  		ListOpenWorkflowExecutions(ctx context.Context, request *manager.ListWorkflowExecutionsRequest) (*InternalListWorkflowExecutionsResponse, error)
    61  		ListClosedWorkflowExecutions(ctx context.Context, request *manager.ListWorkflowExecutionsRequest) (*InternalListWorkflowExecutionsResponse, error)
    62  		ListOpenWorkflowExecutionsByType(ctx context.Context, request *manager.ListWorkflowExecutionsByTypeRequest) (*InternalListWorkflowExecutionsResponse, error)
    63  		ListClosedWorkflowExecutionsByType(ctx context.Context, request *manager.ListWorkflowExecutionsByTypeRequest) (*InternalListWorkflowExecutionsResponse, error)
    64  		ListOpenWorkflowExecutionsByWorkflowID(ctx context.Context, request *manager.ListWorkflowExecutionsByWorkflowIDRequest) (*InternalListWorkflowExecutionsResponse, error)
    65  		ListClosedWorkflowExecutionsByWorkflowID(ctx context.Context, request *manager.ListWorkflowExecutionsByWorkflowIDRequest) (*InternalListWorkflowExecutionsResponse, error)
    66  		ListClosedWorkflowExecutionsByStatus(ctx context.Context, request *manager.ListClosedWorkflowExecutionsByStatusRequest) (*InternalListWorkflowExecutionsResponse, error)
    67  		ListWorkflowExecutions(ctx context.Context, request *manager.ListWorkflowExecutionsRequestV2) (*InternalListWorkflowExecutionsResponse, error)
    68  		ScanWorkflowExecutions(ctx context.Context, request *manager.ListWorkflowExecutionsRequestV2) (*InternalListWorkflowExecutionsResponse, error)
    69  		CountWorkflowExecutions(ctx context.Context, request *manager.CountWorkflowExecutionsRequest) (*manager.CountWorkflowExecutionsResponse, error)
    70  		GetWorkflowExecution(ctx context.Context, request *manager.GetWorkflowExecutionRequest) (*InternalGetWorkflowExecutionResponse, error)
    71  	}
    72  
    73  	// InternalWorkflowExecutionInfo is visibility info for internal response
    74  	InternalWorkflowExecutionInfo struct {
    75  		WorkflowID           string
    76  		RunID                string
    77  		TypeName             string
    78  		StartTime            time.Time
    79  		ExecutionTime        time.Time
    80  		CloseTime            time.Time
    81  		Status               enumspb.WorkflowExecutionStatus
    82  		HistoryLength        int64
    83  		HistorySizeBytes     int64
    84  		StateTransitionCount int64
    85  		Memo                 *commonpb.DataBlob
    86  		TaskQueue            string
    87  		SearchAttributes     *commonpb.SearchAttributes
    88  		ParentWorkflowID     string
    89  		ParentRunID          string
    90  	}
    91  
    92  	// InternalListWorkflowExecutionsResponse is response from ListWorkflowExecutions
    93  	InternalListWorkflowExecutionsResponse struct {
    94  		Executions []*InternalWorkflowExecutionInfo
    95  		// Token to read next page if there are more workflow executions beyond page size.
    96  		// Use this to set NextPageToken on ListWorkflowExecutionsRequest to read the next page.
    97  		NextPageToken []byte
    98  	}
    99  
   100  	// InternalGetWorkflowExecutionResponse is response from GetWorkflowExecution
   101  	InternalGetWorkflowExecutionResponse struct {
   102  		Execution *InternalWorkflowExecutionInfo
   103  	}
   104  
   105  	// InternalVisibilityRequestBase is a base request to visibility APIs.
   106  	InternalVisibilityRequestBase struct {
   107  		NamespaceID      string
   108  		WorkflowID       string
   109  		RunID            string
   110  		WorkflowTypeName string
   111  		StartTime        time.Time
   112  		Status           enumspb.WorkflowExecutionStatus
   113  		ExecutionTime    time.Time
   114  		TaskID           int64
   115  		ShardID          int32
   116  		Memo             *commonpb.DataBlob
   117  		TaskQueue        string
   118  		SearchAttributes *commonpb.SearchAttributes
   119  		ParentWorkflowID *string
   120  		ParentRunID      *string
   121  	}
   122  
   123  	// InternalRecordWorkflowExecutionStartedRequest request to RecordWorkflowExecutionStarted
   124  	InternalRecordWorkflowExecutionStartedRequest struct {
   125  		*InternalVisibilityRequestBase
   126  	}
   127  
   128  	// InternalRecordWorkflowExecutionClosedRequest is request to RecordWorkflowExecutionClosed
   129  	InternalRecordWorkflowExecutionClosedRequest struct {
   130  		*InternalVisibilityRequestBase
   131  		CloseTime            time.Time
   132  		HistoryLength        int64
   133  		HistorySizeBytes     int64
   134  		ExecutionDuration    time.Duration
   135  		StateTransitionCount int64
   136  	}
   137  
   138  	// InternalUpsertWorkflowExecutionRequest is request to UpsertWorkflowExecution
   139  	InternalUpsertWorkflowExecutionRequest struct {
   140  		*InternalVisibilityRequestBase
   141  	}
   142  )