2023-06-25 23:17:00 +10:00
|
|
|
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 (
|
2024-03-22 18:42:43 +02:00
|
|
|
LockIDDeploymentSetup = iota + 1
|
2024-02-28 08:14:11 -08:00
|
|
|
LockIDEnterpriseDeploymentSetup
|
2024-03-22 18:42:43 +02:00
|
|
|
LockIDDBRollup
|
2024-04-22 14:10:32 +03:00
|
|
|
LockIDDBPurge
|
2024-09-18 09:11:44 +02:00
|
|
|
LockIDNotificationsReportGenerator
|
2024-09-19 19:12:44 +01:00
|
|
|
LockIDCryptoKeyRotation
|
2025-04-17 09:29:29 -04:00
|
|
|
LockIDReconcilePrebuilds
|
2026-01-12 18:19:19 -08:00
|
|
|
LockIDReconcileSystemRoles
|
2026-02-06 09:52:17 -07:00
|
|
|
LockIDBoundaryUsageStats
|
2026-09-09 10:16:24 +02:00
|
|
|
// Deprecated: Reserved to prevent reuse. Do not use at runtime.
|
2026-05-22 08:37:27 +02:00
|
|
|
LockIDAIProvidersEnvSeed
|
2026-08-24 10:30:01 +01:00
|
|
|
// Deprecated: Reserved to prevent reuse. Do not use at runtime.
|
2026-07-14 13:51:47 +10:00
|
|
|
LockIDChatModelConfigWrites
|
2026-08-18 16:55:43 +02:00
|
|
|
LockIDChatCapacityAdmission
|
2026-08-27 17:04:13 -04:00
|
|
|
LockIDNotifyUnpricedAIModels
|
2023-06-25 23:17:00 +10:00
|
|
|
)
|
|
|
|
|
|
2026-08-18 21:03:06 +03:00
|
|
|
// Per-setting advisory lock IDs for the chat instruction settings. These
|
|
|
|
|
// derive from the exact site_configs key with GenLockID (FNV-1a 64) instead
|
|
|
|
|
// of the sequential LockID* block above, so writers of different settings
|
|
|
|
|
// never contend and the IDs cannot collide with any sequentially allocated
|
|
|
|
|
// lock ID (different derivation space) or with another subsystem's
|
|
|
|
|
// GenLockID output (the key strings are unique to these settings).
|
|
|
|
|
var (
|
|
|
|
|
LockIDChatInstructionSystemPrompt = GenLockID("agents_chat_system_prompt")
|
|
|
|
|
LockIDChatInstructionPlanMode = GenLockID("agents_chat_plan_mode_instructions")
|
|
|
|
|
)
|
|
|
|
|
|
2023-06-25 23:17:00 +10:00
|
|
|
// GenLockID generates a unique and consistent lock ID from a given string.
|
|
|
|
|
func GenLockID(name string) int64 {
|
|
|
|
|
hash := fnv.New64()
|
|
|
|
|
_, _ = hash.Write([]byte(name))
|
2025-03-26 01:56:39 -05:00
|
|
|
// #nosec G115 - Safe conversion as FNV hash should be treated as random value and both uint64/int64 have the same range of unique values
|
2023-06-25 23:17:00 +10:00
|
|
|
return int64(hash.Sum64())
|
|
|
|
|
}
|