v5.0.63: instance-level mutex to prevent parallel operations on same resource

This commit is contained in:
“Naeel”
2026-07-07 08:27:42 +04:00
parent d9f2c60e90
commit 4ac21d9367
9 changed files with 184 additions and 9 deletions
+14
View File
@@ -21,6 +21,7 @@ import (
"os"
"regexp"
"strings"
"sync"
"time"
)
@@ -36,6 +37,19 @@ type UniversalClient struct {
LogLevel string
}
// instanceMutexes — глобальная карта мьютексов для сериализации операций на одном инстансе.
// Terraform параллелит ресурсы (до 10), но API Nubes не поддерживает параллельные операции
// на одном инстансе (orchestrator error, state_out inconsistency).
var instanceMutexes sync.Map
// LockInstance блокирует мьютекс для указанного instanceUid.
// Возвращает функцию unlock, которую нужно вызывать через defer.
func (c *UniversalClient) LockInstance(instanceUid string) func() {
mu, _ := instanceMutexes.LoadOrStore(instanceUid, &sync.Mutex{})
mu.(*sync.Mutex).Lock()
return func() { mu.(*sync.Mutex).Unlock() }
}
// isProxyAPI returns true if ApiEndpoint uses legacy ?endpoint= proxy pattern (contains "index.cfm").
func (c *UniversalClient) isProxyAPI() bool {
return strings.Contains(c.ApiEndpoint, "index.cfm")