@@ -406,8 +406,11 @@ def check_quota_met(self, session, lock_session, _class, project_id,
406
406
# Note: You cannot just use the current count as the in-use
407
407
# value as we don't want to lock the whole resource table
408
408
try :
409
- quotas = lock_session .query (models .Quotas ).filter_by (
410
- project_id = project_id ).with_for_update ().first ()
409
+ quotas = (lock_session .query (models .Quotas )
410
+ .filter_by (project_id = project_id )
411
+ .populate_existing ()
412
+ .with_for_update ()
413
+ .first ())
411
414
if _class == data_models .LoadBalancer :
412
415
# Decide which quota to use
413
416
if quotas .load_balancer is None :
@@ -575,8 +578,11 @@ def decrement_quota(self, lock_session, _class, project_id, quantity=1):
575
578
576
579
# Lock the project record in the database to block other quota checks
577
580
try :
578
- quotas = lock_session .query (models .Quotas ).filter_by (
579
- project_id = project_id ).with_for_update ().first ()
581
+ quotas = (lock_session .query (models .Quotas )
582
+ .filter_by (project_id = project_id )
583
+ .populate_existing ()
584
+ .with_for_update ()
585
+ .first ())
580
586
if not quotas :
581
587
if not CONF .api_settings .auth_strategy == consts .NOAUTH :
582
588
LOG .error ('Quota decrement on %(clss)s called on '
@@ -742,8 +748,10 @@ def test_and_set_provisioning_status(self, session, id, status,
742
748
:returns: bool
743
749
"""
744
750
with session .begin (subtransactions = True ):
745
- lb = session .query (self .model_class ).with_for_update ().filter_by (
746
- id = id ).one ()
751
+ lb = (session .query (self .model_class )
752
+ .populate_existing ()
753
+ .with_for_update ()
754
+ .filter_by (id = id ).one ())
747
755
is_delete = status == consts .PENDING_DELETE
748
756
acceptable_statuses = (
749
757
consts .DELETABLE_STATUSES
@@ -774,8 +782,10 @@ def set_status_for_failover(self, session, id, status,
774
782
:returns: bool
775
783
"""
776
784
with session .begin (subtransactions = True ):
777
- lb = session .query (self .model_class ).with_for_update ().filter_by (
778
- id = id ).one ()
785
+ lb = (session .query (self .model_class )
786
+ .populate_existing ()
787
+ .with_for_update ()
788
+ .filter_by (id = id ).one ())
779
789
if lb .provisioning_status not in consts .FAILOVERABLE_STATUSES :
780
790
if raise_exception :
781
791
raise exceptions .ImmutableObject (
@@ -1143,10 +1153,13 @@ def increment(self, session, delta_stats):
1143
1153
listener_id = delta_stats .listener_id ,
1144
1154
amphora_id = delta_stats .amphora_id ).count ()
1145
1155
if count :
1146
- existing_stats = session .query (
1147
- self .model_class ).with_for_update ().filter_by (
1148
- listener_id = delta_stats .listener_id ,
1149
- amphora_id = delta_stats .amphora_id ).one ()
1156
+ existing_stats = (
1157
+ session .query (self .model_class )
1158
+ .populate_existing ()
1159
+ .with_for_update ()
1160
+ .filter_by (
1161
+ listener_id = delta_stats .listener_id ,
1162
+ amphora_id = delta_stats .amphora_id ).one ())
1150
1163
existing_stats += delta_stats
1151
1164
existing_stats .active_connections = (
1152
1165
delta_stats .active_connections )
@@ -1229,8 +1242,10 @@ def allocate_and_associate(self, session, load_balancer_id,
1229
1242
filters ['cached_zone' ] = availability_zone
1230
1243
1231
1244
with session .begin (subtransactions = True ):
1232
- amp = session .query (self .model_class ).with_for_update ().filter_by (
1233
- ** filters ).first ()
1245
+ amp = (session .query (self .model_class )
1246
+ .populate_existing ()
1247
+ .with_for_update ()
1248
+ .filter_by (** filters ).first ())
1234
1249
1235
1250
if amp is None :
1236
1251
return None
@@ -1281,12 +1296,15 @@ def get_cert_expiring_amphora(self, session):
1281
1296
seconds = expired_seconds )
1282
1297
1283
1298
with session .begin (subtransactions = True ):
1284
- amp = session .query (self .model_class ).with_for_update ().filter (
1285
- self .model_class .status .notin_ (
1286
- [consts .DELETED , consts .PENDING_DELETE ]),
1287
- self .model_class .cert_busy == false (),
1288
- self .model_class .cert_expiration < expired_date
1289
- ).first ()
1299
+ amp = (session .query (self .model_class )
1300
+ .populate_existing ()
1301
+ .with_for_update ()
1302
+ .filter (
1303
+ self .model_class .status .notin_ (
1304
+ [consts .DELETED , consts .PENDING_DELETE ]),
1305
+ self .model_class .cert_busy == false (),
1306
+ self .model_class .cert_expiration < expired_date )
1307
+ .first ())
1290
1308
1291
1309
if amp is None :
1292
1310
return None
@@ -1385,8 +1403,11 @@ def test_and_set_status_for_delete(self, lock_session, id):
1385
1403
:raises NoResultFound: The amphora was not found or already deleted.
1386
1404
:returns: None
1387
1405
"""
1388
- amp = lock_session .query (self .model_class ).with_for_update ().filter_by (
1389
- id = id ).filter (self .model_class .status != consts .DELETED ).one ()
1406
+ amp = (lock_session .query (self .model_class )
1407
+ .populate_existing ()
1408
+ .with_for_update ()
1409
+ .filter_by (id = id )
1410
+ .filter (self .model_class .status != consts .DELETED ).one ())
1390
1411
if amp .status not in [consts .AMPHORA_READY , consts .ERROR ]:
1391
1412
raise exceptions .ImmutableObject (resource = consts .AMPHORA , id = id )
1392
1413
amp .status = consts .PENDING_DELETE
@@ -1587,6 +1608,7 @@ def get_stale_amphora(self,
1587
1608
# Pick one expired amphora for automatic failover
1588
1609
amp_health = lock_session .query (
1589
1610
self .model_class
1611
+ ).populate_existing (
1590
1612
).with_for_update (
1591
1613
).filter (
1592
1614
self .model_class .amphora_id .in_ (expired_ids_query )
@@ -1911,8 +1933,11 @@ class QuotasRepository(BaseRepository):
1911
1933
def update (self , session , project_id , ** model_kwargs ):
1912
1934
with session .begin (subtransactions = True ):
1913
1935
kwargs_quota = model_kwargs ['quota' ]
1914
- quotas = session .query (self .model_class ).filter_by (
1915
- project_id = project_id ).with_for_update ().first ()
1936
+ quotas = (
1937
+ session .query (self .model_class )
1938
+ .filter_by (project_id = project_id )
1939
+ .populate_existing ()
1940
+ .with_for_update ().first ())
1916
1941
if not quotas :
1917
1942
quotas = models .Quotas (project_id = project_id )
1918
1943
@@ -1924,8 +1949,11 @@ def update(self, session, project_id, **model_kwargs):
1924
1949
1925
1950
def delete (self , session , project_id ):
1926
1951
with session .begin (subtransactions = True ):
1927
- quotas = session .query (self .model_class ).filter_by (
1928
- project_id = project_id ).with_for_update ().first ()
1952
+ quotas = (
1953
+ session .query (self .model_class )
1954
+ .filter_by (project_id = project_id )
1955
+ .populate_existing ()
1956
+ .with_for_update ().first ())
1929
1957
if not quotas :
1930
1958
raise exceptions .NotFound (
1931
1959
resource = data_models .Quotas ._name (), id = project_id )
0 commit comments