go.temporal.io/server@v1.23.0/common/archiver/interface.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  //go:generate mockgen -copyright_file ../../LICENSE -package $GOPACKAGE -source $GOFILE -destination interface_mock.go
    26  
    27  package archiver
    28  
    29  import (
    30  	"context"
    31  
    32  	historypb "go.temporal.io/api/history/v1"
    33  	workflowpb "go.temporal.io/api/workflow/v1"
    34  
    35  	"go.temporal.io/server/common/searchattribute"
    36  
    37  	archiverspb "go.temporal.io/server/api/archiver/v1"
    38  	"go.temporal.io/server/common/cluster"
    39  	"go.temporal.io/server/common/log"
    40  	"go.temporal.io/server/common/metrics"
    41  	"go.temporal.io/server/common/persistence"
    42  )
    43  
    44  type (
    45  	// ArchiveHistoryRequest is request to Archive workflow history
    46  	ArchiveHistoryRequest struct {
    47  		ShardID              int32
    48  		NamespaceID          string
    49  		Namespace            string
    50  		WorkflowID           string
    51  		RunID                string
    52  		BranchToken          []byte
    53  		NextEventID          int64
    54  		CloseFailoverVersion int64
    55  	}
    56  
    57  	// GetHistoryRequest is the request to Get archived history
    58  	GetHistoryRequest struct {
    59  		NamespaceID          string
    60  		WorkflowID           string
    61  		RunID                string
    62  		CloseFailoverVersion *int64
    63  		NextPageToken        []byte
    64  		PageSize             int
    65  	}
    66  
    67  	// GetHistoryResponse is the response of Get archived history
    68  	GetHistoryResponse struct {
    69  		HistoryBatches []*historypb.History
    70  		NextPageToken  []byte
    71  	}
    72  
    73  	// HistoryBootstrapContainer contains components needed by all history Archiver implementations
    74  	HistoryBootstrapContainer struct {
    75  		ExecutionManager persistence.ExecutionManager
    76  		Logger           log.Logger
    77  		MetricsHandler   metrics.Handler
    78  		ClusterMetadata  cluster.Metadata
    79  	}
    80  
    81  	// HistoryArchiver is used to archive history and read archived history
    82  	HistoryArchiver interface {
    83  		// Archive is used to archive a Workflow's history. When the context expires the method should stop trying to archive.
    84  		// Implementors are free to archive however they want, including implementing retries of sub-operations. The URI defines
    85  		// the resource that histories should be archived into. The implementor gets to determine how to interpret the URI.
    86  		// The Archive method may or may not be automatically retried by the caller. ArchiveOptions are used
    87  		// to interact with these retries including giving the implementor the ability to cancel retries and record progress
    88  		// between retry attempts.
    89  		// This method will be invoked after a workflow passes its retention period.
    90  		Archive(ctx context.Context, uri URI, request *ArchiveHistoryRequest, opts ...ArchiveOption) error
    91  		// Get is used to access an archived history. When context expires this method should stop trying to fetch history.
    92  		// The URI identifies the resource from which history should be accessed and it is up to the implementor to interpret this URI.
    93  		// This method should emit api service errors - see the filestore as an example.
    94  		Get(ctx context.Context, url URI, request *GetHistoryRequest) (*GetHistoryResponse, error)
    95  		// ValidateURI is used to define what a valid URI for an implementation is.
    96  		ValidateURI(uri URI) error
    97  	}
    98  
    99  	// VisibilityBootstrapContainer contains components needed by all visibility Archiver implementations
   100  	VisibilityBootstrapContainer struct {
   101  		Logger          log.Logger
   102  		MetricsHandler  metrics.Handler
   103  		ClusterMetadata cluster.Metadata
   104  	}
   105  
   106  	// QueryVisibilityRequest is the request to query archived visibility records
   107  	QueryVisibilityRequest struct {
   108  		NamespaceID   string
   109  		PageSize      int
   110  		NextPageToken []byte
   111  		Query         string
   112  	}
   113  
   114  	// QueryVisibilityResponse is the response of querying archived visibility records
   115  	QueryVisibilityResponse struct {
   116  		Executions    []*workflowpb.WorkflowExecutionInfo
   117  		NextPageToken []byte
   118  	}
   119  
   120  	// VisibilityArchiver is used to archive visibility and read archived visibility
   121  	VisibilityArchiver interface {
   122  		// Archive is used to archive one Workflow visibility record.
   123  		// Check the Archive method of the HistoryArchiver interface for parameters' meaning and requirements.
   124  		// The only difference is that the ArchiveOption parameter won't include an option for recording process.
   125  		// Please make sure your implementation is lossless. If any in-memory batching mechanism is used
   126  		// then those batched records will be lost during server restarts. This method will be invoked when the Workflow closes.
   127  		// Note that because of conflict resolution, it is possible for a Workflow to through the closing process multiple times,
   128  		// which means that this method can be invoked more than once after a Workflow closes.
   129  		Archive(ctx context.Context, uri URI, request *archiverspb.VisibilityRecord, opts ...ArchiveOption) error
   130  		// Query is used to retrieve archived visibility records.
   131  		// Check the Get() method of the HistoryArchiver interface in Step 2 for parameters' meaning and requirements.
   132  		// The request includes a string field called query, which describes what kind of visibility records should be returned.
   133  		// For example, it can be  some SQL-like syntax query string.
   134  		// Your implementation is responsible for parsing and validating the query, and also returning all visibility records that match the query.
   135  		// Currently the maximum context timeout passed into the method is 3 minutes, so it's acceptable if this method takes some time to run.
   136  		Query(ctx context.Context, uri URI, request *QueryVisibilityRequest, saTypeMap searchattribute.NameTypeMap) (*QueryVisibilityResponse, error)
   137  		// ValidateURI is used to define what a valid URI for an implementation is.
   138  		ValidateURI(uri URI) error
   139  	}
   140  )