mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
a31e476623
Previously, UpsertBoundaryUsageStats (INSERT...ON CONFLICT DO UPDATE) and GetAndResetBoundaryUsageSummary (DELETE...RETURNING) could race during telemetry period cutover. Without serialization, an upsert concurrent with the delete could lose data (deleted right after being written) or commit after the delete (miscounted in the next period). Both operations now acquire LockIDBoundaryUsageStats within a transaction to ensure a clean cutover.
27 lines
800 B
Go
27 lines
800 B
Go
package database
|
|
|
|
import "hash/fnv"
|
|
|
|
// Well-known lock IDs for lock functions in the database. These should not
|
|
// change. If locks are deprecated, they should be kept in this list to avoid
|
|
// reusing the same ID.
|
|
const (
|
|
LockIDDeploymentSetup = iota + 1
|
|
LockIDEnterpriseDeploymentSetup
|
|
LockIDDBRollup
|
|
LockIDDBPurge
|
|
LockIDNotificationsReportGenerator
|
|
LockIDCryptoKeyRotation
|
|
LockIDReconcilePrebuilds
|
|
LockIDReconcileSystemRoles
|
|
LockIDBoundaryUsageStats
|
|
)
|
|
|
|
// GenLockID generates a unique and consistent lock ID from a given string.
|
|
func GenLockID(name string) int64 {
|
|
hash := fnv.New64()
|
|
_, _ = hash.Write([]byte(name))
|
|
// #nosec G115 - Safe conversion as FNV hash should be treated as random value and both uint64/int64 have the same range of unique values
|
|
return int64(hash.Sum64())
|
|
}
|