mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
This builds upon https://github.com/temporalio/temporal/pull/65 and implements the logic on top of the provided schemas to make the number of history shards and the cluster name read-only configuration. See PR commits for step by step vertical implementation of a configuration value to the persistence layer.
58 lines
2.4 KiB
Go
58 lines
2.4 KiB
Go
// Copyright (c) 2020 Temporal Technologies, Inc.
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
// in the Software without restriction, including without limitation the rights
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
// furnished to do so, subject to the following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be included in
|
|
// all copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
|
|
|
package postgres
|
|
|
|
import (
|
|
"database/sql"
|
|
|
|
"github.com/temporalio/temporal/common/persistence/sql/sqlplugin"
|
|
)
|
|
|
|
const constMetadataPartition = 0
|
|
const (
|
|
// One time only for the immutable data, so just use idempotent insert that does nothing if a record exists
|
|
// This particular query requires PostgreSQL 9.5, PostgreSQL 9.4 comes out of LTS on February 13, 2020
|
|
// QueryInfo: https://wiki.postgresql.org/wiki/What%27s_new_in_PostgreSQL_9.5#INSERT_..._ON_CONFLICT_DO_NOTHING.2FUPDATE_.28.22UPSERT.22.29
|
|
insertClusterMetadataOneTimeOnlyQry = `INSERT INTO
|
|
cluster_metadata (metadata_partition, immutable_data, immutable_data_encoding)
|
|
VALUES($1, $2, $3)
|
|
ON CONFLICT DO NOTHING`
|
|
|
|
getImmutableClusterMetadataQry = `SELECT immutable_data, immutable_data_encoding FROM
|
|
cluster_metadata WHERE metadata_partition = $1`
|
|
)
|
|
|
|
// Does not follow traditional lock, select, read, insert as we only expect a single row.
|
|
func (pdb *db) InsertIfNotExistsIntoClusterMetadata(row *sqlplugin.ClusterMetadataRow) (sql.Result, error) {
|
|
return pdb.conn.Exec(insertClusterMetadataOneTimeOnlyQry,
|
|
constMetadataPartition,
|
|
row.ImmutableData,
|
|
row.ImmutableDataEncoding)
|
|
}
|
|
|
|
func (pdb *db) GetClusterMetadata() (*sqlplugin.ClusterMetadataRow, error) {
|
|
var row sqlplugin.ClusterMetadataRow
|
|
err := pdb.conn.Get(&row, getImmutableClusterMetadataQry, constMetadataPartition)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &row, err
|
|
}
|