Repository navigation
Expand file tree
/
Copy pathlock.go
More file actions
53 lines (47 loc) · 1.93 KB
/
Copy pathlock.go
File metadata and controls
53 lines (47 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package database
import (
"hash/fnv"
"github.com/google/uuid"
)
// 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
// Deprecated: Reserved to prevent reuse. Do not use at runtime.
LockIDAIProvidersEnvSeed
// Deprecated: Reserved to prevent reuse. Do not use at runtime.
LockIDChatModelConfigWrites
LockIDChatCapacityAdmission
LockIDNotifyUnpricedAIModels
)
// 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")
)
// LockIDChatOrganizationSystemPrompt returns the advisory lock ID that
// serializes writes to one organization's chat system prompt.
func LockIDChatOrganizationSystemPrompt(organizationID uuid.UUID) int64 {
return GenLockID("chat_organization_system_prompt:" + organizationID.String())
}
// 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())
}