mirror of
https://github.com/openziti/zrok.git
synced 2025-06-25 04:02:15 +02:00
locking (#287)
This commit is contained in:
parent
2a770cc3b8
commit
af5afb8aac
@ -66,6 +66,9 @@ func (a *Agent) Stop() {
|
|||||||
|
|
||||||
func (a *Agent) CanCreateEnvironment(acctId int, trx *sqlx.Tx) (bool, error) {
|
func (a *Agent) CanCreateEnvironment(acctId int, trx *sqlx.Tx) (bool, error) {
|
||||||
if a.cfg.Enforcing {
|
if a.cfg.Enforcing {
|
||||||
|
if err := a.str.LimitCheckLock(acctId, trx); err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
if empty, err := a.str.IsAccountLimitJournalEmpty(acctId, trx); err == nil && !empty {
|
if empty, err := a.str.IsAccountLimitJournalEmpty(acctId, trx); err == nil && !empty {
|
||||||
alj, err := a.str.FindLatestAccountLimitJournal(acctId, trx)
|
alj, err := a.str.FindLatestAccountLimitJournal(acctId, trx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -93,6 +96,9 @@ func (a *Agent) CanCreateEnvironment(acctId int, trx *sqlx.Tx) (bool, error) {
|
|||||||
|
|
||||||
func (a *Agent) CanCreateShare(acctId, envId int, trx *sqlx.Tx) (bool, error) {
|
func (a *Agent) CanCreateShare(acctId, envId int, trx *sqlx.Tx) (bool, error) {
|
||||||
if a.cfg.Enforcing {
|
if a.cfg.Enforcing {
|
||||||
|
if err := a.str.LimitCheckLock(acctId, trx); err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
if empty, err := a.str.IsAccountLimitJournalEmpty(acctId, trx); err == nil && !empty {
|
if empty, err := a.str.IsAccountLimitJournalEmpty(acctId, trx); err == nil && !empty {
|
||||||
alj, err := a.str.FindLatestAccountLimitJournal(acctId, trx)
|
alj, err := a.str.FindLatestAccountLimitJournal(acctId, trx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -6,12 +6,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (str *Store) LimitCheckLock(acctId int, trx *sqlx.Tx) error {
|
func (str *Store) LimitCheckLock(acctId int, trx *sqlx.Tx) error {
|
||||||
stmt, err := trx.Prepare("insert into limit_check_locks (account_id) values ($1) on conflict (account_id) do update set updated_at = current_timestamp")
|
if str.cfg.EnableLocking {
|
||||||
if err != nil {
|
stmt, err := trx.Prepare("insert into limit_check_locks (account_id) values ($1) on conflict (account_id) do update set updated_at = current_timestamp")
|
||||||
return errors.Wrap(err, "error preparing upsert on limit_check_locks")
|
if err != nil {
|
||||||
}
|
return errors.Wrap(err, "error preparing upsert on limit_check_locks")
|
||||||
if _, err := stmt.Exec(acctId); err != nil {
|
}
|
||||||
return errors.Wrap(err, "error executing upsert on limit_check_locks")
|
if _, err := stmt.Exec(acctId); err != nil {
|
||||||
|
return errors.Wrap(err, "error executing upsert on limit_check_locks")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user