mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## 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`.
98 lines
2.1 KiB
Go
98 lines
2.1 KiB
Go
package postgresql
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
"go.temporal.io/server/common/persistence/sql/sqlplugin"
|
|
)
|
|
|
|
const (
|
|
createShardQry = `INSERT INTO
|
|
shards (shard_id, range_id, data, data_encoding) VALUES ($1, $2, $3, $4)`
|
|
|
|
getShardQry = `SELECT
|
|
shard_id, range_id, data, data_encoding
|
|
FROM shards WHERE shard_id = $1`
|
|
|
|
updateShardQry = `UPDATE shards
|
|
SET range_id = $1, data = $2, data_encoding = $3
|
|
WHERE shard_id = $4`
|
|
|
|
lockShardQry = `SELECT range_id FROM shards WHERE shard_id = $1 FOR UPDATE`
|
|
readLockShardQry = `SELECT range_id FROM shards WHERE shard_id = $1 FOR SHARE`
|
|
)
|
|
|
|
// InsertIntoShards inserts one or more rows into shards table
|
|
func (pdb *db) InsertIntoShards(
|
|
ctx context.Context,
|
|
row *sqlplugin.ShardsRow,
|
|
) (sql.Result, error) {
|
|
return pdb.ExecContext(ctx,
|
|
createShardQry,
|
|
row.ShardID,
|
|
row.RangeID,
|
|
row.Data,
|
|
row.DataEncoding,
|
|
)
|
|
}
|
|
|
|
// UpdateShards updates one or more rows into shards table
|
|
func (pdb *db) UpdateShards(
|
|
ctx context.Context,
|
|
row *sqlplugin.ShardsRow,
|
|
) (sql.Result, error) {
|
|
return pdb.ExecContext(ctx,
|
|
updateShardQry,
|
|
row.RangeID,
|
|
row.Data,
|
|
row.DataEncoding,
|
|
row.ShardID,
|
|
)
|
|
}
|
|
|
|
// SelectFromShards reads one or more rows from shards table
|
|
func (pdb *db) SelectFromShards(
|
|
ctx context.Context,
|
|
filter sqlplugin.ShardsFilter,
|
|
) (*sqlplugin.ShardsRow, error) {
|
|
var row sqlplugin.ShardsRow
|
|
err := pdb.GetContext(ctx,
|
|
&row,
|
|
getShardQry,
|
|
filter.ShardID,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &row, nil
|
|
}
|
|
|
|
// ReadLockShards acquires a read lock on a single row in shards table
|
|
func (pdb *db) ReadLockShards(
|
|
ctx context.Context,
|
|
filter sqlplugin.ShardsFilter,
|
|
) (int64, error) {
|
|
var rangeID int64
|
|
err := pdb.GetContext(ctx,
|
|
&rangeID,
|
|
readLockShardQry,
|
|
filter.ShardID,
|
|
)
|
|
return rangeID, err
|
|
}
|
|
|
|
// WriteLockShards acquires a write lock on a single row in shards table
|
|
func (pdb *db) WriteLockShards(
|
|
ctx context.Context,
|
|
filter sqlplugin.ShardsFilter,
|
|
) (int64, error) {
|
|
var rangeID int64
|
|
err := pdb.GetContext(ctx,
|
|
&rangeID,
|
|
lockShardQry,
|
|
filter.ShardID,
|
|
)
|
|
return rangeID, err
|
|
}
|