Files
tasks/common/persistence/sql/sqlplugin/mysql/queue_v2.go
T
Alex ShtinandGitHub 8e8f1b0f7c Remove license header from every file (#7689)
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.

## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
2025-05-01 18:50:21 -07:00

130 lines
4.9 KiB
Go

package mysql
import (
"context"
"database/sql"
"go.temporal.io/server/common/persistence/sql/sqlplugin"
)
const (
templateEnqueueMessageQueryV2 = `INSERT INTO queue_messages (queue_type, queue_name, queue_partition, message_id, message_payload, message_encoding) VALUES(:queue_type, :queue_name, :queue_partition, :message_id, :message_payload, :message_encoding)`
templateGetMessagesQueryV2 = `SELECT message_id, message_payload, message_encoding FROM queue_messages WHERE queue_type = ? and queue_name = ? and queue_partition = ? and message_id >= ? ORDER BY message_id ASC LIMIT ?`
templateRangeDeleteMessagesQueryV2 = `DELETE FROM queue_messages WHERE queue_type = ? and queue_name = ? and queue_partition = ? and message_id >= ? and message_id <= ?`
templateGetLastMessageIDQueryV2 = `SELECT max(message_id) FROM queue_messages WHERE queue_type=? and queue_name=? and queue_partition=? and message_id >= (SELECT message_id FROM queue_messages WHERE queue_type=? and queue_name=? and queue_partition=? ORDER BY message_id DESC LIMIT 1) FOR UPDATE`
templateCreateQueueMetadataQueryV2 = `INSERT INTO queues (queue_type, queue_name, metadata_payload, metadata_encoding) VALUES(:queue_type, :queue_name, :metadata_payload, :metadata_encoding)`
templateUpdateQueueMetadataQueryV2 = `UPDATE queues SET metadata_payload = :metadata_payload, metadata_encoding = :metadata_encoding WHERE queue_type = :queue_type and queue_name = :queue_name`
templateGetQueueMetadataQueryV2 = `SELECT metadata_payload, metadata_encoding from queues WHERE queue_type=? and queue_name=?`
templateGetQueueMetadataQueryV2ForUpdate = `SELECT metadata_payload, metadata_encoding from queues WHERE queue_type=? and queue_name=? FOR UPDATE`
templateGetNameFromQueueMetadataV2 = `SELECT queue_type, queue_name, metadata_payload, metadata_encoding from queues WHERE queue_type=? LIMIT ? OFFSET ?`
)
func (mdb *db) InsertIntoQueueV2Metadata(ctx context.Context, row *sqlplugin.QueueV2MetadataRow) (sql.Result, error) {
return mdb.NamedExecContext(ctx,
templateCreateQueueMetadataQueryV2,
row,
)
}
func (mdb *db) UpdateQueueV2Metadata(ctx context.Context, row *sqlplugin.QueueV2MetadataRow) (sql.Result, error) {
return mdb.NamedExecContext(ctx,
templateUpdateQueueMetadataQueryV2,
row,
)
}
func (mdb *db) SelectFromQueueV2Metadata(ctx context.Context, filter sqlplugin.QueueV2MetadataFilter) (*sqlplugin.QueueV2MetadataRow, error) {
var row sqlplugin.QueueV2MetadataRow
err := mdb.GetContext(ctx,
&row,
templateGetQueueMetadataQueryV2,
filter.QueueType,
filter.QueueName,
)
if err != nil {
return nil, err
}
return &row, nil
}
func (mdb *db) SelectFromQueueV2MetadataForUpdate(ctx context.Context, filter sqlplugin.QueueV2MetadataFilter) (*sqlplugin.QueueV2MetadataRow, error) {
var row sqlplugin.QueueV2MetadataRow
err := mdb.GetContext(ctx,
&row,
templateGetQueueMetadataQueryV2ForUpdate,
filter.QueueType,
filter.QueueName,
)
if err != nil {
return nil, err
}
return &row, nil
}
func (mdb *db) SelectNameFromQueueV2Metadata(ctx context.Context, filter sqlplugin.QueueV2MetadataTypeFilter) ([]sqlplugin.QueueV2MetadataRow, error) {
var rows []sqlplugin.QueueV2MetadataRow
err := mdb.SelectContext(ctx,
&rows,
templateGetNameFromQueueMetadataV2,
filter.QueueType,
filter.PageSize,
filter.PageOffset,
)
if err != nil {
return nil, err
}
return rows, nil
}
func (mdb *db) InsertIntoQueueV2Messages(ctx context.Context, row []sqlplugin.QueueV2MessageRow) (sql.Result, error) {
return mdb.NamedExecContext(ctx,
templateEnqueueMessageQueryV2,
row,
)
}
func (mdb *db) RangeSelectFromQueueV2Messages(ctx context.Context, filter sqlplugin.QueueV2MessagesFilter) ([]sqlplugin.QueueV2MessageRow, error) {
var rows []sqlplugin.QueueV2MessageRow
err := mdb.SelectContext(ctx,
&rows,
templateGetMessagesQueryV2,
filter.QueueType,
filter.QueueName,
filter.Partition,
filter.MinMessageID,
filter.PageSize,
)
return rows, err
}
func (mdb *db) RangeDeleteFromQueueV2Messages(ctx context.Context, filter sqlplugin.QueueV2MessagesFilter) (sql.Result, error) {
return mdb.ExecContext(ctx,
templateRangeDeleteMessagesQueryV2,
filter.QueueType,
filter.QueueName,
filter.Partition,
filter.MinMessageID,
filter.MaxMessageID,
)
}
func (mdb *db) GetLastEnqueuedMessageIDForUpdateV2(ctx context.Context, filter sqlplugin.QueueV2Filter) (int64, error) {
var lastMessageID *int64
err := mdb.GetContext(ctx,
&lastMessageID,
templateGetLastMessageIDQueryV2,
filter.QueueType,
filter.QueueName,
filter.Partition,
filter.QueueType,
filter.QueueName,
filter.Partition,
)
if lastMessageID == nil {
// The layer of code above us expects ErrNoRows when the queue is empty. MAX() yields
// null when the queue is empty, so we need to turn that into the correct error.
return 0, sql.ErrNoRows
}
return *lastMessageID, err
}