mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
DERP mesh key setup would do a SELECT and then an INSERT on failure, without a lock. During some testing with multiple replicas, I managed to cause a replica to crash due to them initializing simultaneously. Fixes: Encountered an error running "coder server" create coder API: insert mesh key: pq: duplicate key value violates unique constraint "site_configs_key_key" Co-authored-by: Cian Johnston <cian@coder.com>
21 lines
561 B
Go
21 lines
561 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 (
|
|
// Keep the unused iota here so we don't need + 1 every time
|
|
lockIDUnused = iota
|
|
LockIDDeploymentSetup
|
|
LockIDEnterpriseDeploymentSetup
|
|
)
|
|
|
|
// GenLockID generates a unique and consistent lock ID from a given string.
|
|
func GenLockID(name string) int64 {
|
|
hash := fnv.New64()
|
|
_, _ = hash.Write([]byte(name))
|
|
return int64(hash.Sum64())
|
|
}
|