go.temporal.io/server@v1.23.0/common/persistence/persistence_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 mock -source $GOFILE -destination mock/store_mock.go -aux_files go.temporal.io/server/common/persistence=data_interfaces.go 26 27 package persistence 28 29 import ( 30 "context" 31 "math" 32 "time" 33 34 commonpb "go.temporal.io/api/common/v1" 35 enumspb "go.temporal.io/api/enums/v1" 36 "google.golang.org/protobuf/types/known/timestamppb" 37 38 persistencespb "go.temporal.io/server/api/persistence/v1" 39 "go.temporal.io/server/service/history/tasks" 40 ) 41 42 const ( 43 EmptyQueueMessageID = int64(-1) 44 MaxQueueMessageID = math.MaxInt64 45 ) 46 47 type ( 48 // //////////////////////////////////////////////////////////////////// 49 // Persistence interface is a lower layer of dataInterface. 50 // The intention is to let different persistence implementation(SQL,Cassandra/etc) share some common logic 51 // Right now the only common part is serialization/deserialization. 52 // //////////////////////////////////////////////////////////////////// 53 54 // ShardStore is a lower level of ShardManager 55 ShardStore interface { 56 Closeable 57 GetName() string 58 GetClusterName() string 59 GetOrCreateShard(ctx context.Context, request *InternalGetOrCreateShardRequest) (*InternalGetOrCreateShardResponse, error) 60 UpdateShard(ctx context.Context, request *InternalUpdateShardRequest) error 61 AssertShardOwnership(ctx context.Context, request *AssertShardOwnershipRequest) error 62 } 63 64 // TaskStore is a lower level of TaskManager 65 TaskStore interface { 66 Closeable 67 GetName() string 68 CreateTaskQueue(ctx context.Context, request *InternalCreateTaskQueueRequest) error 69 GetTaskQueue(ctx context.Context, request *InternalGetTaskQueueRequest) (*InternalGetTaskQueueResponse, error) 70 UpdateTaskQueue(ctx context.Context, request *InternalUpdateTaskQueueRequest) (*UpdateTaskQueueResponse, error) 71 ListTaskQueue(ctx context.Context, request *ListTaskQueueRequest) (*InternalListTaskQueueResponse, error) 72 DeleteTaskQueue(ctx context.Context, request *DeleteTaskQueueRequest) error 73 CreateTasks(ctx context.Context, request *InternalCreateTasksRequest) (*CreateTasksResponse, error) 74 GetTasks(ctx context.Context, request *GetTasksRequest) (*InternalGetTasksResponse, error) 75 CompleteTask(ctx context.Context, request *CompleteTaskRequest) error 76 CompleteTasksLessThan(ctx context.Context, request *CompleteTasksLessThanRequest) (int, error) 77 GetTaskQueueUserData(ctx context.Context, request *GetTaskQueueUserDataRequest) (*InternalGetTaskQueueUserDataResponse, error) 78 UpdateTaskQueueUserData(ctx context.Context, request *InternalUpdateTaskQueueUserDataRequest) error 79 ListTaskQueueUserDataEntries(ctx context.Context, request *ListTaskQueueUserDataEntriesRequest) (*InternalListTaskQueueUserDataEntriesResponse, error) 80 GetTaskQueuesByBuildId(ctx context.Context, request *GetTaskQueuesByBuildIdRequest) ([]string, error) 81 CountTaskQueuesByBuildId(ctx context.Context, request *CountTaskQueuesByBuildIdRequest) (int, error) 82 } 83 // MetadataStore is a lower level of MetadataManager 84 MetadataStore interface { 85 Closeable 86 GetName() string 87 CreateNamespace(ctx context.Context, request *InternalCreateNamespaceRequest) (*CreateNamespaceResponse, error) 88 GetNamespace(ctx context.Context, request *GetNamespaceRequest) (*InternalGetNamespaceResponse, error) 89 UpdateNamespace(ctx context.Context, request *InternalUpdateNamespaceRequest) error 90 RenameNamespace(ctx context.Context, request *InternalRenameNamespaceRequest) error 91 DeleteNamespace(ctx context.Context, request *DeleteNamespaceRequest) error 92 DeleteNamespaceByName(ctx context.Context, request *DeleteNamespaceByNameRequest) error 93 ListNamespaces(ctx context.Context, request *InternalListNamespacesRequest) (*InternalListNamespacesResponse, error) 94 GetMetadata(ctx context.Context) (*GetMetadataResponse, error) 95 } 96 97 // ClusterMetadataStore is a lower level of ClusterMetadataManager. 98 // There is no Internal constructs needed to abstract away at the interface level currently, 99 // so we can reimplement the ClusterMetadataManager and leave this as a placeholder. 100 ClusterMetadataStore interface { 101 Closeable 102 GetName() string 103 ListClusterMetadata(ctx context.Context, request *InternalListClusterMetadataRequest) (*InternalListClusterMetadataResponse, error) 104 GetClusterMetadata(ctx context.Context, request *InternalGetClusterMetadataRequest) (*InternalGetClusterMetadataResponse, error) 105 SaveClusterMetadata(ctx context.Context, request *InternalSaveClusterMetadataRequest) (bool, error) 106 DeleteClusterMetadata(ctx context.Context, request *InternalDeleteClusterMetadataRequest) error 107 // Membership APIs 108 GetClusterMembers(ctx context.Context, request *GetClusterMembersRequest) (*GetClusterMembersResponse, error) 109 UpsertClusterMembership(ctx context.Context, request *UpsertClusterMembershipRequest) error 110 PruneClusterMembership(ctx context.Context, request *PruneClusterMembershipRequest) error 111 } 112 113 // ExecutionStore is used to manage workflow execution including mutable states / history / tasks. 114 ExecutionStore interface { 115 Closeable 116 GetName() string 117 GetHistoryBranchUtil() HistoryBranchUtil 118 119 // The below three APIs are related to serialization/deserialization 120 CreateWorkflowExecution(ctx context.Context, request *InternalCreateWorkflowExecutionRequest) (*InternalCreateWorkflowExecutionResponse, error) 121 UpdateWorkflowExecution(ctx context.Context, request *InternalUpdateWorkflowExecutionRequest) error 122 ConflictResolveWorkflowExecution(ctx context.Context, request *InternalConflictResolveWorkflowExecutionRequest) error 123 124 DeleteWorkflowExecution(ctx context.Context, request *DeleteWorkflowExecutionRequest) error 125 DeleteCurrentWorkflowExecution(ctx context.Context, request *DeleteCurrentWorkflowExecutionRequest) error 126 GetCurrentExecution(ctx context.Context, request *GetCurrentExecutionRequest) (*InternalGetCurrentExecutionResponse, error) 127 GetWorkflowExecution(ctx context.Context, request *GetWorkflowExecutionRequest) (*InternalGetWorkflowExecutionResponse, error) 128 SetWorkflowExecution(ctx context.Context, request *InternalSetWorkflowExecutionRequest) error 129 130 // Scan related methods 131 ListConcreteExecutions(ctx context.Context, request *ListConcreteExecutionsRequest) (*InternalListConcreteExecutionsResponse, error) 132 133 // Tasks related APIs 134 135 // Hints for persistence implementaion regarding hisotry task readers 136 RegisterHistoryTaskReader(ctx context.Context, request *RegisterHistoryTaskReaderRequest) error 137 UnregisterHistoryTaskReader(ctx context.Context, request *UnregisterHistoryTaskReaderRequest) 138 UpdateHistoryTaskReaderProgress(ctx context.Context, request *UpdateHistoryTaskReaderProgressRequest) 139 140 AddHistoryTasks(ctx context.Context, request *InternalAddHistoryTasksRequest) error 141 GetHistoryTasks(ctx context.Context, request *GetHistoryTasksRequest) (*InternalGetHistoryTasksResponse, error) 142 CompleteHistoryTask(ctx context.Context, request *CompleteHistoryTaskRequest) error 143 RangeCompleteHistoryTasks(ctx context.Context, request *RangeCompleteHistoryTasksRequest) error 144 145 PutReplicationTaskToDLQ(ctx context.Context, request *PutReplicationTaskToDLQRequest) error 146 GetReplicationTasksFromDLQ(ctx context.Context, request *GetReplicationTasksFromDLQRequest) (*InternalGetReplicationTasksFromDLQResponse, error) 147 DeleteReplicationTaskFromDLQ(ctx context.Context, request *DeleteReplicationTaskFromDLQRequest) error 148 RangeDeleteReplicationTaskFromDLQ(ctx context.Context, request *RangeDeleteReplicationTaskFromDLQRequest) error 149 IsReplicationDLQEmpty(ctx context.Context, request *GetReplicationTasksFromDLQRequest) (bool, error) 150 151 // The below are history V2 APIs 152 // V2 regards history events growing as a tree, decoupled from workflow concepts 153 154 // AppendHistoryNodes add a node to history node table 155 AppendHistoryNodes(ctx context.Context, request *InternalAppendHistoryNodesRequest) error 156 // DeleteHistoryNodes delete a node from history node table 157 DeleteHistoryNodes(ctx context.Context, request *InternalDeleteHistoryNodesRequest) error 158 // ReadHistoryBranch returns history node data for a branch 159 ReadHistoryBranch(ctx context.Context, request *InternalReadHistoryBranchRequest) (*InternalReadHistoryBranchResponse, error) 160 // ForkHistoryBranch forks a new branch from a old branch 161 ForkHistoryBranch(ctx context.Context, request *InternalForkHistoryBranchRequest) error 162 // DeleteHistoryBranch removes a branch 163 DeleteHistoryBranch(ctx context.Context, request *InternalDeleteHistoryBranchRequest) error 164 // GetHistoryTree returns all branch information of a tree 165 GetHistoryTree(ctx context.Context, request *GetHistoryTreeRequest) (*InternalGetHistoryTreeResponse, error) 166 // GetAllHistoryTreeBranches returns all branches of all trees. 167 // Note that branches may be skipped or duplicated across pages if there are branches created or deleted while 168 // paginating through results. 169 GetAllHistoryTreeBranches(ctx context.Context, request *GetAllHistoryTreeBranchesRequest) (*InternalGetAllHistoryTreeBranchesResponse, error) 170 } 171 172 // Queue is a store to enqueue and get messages 173 Queue interface { 174 Closeable 175 Init(ctx context.Context, blob *commonpb.DataBlob) error 176 EnqueueMessage(ctx context.Context, blob *commonpb.DataBlob) error 177 ReadMessages(ctx context.Context, lastMessageID int64, maxCount int) ([]*QueueMessage, error) 178 DeleteMessagesBefore(ctx context.Context, messageID int64) error 179 UpdateAckLevel(ctx context.Context, metadata *InternalQueueMetadata) error 180 GetAckLevels(ctx context.Context) (*InternalQueueMetadata, error) 181 182 EnqueueMessageToDLQ(ctx context.Context, blob *commonpb.DataBlob) (int64, error) 183 ReadMessagesFromDLQ(ctx context.Context, firstMessageID int64, lastMessageID int64, pageSize int, pageToken []byte) ([]*QueueMessage, []byte, error) 184 DeleteMessageFromDLQ(ctx context.Context, messageID int64) error 185 RangeDeleteMessagesFromDLQ(ctx context.Context, firstMessageID int64, lastMessageID int64) error 186 UpdateDLQAckLevel(ctx context.Context, metadata *InternalQueueMetadata) error 187 GetDLQAckLevels(ctx context.Context) (*InternalQueueMetadata, error) 188 } 189 190 // QueueMessage is the message that stores in the queue 191 QueueMessage struct { 192 QueueType QueueType `json:"queue_type"` 193 ID int64 `json:"message_id"` 194 Data []byte `json:"message_payload"` 195 Encoding string `json:"message_encoding"` 196 } 197 198 InternalQueueMetadata struct { 199 Blob *commonpb.DataBlob 200 Version int64 201 } 202 203 // InternalGetOrCreateShardRequest is used by ShardStore to retrieve or create a shard. 204 // GetOrCreateShard should: if shard exists, return it. If not, call CreateShardInfo and 205 // create the shard with the returned value. 206 InternalGetOrCreateShardRequest struct { 207 ShardID int32 208 CreateShardInfo func() (rangeID int64, shardInfo *commonpb.DataBlob, err error) 209 LifecycleContext context.Context // cancelled when shard is unloaded 210 } 211 212 // InternalGetOrCreateShardResponse is the response to GetShard 213 InternalGetOrCreateShardResponse struct { 214 ShardInfo *commonpb.DataBlob 215 } 216 217 // InternalUpdateShardRequest is used by ShardStore to update a shard 218 InternalUpdateShardRequest struct { 219 ShardID int32 220 RangeID int64 221 Owner string 222 ShardInfo *commonpb.DataBlob 223 PreviousRangeID int64 224 } 225 226 InternalCreateTaskQueueRequest struct { 227 NamespaceID string 228 TaskQueue string 229 TaskType enumspb.TaskQueueType 230 RangeID int64 231 TaskQueueInfo *commonpb.DataBlob 232 233 TaskQueueKind enumspb.TaskQueueKind 234 ExpiryTime *timestamppb.Timestamp 235 } 236 237 InternalGetTaskQueueRequest struct { 238 NamespaceID string 239 TaskQueue string 240 TaskType enumspb.TaskQueueType 241 } 242 243 InternalGetTaskQueueResponse struct { 244 RangeID int64 245 TaskQueueInfo *commonpb.DataBlob 246 } 247 248 InternalGetTaskQueueUserDataResponse struct { 249 Version int64 250 UserData *commonpb.DataBlob 251 } 252 253 InternalUpdateTaskQueueRequest struct { 254 NamespaceID string 255 TaskQueue string 256 TaskType enumspb.TaskQueueType 257 RangeID int64 258 TaskQueueInfo *commonpb.DataBlob 259 260 TaskQueueKind enumspb.TaskQueueKind 261 ExpiryTime *timestamppb.Timestamp 262 263 PrevRangeID int64 264 } 265 266 InternalUpdateTaskQueueUserDataRequest struct { 267 NamespaceID string 268 TaskQueue string 269 Version int64 270 UserData *commonpb.DataBlob 271 // Used to build an index of build_id to task_queues 272 BuildIdsAdded []string 273 BuildIdsRemoved []string 274 } 275 276 InternalTaskQueueUserDataEntry struct { 277 TaskQueue string 278 Data *commonpb.DataBlob 279 Version int64 280 } 281 282 InternalListTaskQueueUserDataEntriesResponse struct { 283 NextPageToken []byte 284 Entries []InternalTaskQueueUserDataEntry 285 } 286 287 InternalCreateTasksRequest struct { 288 NamespaceID string 289 TaskQueue string 290 TaskType enumspb.TaskQueueType 291 RangeID int64 292 TaskQueueInfo *commonpb.DataBlob 293 Tasks []*InternalCreateTask 294 } 295 296 InternalCreateTask struct { 297 TaskId int64 298 ExpiryTime *timestamppb.Timestamp 299 Task *commonpb.DataBlob 300 } 301 302 InternalGetTasksResponse struct { 303 Tasks []*commonpb.DataBlob 304 NextPageToken []byte 305 } 306 307 InternalListTaskQueueResponse struct { 308 Items []*InternalListTaskQueueItem 309 NextPageToken []byte 310 } 311 312 InternalListTaskQueueItem struct { 313 TaskQueue *commonpb.DataBlob // serialized PersistedTaskQueueInfo 314 RangeID int64 315 } 316 317 // DataBlob represents a blob for any binary data. 318 // It contains raw data, and metadata(right now only encoding) in other field 319 // Note that it should be only used for Persistence layer, below dataInterface and application(historyEngine/etc) 320 321 // InternalCreateWorkflowExecutionRequest is used to write a new workflow execution 322 InternalCreateWorkflowExecutionRequest struct { 323 ShardID int32 324 RangeID int64 325 326 Mode CreateWorkflowMode 327 328 PreviousRunID string 329 PreviousLastWriteVersion int64 330 331 NewWorkflowSnapshot InternalWorkflowSnapshot 332 NewWorkflowNewEvents []*InternalAppendHistoryNodesRequest 333 } 334 335 // InternalCreateWorkflowExecutionResponse is the response from persistence for create new workflow execution 336 InternalCreateWorkflowExecutionResponse struct { 337 } 338 339 // InternalUpdateWorkflowExecutionRequest is used to update a workflow execution for Persistence Interface 340 InternalUpdateWorkflowExecutionRequest struct { 341 ShardID int32 342 RangeID int64 343 344 Mode UpdateWorkflowMode 345 346 UpdateWorkflowMutation InternalWorkflowMutation 347 UpdateWorkflowNewEvents []*InternalAppendHistoryNodesRequest 348 NewWorkflowSnapshot *InternalWorkflowSnapshot 349 NewWorkflowNewEvents []*InternalAppendHistoryNodesRequest 350 } 351 352 // InternalConflictResolveWorkflowExecutionRequest is used to reset workflow execution state for Persistence Interface 353 InternalConflictResolveWorkflowExecutionRequest struct { 354 ShardID int32 355 RangeID int64 356 357 Mode ConflictResolveWorkflowMode 358 359 // workflow to be resetted 360 ResetWorkflowSnapshot InternalWorkflowSnapshot 361 ResetWorkflowEventsNewEvents []*InternalAppendHistoryNodesRequest 362 // maybe new workflow 363 NewWorkflowSnapshot *InternalWorkflowSnapshot 364 NewWorkflowEventsNewEvents []*InternalAppendHistoryNodesRequest 365 366 // current workflow 367 CurrentWorkflowMutation *InternalWorkflowMutation 368 CurrentWorkflowEventsNewEvents []*InternalAppendHistoryNodesRequest 369 } 370 InternalSetWorkflowExecutionRequest struct { 371 ShardID int32 372 RangeID int64 373 374 SetWorkflowSnapshot InternalWorkflowSnapshot 375 } 376 377 // InternalWorkflowMutableState indicates workflow related state for Persistence Interface 378 InternalWorkflowMutableState struct { 379 ActivityInfos map[int64]*commonpb.DataBlob // ActivityInfo 380 TimerInfos map[string]*commonpb.DataBlob // TimerInfo 381 ChildExecutionInfos map[int64]*commonpb.DataBlob // ChildExecutionInfo 382 RequestCancelInfos map[int64]*commonpb.DataBlob // RequestCancelInfo 383 SignalInfos map[int64]*commonpb.DataBlob // SignalInfo 384 SignalRequestedIDs []string 385 ExecutionInfo *commonpb.DataBlob // WorkflowExecutionInfo 386 ExecutionState *commonpb.DataBlob // WorkflowExecutionState 387 NextEventID int64 388 BufferedEvents []*commonpb.DataBlob 389 Checksum *commonpb.DataBlob // persistencespb.Checksum 390 DBRecordVersion int64 391 } 392 393 InternalHistoryTask struct { 394 Key tasks.Key 395 Blob *commonpb.DataBlob 396 } 397 398 // InternalAddHistoryTasksRequest is used to write new tasks 399 InternalAddHistoryTasksRequest struct { 400 ShardID int32 401 RangeID int64 402 403 NamespaceID string 404 WorkflowID string 405 RunID string 406 407 Tasks map[tasks.Category][]InternalHistoryTask 408 } 409 410 // InternalWorkflowMutation is used as generic workflow execution state mutation for Persistence Interface 411 InternalWorkflowMutation struct { 412 // TODO: properly set this on call sites 413 NamespaceID string 414 WorkflowID string 415 RunID string 416 417 ExecutionInfo *persistencespb.WorkflowExecutionInfo 418 ExecutionInfoBlob *commonpb.DataBlob 419 ExecutionState *persistencespb.WorkflowExecutionState 420 ExecutionStateBlob *commonpb.DataBlob 421 NextEventID int64 422 StartVersion int64 423 LastWriteVersion int64 424 DBRecordVersion int64 425 426 UpsertActivityInfos map[int64]*commonpb.DataBlob 427 DeleteActivityInfos map[int64]struct{} 428 UpsertTimerInfos map[string]*commonpb.DataBlob 429 DeleteTimerInfos map[string]struct{} 430 UpsertChildExecutionInfos map[int64]*commonpb.DataBlob 431 DeleteChildExecutionInfos map[int64]struct{} 432 UpsertRequestCancelInfos map[int64]*commonpb.DataBlob 433 DeleteRequestCancelInfos map[int64]struct{} 434 UpsertSignalInfos map[int64]*commonpb.DataBlob 435 DeleteSignalInfos map[int64]struct{} 436 UpsertSignalRequestedIDs map[string]struct{} 437 DeleteSignalRequestedIDs map[string]struct{} 438 NewBufferedEvents *commonpb.DataBlob 439 ClearBufferedEvents bool 440 441 Tasks map[tasks.Category][]InternalHistoryTask 442 443 Condition int64 444 445 Checksum *commonpb.DataBlob 446 } 447 448 // InternalWorkflowSnapshot is used as generic workflow execution state snapshot for Persistence Interface 449 InternalWorkflowSnapshot struct { 450 // TODO: properly set this on call sites 451 NamespaceID string 452 WorkflowID string 453 RunID string 454 455 ExecutionInfo *persistencespb.WorkflowExecutionInfo 456 ExecutionInfoBlob *commonpb.DataBlob 457 ExecutionState *persistencespb.WorkflowExecutionState 458 ExecutionStateBlob *commonpb.DataBlob 459 StartVersion int64 460 LastWriteVersion int64 461 NextEventID int64 462 DBRecordVersion int64 463 464 ActivityInfos map[int64]*commonpb.DataBlob 465 TimerInfos map[string]*commonpb.DataBlob 466 ChildExecutionInfos map[int64]*commonpb.DataBlob 467 RequestCancelInfos map[int64]*commonpb.DataBlob 468 SignalInfos map[int64]*commonpb.DataBlob 469 SignalRequestedIDs map[string]struct{} 470 471 Tasks map[tasks.Category][]InternalHistoryTask 472 473 Condition int64 474 475 Checksum *commonpb.DataBlob 476 } 477 478 InternalGetCurrentExecutionResponse struct { 479 RunID string 480 ExecutionState *persistencespb.WorkflowExecutionState 481 } 482 483 // InternalHistoryNode represent a history node metadata 484 InternalHistoryNode struct { 485 // The first eventID becomes the nodeID to be appended 486 NodeID int64 487 // requested TransactionID for this write operation. For the same eventID, the node with larger TransactionID always wins 488 TransactionID int64 489 // TransactionID for events before these events. For events chaining 490 PrevTransactionID int64 491 // The events to be appended 492 Events *commonpb.DataBlob 493 } 494 495 // InternalAppendHistoryNodesRequest is used to append a batch of history nodes 496 InternalAppendHistoryNodesRequest struct { 497 // The raw branch token 498 BranchToken []byte 499 // True if it is the first append request to the branch 500 IsNewBranch bool 501 // The info for clean up data in background 502 Info string 503 // The branch to be appended 504 BranchInfo *persistencespb.HistoryBranch 505 // Serialized TreeInfo 506 TreeInfo *commonpb.DataBlob 507 // The history node 508 Node InternalHistoryNode 509 // Used in sharded data stores to identify which shard to use 510 ShardID int32 511 } 512 513 // InternalGetWorkflowExecutionResponse is the response to GetworkflowExecution for Persistence Interface 514 InternalGetWorkflowExecutionResponse struct { 515 State *InternalWorkflowMutableState 516 DBRecordVersion int64 517 } 518 519 // InternalListConcreteExecutionsResponse is the response to ListConcreteExecutions for Persistence Interface 520 InternalListConcreteExecutionsResponse struct { 521 States []*InternalWorkflowMutableState 522 NextPageToken []byte 523 } 524 525 InternalGetHistoryTaskResponse struct { 526 InternalHistoryTask 527 } 528 529 InternalGetHistoryTasksResponse struct { 530 Tasks []InternalHistoryTask 531 NextPageToken []byte 532 } 533 534 InternalGetReplicationTasksFromDLQResponse = InternalGetHistoryTasksResponse 535 536 // InternalForkHistoryBranchRequest is used to fork a history branch 537 InternalForkHistoryBranchRequest struct { 538 // The base branch token 539 ForkBranchToken []byte 540 // The base branch to fork from 541 ForkBranchInfo *persistencespb.HistoryBranch 542 // Serialized TreeInfo 543 TreeInfo *commonpb.DataBlob 544 // The nodeID to fork from, the new branch will start from ( inclusive ), the base branch will stop at(exclusive) 545 ForkNodeID int64 546 // branchID of the new branch 547 NewBranchID string 548 // the info for clean up data in background 549 Info string 550 // Used in sharded data stores to identify which shard to use 551 ShardID int32 552 } 553 554 // InternalDeleteHistoryNodesRequest is used to remove a history node 555 InternalDeleteHistoryNodesRequest struct { 556 // The raw branch token 557 BranchToken []byte 558 // Used in sharded data stores to identify which shard to use 559 ShardID int32 560 // The branch to be appended 561 BranchInfo *persistencespb.HistoryBranch 562 // node ID of the history node 563 NodeID int64 564 // transaction ID of the history node 565 TransactionID int64 566 } 567 568 // InternalDeleteHistoryBranchRequest is used to remove a history branch 569 InternalDeleteHistoryBranchRequest struct { 570 // The raw branch token 571 BranchToken []byte 572 // The branch 573 BranchInfo *persistencespb.HistoryBranch 574 // Used in sharded data stores to identify which shard to use 575 ShardID int32 576 // branch ranges is used to delete range of history nodes from target branch and it ancestors. 577 BranchRanges []InternalDeleteHistoryBranchRange 578 } 579 580 // InternalDeleteHistoryBranchRange is used to delete a range of history nodes of a branch 581 InternalDeleteHistoryBranchRange struct { 582 BranchId string 583 BeginNodeId int64 // delete nodes with ID >= BeginNodeId 584 } 585 586 // InternalReadHistoryBranchRequest is used to read a history branch 587 InternalReadHistoryBranchRequest struct { 588 // The raw branch token 589 BranchToken []byte 590 // The branch range to be read 591 BranchID string 592 // Get the history nodes from MinNodeID. Inclusive. 593 MinNodeID int64 594 // Get the history nodes upto MaxNodeID. Exclusive. 595 MaxNodeID int64 596 // passing thru for pagination 597 PageSize int 598 // Pagination token 599 NextPageToken []byte 600 // Used in sharded data stores to identify which shard to use 601 ShardID int32 602 // whether to only return metadata, excluding node content 603 MetadataOnly bool 604 // whether we iterate in reverse order 605 ReverseOrder bool 606 } 607 608 // InternalCompleteForkBranchRequest is used to update some tree/branch meta data for forking 609 InternalCompleteForkBranchRequest struct { 610 // branch to be updated 611 BranchInfo persistencespb.HistoryBranch 612 // whether fork is successful 613 Success bool 614 // Used in sharded data stores to identify which shard to use 615 ShardID int32 616 } 617 618 // InternalReadHistoryBranchResponse is the response to ReadHistoryBranchRequest 619 InternalReadHistoryBranchResponse struct { 620 // History nodes 621 Nodes []InternalHistoryNode 622 // Pagination token 623 NextPageToken []byte 624 } 625 626 // InternalGetAllHistoryTreeBranchesResponse is response to GetAllHistoryTreeBranches 627 // Only used by persistence layer 628 InternalGetAllHistoryTreeBranchesResponse struct { 629 // pagination token 630 NextPageToken []byte 631 // all branches of all trees 632 Branches []InternalHistoryBranchDetail 633 } 634 635 // InternalHistoryBranchDetail used by InternalGetAllHistoryTreeBranchesResponse 636 InternalHistoryBranchDetail struct { 637 TreeID string 638 BranchID string 639 Encoding string 640 Data []byte // HistoryTreeInfo blob 641 } 642 643 // InternalGetHistoryTreeResponse is response to GetHistoryTree 644 // Only used by persistence layer 645 InternalGetHistoryTreeResponse struct { 646 // TreeInfos 647 TreeInfos []*commonpb.DataBlob 648 } 649 650 // InternalCreateNamespaceRequest is used to create the namespace 651 InternalCreateNamespaceRequest struct { 652 ID string 653 Name string 654 Namespace *commonpb.DataBlob 655 IsGlobal bool 656 } 657 658 // InternalGetNamespaceResponse is the response for GetNamespace 659 InternalGetNamespaceResponse struct { 660 Namespace *commonpb.DataBlob 661 IsGlobal bool 662 NotificationVersion int64 663 } 664 665 // InternalUpdateNamespaceRequest is used to update namespace 666 InternalUpdateNamespaceRequest struct { 667 Id string 668 Name string 669 Namespace *commonpb.DataBlob 670 NotificationVersion int64 671 IsGlobal bool 672 } 673 674 InternalRenameNamespaceRequest struct { 675 *InternalUpdateNamespaceRequest 676 PreviousName string 677 } 678 679 InternalListNamespacesRequest struct { 680 PageSize int 681 NextPageToken []byte 682 } 683 684 // InternalListNamespacesResponse is the response for GetNamespace 685 InternalListNamespacesResponse struct { 686 Namespaces []*InternalGetNamespaceResponse 687 NextPageToken []byte 688 } 689 690 // InternalListClusterMetadataRequest is the request for ListClusterMetadata 691 InternalListClusterMetadataRequest struct { 692 PageSize int 693 NextPageToken []byte 694 } 695 696 // InternalListClusterMetadataResponse is the response for ListClusterMetadata 697 InternalListClusterMetadataResponse struct { 698 ClusterMetadata []*InternalGetClusterMetadataResponse 699 NextPageToken []byte 700 } 701 702 // InternalGetClusterMetadataRequest is the request for GetClusterMetadata 703 InternalGetClusterMetadataRequest struct { 704 ClusterName string 705 } 706 707 // InternalGetClusterMetadataResponse is the response for GetClusterMetadata 708 InternalGetClusterMetadataResponse struct { 709 // Serialized MutableCusterMetadata. 710 ClusterMetadata *commonpb.DataBlob 711 Version int64 712 } 713 714 // InternalSaveClusterMetadataRequest is the request for SaveClusterMetadata 715 InternalSaveClusterMetadataRequest struct { 716 ClusterName string 717 // Serialized MutableCusterMetadata. 718 ClusterMetadata *commonpb.DataBlob 719 Version int64 720 } 721 722 // InternalDeleteClusterMetadataRequest is the request for DeleteClusterMetadata 723 InternalDeleteClusterMetadataRequest struct { 724 ClusterName string 725 } 726 727 // InternalUpsertClusterMembershipRequest is the request to UpsertClusterMembership 728 InternalUpsertClusterMembershipRequest struct { 729 ClusterMember 730 RecordExpiry time.Time 731 } 732 733 // QueueV2 is an interface for a generic FIFO queue. It should eventually replace the Queue interface. Why do we 734 // need this migration? The main problem is very simple. The `queue_metadata` table in Cassandra has a primary key 735 // of (queue_type). This means that we can only have one queue of each type. This is a problem because we want to 736 // have multiple queues of the same type, but with different names. For example, we want to have a DLQ for 737 // replication tasks from one cluster to another, and cluster names are dynamic, so we can't create separate static 738 // queue types for each cluster. The solution is to add a queue_name column to the table, and make the primary key 739 // (queue_type, queue_name). This allows us to have multiple queues of the same type, but with different names. 740 // Since the new table (which is called `queues` in Cassandra), supports dynamic names, the interface built around 741 // it should also support dynamic names. This is why we need a new interface. There are other types built on top of 742 // this up the stack, like HistoryTaskQueueManager, for which the same principle of needing a new type because we 743 // now support dynamic names applies. 744 QueueV2 interface { 745 // EnqueueMessage adds a message to the back of the queue. 746 EnqueueMessage( 747 ctx context.Context, 748 request *InternalEnqueueMessageRequest, 749 ) (*InternalEnqueueMessageResponse, error) 750 // ReadMessages returns messages in order of increasing message ID. 751 ReadMessages( 752 ctx context.Context, 753 request *InternalReadMessagesRequest, 754 ) (*InternalReadMessagesResponse, error) 755 // CreateQueue creates a new queue. An error will be returned if the queue already exists. In addition, an error 756 // will be returned if you attempt to operate on a queue with something like EnqueueMessage or ReadMessages 757 // before the queue is created. 758 CreateQueue( 759 ctx context.Context, 760 request *InternalCreateQueueRequest, 761 ) (*InternalCreateQueueResponse, error) 762 RangeDeleteMessages( 763 ctx context.Context, 764 request *InternalRangeDeleteMessagesRequest, 765 ) (*InternalRangeDeleteMessagesResponse, error) 766 ListQueues( 767 ctx context.Context, 768 request *InternalListQueuesRequest, 769 ) (*InternalListQueuesResponse, error) 770 } 771 772 QueueV2Type int 773 774 MessageMetadata struct { 775 ID int64 776 } 777 778 QueueV2Message struct { 779 MetaData MessageMetadata 780 Data *commonpb.DataBlob 781 } 782 783 InternalEnqueueMessageRequest struct { 784 QueueType QueueV2Type 785 QueueName string 786 Blob *commonpb.DataBlob 787 } 788 789 InternalEnqueueMessageResponse struct { 790 Metadata MessageMetadata 791 } 792 793 InternalReadMessagesRequest struct { 794 QueueType QueueV2Type 795 QueueName string 796 PageSize int 797 NextPageToken []byte 798 } 799 800 InternalReadMessagesResponse struct { 801 Messages []QueueV2Message 802 NextPageToken []byte 803 } 804 805 InternalCreateQueueRequest struct { 806 QueueType QueueV2Type 807 QueueName string 808 } 809 810 InternalCreateQueueResponse struct { 811 // empty 812 } 813 814 // InternalRangeDeleteMessagesRequest deletes all messages with ID <= given messageID 815 InternalRangeDeleteMessagesRequest struct { 816 QueueType QueueV2Type 817 QueueName string 818 InclusiveMaxMessageMetadata MessageMetadata 819 } 820 821 InternalRangeDeleteMessagesResponse struct { 822 MessagesDeleted int64 823 } 824 825 InternalListQueuesRequest struct { 826 QueueType QueueV2Type 827 PageSize int 828 NextPageToken []byte 829 } 830 831 QueueInfo struct { 832 QueueName string 833 MessageCount int64 834 } 835 836 InternalListQueuesResponse struct { 837 Queues []QueueInfo 838 NextPageToken []byte 839 } 840 )