go.temporal.io/server@v1.23.0/common/persistence/sql/sqlplugin/mysql/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 mysql 26 27 import ( 28 "context" 29 "database/sql" 30 31 "go.temporal.io/server/common/persistence/sql/sqlplugin" 32 ) 33 34 const ( 35 executionsColumns = `shard_id, namespace_id, workflow_id, run_id, next_event_id, last_write_version, data, data_encoding, state, state_encoding, db_record_version` 36 37 createExecutionQuery = `INSERT INTO executions(` + executionsColumns + `) 38 VALUES(:shard_id, :namespace_id, :workflow_id, :run_id, :next_event_id, :last_write_version, :data, :data_encoding, :state, :state_encoding, :db_record_version)` 39 40 updateExecutionQuery = `UPDATE executions SET 41 db_record_version = :db_record_version, next_event_id = :next_event_id, last_write_version = :last_write_version, data = :data, data_encoding = :data_encoding, state = :state, state_encoding = :state_encoding 42 WHERE shard_id = :shard_id AND namespace_id = :namespace_id AND workflow_id = :workflow_id AND run_id = :run_id` 43 44 getExecutionQuery = `SELECT ` + executionsColumns + ` FROM executions 45 WHERE shard_id = ? AND namespace_id = ? AND workflow_id = ? AND run_id = ?` 46 47 deleteExecutionQuery = `DELETE FROM executions 48 WHERE shard_id = ? AND namespace_id = ? AND workflow_id = ? AND run_id = ?` 49 50 lockExecutionQueryBase = `SELECT db_record_version, next_event_id FROM executions 51 WHERE shard_id = ? AND namespace_id = ? AND workflow_id = ? AND run_id = ?` 52 53 writeLockExecutionQuery = lockExecutionQueryBase + ` FOR UPDATE` 54 readLockExecutionQuery = lockExecutionQueryBase + ` LOCK IN SHARE MODE` 55 56 createCurrentExecutionQuery = `INSERT INTO current_executions 57 (shard_id, namespace_id, workflow_id, run_id, create_request_id, state, status, last_write_version) VALUES 58 (:shard_id, :namespace_id, :workflow_id, :run_id, :create_request_id, :state, :status, :last_write_version)` 59 60 deleteCurrentExecutionQuery = "DELETE FROM current_executions WHERE shard_id=? AND namespace_id=? AND workflow_id=? AND run_id=?" 61 62 getCurrentExecutionQuery = `SELECT 63 shard_id, namespace_id, workflow_id, run_id, create_request_id, state, status, last_write_version 64 FROM current_executions WHERE shard_id = ? AND namespace_id = ? AND workflow_id = ?` 65 66 lockCurrentExecutionJoinExecutionsQuery = `SELECT 67 ce.shard_id, ce.namespace_id, ce.workflow_id, ce.run_id, ce.create_request_id, ce.state, ce.status, e.last_write_version 68 FROM current_executions ce 69 INNER JOIN executions e ON e.shard_id = ce.shard_id AND e.namespace_id = ce.namespace_id AND e.workflow_id = ce.workflow_id AND e.run_id = ce.run_id 70 WHERE ce.shard_id = ? AND ce.namespace_id = ? AND ce.workflow_id = ? FOR UPDATE` 71 72 lockCurrentExecutionQuery = getCurrentExecutionQuery + ` FOR UPDATE` 73 74 updateCurrentExecutionsQuery = `UPDATE current_executions SET 75 run_id = :run_id, 76 create_request_id = :create_request_id, 77 state = :state, 78 status = :status, 79 last_write_version = :last_write_version 80 WHERE 81 shard_id = :shard_id AND 82 namespace_id = :namespace_id AND 83 workflow_id = :workflow_id 84 ` 85 86 createHistoryImmediateTasksQuery = `INSERT INTO history_immediate_tasks(shard_id, category_id, task_id, data, data_encoding) 87 VALUES(:shard_id, :category_id, :task_id, :data, :data_encoding)` 88 89 getHistoryImmediateTasksQuery = `SELECT task_id, data, data_encoding 90 FROM history_immediate_tasks WHERE shard_id = ? AND category_id = ? AND task_id >= ? AND task_id < ? ORDER BY task_id LIMIT ?` 91 92 deleteHistoryImmediateTaskQuery = `DELETE FROM history_immediate_tasks WHERE shard_id = ? AND category_id = ? AND task_id = ?` 93 rangeDeleteHistoryImmediateTasksQuery = `DELETE FROM history_immediate_tasks WHERE shard_id = ? AND category_id = ? AND task_id >= ? AND task_id < ?` 94 95 createHistoryScheduledTasksQuery = `INSERT INTO history_scheduled_tasks (shard_id, category_id, visibility_timestamp, task_id, data, data_encoding) 96 VALUES (:shard_id, :category_id, :visibility_timestamp, :task_id, :data, :data_encoding)` 97 98 getHistoryScheduledTasksQuery = `SELECT visibility_timestamp, task_id, data, data_encoding FROM history_scheduled_tasks 99 WHERE shard_id = ? 100 AND category_id = ? 101 AND ((visibility_timestamp >= ? AND task_id >= ?) OR visibility_timestamp > ?) 102 AND visibility_timestamp < ? 103 ORDER BY visibility_timestamp,task_id LIMIT ?` 104 105 deleteHistoryScheduledTaskQuery = `DELETE FROM history_scheduled_tasks WHERE shard_id = ? AND category_id = ? AND visibility_timestamp = ? AND task_id = ?` 106 rangeDeleteHistoryScheduledTasksQuery = `DELETE FROM history_scheduled_tasks WHERE shard_id = ? AND category_id = ? AND visibility_timestamp >= ? AND visibility_timestamp < ?` 107 108 createTransferTasksQuery = `INSERT INTO transfer_tasks(shard_id, task_id, data, data_encoding) 109 VALUES(:shard_id, :task_id, :data, :data_encoding)` 110 111 getTransferTasksQuery = `SELECT task_id, data, data_encoding 112 FROM transfer_tasks WHERE shard_id = ? AND task_id >= ? AND task_id < ? ORDER BY task_id LIMIT ?` 113 114 deleteTransferTaskQuery = `DELETE FROM transfer_tasks WHERE shard_id = ? AND task_id = ?` 115 rangeDeleteTransferTaskQuery = `DELETE FROM transfer_tasks WHERE shard_id = ? AND task_id >= ? AND task_id < ?` 116 117 createTimerTasksQuery = `INSERT INTO timer_tasks (shard_id, visibility_timestamp, task_id, data, data_encoding) 118 VALUES (:shard_id, :visibility_timestamp, :task_id, :data, :data_encoding)` 119 120 getTimerTasksQuery = `SELECT visibility_timestamp, task_id, data, data_encoding FROM timer_tasks 121 WHERE shard_id = ? 122 AND ((visibility_timestamp >= ? AND task_id >= ?) OR visibility_timestamp > ?) 123 AND visibility_timestamp < ? 124 ORDER BY visibility_timestamp,task_id LIMIT ?` 125 126 deleteTimerTaskQuery = `DELETE FROM timer_tasks WHERE shard_id = ? AND visibility_timestamp = ? AND task_id = ?` 127 rangeDeleteTimerTaskQuery = `DELETE FROM timer_tasks WHERE shard_id = ? AND visibility_timestamp >= ? AND visibility_timestamp < ?` 128 129 createReplicationTasksQuery = `INSERT INTO replication_tasks (shard_id, task_id, data, data_encoding) 130 VALUES(:shard_id, :task_id, :data, :data_encoding)` 131 132 getReplicationTasksQuery = `SELECT task_id, data, data_encoding FROM replication_tasks WHERE 133 shard_id = ? AND task_id >= ? AND task_id < ? ORDER BY task_id LIMIT ?` 134 135 deleteReplicationTaskQuery = `DELETE FROM replication_tasks WHERE shard_id = ? AND task_id = ?` 136 rangeDeleteReplicationTaskQuery = `DELETE FROM replication_tasks WHERE shard_id = ? AND task_id >= ? AND task_id < ?` 137 138 getReplicationTasksDLQQuery = `SELECT task_id, data, data_encoding FROM replication_tasks_dlq WHERE 139 source_cluster_name = ? AND 140 shard_id = ? AND 141 task_id >= ? AND 142 task_id < ? 143 ORDER BY task_id LIMIT ?` 144 145 createVisibilityTasksQuery = `INSERT INTO visibility_tasks(shard_id, task_id, data, data_encoding) 146 VALUES(:shard_id, :task_id, :data, :data_encoding)` 147 148 getVisibilityTasksQuery = `SELECT task_id, data, data_encoding 149 FROM visibility_tasks WHERE shard_id = ? AND task_id >= ? AND task_id < ? ORDER BY task_id LIMIT ?` 150 151 deleteVisibilityTaskQuery = `DELETE FROM visibility_tasks WHERE shard_id = ? AND task_id = ?` 152 rangeDeleteVisibilityTaskQuery = `DELETE FROM visibility_tasks WHERE shard_id = ? AND task_id >= ? AND task_id < ?` 153 154 bufferedEventsColumns = `shard_id, namespace_id, workflow_id, run_id, data, data_encoding` 155 createBufferedEventsQuery = `INSERT INTO buffered_events(` + bufferedEventsColumns + `) 156 VALUES (:shard_id, :namespace_id, :workflow_id, :run_id, :data, :data_encoding)` 157 158 deleteBufferedEventsQuery = `DELETE FROM buffered_events WHERE shard_id=? AND namespace_id=? AND workflow_id=? AND run_id=?` 159 getBufferedEventsQuery = `SELECT data, data_encoding FROM buffered_events WHERE 160 shard_id=? AND namespace_id=? AND workflow_id=? AND run_id=?` 161 162 insertReplicationTaskDLQQuery = ` 163 INSERT INTO replication_tasks_dlq 164 (source_cluster_name, 165 shard_id, 166 task_id, 167 data, 168 data_encoding) 169 VALUES (:source_cluster_name, 170 :shard_id, 171 :task_id, 172 :data, 173 :data_encoding) 174 ` 175 deleteReplicationTaskFromDLQQuery = ` 176 DELETE FROM replication_tasks_dlq 177 WHERE source_cluster_name = ? 178 AND shard_id = ? 179 AND task_id = ?` 180 181 rangeDeleteReplicationTaskFromDLQQuery = ` 182 DELETE FROM replication_tasks_dlq 183 WHERE source_cluster_name = ? 184 AND shard_id = ? 185 AND task_id >= ? 186 AND task_id < ?` 187 ) 188 189 // InsertIntoExecutions inserts a row into executions table 190 func (mdb *db) InsertIntoExecutions( 191 ctx context.Context, 192 row *sqlplugin.ExecutionsRow, 193 ) (sql.Result, error) { 194 return mdb.conn.NamedExecContext(ctx, 195 createExecutionQuery, 196 row, 197 ) 198 } 199 200 // UpdateExecutions updates a single row in executions table 201 func (mdb *db) UpdateExecutions( 202 ctx context.Context, 203 row *sqlplugin.ExecutionsRow, 204 ) (sql.Result, error) { 205 return mdb.conn.NamedExecContext(ctx, 206 updateExecutionQuery, 207 row, 208 ) 209 } 210 211 // SelectFromExecutions reads a single row from executions table 212 func (mdb *db) SelectFromExecutions( 213 ctx context.Context, 214 filter sqlplugin.ExecutionsFilter, 215 ) (*sqlplugin.ExecutionsRow, error) { 216 var row sqlplugin.ExecutionsRow 217 err := mdb.conn.GetContext(ctx, 218 &row, getExecutionQuery, 219 filter.ShardID, 220 filter.NamespaceID, 221 filter.WorkflowID, 222 filter.RunID, 223 ) 224 if err != nil { 225 return nil, err 226 } 227 return &row, err 228 } 229 230 // DeleteFromExecutions deletes a single row from executions table 231 func (mdb *db) DeleteFromExecutions( 232 ctx context.Context, 233 filter sqlplugin.ExecutionsFilter, 234 ) (sql.Result, error) { 235 return mdb.conn.ExecContext(ctx, 236 deleteExecutionQuery, 237 filter.ShardID, 238 filter.NamespaceID, 239 filter.WorkflowID, 240 filter.RunID, 241 ) 242 } 243 244 // ReadLockExecutions acquires a write lock on a single row in executions table 245 func (mdb *db) ReadLockExecutions( 246 ctx context.Context, 247 filter sqlplugin.ExecutionsFilter, 248 ) (int64, int64, error) { 249 var executionVersion sqlplugin.ExecutionVersion 250 err := mdb.conn.GetContext(ctx, 251 &executionVersion, 252 readLockExecutionQuery, 253 filter.ShardID, 254 filter.NamespaceID, 255 filter.WorkflowID, 256 filter.RunID, 257 ) 258 return executionVersion.DBRecordVersion, executionVersion.NextEventID, err 259 } 260 261 // WriteLockExecutions acquires a write lock on a single row in executions table 262 func (mdb *db) WriteLockExecutions( 263 ctx context.Context, 264 filter sqlplugin.ExecutionsFilter, 265 ) (int64, int64, error) { 266 var executionVersion sqlplugin.ExecutionVersion 267 err := mdb.conn.GetContext(ctx, 268 &executionVersion, 269 writeLockExecutionQuery, 270 filter.ShardID, 271 filter.NamespaceID, 272 filter.WorkflowID, 273 filter.RunID, 274 ) 275 return executionVersion.DBRecordVersion, executionVersion.NextEventID, err 276 } 277 278 // InsertIntoCurrentExecutions inserts a single row into current_executions table 279 func (mdb *db) InsertIntoCurrentExecutions( 280 ctx context.Context, 281 row *sqlplugin.CurrentExecutionsRow, 282 ) (sql.Result, error) { 283 return mdb.conn.NamedExecContext(ctx, 284 createCurrentExecutionQuery, 285 row, 286 ) 287 } 288 289 // UpdateCurrentExecutions updates a single row in current_executions table 290 func (mdb *db) UpdateCurrentExecutions( 291 ctx context.Context, 292 row *sqlplugin.CurrentExecutionsRow, 293 ) (sql.Result, error) { 294 return mdb.conn.NamedExecContext(ctx, 295 updateCurrentExecutionsQuery, 296 row, 297 ) 298 } 299 300 // SelectFromCurrentExecutions reads one or more rows from current_executions table 301 func (mdb *db) SelectFromCurrentExecutions( 302 ctx context.Context, 303 filter sqlplugin.CurrentExecutionsFilter, 304 ) (*sqlplugin.CurrentExecutionsRow, error) { 305 var row sqlplugin.CurrentExecutionsRow 306 err := mdb.conn.GetContext(ctx, 307 &row, 308 getCurrentExecutionQuery, 309 filter.ShardID, 310 filter.NamespaceID, 311 filter.WorkflowID, 312 ) 313 return &row, err 314 } 315 316 // DeleteFromCurrentExecutions deletes a single row in current_executions table 317 func (mdb *db) DeleteFromCurrentExecutions( 318 ctx context.Context, 319 filter sqlplugin.CurrentExecutionsFilter, 320 ) (sql.Result, error) { 321 return mdb.conn.ExecContext(ctx, 322 deleteCurrentExecutionQuery, 323 filter.ShardID, 324 filter.NamespaceID, 325 filter.WorkflowID, 326 filter.RunID, 327 ) 328 } 329 330 // LockCurrentExecutions acquires a write lock on a single row in current_executions table 331 func (mdb *db) LockCurrentExecutions( 332 ctx context.Context, 333 filter sqlplugin.CurrentExecutionsFilter, 334 ) (*sqlplugin.CurrentExecutionsRow, error) { 335 var row sqlplugin.CurrentExecutionsRow 336 err := mdb.conn.GetContext(ctx, 337 &row, 338 lockCurrentExecutionQuery, 339 filter.ShardID, 340 filter.NamespaceID, 341 filter.WorkflowID, 342 ) 343 return &row, err 344 } 345 346 // LockCurrentExecutionsJoinExecutions joins a row in current_executions with executions table and acquires a 347 // write lock on the result 348 func (mdb *db) LockCurrentExecutionsJoinExecutions( 349 ctx context.Context, 350 filter sqlplugin.CurrentExecutionsFilter, 351 ) ([]sqlplugin.CurrentExecutionsRow, error) { 352 var rows []sqlplugin.CurrentExecutionsRow 353 err := mdb.conn.SelectContext(ctx, 354 &rows, 355 lockCurrentExecutionJoinExecutionsQuery, 356 filter.ShardID, 357 filter.NamespaceID, 358 filter.WorkflowID, 359 ) 360 return rows, err 361 } 362 363 // InsertIntoHistoryImmediateTasks inserts one or more rows into history_immediate_tasks table 364 func (mdb *db) InsertIntoHistoryImmediateTasks( 365 ctx context.Context, 366 rows []sqlplugin.HistoryImmediateTasksRow, 367 ) (sql.Result, error) { 368 return mdb.conn.NamedExecContext(ctx, 369 createHistoryImmediateTasksQuery, 370 rows, 371 ) 372 } 373 374 // RangeSelectFromHistoryImmediateTasks reads one or more rows from transfer_tasks table 375 func (mdb *db) RangeSelectFromHistoryImmediateTasks( 376 ctx context.Context, 377 filter sqlplugin.HistoryImmediateTasksRangeFilter, 378 ) ([]sqlplugin.HistoryImmediateTasksRow, error) { 379 var rows []sqlplugin.HistoryImmediateTasksRow 380 if err := mdb.conn.SelectContext(ctx, 381 &rows, 382 getHistoryImmediateTasksQuery, 383 filter.ShardID, 384 filter.CategoryID, 385 filter.InclusiveMinTaskID, 386 filter.ExclusiveMaxTaskID, 387 filter.PageSize, 388 ); err != nil { 389 return nil, err 390 } 391 return rows, nil 392 } 393 394 // DeleteFromHistoryImmediateTasks deletes one or more rows from transfer_tasks table 395 func (mdb *db) DeleteFromHistoryImmediateTasks( 396 ctx context.Context, 397 filter sqlplugin.HistoryImmediateTasksFilter, 398 ) (sql.Result, error) { 399 return mdb.conn.ExecContext(ctx, 400 deleteHistoryImmediateTaskQuery, 401 filter.ShardID, 402 filter.CategoryID, 403 filter.TaskID, 404 ) 405 } 406 407 // RangeDeleteFromHistoryImmediateTasks deletes one or more rows from transfer_tasks table 408 func (mdb *db) RangeDeleteFromHistoryImmediateTasks( 409 ctx context.Context, 410 filter sqlplugin.HistoryImmediateTasksRangeFilter, 411 ) (sql.Result, error) { 412 return mdb.conn.ExecContext(ctx, 413 rangeDeleteHistoryImmediateTasksQuery, 414 filter.ShardID, 415 filter.CategoryID, 416 filter.InclusiveMinTaskID, 417 filter.ExclusiveMaxTaskID, 418 ) 419 } 420 421 // InsertIntoHistoryScheduledTasks inserts one or more rows into timer_tasks table 422 func (mdb *db) InsertIntoHistoryScheduledTasks( 423 ctx context.Context, 424 rows []sqlplugin.HistoryScheduledTasksRow, 425 ) (sql.Result, error) { 426 for i := range rows { 427 rows[i].VisibilityTimestamp = mdb.converter.ToMySQLDateTime(rows[i].VisibilityTimestamp) 428 } 429 return mdb.conn.NamedExecContext( 430 ctx, 431 createHistoryScheduledTasksQuery, 432 rows, 433 ) 434 } 435 436 // RangeSelectFromHistoryScheduledTasks reads one or more rows from timer_tasks table 437 func (mdb *db) RangeSelectFromHistoryScheduledTasks( 438 ctx context.Context, 439 filter sqlplugin.HistoryScheduledTasksRangeFilter, 440 ) ([]sqlplugin.HistoryScheduledTasksRow, error) { 441 var rows []sqlplugin.HistoryScheduledTasksRow 442 filter.InclusiveMinVisibilityTimestamp = mdb.converter.ToMySQLDateTime(filter.InclusiveMinVisibilityTimestamp) 443 filter.ExclusiveMaxVisibilityTimestamp = mdb.converter.ToMySQLDateTime(filter.ExclusiveMaxVisibilityTimestamp) 444 if err := mdb.conn.SelectContext(ctx, 445 &rows, 446 getHistoryScheduledTasksQuery, 447 filter.ShardID, 448 filter.CategoryID, 449 filter.InclusiveMinVisibilityTimestamp, 450 filter.InclusiveMinTaskID, 451 filter.InclusiveMinVisibilityTimestamp, 452 filter.ExclusiveMaxVisibilityTimestamp, 453 filter.PageSize, 454 ); err != nil { 455 return nil, err 456 } 457 for i := range rows { 458 rows[i].VisibilityTimestamp = mdb.converter.FromMySQLDateTime(rows[i].VisibilityTimestamp) 459 } 460 return rows, nil 461 } 462 463 // DeleteFromHistoryScheduledTasks deletes one or more rows from timer_tasks table 464 func (mdb *db) DeleteFromHistoryScheduledTasks( 465 ctx context.Context, 466 filter sqlplugin.HistoryScheduledTasksFilter, 467 ) (sql.Result, error) { 468 filter.VisibilityTimestamp = mdb.converter.ToMySQLDateTime(filter.VisibilityTimestamp) 469 return mdb.conn.ExecContext(ctx, 470 deleteHistoryScheduledTaskQuery, 471 filter.ShardID, 472 filter.CategoryID, 473 filter.VisibilityTimestamp, 474 filter.TaskID, 475 ) 476 } 477 478 // RangeDeleteFromHistoryScheduledTasks deletes one or more rows from timer_tasks table 479 func (mdb *db) RangeDeleteFromHistoryScheduledTasks( 480 ctx context.Context, 481 filter sqlplugin.HistoryScheduledTasksRangeFilter, 482 ) (sql.Result, error) { 483 filter.InclusiveMinVisibilityTimestamp = mdb.converter.ToMySQLDateTime(filter.InclusiveMinVisibilityTimestamp) 484 filter.ExclusiveMaxVisibilityTimestamp = mdb.converter.ToMySQLDateTime(filter.ExclusiveMaxVisibilityTimestamp) 485 return mdb.conn.ExecContext(ctx, 486 rangeDeleteHistoryScheduledTasksQuery, 487 filter.ShardID, 488 filter.CategoryID, 489 filter.InclusiveMinVisibilityTimestamp, 490 filter.ExclusiveMaxVisibilityTimestamp, 491 ) 492 } 493 494 // InsertIntoTransferTasks inserts one or more rows into transfer_tasks table 495 func (mdb *db) InsertIntoTransferTasks( 496 ctx context.Context, 497 rows []sqlplugin.TransferTasksRow, 498 ) (sql.Result, error) { 499 return mdb.conn.NamedExecContext(ctx, 500 createTransferTasksQuery, 501 rows, 502 ) 503 } 504 505 // RangeSelectFromTransferTasks reads one or more rows from transfer_tasks table 506 func (mdb *db) RangeSelectFromTransferTasks( 507 ctx context.Context, 508 filter sqlplugin.TransferTasksRangeFilter, 509 ) ([]sqlplugin.TransferTasksRow, error) { 510 var rows []sqlplugin.TransferTasksRow 511 if err := mdb.conn.SelectContext(ctx, 512 &rows, 513 getTransferTasksQuery, 514 filter.ShardID, 515 filter.InclusiveMinTaskID, 516 filter.ExclusiveMaxTaskID, 517 filter.PageSize, 518 ); err != nil { 519 return nil, err 520 } 521 return rows, nil 522 } 523 524 // DeleteFromTransferTasks deletes one or more rows from transfer_tasks table 525 func (mdb *db) DeleteFromTransferTasks( 526 ctx context.Context, 527 filter sqlplugin.TransferTasksFilter, 528 ) (sql.Result, error) { 529 return mdb.conn.ExecContext(ctx, 530 deleteTransferTaskQuery, 531 filter.ShardID, 532 filter.TaskID, 533 ) 534 } 535 536 // RangeDeleteFromTransferTasks deletes one or more rows from transfer_tasks table 537 func (mdb *db) RangeDeleteFromTransferTasks( 538 ctx context.Context, 539 filter sqlplugin.TransferTasksRangeFilter, 540 ) (sql.Result, error) { 541 return mdb.conn.ExecContext(ctx, 542 rangeDeleteTransferTaskQuery, 543 filter.ShardID, 544 filter.InclusiveMinTaskID, 545 filter.ExclusiveMaxTaskID, 546 ) 547 } 548 549 // InsertIntoTimerTasks inserts one or more rows into timer_tasks table 550 func (mdb *db) InsertIntoTimerTasks( 551 ctx context.Context, 552 rows []sqlplugin.TimerTasksRow, 553 ) (sql.Result, error) { 554 for i := range rows { 555 rows[i].VisibilityTimestamp = mdb.converter.ToMySQLDateTime(rows[i].VisibilityTimestamp) 556 } 557 return mdb.conn.NamedExecContext( 558 ctx, 559 createTimerTasksQuery, 560 rows, 561 ) 562 } 563 564 // RangeSelectFromTimerTasks reads one or more rows from timer_tasks table 565 func (mdb *db) RangeSelectFromTimerTasks( 566 ctx context.Context, 567 filter sqlplugin.TimerTasksRangeFilter, 568 ) ([]sqlplugin.TimerTasksRow, error) { 569 var rows []sqlplugin.TimerTasksRow 570 filter.InclusiveMinVisibilityTimestamp = mdb.converter.ToMySQLDateTime(filter.InclusiveMinVisibilityTimestamp) 571 filter.ExclusiveMaxVisibilityTimestamp = mdb.converter.ToMySQLDateTime(filter.ExclusiveMaxVisibilityTimestamp) 572 if err := mdb.conn.SelectContext(ctx, 573 &rows, 574 getTimerTasksQuery, 575 filter.ShardID, 576 filter.InclusiveMinVisibilityTimestamp, 577 filter.InclusiveMinTaskID, 578 filter.InclusiveMinVisibilityTimestamp, 579 filter.ExclusiveMaxVisibilityTimestamp, 580 filter.PageSize, 581 ); err != nil { 582 return nil, err 583 } 584 for i := range rows { 585 rows[i].VisibilityTimestamp = mdb.converter.FromMySQLDateTime(rows[i].VisibilityTimestamp) 586 } 587 return rows, nil 588 } 589 590 // DeleteFromTimerTasks deletes one or more rows from timer_tasks table 591 func (mdb *db) DeleteFromTimerTasks( 592 ctx context.Context, 593 filter sqlplugin.TimerTasksFilter, 594 ) (sql.Result, error) { 595 filter.VisibilityTimestamp = mdb.converter.ToMySQLDateTime(filter.VisibilityTimestamp) 596 return mdb.conn.ExecContext(ctx, 597 deleteTimerTaskQuery, 598 filter.ShardID, 599 filter.VisibilityTimestamp, 600 filter.TaskID, 601 ) 602 } 603 604 // RangeDeleteFromTimerTasks deletes one or more rows from timer_tasks table 605 func (mdb *db) RangeDeleteFromTimerTasks( 606 ctx context.Context, 607 filter sqlplugin.TimerTasksRangeFilter, 608 ) (sql.Result, error) { 609 filter.InclusiveMinVisibilityTimestamp = mdb.converter.ToMySQLDateTime(filter.InclusiveMinVisibilityTimestamp) 610 filter.ExclusiveMaxVisibilityTimestamp = mdb.converter.ToMySQLDateTime(filter.ExclusiveMaxVisibilityTimestamp) 611 return mdb.conn.ExecContext(ctx, 612 rangeDeleteTimerTaskQuery, 613 filter.ShardID, 614 filter.InclusiveMinVisibilityTimestamp, 615 filter.ExclusiveMaxVisibilityTimestamp, 616 ) 617 } 618 619 // InsertIntoBufferedEvents inserts one or more rows into buffered_events table 620 func (mdb *db) InsertIntoBufferedEvents( 621 ctx context.Context, 622 rows []sqlplugin.BufferedEventsRow, 623 ) (sql.Result, error) { 624 return mdb.conn.NamedExecContext(ctx, 625 createBufferedEventsQuery, 626 rows, 627 ) 628 } 629 630 // SelectFromBufferedEvents reads one or more rows from buffered_events table 631 func (mdb *db) SelectFromBufferedEvents( 632 ctx context.Context, 633 filter sqlplugin.BufferedEventsFilter, 634 ) ([]sqlplugin.BufferedEventsRow, error) { 635 var rows []sqlplugin.BufferedEventsRow 636 if err := mdb.conn.SelectContext(ctx, 637 &rows, 638 getBufferedEventsQuery, 639 filter.ShardID, 640 filter.NamespaceID, 641 filter.WorkflowID, 642 filter.RunID, 643 ); err != nil { 644 return nil, err 645 } 646 for i := 0; i < len(rows); i++ { 647 rows[i].NamespaceID = filter.NamespaceID 648 rows[i].WorkflowID = filter.WorkflowID 649 rows[i].RunID = filter.RunID 650 rows[i].ShardID = filter.ShardID 651 } 652 return rows, nil 653 } 654 655 // DeleteFromBufferedEvents deletes one or more rows from buffered_events table 656 func (mdb *db) DeleteFromBufferedEvents( 657 ctx context.Context, 658 filter sqlplugin.BufferedEventsFilter, 659 ) (sql.Result, error) { 660 return mdb.conn.ExecContext(ctx, 661 deleteBufferedEventsQuery, 662 filter.ShardID, 663 filter.NamespaceID, 664 filter.WorkflowID, 665 filter.RunID, 666 ) 667 } 668 669 // InsertIntoReplicationTasks inserts one or more rows into replication_tasks table 670 func (mdb *db) InsertIntoReplicationTasks( 671 ctx context.Context, 672 rows []sqlplugin.ReplicationTasksRow, 673 ) (sql.Result, error) { 674 return mdb.conn.NamedExecContext(ctx, 675 createReplicationTasksQuery, 676 rows, 677 ) 678 } 679 680 // RangeSelectFromReplicationTasks reads one or more rows from replication_tasks table 681 func (mdb *db) RangeSelectFromReplicationTasks( 682 ctx context.Context, 683 filter sqlplugin.ReplicationTasksRangeFilter, 684 ) ([]sqlplugin.ReplicationTasksRow, error) { 685 var rows []sqlplugin.ReplicationTasksRow 686 err := mdb.conn.SelectContext(ctx, 687 &rows, 688 getReplicationTasksQuery, 689 filter.ShardID, 690 filter.InclusiveMinTaskID, 691 filter.ExclusiveMaxTaskID, 692 filter.PageSize, 693 ) 694 return rows, err 695 } 696 697 // DeleteFromReplicationTasks deletes one row from replication_tasks table 698 func (mdb *db) DeleteFromReplicationTasks( 699 ctx context.Context, 700 filter sqlplugin.ReplicationTasksFilter, 701 ) (sql.Result, error) { 702 return mdb.conn.ExecContext(ctx, 703 deleteReplicationTaskQuery, 704 filter.ShardID, 705 filter.TaskID, 706 ) 707 } 708 709 // RangeDeleteFromReplicationTasks deletes multi rows from replication_tasks table 710 func (mdb *db) RangeDeleteFromReplicationTasks( 711 ctx context.Context, 712 filter sqlplugin.ReplicationTasksRangeFilter, 713 ) (sql.Result, error) { 714 return mdb.conn.ExecContext(ctx, 715 rangeDeleteReplicationTaskQuery, 716 filter.ShardID, 717 filter.InclusiveMinTaskID, 718 filter.ExclusiveMaxTaskID, 719 ) 720 } 721 722 // InsertIntoReplicationDLQTasks inserts one or more rows into replication_tasks_dlq table 723 func (mdb *db) InsertIntoReplicationDLQTasks( 724 ctx context.Context, 725 rows []sqlplugin.ReplicationDLQTasksRow, 726 ) (sql.Result, error) { 727 return mdb.conn.NamedExecContext(ctx, 728 insertReplicationTaskDLQQuery, 729 rows, 730 ) 731 } 732 733 // RangeSelectFromReplicationDLQTasks reads one or more rows from replication_tasks_dlq table 734 func (mdb *db) RangeSelectFromReplicationDLQTasks( 735 ctx context.Context, 736 filter sqlplugin.ReplicationDLQTasksRangeFilter, 737 ) ([]sqlplugin.ReplicationDLQTasksRow, error) { 738 var rows []sqlplugin.ReplicationDLQTasksRow 739 err := mdb.conn.SelectContext(ctx, 740 &rows, getReplicationTasksDLQQuery, 741 filter.SourceClusterName, 742 filter.ShardID, 743 filter.InclusiveMinTaskID, 744 filter.ExclusiveMaxTaskID, 745 filter.PageSize, 746 ) 747 return rows, err 748 } 749 750 // DeleteFromReplicationDLQTasks deletes one row from replication_tasks_dlq table 751 func (mdb *db) DeleteFromReplicationDLQTasks( 752 ctx context.Context, 753 filter sqlplugin.ReplicationDLQTasksFilter, 754 ) (sql.Result, error) { 755 756 return mdb.conn.ExecContext(ctx, 757 deleteReplicationTaskFromDLQQuery, 758 filter.SourceClusterName, 759 filter.ShardID, 760 filter.TaskID, 761 ) 762 } 763 764 // RangeDeleteFromReplicationDLQTasks deletes one or more rows from replication_tasks_dlq table 765 func (mdb *db) RangeDeleteFromReplicationDLQTasks( 766 ctx context.Context, 767 filter sqlplugin.ReplicationDLQTasksRangeFilter, 768 ) (sql.Result, error) { 769 770 return mdb.conn.ExecContext(ctx, 771 rangeDeleteReplicationTaskFromDLQQuery, 772 filter.SourceClusterName, 773 filter.ShardID, 774 filter.InclusiveMinTaskID, 775 filter.ExclusiveMaxTaskID, 776 ) 777 } 778 779 // InsertIntoVisibilityTasks inserts one or more rows into visibility_tasks table 780 func (mdb *db) InsertIntoVisibilityTasks( 781 ctx context.Context, 782 rows []sqlplugin.VisibilityTasksRow, 783 ) (sql.Result, error) { 784 return mdb.conn.NamedExecContext(ctx, 785 createVisibilityTasksQuery, 786 rows, 787 ) 788 } 789 790 // RangeSelectFromVisibilityTasks reads one or more rows from visibility_tasks table 791 func (mdb *db) RangeSelectFromVisibilityTasks( 792 ctx context.Context, 793 filter sqlplugin.VisibilityTasksRangeFilter, 794 ) ([]sqlplugin.VisibilityTasksRow, error) { 795 var rows []sqlplugin.VisibilityTasksRow 796 if err := mdb.conn.SelectContext(ctx, 797 &rows, 798 getVisibilityTasksQuery, 799 filter.ShardID, 800 filter.InclusiveMinTaskID, 801 filter.ExclusiveMaxTaskID, 802 filter.PageSize, 803 ); err != nil { 804 return nil, err 805 } 806 return rows, nil 807 } 808 809 // DeleteFromVisibilityTasks deletes one or more rows from visibility_tasks table 810 func (mdb *db) DeleteFromVisibilityTasks( 811 ctx context.Context, 812 filter sqlplugin.VisibilityTasksFilter, 813 ) (sql.Result, error) { 814 return mdb.conn.ExecContext(ctx, 815 deleteVisibilityTaskQuery, 816 filter.ShardID, 817 filter.TaskID, 818 ) 819 } 820 821 // RangeDeleteFromVisibilityTasks deletes one or more rows from visibility_tasks table 822 func (mdb *db) RangeDeleteFromVisibilityTasks( 823 ctx context.Context, 824 filter sqlplugin.VisibilityTasksRangeFilter, 825 ) (sql.Result, error) { 826 return mdb.conn.ExecContext(ctx, 827 rangeDeleteVisibilityTaskQuery, 828 filter.ShardID, 829 filter.InclusiveMinTaskID, 830 filter.ExclusiveMaxTaskID, 831 ) 832 }