mirror of
https://github.com/dkmstr/openuds.git
synced 2024-12-22 13:34:04 +03:00
Fixed several concurrency issues (very rare, btw, but possible :) )
This commit is contained in:
parent
689b20ce2f
commit
9e26580af5
@ -51,7 +51,7 @@ import requests
|
||||
import json
|
||||
import logging
|
||||
|
||||
__updated__ = '2019-02-22'
|
||||
__updated__ = '2019-02-24'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
traceLogger = logging.getLogger('traceLog')
|
||||
@ -286,17 +286,12 @@ class UserServiceManager(object):
|
||||
cache = None
|
||||
|
||||
if cache:
|
||||
cache.assignToUser(user)
|
||||
cache.save() # Store assigned ASAP, we do not know how long assignToUser method of instance will take
|
||||
cache.assignToUser(user, save=True) # Store assigned ASAP, we do not know how long assignToUser method of instance will take
|
||||
|
||||
# Out of atomic transaction
|
||||
if cache is not None:
|
||||
logger.debug('Found a cached-ready service from {0} for user {1}, item {2}'.format(ds, user, cache))
|
||||
events.addEvent(ds, events.ET_CACHE_HIT, fld1=ds.cachedUserServices().filter(cache_level=services.UserDeployment.L1_CACHE, state=State.USABLE).count())
|
||||
ci = cache.getInstance() # User Deployment instance
|
||||
ci.assignToUser(user)
|
||||
cache.updateData(ci)
|
||||
cache.save()
|
||||
return cache
|
||||
|
||||
# Cache missed
|
||||
@ -309,8 +304,7 @@ class UserServiceManager(object):
|
||||
if ds.cachedUserServices().select_for_update().filter(user=None, uuid=cache.uuid).update(user=user, cache_level=0) != 1:
|
||||
cache = None
|
||||
else:
|
||||
cache.assignToUser(user)
|
||||
cache.save()
|
||||
cache.assignToUser(user, save=True) # Store assigned ASAP, we do not know how long assignToUser method of instance will take
|
||||
else:
|
||||
cache = None
|
||||
|
||||
@ -318,10 +312,6 @@ class UserServiceManager(object):
|
||||
if cache is not None:
|
||||
logger.debug('Found a cached-preparing service from {0} for user {1}, item {2}'.format(ds, user, cache))
|
||||
events.addEvent(ds, events.ET_CACHE_MISS, fld1=ds.cachedUserServices().filter(cache_level=services.UserDeployment.L1_CACHE, state=State.PREPARING).count())
|
||||
ci = cache.getInstance() # User Deployment instance
|
||||
ci.assignToUser(user)
|
||||
cache.updateData(ci)
|
||||
cache.save()
|
||||
return cache
|
||||
|
||||
# Can't assign directly from L2 cache... so we check if we can create e new service in the limits requested
|
||||
|
@ -55,7 +55,7 @@ from uds.models.Util import getSqlDatetime
|
||||
|
||||
import logging
|
||||
|
||||
__updated__ = '2018-09-19'
|
||||
__updated__ = '2019-02-24'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -334,7 +334,7 @@ class UserService(UUIDModel):
|
||||
self.state_date = getSqlDatetime()
|
||||
self.os_state = state
|
||||
|
||||
def assignToUser(self, user):
|
||||
def assignToUser(self, user, save=False):
|
||||
'''
|
||||
Assigns this user deployed service to an user.
|
||||
|
||||
@ -344,6 +344,8 @@ class UserService(UUIDModel):
|
||||
self.cache_level = 0
|
||||
self.state_date = getSqlDatetime()
|
||||
self.user = user
|
||||
if save:
|
||||
self.save(update_fields=['cache_level', 'state_date', 'user'])
|
||||
|
||||
def setInUse(self, state):
|
||||
'''
|
||||
|
Loading…
Reference in New Issue
Block a user