|
140 | 140 | ) |
141 | 141 |
|
142 | 142 |
|
| 143 | +# About synchronize_session: |
| 144 | +# The FTS3DB class uses SQLAlchemy in a mixed mode: |
| 145 | +# both the ORM and the Core style. |
| 146 | +# Up to 1.3, the `session.execute` statements had no ORM functionality, |
| 147 | +# meaning that the session cache were not updated when using `update` or `delete` |
| 148 | +# Although it could be an issue, it was not really one in our case, since we always close |
| 149 | +# the session |
| 150 | +# As of 1.4, `session.execute` supports ORM functionality, and thus needs more info to know |
| 151 | +# how to manage `update` or `delete`. Hense the `synchronize_session` option. |
| 152 | +# We set it to `False` simply because we do not rely on the session cache. |
| 153 | +# Please see https://github.com/sqlalchemy/sqlalchemy/discussions/6159 for detailed discussion |
| 154 | + |
143 | 155 | ######################################################################## |
144 | 156 | class FTS3DB(object): |
145 | 157 | """ |
@@ -312,6 +324,7 @@ def getActiveJobs(self, limit=20, lastMonitor=None, jobAssignmentTag="Assigned") |
312 | 324 | .where(FTS3Job.jobID.in_(jobIds) |
313 | 325 | ) |
314 | 326 | .values({'assignment': jobAssignmentTag}) |
| 327 | + .execution_options(synchronize_session=False) # see comment about synchronize_session |
315 | 328 | ) |
316 | 329 |
|
317 | 330 | session.commit() |
@@ -384,7 +397,8 @@ def updateFileStatus(self, fileStatusDict, ftsGUID=None): |
384 | 397 | updateQuery = update(FTS3File)\ |
385 | 398 | .where(and_(*whereConditions) |
386 | 399 | )\ |
387 | | - .values(updateDict) |
| 400 | + .values(updateDict)\ |
| 401 | + .execution_options(synchronize_session=False) # see comment about synchronize_session |
388 | 402 |
|
389 | 403 | session.execute(updateQuery) |
390 | 404 |
|
@@ -435,6 +449,7 @@ def updateJobStatus(self, jobStatusDict): |
435 | 449 | ) |
436 | 450 | ) |
437 | 451 | .values(updateDict) |
| 452 | + .execution_options(synchronize_session=False) # see comment about synchronize_session |
438 | 453 | ) |
439 | 454 | session.commit() |
440 | 455 |
|
@@ -480,7 +495,8 @@ def cancelNonExistingJob(self, operationID, ftsGUID): |
480 | 495 | .where(and_(FTS3File.operationID == FTS3Job.operationID, |
481 | 496 | FTS3File.ftsGUID == FTS3Job.ftsGUID, |
482 | 497 | FTS3Job.operationID == operationID, |
483 | | - FTS3Job.ftsGUID == ftsGUID)) |
| 498 | + FTS3Job.ftsGUID == ftsGUID))\ |
| 499 | + .execution_options(synchronize_session=False) # see comment about synchronize_session |
484 | 500 |
|
485 | 501 | session.execute(updStmt) |
486 | 502 | session.commit() |
@@ -541,6 +557,7 @@ def getNonFinishedOperations(self, limit=20, operationAssignmentTag="Assigned"): |
541 | 557 | .where(FTS3Operation.operationID.in_(operationIDs) |
542 | 558 | ) |
543 | 559 | .values({'assignment': operationAssignmentTag}) |
| 560 | + .execution_options(synchronize_session=False) # see comment about synchronize_session |
544 | 561 | ) |
545 | 562 |
|
546 | 563 | session.commit() |
@@ -588,7 +605,9 @@ def kickStuckOperations(self, limit=20, kickDelay=2): |
588 | 605 | 'INTERVAL %d HOUR' % |
589 | 606 | kickDelay)))) .values( |
590 | 607 | { |
591 | | - 'assignment': None})) |
| 608 | + 'assignment': None}) |
| 609 | + .execution_options(synchronize_session=False) # see comment about synchronize_session |
| 610 | + ) |
592 | 611 | rowCount = result.rowcount |
593 | 612 |
|
594 | 613 | session.commit() |
@@ -636,7 +655,9 @@ def kickStuckJobs(self, limit=20, kickDelay=2): |
636 | 655 | 'INTERVAL %d HOUR' % |
637 | 656 | kickDelay)))) .values( |
638 | 657 | { |
639 | | - 'assignment': None})) |
| 658 | + 'assignment': None}) |
| 659 | + .execution_options(synchronize_session=False) # see comment about synchronize_session |
| 660 | + ) |
640 | 661 | rowCount = result.rowcount |
641 | 662 |
|
642 | 663 | session.commit() |
@@ -677,7 +698,8 @@ def deleteFinalOperations(self, limit=20, deleteDelay=180): |
677 | 698 | rowCount = 0 |
678 | 699 | if opIDs: |
679 | 700 | result = session.execute(delete(FTS3Operation) |
680 | | - .where(FTS3Operation.operationID.in_(opIDs))) |
| 701 | + .where(FTS3Operation.operationID.in_(opIDs)) |
| 702 | + .execution_options(synchronize_session=False)) |
681 | 703 | rowCount = result.rowcount |
682 | 704 |
|
683 | 705 | session.commit() |
|
0 commit comments